# jananaya/tm-facturasapi architecture

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

- Interactive diagram: https://gitdiagram.com/jananaya/tm-facturasapi
- Repository: https://github.com/jananaya/tm-facturasapi

## Overview

##### Main Components
- API/Presentation Layer: Represented by the Controllers folder and the Program.cs entry point. This layer is responsible for handling HTTP requests and returning responses.
- Business Logic Layer: This includes the Managers found under Infrastructure/Managers along with their corresponding Interfaces. They process business rules and orchestrate the workflow.
- Data Access Layer: This is built into the Repositories under Infrastructure/Repositories and the UnitOfWork. Entities (from Infrastructure/Entities) and DTOs (from Infrastructure/Dtos) help in mapping data between the application and the data source.
- Database/Context: Even though it’s not explicitly a database file, the Infrastructure/AppDbContext.cs suggests an Entity Framework-based connection to a database.
- Middleware: ErrorHandlerMiddleware in the Infrastructure/Middlewares deals with centralized exception handling.
- Containerization & Deployment: The Dockerfile, docker-compose.yml, and Dockerfile.dev indicate how the API is packaged as a containerized service.

##### Relationships and Interactions
- The Controllers receive incoming HTTP requests, forward them to the appropriate Manager (business logic layer), which in turn calls the Repository interfaces to perform CRUD operations on data.
- Managers rely on DTOs for data validation and transformation. Data flows from controllers → managers → repositories.
- The Repositories interact with the database via the AppDbContext.
- Middleware (ErrorHandlerMiddleware) sits in the HTTP pipeline to handle errors uniformly across all requests.
- The project’s configuration (appsettings.json and environment-specific files) integrates these layers and provides runtime settings.
- Containerization through Docker orchestrates the entire API for deployment and ensures the environment is consistent.

