# iktakahiro/dddpy architecture

> Architecture diagram of the GitHub repository iktakahiro/dddpy, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/iktakahiro/dddpy
- Repository: https://github.com/iktakahiro/dddpy

## Overview

##### Main Components
- Domain Layer: Represented by the dddpy/domain directory. This layer includes the core business logic, defining entities (e.g., the Todo entity in dddpy/domain/todo/entities/todo.py), value objects (todo_title, todo_description, etc.), repository interfaces, and domain-specific exceptions.
- Usecase Layer: Found under dddpy/usecase. Each use case (create, update, delete, start, complete, find) encapsulates a business rule and an execute() method. This layer orchestrates interactions between the domain layer and the external world.
- Infrastructure Layer: Located in dddpy/infrastructure. It implements persistence using SQLite (see dddpy/infrastructure/sqlite) and contains the dependency injection configuration (dddpy/infrastructure/di/injection.py). This layer provides concrete implementations of the repository interfaces.
- Presentation Layer: Found in dddpy/presentation/api. It consists of FastAPI route handlers, schemas, and error message definitions that expose a RESTful interface for the application.

- The Infrastructure layer should be depicted as an outer adapter that implements the abstractions defined in the Domain layer (especially repository interfaces). Indicate dependency injection where the Usecase layer receives concrete repository implementations from this layer.
- An external “Database” component (SQLite) that is used by the Infrastructure layer, along with the dependency injection container that binds the abstraction to its implementation.

##### Architectural Patterns and Design Principles
- Onion Architecture by showing how the domain (core business logic) is isolated from external concerns.
- Reliance on DDD principles, such as using value objects (immutable data structures) and clearly defined entity behavior.
- That error handling is domain-specific with custom exceptions and corresponding error messages in the API layer.
- The clear separation of concerns improves maintainability and testability; include the tests folder to represent integration and unit tests validating each layer.

##### Relevant Technologies
- FastAPI is used in the Presentation layer.
- SQLite is used for persistence (via SQLAlchemy patterns as suggested by the README).
- Docker is used (see .devcontainer) to standardize the development environment.
- The uv tool (from uv.lock and README instructions) is used for dependency management, and testing is supported by pytest (tests directory).
- Additionally, configuration files such as logging.conf, Makefile, and CI workflows in .github/workflows should be noted as they contribute to the deployment and quality assurance processes.

## Diagram (Mermaid)

```mermaid
flowchart TD

    %% Presentation Layer
    subgraph "Presentation Layer"
        PA["Todo API Route Handler"]:::presentation
        PS["API Schemas"]:::presentation
        PE["API Error Messages"]:::presentation
    end

    %% Usecase Layer
    subgraph "Usecase Layer"
        UC["Todo Use Cases"]:::usecase
    end

    %% Domain Layer
    subgraph "Domain Layer"
        DE["Todo Entity"]:::domain
        VO["Value Objects"]:::domain
        RI["Todo Repository Interface"]:::domain
        DX["Domain Exceptions"]:::domain
    end

    %% Infrastructure Layer
    subgraph "Infrastructure Layer"
        DI["Dependency Injection"]:::infrastructure
        SR["SQLite Repository Implementation"]:::infrastructure
    end

    %% External Database Component
    DB["SQLite Database"]:::database

    %% External Dependencies
    subgraph "External Dependencies"
        EX1["FastAPI"]:::external
        EX2["Docker"]:::external
        EX3["uv (Dependency Management)"]:::external
        EX4["pytest"]:::external
        EX5["CI/CD Workflows"]:::external
    end

    %% Arrows representing relationships
    PA -->|"calls"| UC
    PA -->|"uses"| PS
    PA -->|"handlesErrors"| PE

    UC -->|"operatesOn"| DE
    UC -->|"utilizes"| RI

    %% Dependency Injection provides repository implementation to Usecases
    UC -->|"getsImplFrom"| DI
    DI -->|"injects"| SR
    SR -->|"storesDataIn"| DB

    %% Domain Layer associations
    DE ---|"composedWith"| VO
    DE ---|"raises"| DX

    %% Styles and Classes
    classDef presentation fill:#b3e5fc,stroke:#0288d1,stroke-width:2px
    classDef usecase fill:#c8e6c9,stroke:#2e7d32,stroke-width:2px
    classDef domain fill:#f8bbd0,stroke:#ad1457,stroke-width:2px
    classDef infrastructure fill:#fff9c4,stroke:#f9a825,stroke-width:2px
    classDef database fill:#e0e0e0,stroke:#757575,stroke-width:2px,stroke-dasharray: 5, 5
    classDef external fill:#d7ccc8,stroke:#5d4037,stroke-width:2px

    %% Click Events for Component Mapping
    click DE "https://github.com/iktakahiro/dddpy/blob/main/dddpy/domain/todo/entities/todo.py"
    click VO "https://github.com/iktakahiro/dddpy/tree/main/dddpy/domain/todo/value_objects/"
    click RI "https://github.com/iktakahiro/dddpy/blob/main/dddpy/domain/todo/repositories/todo_repository.py"
    click DX "https://github.com/iktakahiro/dddpy/tree/main/dddpy/domain/todo/exceptions/"
    click UC "https://github.com/iktakahiro/dddpy/tree/main/dddpy/usecase/todo/"
    click DI "https://github.com/iktakahiro/dddpy/blob/main/dddpy/infrastructure/di/injection.py"
    click SR "https://github.com/iktakahiro/dddpy/tree/main/dddpy/infrastructure/sqlite/"
    click PA "https://github.com/iktakahiro/dddpy/blob/main/dddpy/presentation/api/todo/handlers/todo_api_route_handler.py"
    click PS "https://github.com/iktakahiro/dddpy/tree/main/dddpy/presentation/api/todo/schemas/"
    click PE "https://github.com/iktakahiro/dddpy/tree/main/dddpy/presentation/api/todo/error_messages/"
```
