# franciscowatson/sistema-de-ordenes-de-inversion architecture

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

- Interactive diagram: https://gitdiagram.com/franciscowatson/sistema-de-ordenes-de-inversion
- Repository: https://github.com/franciscowatson/sistema-de-ordenes-de-inversion

## Overview

##### Project Overview
- This is a REST API that manages investment orders using a Clean Architecture approach and the CQRS pattern.
- It is built with .NET 8 and leverages Entity Framework Core for data persistence, MediatR for command/query handling, FluentValidation for inputs, JWT for authentication, and AutoMapper for data mapping.

##### Main Layers/Components
a. SOI.API (Presentation Layer)
– Contains controllers (e.g., AuthenticationController, OrdenController) and entry point (Program.cs).
– Exposes REST endpoints and handles incoming HTTP requests.
b. SOI.Application (Application Layer)
– Houses the core application logic using Commands, Queries, Handlers (MediatR), DTOs, and Validators.
– This layer implements CQRS, handling separate operations for state changes (commands) and data retrieval (queries).
c. SOI.Domain (Domain Layer)
– Contains the domain entities (Cuenta, Orden, Activo, etc.) and domain services (e.g., IOrdenDomainService, authentication services).
– Represents the core business model, logic, and interfaces that define the domain rules.
d. SOI.Infrastructure (Infrastructure Layer)
– Provides implementations for data persistence with Entity Framework Core (SoiDbContext, Configurations, Migrations).
– Contains repository implementations and authentication service details (JWT token generation, etc.).

##### Relationships and Interactions
- The API layer receives HTTP requests and routes them to Controllers which call MediatR.
- MediatR interacts with the Application layer by triggering specific Commands/Queries.
- Handlers in the Application layer execute business logic, possibly invoking domain services from the Domain layer.
- For database operations, the Application layer calls interfaces (e.g., IOrdenRepository) that are implemented in the Infrastructure layer.
- The Infrastructure layer manages persistence, migrations, and configuration using Entity Framework Core.
- Additionally, JWT-based authentication involves both the Domain (interfaces for JWT generation) and Infrastructure for concrete implementations.

##### Architectural Patterns and Design Principles
- Clean Architecture: Separation into Presentation (API), Application (CQRS logic), Domain (business rules and entities), and Infrastructure (data access and external integration).
- CQRS Pattern with MediatR: Distinct Commands and Queries with corresponding Handlers.
- Dependency Injection and Inversion of Control: Interfaces in Domain/Application are wired up with implementations in Infrastructure.
- Separation of Concerns: Each project has a clear responsibility, helping maintain scalability and testability.

##### Technologies & Frameworks Highlighted
- .NET 8 and ASP.NET Core: For web API development.
- Entity Framework Core: For interacting with SQL Server.
- Docker: For containerizing the service.
- MediatR: For orchestrating the command/query flows.
- FluentValidation: To validate incoming data.
- AutoMapper: For data transfer object (DTO) mapping.
- JWT: For implementing secure authentication.

