# juanpabloleonf/microservice-movie architecture

> Architecture diagram of the GitHub repository juanpabloleonf/microservice-movie, 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-movie
- Repository: https://github.com/juanpabloleonf/microservice-movie

## Overview

##### Main Components
- Configuration: Contains the setup for the FastAPI server (CORS, Swagger, exception handling, environment configuration, routers) under app/configuration.
- Application Layer: Contains the business logic, DTOs, handlers, mappers, and utility functions (inside app/src/application). This layer orchestrates the communication between external interfaces and the business/domain logic.
- Domain Layer: Holds the core modeling of the domain, including the movie model, persistence interfaces, services, and use case implementations (found in app/src/domain). This is the heart of the hexagonal architecture.
- Infrastructure Layer: Divided into two key parts:
- Inputs (REST controllers): Present in app/src/infrastructure/inputs/rest – manages incoming HTTP requests, validates and maps data from external sources.
- Outputs (MySQL related artifacts): Found in app/src/infrastructure/outputs/mysql – adapts the domain logic to the MySQL database by providing repositories, entities, mappers, and database settings.
- Deployment/Orchestration: Docker and docker-compose configurations indicate containerized deployment.

##### Relationships and Interactions
- The main data flow starts at the REST API endpoints (infrastructure/inputs/rest/controllers) which receive and validate HTTP requests.
- Requests are then mapped (using DTOs and mappers) and sent into the Application layer, which coordinates use cases (inside domain/useCases) and business logic.
- The domain layer encapsulates the movie model and uses defined interfaces (persistence and service interfaces) to interact with the database.
- The Infrastructure layer on the outputs side communicates with the MySQL database through repositories and adapters.
- Configuration components (including environment settings and middleware) ensure proper server behavior and manage cross-cutting concerns (e.g., error handling, CORS, dependency injection).

##### Architectural Patterns and Design Principles
- Hexagonal Architecture: Emphasize the separation between core domain logic and external adapters (REST input & MySQL output).
- Inversion of Control (IoC) and Dependency Injection: The project uses Injector for decoupling and dynamic binding, significant in the configuration modules.
- Layered Architecture: Separate layers for configuration, application logic, domain modeling, and infrastructure concerns.
- API Documentation and Error Handling: Clear concerns for API docs (Swagger/Redoc) and unified error handling.

##### Relevant Technologies and Frameworks
- FastAPI: For handling HTTP requests and serving the REST API.
- SQLAlchemy: Likely used in the infrastructure MySQL repository for ORM.
- Pydantic: Used for request validation and DTO creation.
- Docker & Docker Compose: For container orchestration and deployment.
- Cryptography: Placed in the context of data protection and secure processing.

- Clear labels for each main component: “Configuration”, “Application”, “Domain”, “Infrastructure – Inputs (REST)”, “Infrastructure – Outputs (MySQL)”, “Deployment (Docker)”.
- Additional notes or callouts for important design choices such as dependency injection, global exception handling, asynchronous context management, and API documentation endpoints.

- Inside, create the “Application” bubble where DTOs, handlers (commands), and mappers reside.
- Center the “Domain” bubble that contains movie models, interfaces (persistence and services), and use cases.
- On the side, add a “Configuration” section that feeds into the REST API and application layers, noting environment variables, middleware, and global exception handlers.
- Finally, indicate the deployment environment with Docker, linking it to the main service and database container.

## Diagram (Mermaid)

```mermaid
graph TD
    subgraph "Deployment (Docker)"
        DC["docker-compose.yml"]:::deploy
        DF["Dockerfile"]:::deploy
    end

    Config["Configuration"]:::config
    Rest["Infrastructure - Inputs (REST)"]:::rest
    App["Application Layer"]:::app
    Dom["Domain Layer"]:::domain
    MySQL["Infrastructure - Outputs (MySQL)"]:::db

    DC --> Config
    DF --> Config
    Config --> Rest
    Rest --> App
    App --> Dom
    Dom --> MySQL
    MySQL --"returns"--> Dom
    Dom --"returns"--> App
    App --"returns"--> Rest

    click Config "https://github.com/juanpabloleonf/microservice-movie/tree/main/app/configuration/"
    click App "https://github.com/juanpabloleonf/microservice-movie/tree/main/app/src/application/"
    click Dom "https://github.com/juanpabloleonf/microservice-movie/tree/main/app/src/domain/"
    click Rest "https://github.com/juanpabloleonf/microservice-movie/tree/main/app/src/infrastructure/inputs/rest/"
    click MySQL "https://github.com/juanpabloleonf/microservice-movie/tree/main/app/src/infrastructure/outputs/mysql/"
    click DC "https://github.com/juanpabloleonf/microservice-movie/blob/main/docker-compose.yml"
    click DF "https://github.com/juanpabloleonf/microservice-movie/tree/main/docker/Dockerfile"

    classDef deploy fill:#b39ddb,stroke:#333,stroke-width:2px,color:#fff;
    classDef config fill:#ffcc80,stroke:#333,stroke-width:2px,color:#000;
    classDef rest fill:#f48fb1,stroke:#333,stroke-width:2px,color:#fff;
    classDef app fill:#aed581,stroke:#333,stroke-width:2px,color:#000;
    classDef domain fill:#90caf9,stroke:#333,stroke-width:2px,color:#000;
    classDef db fill:#ffe082,stroke:#333,stroke-width:2px,color:#000;
```
