# juanpabloleonf/microservice-user architecture

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

## Overview

##### Main Components
- Entry Point & Server: Mark main.py as your starting point, which initializes Uvicorn with the FastAPI app.
- Configuration Layer: Represent the “app/configuration” directory which sets up the server parameters, environment variables, exception handlers, CORS policies, dependency injection, modular routing, and Swagger API documentation.
- Application Layer: This includes the “app/src/application” directory. It covers:
- Data Transfer Objects (DTOs): request_user, response_user, and response_error.
- Handlers that process incoming user requests.
- Mappers to convert between domain models and DTOs.
- Domain Layer: Found in “app/src/domain”, this is the core of your business logic. It contains:
- Domain models (user_model).
- Persistence ports that define interfaces for data storage (i_persistence_port_user).
- Domain services and use cases (e.g., use_case_user) that encapsulate business rules.
- Utility functions (e.g., util_bcrypt for password encryption).
- Infrastructure Layer: In “app/src/infrastructure”, separate into two parts:
- Inputs (REST controllers): This includes controllers, REST-specific DTOs, and mappers for handling API requests.
- Outputs (MySQL adapters and repositories): Contains the MySQL adapter, entity mapping, repository implementations, and database configurations.

##### Representing Relationships & Data Flow
- Data flowing from the external API request (via REST controllers in the Infrastructure Inputs section) into the Application layer (handlers and mappers), then into the Domain layer where the business logic and use cases reside.
- From the Domain’s output ports, illustrate how calls pass into the Infrastructure Outputs (MySQL adapters, repositories) for data storage, and then back the response path.

##### Architectural Patterns & Design Principles
- Separation of concerns inherent in the hexagonal architecture: adapters (external interactions) vs. the core domain logic.
- Dependency Injection as seen in the configuration for routers and module injector for the user.
- That error handling, CORS, and environment configurations are applied at the entry configuration layer.