##### Final Inclusions
- You include:
- Inside each, include key submodules (Controllers, Commands/Queries, Handlers, Entities, Repositories, etc.).
- A segment showing “Database” as a separate component interacting with the Infrastructure layer (SoiDbContext and Migrations).

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "SOI.API (Presentation Layer)"
        A1["AuthenticationController"]:::presentation
        A2["OrdenController"]:::presentation
        A3["Program.cs"]:::presentation
    end

    subgraph "SOI.Application (Application Layer)"
        B1["Commands"]:::application
        B2["Handlers"]:::application
        B3["DTOs"]:::application
        B4["Validations"]:::application
        B5["Mappings"]:::application
        B6["Queries"]:::application
        B7["Repositories Interface"]:::application
        B8["ApplicationConfiguration"]:::application
    end

    subgraph "SOI.Domain (Domain Layer)"
        C1["Entities"]:::domain
        C2["Authentication Interfaces"]:::domain
        C3["Domain Services"]:::domain
    end

    subgraph "SOI.Infrastructure (Infrastructure Layer)"
        D1["Authentication Service"]:::infrastructure
        D2["Persistence"]:::infrastructure
        D3["Configurations"]:::infrastructure
        D4["Migrations"]:::infrastructure
        D5["Repositories"]:::infrastructure
        D6["Infrastructure Config"]:::infrastructure
    end

    DB["Database (SQL Server)"]:::database

    %% Relationships
    A1 -->|"HTTP_Request_(Auth)"| B1
    A2 -->|"HTTP_Request_(Orden)"| B1
    B1 -->|"Dispatch_Command/Query"| B2
    B2 -->|"Business_Logic"| C3
    B2 -->|"Data_Access"| B7
    B7 -->|"Repository_Call"| D5
    D2 -->|"EF_Core_Operations"| DB
    %% Authentication Flow
    A1 -->|"JWT_Auth_Request"| D1
    D1 -->|"JWT_Generation"| C2
    %% Additional Internal Flows
    B2 -->|"Mapping"| B3
    B2 -->|"Validation"| B4
    B2 -->|"Mapping_Profiles"| B5
    B2 -->|"Query_Handling"| B6
    C3 -->|"Uses_Entities"| C1
    B8 -->|"Configures_DI"| D6

    %% Click Events for SOI.API
    click A1 "https://github.com/franciscowatson/sistema-de-ordenes-de-inversion/blob/main/SOI.API/Controllers/AuthenticationController.cs"
    click A2 "https://github.com/franciscowatson/sistema-de-ordenes-de-inversion/blob/main/SOI.API/Controllers/OrdenController.cs"
    click A3 "https://github.com/franciscowatson/sistema-de-ordenes-de-inversion/blob/main/SOI.API/Program.cs"

    %% Click Events for SOI.Application
    click B1 "https://github.com/franciscowatson/sistema-de-ordenes-de-inversion/tree/main/SOI.Application/Commands"
    click B2 "https://github.com/franciscowatson/sistema-de-ordenes-de-inversion/tree/main/SOI.Application/Handlers"
    click B3 "https://github.com/franciscowatson/sistema-de-ordenes-de-inversion/tree/main/SOI.Application/DTOs"
    click B4 "https://github.com/franciscowatson/sistema-de-ordenes-de-inversion/tree/main/SOI.Application/Validations"
    click B5 "https://github.com/franciscowatson/sistema-de-ordenes-de-inversion/tree/main/SOI.Application/Mappings"
    click B6 "https://github.com/franciscowatson/sistema-de-ordenes-de-inversion/tree/main/SOI.Application/Queries"
    click B7 "https://github.com/franciscowatson/sistema-de-ordenes-de-inversion/tree/main/SOI.Application/Interfaces/Repositories"
    click B8 "https://github.com/franciscowatson/sistema-de-ordenes-de-inversion/blob/main/SOI.Application/ApplicationConfiguration.cs"

    %% Click Events for SOI.Domain
    click C1 "https://github.com/franciscowatson/sistema-de-ordenes-de-inversion/tree/main/SOI.Domain/Entities"
    click C2 "https://github.com/franciscowatson/sistema-de-ordenes-de-inversion/tree/main/SOI.Domain/Authentication"
    click C3 "https://github.com/franciscowatson/sistema-de-ordenes-de-inversion/tree/main/SOI.Domain/Services"

    %% Click Events for SOI.Infrastructure
    click D1 "https://github.com/franciscowatson/sistema-de-ordenes-de-inversion/tree/main/SOI.Infrastructure/Authentication"
    click D2 "https://github.com/franciscowatson/sistema-de-ordenes-de-inversion/tree/main/SOI.Infrastructure/Persistence"
    click D3 "https://github.com/franciscowatson/sistema-de-ordenes-de-inversion/tree/main/SOI.Infrastructure/Persistence/Configurations"
    click D4 "https://github.com/franciscowatson/sistema-de-ordenes-de-inversion/tree/main/SOI.Infrastructure/Persistence/Migrations"
    click D5 "https://github.com/franciscowatson/sistema-de-ordenes-de-inversion/tree/main/SOI.Infrastructure/Persistence/Repositories"
    click D6 "https://github.com/franciscowatson/sistema-de-ordenes-de-inversion/blob/main/SOI.Infrastructure/InfrastructureLayerConfiguration.cs"

    %% Styles
    classDef presentation fill:#add8e6,stroke:#000,stroke-width:2px;
    classDef application fill:#90ee90,stroke:#000,stroke-width:2px;
    classDef domain fill:#dda0dd,stroke:#000,stroke-width:2px;
    classDef infrastructure fill:#ffa500,stroke:#000,stroke-width:2px;
    classDef database fill:#ffff99,stroke:#000,stroke-width:2px;
```
