# alexsiilvaa/pequibank architecture

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

- Interactive diagram: https://gitdiagram.com/alexsiilvaa/pequibank
- Repository: https://github.com/alexsiilvaa/pequibank

## Overview

##### Main Components
- Client layers (e.g., REST clients, load‐test tools)
- Nginx reverse proxy / API gateway
- .NET WebAPI service, comprised of:
– Presentation (endpoints, exception handlers, health checks)
– Application (use‐case handlers, interfaces)
– Domain (entities, business rules, exceptions)
– Infrastructure (data access, background services, settings)
- PostgreSQL database
- Docker & Docker‐Compose orchestration
- Load‐testing setup (Bruno scripts, Gatling simulation results)

##### Relationships & Data Flows
1. External clients (or load‐test tools) → HTTP requests → Nginx
2. Nginx routes to .NET service (Presentation)
3. Presentation invokes Application features (CreateFinancialTransaction, GetBankStatement)
4. Application layer calls Repository interfaces (ICustomerRepository, IFinancialTransactionRepository)
5. Infrastructure implements repositories → Database
6. BackgroundServices (CreateFinancialTransactionBackgroundService) subscribe/poll and perform async work → Repositories → DB
7. HealthCheck endpoint → Infrastructure health checks (DatabaseHealthCheck) → DB
8. Docker‐Compose manages containers: nginx, api service, postgres; init.sql seeds DB
9. Load‐testing scripts (Bruno .bru) and Gatling results connect to Nginx to simulate traffic

##### Architectural Patterns & Key Technologies
- Layered (Onion/Clean) architecture: Presentation → Application → Domain → Infrastructure
- Dependency inversion: interfaces in Application (ICustomerRepository, etc.) injected into Infrastructure
- Hosted background service for asynchronous transaction creation
- Health check endpoints for liveness/readiness
- Containerization: Dockerfile for app, docker-compose.yml for multi‐container setup
- Configuration: appsettings.{Development,Production}.json, DatabaseOptions + validator
- Reverse proxy: nginx.conf for SSL/traffic management
- Persistence: PostgreSQL with init.sql seeding

##### Detailed Elements to Capture
– Docker orchestration: show docker-compose linking containers
– init.sql seeder as part of DB container initialization
– Bruno scripts (.bru) and environments (Dev, Live) as load‐test definitions
– Gatling output directory under load‐test for performance reporting
– BackgroundServices block inside the API container interacting with the Application/Repository
– HealthCheck endpoint feeding into Nginx health checks (if configured)

## Diagram (Mermaid)