##### Technologies, Frameworks, & External Services
- MySQL as the external database service.
- Docker and Docker Compose as orchestration and deployment layers that package and run the microservice in containers.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Deployment Layer
    subgraph "Deployment"
        deploy_compose["docker-compose.yml"]:::deployment
        deploy_dockerfile["Dockerfile"]:::deployment
    end

    %% Entry Point & Configuration
    subgraph "Entry Point & Configuration"
        mainEntry["main.py"]:::entry
        subgraph "Configuration Layer"
            config_env["enviroments_config.py"]:::config
            config_exc["exceptions_handlers_global.py"]:::config
            config_cors["milddware_cors.py"]:::config
            config_inject["module_injector_user.py"]:::config
            config_router["routers_config.py"]:::config
            config_swagger["swagger_config.py"]:::config
        end
    end

    %% Application Layer
    subgraph "Application Layer"
        subgraph "DTOs"
            dto_request["request_user.py"]:::dto
            dto_response_error["response_error.py"]:::dto
            dto_response_user["response_user.py"]:::dto
        end
        subgraph "Handlers"
            handler_interface["i_handler_user.py"]:::handler
            handler_impl["implementation_handler_user.py"]:::handler
        end
        subgraph "Mappers"
            app_mapper["i_mapper_handler.py"]:::mapper
        end
    end

    %% Domain Layer
    subgraph "Domain Layer"
        domain_model["user_model.py"]:::domain
        persistence_port["i_persistence_port_user.py"]:::domain
        service_port["i_services_port_user.py"]:::domain
        use_case["use_case_user.py"]:::domain
        util_bcrypt["util_bcrypt.py"]:::domain
    end

    %% Infrastructure Layer
    subgraph "Infrastructure Layer"
        subgraph "Inputs (REST)"
            controller["controller_user.py"]:::infrastructure
            rest_dto["request_user_controller.py"]:::infrastructure
            rest_mapper["mapper_user_controller.py"]:::infrastructure
        end
        subgraph "Outputs (MySQL)"
            mysql_adapter["adapter_user.py"]:::mysql
            mysql_entity["entity_user.py"]:::mysql
            mysql_mapper["i_mappers_user.py"]:::mysql
            mysql_repo_interface["i_repository_user.py"]:::mysql
            mysql_repo_impl["implementation_repository_user.py"]:::mysql
            mysql_dbconfig["database_config.py"]:::mysql
        end
    end

    %% External Database
    external_db["MySQL Database"]:::database

    %% Data Flow Connections
    deploy_compose --> mainEntry
    deploy_dockerfile --> mainEntry
    mainEntry --> config_inject
    config_inject --> config_router
    config_router --> controller
    rest_dto --> controller
    rest_mapper --> controller
    controller --> handler_impl
    handler_impl --> use_case
    use_case --> domain_model
    use_case --> persistence_port
    persistence_port --> mysql_repo_impl
    mysql_repo_impl --> mysql_dbconfig
    mysql_dbconfig --> external_db
    use_case --> dto_response_user
    handler_impl --> app_mapper
    rest_dto --> dto_request
    handler_impl --> dto_response_error

    %% Styling
    classDef deployment fill:#d3adeb,stroke:#4b0082,stroke-width:2px;
    classDef entry fill:#e3f2fd,stroke:#1565C0,stroke-width:2px;
    classDef config fill:#bbdefb,stroke:#0D47A1,stroke-width:2px;
    classDef dto fill:#c8e6c9,stroke:#2E7D32,stroke-width:2px;
    classDef handler fill:#fff9c4,stroke:#F9A825,stroke-width:2px;
    classDef mapper fill:#ffe0b2,stroke:#E64A19,stroke-width:2px;
    classDef domain fill:#ffccbc,stroke:#BF360C,stroke-width:2px;
    classDef infrastructure fill:#d1c4e9,stroke:#512DA8,stroke-width:2px;
    classDef mysql fill:#f8bbd0,stroke:#AD1457,stroke-width:2px;
    classDef database fill:#fff9c4,stroke:#F57F17,stroke-width:2px;

    %% Click Events
    click mainEntry "https://github.com/juanpabloleonf/microservice-user/blob/main/main.py"
    click config_env "https://github.com/juanpabloleonf/microservice-user/blob/main/app/configuration/enviroments_config.py"
    click config_exc "https://github.com/juanpabloleonf/microservice-user/blob/main/app/configuration/exceptions_handlers_global.py"
    click config_cors "https://github.com/juanpabloleonf/microservice-user/blob/main/app/configuration/milddware_cors.py"
    click config_inject "https://github.com/juanpabloleonf/microservice-user/blob/main/app/configuration/module_injector_user.py"
    click config_router "https://github.com/juanpabloleonf/microservice-user/blob/main/app/configuration/routers_config.py"
    click config_swagger "https://github.com/juanpabloleonf/microservice-user/blob/main/app/configuration/swagger_config.py"
    click dto_request "https://github.com/juanpabloleonf/microservice-user/blob/main/app/src/application/dto/request_user.py"
    click dto_response_error "https://github.com/juanpabloleonf/microservice-user/blob/main/app/src/application/dto/response_error.py"
    click dto_response_user "https://github.com/juanpabloleonf/microservice-user/blob/main/app/src/application/dto/response_user.py"
    click handler_interface "https://github.com/juanpabloleonf/microservice-user/blob/main/app/src/application/handlers/i_handler_user.py"
    click handler_impl "https://github.com/juanpabloleonf/microservice-user/blob/main/app/src/application/handlers/implementation_handler_user.py"
    click app_mapper "https://github.com/juanpabloleonf/microservice-user/blob/main/app/src/application/mappers/i_mapper_handler.py"
    click domain_model "https://github.com/juanpabloleonf/microservice-user/blob/main/app/src/domain/models/user_model.py"
    click persistence_port "https://github.com/juanpabloleonf/microservice-user/blob/main/app/src/domain/persistence/i_persistence_port_user.py"
    click service_port "https://github.com/juanpabloleonf/microservice-user/blob/main/app/src/domain/services/i_services_port_user.py"
    click use_case "https://github.com/juanpabloleonf/microservice-user/blob/main/app/src/domain/useCases/use_case_user.py"
    click util_bcrypt "https://github.com/juanpabloleonf/microservice-user/blob/main/app/src/domain/utils/util_bcrypt.py"
    click controller "https://github.com/juanpabloleonf/microservice-user/blob/main/app/src/infrastructure/inputs/rest/controllers/controller_user.py"
    click rest_dto "https://github.com/juanpabloleonf/microservice-user/blob/main/app/src/infrastructure/inputs/rest/dto/request_user_controller.py"
    click rest_mapper "https://github.com/juanpabloleonf/microservice-user/blob/main/app/src/infrastructure/inputs/rest/mappers/mapper_user_controller.py"
    click mysql_adapter "https://github.com/juanpabloleonf/microservice-user/blob/main/app/src/infrastructure/outputs/mysql/adapters/adapter_user.py"
    click mysql_entity "https://github.com/juanpabloleonf/microservice-user/blob/main/app/src/infrastructure/outputs/mysql/entities/entity_user.py"
    click mysql_mapper "https://github.com/juanpabloleonf/microservice-user/blob/main/app/src/infrastructure/outputs/mysql/mappers/i_mappers_user.py"
    click mysql_repo_interface "https://github.com/juanpabloleonf/microservice-user/blob/main/app/src/infrastructure/outputs/mysql/repositories/i_repository_user.py"
    click mysql_repo_impl "https://github.com/juanpabloleonf/microservice-user/blob/main/app/src/infrastructure/outputs/mysql/repositories/implementation_repository_user.py"
    click mysql_dbconfig "https://github.com/juanpabloleonf/microservice-user/blob/main/app/src/infrastructure/outputs/mysql/settings/database_config.py"
    click deploy_compose "https://github.com/juanpabloleonf/microservice-user/blob/main/docker-compose.yml"
    click deploy_dockerfile "https://github.com/juanpabloleonf/microservice-user/tree/main/docker/Dockerfile"
```
