# luanroger/allinoneaspnet architecture

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

- Interactive diagram: https://gitdiagram.com/luanroger/allinoneaspnet
- Repository: https://github.com/luanroger/allinoneaspnet

## Overview

##### Main Architectural Layers and Components

a. API/Presentation Layer
- Entry Point: The Program.cs file configures the entire application.
- Endpoint Mappings: The “Endpoints” folder defines grouped routes (UserEndpoints and ClientEndpoints) using Minimal API’s MapGroup. These endpoints serve as the public interface, handle the HTTP request/response cycle, and forward requests to the controllers.
- Swagger UI: Integrated Swagger middlewares (UseSwagger and UseSwaggerUI) automatically document the endpoints and serve as an interactive interface.

b. Application/Domain Layer
- Controllers: Located in the “Controllers” folder (UserController and ClientController). They encapsulate business logic for user signin/login and client CRUD operations.
- Models: The “Models” folder contains domain models (for both User and Client), as well as specialized read and request models. This separation ensures that the API’s input/output contracts differ from persistence objects.
- Validation: FluentValidation classes (in the “Validators” folder) define rules for request models. They are injected into controllers to guard against invalid data.
- Exception Handling: Custom exceptions (in the “Exceptions” folder) represent domain-level errors for cases like “UserNotFound”, “InvalidRequest”, or “ClientNotFound”.

c. Persistence/Infrastructure Layer
- Repository Pattern: Interfaces (in “Repositories”) and classes (UserRepository and ClientRepository) encapsulate data access logic. They use EF Core’s DatabaseContext (in “Repositories/Contexts”) to perform CRUD operations against a SQLite database.
- Entity Framework Core: Models are annotated with data annotation attributes to define database schemas. The DatabaseContext ties these models to underlying tables.

d. Cross-Cutting Services
- JWT Authentication: A dedicated “JwtService” (under “Services/Jwt”) is used in controllers to generate tokens. JWT-related constants (in JwtConsts) and middleware configuration (in Program.cs) ensure that endpoints (especially in the “client” group) are secured.
- Logging: Serilog is used as the logging mechanism. The Program.cs file configures Serilog to capture application events that are then used in controllers and other components.
- Dependency Injection: All controllers, repositories, validators, DbContext, and the JWT service are registered in the DI container. This results in clean constructor injection throughout the system.

##### How to Represent Interactions and Data Flow
– Begin at the Client (API consumer) side. Show the HTTP client sending requests to the ASP.NET API.
– For requests targeting registration or login, represent those being forwarded to the corresponding Controller.
– In each controller, show the following sub-flows:
- Validation: The controller invokes the appropriate FluentValidation component.
- Business Logic: If validation passes, the controller either registers a new user (or logs in an existing one) and calls the JWT service to generate a token OR manages client data.
- Data Persistence: When client/user data changes, controllers call the appropriate Repository. The repositories in turn interact with the DatabaseContext which uses EF Core to read or write to the SQLite database.
- Use logging symbols to indicate that Serilog is recording events.

## Diagram (Mermaid)

