How adamhavlicek/fastapi-todo-ddd works
The project is a FastAPI-based backend service that follows Domain-Driven Design (DDD) and Clean Architecture principles. Its main purpose is to provide a well-organized, modular API to manage domain-specific functionality—specifically for “user” and “task” features—with clearly separated responsibilities for presentation, domain logic, and data persistence (using PostgreSQL through SQLAlchemy).
Main Components
• API Layer: Represented by the FastAPI application (main.py) and the presentation layer within each feature (app/features/task/presentation and app/features/user/presentation). These layers handle incoming HTTP requests and define endpoints (e.g., create, update, delete, and get routes).
• Domain Layer: This includes the domain entities, use cases, and repository interfaces (e.g., files under app/features/task/domain and app/features/user/domain). This layer encapsulates business logic and rules.
• Data Layer: Shows the implementation details (repository implementations, data models, and query services) under app/features/task/data and app/features/user/data, and the global data access logic under app/core/database. This layer is responsible for communication with the PostgreSQL database.
• Core Components: Highlight shared modules like error handling (app/core/error), configuration (app/config.py), unit of work (app/core/unit_of_work), and common models.
• Infrastructure: The PostgreSQL database and Docker (with Docker Compose, Dockerfile, etc.), which offer deployment and operational support.
Relationships and Interactions
• These API routes then invoke use cases in the Domain Layer. Indicate directional flows showing that controllers (routes) call the appropriate use cases (e.g., create_user, update_task).
• Additionally, show how the “Unit of Work” wraps data operations to manage transactions and consistency.
Architectural Patterns and Design Principles
• Domain-driven concepts: Note the use of entities, value objects, aggregates, services, factories, and repositories. Annotate these within the domain components.
• Dependency Inversion: Indicate that high-level modules (domain and use cases) do not depend on low-level data access implementations but instead depend on abstractions.
• Docker and containerization: Represent the environment where the application and database run (Docker, docker-compose.yml, Dockerfile).
Relevant Technologies and Frameworks
• FastAPI as the main framework for handling HTTP endpoints.
• SQLAlchemy for ORM functionality to interact with the Postgres database.
• Docker for containerizing the application and managing deployments via Docker Compose.
• Python and Poetry for dependency management and building the project.
Diagrammatic Elements
• Clear labels for every component (e.g., “User Routes”, “Task Use Cases”, “User Repository Interface”, “Postgres Database”, etc.).