```mermaid
graph TD
    %% External entities
    Clients["External Clients"]:::external
    subgraph "Load Testing" 
        BrunoScripts["Bruno Scripts"]:::external
        Gatling["Gatling Results"]:::external
    end

    %% Docker Compose group
    subgraph "Docker-Compose"
        subgraph "nginx" 
            Nginx["Nginx Reverse Proxy"]:::external
        end
        subgraph "pequibank-api"
            subgraph "Presentation Layer"
                Program["Program.cs"]:::presentation
                Endpoints["ClienteEndpoints.cs"]:::presentation
                ExceptionHandlers["ExceptionHandlers"]:::presentation
                HealthCheck["DatabaseHealthCheck.cs"]:::presentation
                Extensions["Extensions"]:::presentation
                AppSettings["appsettings.json"]:::presentation
                AppSettingsDev["appsettings.Development.json"]:::presentation
                LaunchSettings["launchSettings.json"]:::presentation
            end
            subgraph "Application Layer"
                CreateFTFeature["CreateFinancialTransaction Feature"]:::application
                GetBSFeature["GetBankStatement Feature"]:::application
                ICustomerRepo["ICustomerRepository.cs"]:::application
                ITransactionRepo["IFinancialTransactionRepository.cs"]:::application
            end
            subgraph "Domain Layer"
                CustomerModel["Customer.cs"]:::domain
                FTModel["FinancialTransaction.cs"]:::domain
                DomainExceptions["Domain Exceptions"]:::domain
            end
            subgraph "Infrastructure Layer"
                DatabaseData["Database.cs"]:::infrastructure
                IDatabase["IDatabase.cs"]:::infrastructure
                CustomerRepoImpl["CustomerRepository.cs"]:::infrastructure
                FTRepoImpl["FinancialTransactionRepository.cs"]:::infrastructure
                DBOptions["DatabaseOptions & Validator"]:::infrastructure
                BGService["CreateFinancialTransactionBackgroundService.cs"]:::infrastructure
            end
        end
        subgraph "postgres"
            Postgres["PostgreSQL Database"]:::external
            Seeder["init.sql"]:::external
        end
        Dockerfile["Dockerfile"]:::external
        ComposeFile["docker-compose.yml"]:::external
        Makefile["Makefile"]:::external
    end

    %% Connections
    Clients -->|HTTP Requests| Nginx
    BrunoScripts -->|Simulated Traffic| Nginx
    Gatling -->|Performance Reports| Nginx
    Nginx -->|Routes Requests| Program
    Program -->|calls Endpoints| Endpoints
    Endpoints -->|handles Health| HealthCheck
    Endpoints -->|invokes Use-Cases| CreateFTFeature
    Endpoints -->|invokes Use-Cases| GetBSFeature
    CreateFTFeature -->|uses| ICustomerRepo
    CreateFTFeature -->|uses| ITransactionRepo
    GetBSFeature -->|uses| ICustomerRepo
    GetBSFeature -->|uses| ITransactionRepo
    ICustomerRepo -->|implemented by| CustomerRepoImpl
    ITransactionRepo -->|implemented by| FTRepoImpl
    CustomerRepoImpl -->|reads/writes| Postgres
    FTRepoImpl -->|reads/writes| Postgres
    BGService -->|uses| CustomerRepoImpl
    BGService -->|uses| FTRepoImpl
    HealthCheck -->|checks| Postgres
    AppSettings -->|configures| Program
    AppSettingsDev -->|configures| Program
    LaunchSettings -->|configures| Program
    Dockerfile -->|builds| pequibank-api
    ComposeFile -->|orchestrates| nginx
    ComposeFile -->|orchestrates| pequibank-api
    ComposeFile -->|orchestrates| postgres
    Makefile -->|runs| ComposeFile
    Seeder -->|initializes| Postgres

    %% Click Events
    click Nginx "https://github.com/alexsiilvaa/pequibank/blob/main/nginx.conf"
    click Program "https://github.com/alexsiilvaa/pequibank/blob/main/src/Presentation/Program.cs"
    click Endpoints "https://github.com/alexsiilvaa/pequibank/blob/main/src/Presentation/Endpoints/ClienteEndpoints.cs"
    click ExceptionHandlers "https://github.com/alexsiilvaa/pequibank/tree/main/src/Presentation/ExceptionHandlers"
    click HealthCheck "https://github.com/alexsiilvaa/pequibank/blob/main/src/Presentation/Health/DatabaseHealthCheck.cs"
    click Extensions "https://github.com/alexsiilvaa/pequibank/tree/main/src/Presentation/Extensions"
    click AppSettings "https://github.com/alexsiilvaa/pequibank/blob/main/src/Presentation/appsettings.json"
    click AppSettingsDev "https://github.com/alexsiilvaa/pequibank/blob/main/src/Presentation/appsettings.Development.json"
    click LaunchSettings "https://github.com/alexsiilvaa/pequibank/blob/main/src/Presentation/Properties/launchSettings.json"
    click CreateFTFeature "https://github.com/alexsiilvaa/pequibank/tree/main/src/Application/Features/CreateFinancialTransaction/*"
    click GetBSFeature "https://github.com/alexsiilvaa/pequibank/tree/main/src/Application/Features/GetBankStatement/*"
    click ICustomerRepo "https://github.com/alexsiilvaa/pequibank/blob/main/src/Application/Repository/ICustomerRepository.cs"
    click ITransactionRepo "https://github.com/alexsiilvaa/pequibank/blob/main/src/Application/Repository/IFinancialTransactionRepository.cs"
    click CustomerModel "https://github.com/alexsiilvaa/pequibank/blob/main/src/Domain/Model/Customer.cs"
    click FTModel "https://github.com/alexsiilvaa/pequibank/blob/main/src/Domain/Model/FinancialTransaction.cs"
    click DomainExceptions "https://github.com/alexsiilvaa/pequibank/tree/main/src/Domain/Exceptions"
    click DatabaseData "https://github.com/alexsiilvaa/pequibank/blob/main/src/Infrastructure/Data/Database.cs"
    click IDatabase "https://github.com/alexsiilvaa/pequibank/blob/main/src/Infrastructure/Data/IDatabase.cs"
    click CustomerRepoImpl "https://github.com/alexsiilvaa/pequibank/blob/main/src/Infrastructure/Repository/CustomerRepository.cs"
    click FTRepoImpl "https://github.com/alexsiilvaa/pequibank/blob/main/src/Infrastructure/Repository/FinancialTransactionRepository.cs"
    click DBOptions "https://github.com/alexsiilvaa/pequibank/blob/main/src/Infrastructure/Settings/DatabaseOptions.cs"
    click BGService "https://github.com/alexsiilvaa/pequibank/blob/main/src/Infrastructure/BackgroundServices/CreateFinancialTransactionBackgroundService.cs"
    click Seeder "https://github.com/alexsiilvaa/pequibank/blob/main/init.sql"
    click Dockerfile "https://github.com/alexsiilvaa/pequibank/tree/main/Dockerfile"
    click ComposeFile "https://github.com/alexsiilvaa/pequibank/blob/main/docker-compose.yml"
    click Makefile "https://github.com/alexsiilvaa/pequibank/tree/main/Makefile"
    click BrunoScripts "https://github.com/alexsiilvaa/pequibank/blob/main/bruno/Create Transaction.bru"
    click Gatling "https://github.com/alexsiilvaa/pequibank/tree/main/load-test/simulation-20240303223949692/"

    %% Styles
    classDef external fill:#cccccc,stroke:#333,stroke-width:1px
    classDef presentation fill:#b7e4c7,stroke:#333,stroke-width:1px
    classDef application fill:#d9f7be,stroke:#333,stroke-width:1px
    classDef domain fill:#a0c4ff,stroke:#333,stroke-width:1px
    classDef infrastructure fill:#ffd6a5,stroke:#333,stroke-width:1px
```
