Skip to content

kyomel/todo-flaskAPI

Repository files navigation

Todo API - Clean Architecture

A RESTful API for managing todo items, built with Flask and following Clean Architecture principles.

Project Overview

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

Features

  • 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

API Endpoints

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

Getting Started

Prerequisites

  • Python 3.8 or higher
  • pip or uv package manager

Installation

  1. Clone the repository
git clone <repository-url>
cd api-flask
  1. Install dependencies
pip install -r requirements.txt
# or with uv
uv pip install -r requirements.txt

Running the Application

python app.py

The API will be available at http://localhost:5000.

Environment Variables

  • FLASK_CONFIG: Set the configuration environment (development, testing, or production). Defaults to development.

Project Structure

.
├── 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

Testing

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

Todo Entity Structure

Each todo item has the following properties:

  • id: Unique identifier (auto-generated)
  • title: Title of the todo
  • description: Detailed description
  • completed: Boolean status (default: false)
  • created_at: Timestamp of creation
  • updated_at: Timestamp of last update

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages