A RESTful API for managing todo items, built with Flask and following Clean Architecture principles.
This project demonstrates the implementation of a Todo API using Clean Architecture, which separates the application into distinct layers:
- Domain Layer: Contains the business entities and rules
- Use Cases Layer: Contains the application-specific business rules
- Interface Adapters Layer: Contains controllers and presenters
- Frameworks & Drivers Layer: Contains web, database, and external interfaces
- Create, read, update, and delete todo items
- In-memory data storage (easily replaceable with a persistent database)
- Clean Architecture design for maintainability and testability
- 100% test coverage
Method | Endpoint | Description |
---|---|---|
GET | / |
Home page with API information |
GET | /todos |
Get all todos |
GET | /todos/:id |
Get a specific todo by ID |
POST | /todos |
Create a new todo |
PUT | /todos/:id |
Update an existing todo |
DELETE | /todos/:id |
Delete a todo |
- Python 3.8 or higher
- pip or uv package manager
- Clone the repository
git clone <repository-url>
cd api-flask
- Install dependencies
pip install -r requirements.txt
# or with uv
uv pip install -r requirements.txt
python app.py
The API will be available at http://localhost:5000
.
FLASK_CONFIG
: Set the configuration environment (development
,testing
, orproduction
). Defaults todevelopment
.
.
├── app.py # Application entry point
├── config.py # Configuration settings
├── domain/ # Domain layer
│ └── entities.py # Business entities (Todo)
├── use_cases/ # Use cases layer
│ └── todo_use_cases.py # Application business rules
├── interface_adapters/ # Interface adapters layer
│ └── controllers/ # Controllers
│ └── todo_controller.py
├── frameworks/ # Frameworks and drivers layer
│ ├── database/ # Database implementations
│ │ └── in_memory_db.py # In-memory repository
│ └── web/ # Web framework components
│ └── routes.py # API routes
└── tests/ # Test suite
├── conftest.py # Test fixtures
├── integration/ # Integration tests
│ └── test_api.py # API endpoint tests
└── unit/ # Unit tests
├── test_app.py # App configuration tests
├── test_entities.py # Entity tests
├── test_repositories.py # Repository tests
└── test_use_cases.py # Use case tests
The project includes a comprehensive test suite with 100% code coverage. To run the tests:
pytest tests/
To run tests with coverage report:
pytest tests/ --cov=app --cov-report term-missing
Each todo item has the following properties:
id
: Unique identifier (auto-generated)title
: Title of the tododescription
: Detailed descriptioncompleted
: Boolean status (default: false)created_at
: Timestamp of creationupdated_at
: Timestamp of last update
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.