```mermaid
graph TD
    A1("HTTP Client"):::external

    P("API Gateway (Program.cs)"):::api
    S("Swagger UI"):::api
    L("Logging (Serilog)"):::api
    JMW("JWT Auth Middleware"):::api

    subgraph "API Endpoints"
        UEP("User Endpoints"):::endpoints
        CEP("Client Endpoints"):::endpoints
    end

    subgraph "Application/Domain Layer"
        subgraph "Controllers"
            UC("User Controller"):::domain
            IUC("IUser Controller Interface"):::domain
            CC("Client Controller"):::domain
            ICC("IClient Controller Interface"):::domain
        end
        subgraph "Models"
            UM("User Models"):::domain
            CM("Client Models"):::domain
        end
        subgraph "Validation"
            UV("User Validators"):::domain
            CV("Client Validators"):::domain
        end
        EX("Exception Handling"):::domain
    end

    subgraph "Persistence/Infrastructure Layer"
        subgraph "Repositories"
            UR("User Repository"):::persistence
            CR("Client Repository"):::persistence
            UIR("IUser Repository"):::persistence
            CIR("IClient Repository"):::persistence
        end
        DB("DatabaseContext (SQLite/EF Core)"):::database
    end

    subgraph "Cross-Cutting Services"
        JWTS("JWT Service"):::cross
        JWTC("JWT Constants"):::cross
    end

    DI("DI Container"):::di

    %% Flow Connections
    A1 --> P
    P --> UEP
    P --> CEP
    P --> S
    P --> L
    P --> JMW

    UEP --> UC
    CEP --> CC

    UC --> UV
    CC --> CV

    UC --> UR
    CC --> CR

    UR --> DB
    CR --> DB

    UC --> JWTS
    JWTS --> JWTC

    %% Dependency Injection (dashed lines)
    DI -.-> UC
    DI -.-> CC
    DI -.-> UR
    DI -.-> CR
    DI -.-> UV
    DI -.-> CV
    DI -.-> JWTS

    %% Click Events
    click P "https://github.com/luanroger/allinoneaspnet/blob/main/Program.cs"
    click UEP "https://github.com/luanroger/allinoneaspnet/blob/main/Endpoints/UserEndpoints.cs"
    click CEP "https://github.com/luanroger/allinoneaspnet/blob/main/Endpoints/ClientEndpoints.cs"
    click UC "https://github.com/luanroger/allinoneaspnet/blob/main/Controllers/UserController.cs"
    click IUC "https://github.com/luanroger/allinoneaspnet/blob/main/Controllers/IUserController.cs"
    click CC "https://github.com/luanroger/allinoneaspnet/blob/main/Controllers/ClientController.cs"
    click ICC "https://github.com/luanroger/allinoneaspnet/blob/main/Controllers/IClientController.cs"
    click UM "https://github.com/luanroger/allinoneaspnet/tree/main/Models/UserModels"
    click CM "https://github.com/luanroger/allinoneaspnet/tree/main/Models/ClientModels"
    click UV "https://github.com/luanroger/allinoneaspnet/tree/main/Validators/UserValidators"
    click CV "https://github.com/luanroger/allinoneaspnet/tree/main/Validators/ClientValidators"
    click EX "https://github.com/luanroger/allinoneaspnet/tree/main/Exceptions"
    click UR "https://github.com/luanroger/allinoneaspnet/blob/main/Repositories/UserRepository.cs"
    click CR "https://github.com/luanroger/allinoneaspnet/blob/main/Repositories/ClientRepository.cs"
    click UIR "https://github.com/luanroger/allinoneaspnet/blob/main/Repositories/IUserRepository.cs"
    click CIR "https://github.com/luanroger/allinoneaspnet/blob/main/Repositories/IClientRepository.cs"
    click DB "https://github.com/luanroger/allinoneaspnet/blob/main/Repositories/Contexts/DatabaseContext.cs"
    click JWTS "https://github.com/luanroger/allinoneaspnet/blob/main/Services/Jwt/JwtService.cs"
    click JWTC "https://github.com/luanroger/allinoneaspnet/blob/main/Services/Jwt/JwtConsts.cs"

    %% Class Definitions
    classDef external fill:#fceabb,stroke:#e88900,stroke-width:2px;
    classDef api fill:#c8e1ff,stroke:#007acc,stroke-width:2px;
    classDef endpoints fill:#d0f0c0,stroke:#006400,stroke-width:2px;
    classDef domain fill:#ffd1dc,stroke:#ff69b4,stroke-width:2px;
    classDef persistence fill:#e6e6fa,stroke:#9370db,stroke-width:2px;
    classDef database fill:#fffacd,stroke:#daa520,stroke-width:2px;
    classDef cross fill:#ffe4e1,stroke:#ff4500,stroke-width:2px;
    classDef di fill:#d3d3d3,stroke:#696969,stroke-width:2px;
```