##### Architectural Patterns and Design Principles
- Layered Architecture: Separation into controllers, managers, and repositories.
- Dependency Injection (implied by the use of interfaces in managers and repositories).
- Unit of Work Pattern: To manage repository transactions.
- RESTful API design is likely followed in the Controllers.
- Containerization: Deployment using Docker Compose.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% API/Presentation Layer
    subgraph "API/Presentation Layer"
        A1["Program.cs"]
        A2["BaseController.cs"]
        A3["DetallesFacturaController.cs"]
        A4["FacturasController.cs"]
        A5["HomeController.cs"]
    end

    %% Business Logic Layer
    subgraph "Business Logic Layer"
        B1["DetallesFacturaManager.cs"]
        B2["FacturasManager.cs"]
        B3["IDetallesFacturaManager.cs"]
        B4["IFacturasManager.cs"]
    end

    %% Data Access Layer
    subgraph "Data Access Layer"
        C1["BaseRepository.cs"]
        C2["DetallesFacturaRepository.cs"]
        C3["FacturasRepository.cs"]
        C4["IBaseRepository.cs"]
        C5["IDetallesFacturaRepository.cs"]
        C6["IFacturasRepository.cs"]
        C7["UnitOfWork.cs"]
        C8["IUnitOfWork.cs"]
    end

    %% Data Transfer Objects (DTOs)
    subgraph "Data Transfer Objects (DTOs)"
        D1["CreateDetalleFacturaDto.cs"]
        D2["CreateFacturaDto.cs"]
        D3["DetalleFacturaDto.cs"]
        D4["FacturaDto.cs"]
        D5["UpdateDetalleFacturaDto.cs"]
    end

    %% Database/Context
    subgraph "Database/Context"
        E1["AppDbContext.cs"]
    end

    %% Middleware
    subgraph "Middleware"
        F1["ErrorHandlerMiddleware.cs"]
    end

    %% Containerization & Deployment
    subgraph "Containerization & Deployment"
        G1["Dockerfile"]
        G2["Dockerfile.dev"]
        G3["docker-compose.yml"]
    end

    %% Connections
    %% API Layer flows to Business Logic
    A3 -->|"calls"| B1
    A4 -->|"calls"| B2
    A1 -->|"initializes"| A2
    A1 -->|"initializes"| A3
    A1 -->|"initializes"| A4
    A1 -->|"initializes"| A5

    %% Business Logic uses DTOs
    B1 -->|"transforms"| D1
    B1 -->|"transforms"| D3
    B1 -->|"transforms"| D5
    B2 -->|"transforms"| D2
    B2 -->|"transforms"| D4

    %% Business Logic delegates to Data Access
    B1 -->|"invokes"| C2
    B2 -->|"invokes"| C3

    %% Data Access interacts with Database/Context
    C2 -->|"queries"| E1
    C3 -->|"queries"| E1

    %% Middleware intercepts API requests
    A3 ---|"intercepted by"| F1
    A4 ---|"intercepted by"| F1
    A2 ---|"intercepted by"| F1
    A5 ---|"intercepted by"| F1

    %% Containerization deploys the API service
    G3 -->|"deploys"| A1
    G1 ---|"builds image"| A1
    G2 ---|"builds dev image"| A1

    %% Styling classes
    class A1,A2,A3,A4,A5 apiLayer
    class B1,B2,B3,B4 business
    class C1,C2,C3,C4,C5,C6,C7,C8 dataaccess
    class D1,D2,D3,D4,D5 dto
    class E1 database
    class F1 middleware
    class G1,G2,G3 container

    %% Class Definitions with Colors
    classDef apiLayer fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef business fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef dataaccess fill:#F4A460,stroke:#000,stroke-width:2px;
    classDef dto fill:#D8BFD8,stroke:#000,stroke-width:2px;
    classDef database fill:#FFC0CB,stroke:#000,stroke-width:2px;
    classDef middleware fill:#D3D3D3,stroke:#000,stroke-width:2px;
    classDef container fill:#FFFFE0,stroke:#000,stroke-width:2px;

    %% Click Events for API/Presentation Layer
    click A1 "https://github.com/jananaya/tm-facturasapi/blob/main/Program.cs"
    click A2 "https://github.com/jananaya/tm-facturasapi/blob/main/Controllers/BaseController.cs"
    click A3 "https://github.com/jananaya/tm-facturasapi/blob/main/Controllers/DetallesFacturaController.cs"
    click A4 "https://github.com/jananaya/tm-facturasapi/blob/main/Controllers/FacturasController.cs"
    click A5 "https://github.com/jananaya/tm-facturasapi/blob/main/Controllers/HomeController.cs"

    %% Click Events for Business Logic Layer
    click B1 "https://github.com/jananaya/tm-facturasapi/blob/main/Infrastructure/Managers/DetallesFacturaManager.cs"
    click B2 "https://github.com/jananaya/tm-facturasapi/blob/main/Infrastructure/Managers/FacturasManager.cs"
    click B3 "https://github.com/jananaya/tm-facturasapi/blob/main/Infrastructure/Managers/Interfaces/IDetallesFacturaManager.cs"
    click B4 "https://github.com/jananaya/tm-facturasapi/blob/main/Infrastructure/Managers/Interfaces/IFacturasManager.cs"

    %% Click Events for Data Access Layer
    click C1 "https://github.com/jananaya/tm-facturasapi/blob/main/Infrastructure/Repositories/BaseRepository.cs"
    click C2 "https://github.com/jananaya/tm-facturasapi/blob/main/Infrastructure/Repositories/DetallesFacturaRepository.cs"
    click C3 "https://github.com/jananaya/tm-facturasapi/blob/main/Infrastructure/Repositories/FacturasRepository.cs"
    click C4 "https://github.com/jananaya/tm-facturasapi/blob/main/Infrastructure/Repositories/Interfaces/IBaseRepository.cs"
    click C5 "https://github.com/jananaya/tm-facturasapi/blob/main/Infrastructure/Repositories/Interfaces/IDetallesFacturaRepository.cs"
    click C6 "https://github.com/jananaya/tm-facturasapi/blob/main/Infrastructure/Repositories/Interfaces/IFacturasRepository.cs"
    click C7 "https://github.com/jananaya/tm-facturasapi/blob/main/Infrastructure/Repositories/UnitOfWork.cs"
    click C8 "https://github.com/jananaya/tm-facturasapi/blob/main/Infrastructure/Repositories/Interfaces/IUnitOfWork.cs"

    %% Click Events for DTOs
    click D1 "https://github.com/jananaya/tm-facturasapi/blob/main/Infrastructure/Dtos/CreateDetalleFacturaDto.cs"
    click D2 "https://github.com/jananaya/tm-facturasapi/blob/main/Infrastructure/Dtos/CreateFacturaDto.cs"
    click D3 "https://github.com/jananaya/tm-facturasapi/blob/main/Infrastructure/Dtos/DetalleFacturaDto.cs"
    click D4 "https://github.com/jananaya/tm-facturasapi/blob/main/Infrastructure/Dtos/FacturaDto.cs"
    click D5 "https://github.com/jananaya/tm-facturasapi/blob/main/Infrastructure/Dtos/UpdateDetalleFacturaDto.cs"

    %% Click Event for Database/Context
    click E1 "https://github.com/jananaya/tm-facturasapi/blob/main/Infrastructure/AppDbContext.cs"

    %% Click Event for Middleware
    click F1 "https://github.com/jananaya/tm-facturasapi/blob/main/Infrastructure/Middlewares/ErrorHandlerMiddleware.cs"

    %% Click Events for Containerization & Deployment
    click G1 "https://github.com/jananaya/tm-facturasapi/tree/main/Dockerfile"
    click G2 "https://github.com/jananaya/tm-facturasapi/blob/main/Dockerfile.dev"
    click G3 "https://github.com/jananaya/tm-facturasapi/blob/main/docker-compose.yml"
```
