# juanpabloleonf/microservice-series architecture

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

- Interactive diagram: https://gitdiagram.com/juanpabloleonf/microservice-series
- Repository: https://github.com/juanpabloleonf/microservice-series

## Overview

##### Main Components
- API Layer (Presentation/Interface): Represented by the REST controllers found under app/src/infrastructure/inputs/rest/controllers. These controllers translate HTTP requests into application calls.
- Application Layer: Contains the use cases, DTOs, and handlers (i.e., the business logic) under app/src/application. This is where request DTOs are handled and converted into domain actions.
- Domain Layer: Holds the core business models, domain interfaces (services), persistence interfaces, and domain-specific use cases (in app/src/domain). This layer represents the core business rules and entity models for Series, Season, and Chapter.
- Infrastructure Layer: Includes both inputs (API specifics) and outputs such as the MySQL-related repositories, entity mappings, and configuration. The infrastructure adapters (e.g., MySQL repositories in app/src/infrastructure/outputs/mysql) implement persistence interfaces from the domain layer.
- Configuration and Dependency Injection: Found under app/configuration, this component sets up the environment, dependency injections, global error handling, and CORS, integrating all other components.
- External Dependencies/Services: Include the MySQL database (for persistence), Docker engine for container orchestration, and external tools (Swagger for API documentation, Cryptography libraries, etc.).

##### Out the Relationships and Interactions
- HTTP Request → Controller → Request DTO behavior.
- The Application layer then interacts with the Domain Layer’s use cases:
- Application handler → Domain use cases → Domain models and business rules.
- The Domain Layer defines interfaces (ports) for persistence; its implementations are provided by the Infrastructure layer (MySQL repositories and adapters).
- Finally, error handling, validation (via Pydantic), and dependency injection configurations that bind all these layers are also highlighted.

##### Architectural Patterns and Key Technologies
- Hexagonal Architecture (Ports & Adapters): Emphasize the clear separation where the application’s core (Domain and Application layers) remains independent of external delivery mechanisms (REST controllers) and storage mechanisms (MySQL repositories).
- Technology Stack:
- FastAPI (API and controllers)
- SQLAlchemy (via repositories and ORM concepts)
- Pydantic (data validation)
- MySQL (persistent storage)
- Docker (containerization)
- Additional libraries for cryptography and error handling

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Services
    subgraph "External Services"
        E1["HTTP Request (Client)"]:::external
        E2["MySQL Database"]:::external
        E3["Docker Engine"]:::external
        E4["Swagger UI"]:::external
        D1["Dockerfile"]:::external
        D2["docker-compose.yml"]:::external
    end

    %% Presentation Layer
    subgraph "Presentation Layer"
        PC["REST Controller for Series"]:::presentation
    end

    %% Application Layer
    subgraph "Application Layer"
        AC["Use Case: Handle Series Request"]:::application
    end

    %% Domain Layer
    subgraph "Domain Layer"
        DU["Domain Use Case: Manage Series"]:::domain
        DC["Domain Model: Series"]:::domain
    end

    %% Infrastructure Layer
    subgraph "Infrastructure Layer"
        MC["MySQL Repository for Series"]:::infrastructure
        EM["Entity Mappings"]:::infrastructure
    end

    %% Configuration & Dependency Injection
    subgraph "Configuration & DI"
        CI["Dependency Injector & Configuration"]:::configuration
        ENV["Env Config"]:::configuration
    end

    %% Flow of Requests and Processing
    E1 -->|"HTTP_Request"| PC
    PC -->|"calls_handler"| AC
    AC -->|"triggers_usecase"| DU
    DU -->|"applies_logic"| DC
    DU -->|"persists_data"| MC
    MC -->|"stores_in"| E2

    %% Dependency Injection Connections (dashed lines)
    CI -.-> PC
    CI -.-> AC
    CI -.-> MC
    ENV -->|"configures"| CI

    %% External Containerization Connections
    D1 -->|"builds"| E3
    D2 -->|"orchestrates"| E3

    %% External API Documentation
    PC -->|"documents_via"| E4

    %% Styles
    classDef presentation fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef application fill:#ABEBC6,stroke:#1E8449,stroke-width:2px;
    classDef domain fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef infrastructure fill:#F5CBA7,stroke:#CB4335,stroke-width:2px;
    classDef configuration fill:#D7BDE2,stroke:#6C3483,stroke-width:2px;
    classDef external fill:#D6EAF8,stroke:#2471A3,stroke-width:2px;

    %% Click Events
    click PC "https://github.com/juanpabloleonf/microservice-series/tree/main/app/src/infrastructure/inputs/rest/controllers"
    click AC "https://github.com/juanpabloleonf/microservice-series/tree/main/app/src/application"
    click DC "https://github.com/juanpabloleonf/microservice-series/tree/main/app/src/domain"
    click MC "https://github.com/juanpabloleonf/microservice-series/tree/main/app/src/infrastructure/outputs/mysql"
    click CI "https://github.com/juanpabloleonf/microservice-series/tree/main/app/configuration"
    click ENV "https://github.com/juanpabloleonf/microservice-series/blob/main/app/configuration/enviroments_config.py"
    click D1 "https://github.com/juanpabloleonf/microservice-series/tree/main/docker/Dockerfile"
    click D2 "https://github.com/juanpabloleonf/microservice-series/blob/main/docker-compose.yml"
```
