# rocafi/api_banca architecture

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

- Interactive diagram: https://gitdiagram.com/rocafi/api_banca
- Repository: https://github.com/rocafi/api_banca

## Overview

##### Project type and purpose
- API_Banca is a backend Web API built on .NET 8. Its sole responsibility is to expose RESTful endpoints for managing Users, Accounts and Transactions in a simple banking context. It uses Entity Framework Core over a SQLite file-based database. There is also a separate unit-test project (`API_Banca.Tests`).

##### File structure
- Top level:
- API_Banca.sln – solution file.
- API_Banca/ – main Web API project.
- API_Banca.Tests/ – unit tests.
- README.md, .gitignore, etc.
- Inside API_Banca:
- Controllers/ – HTTP layer (AccountController, TransactionController, UserController).
- Services/ – business logic for each aggregate (AccountServices, TransactionServices, UserServices).
- Data/ – EF Core DataContext.
- Models/ – POCOs: User, Account, Transaction.
- Program.cs & launchSettings.json – app host and configuration (DI container, middleware).
- appsettings.json and SQLite files.
- Tests:
- Verify service and data logic via in-memory or test database helpers.

##### README for additional insights
- Confirms it’s a simple CRUD API.
- Endpoints grouped by resource path (/api/user, /api/account, /api/transaction).
- Notes the DB resets by default on startup (`EnsureDeleted()` in Program.cs).
- Shows test execution via `dotnet test`.

##### Elements
Client → Controllers → Services → DataContext → SQLite
- Blue for runtime components (Host, Controllers, Services).
- Green for persistence (DataContext, SQLite).
- Orange for external pieces (Client, Tests).
- Rectangles for code components.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Clients
    Client["Client (Postman / Web / Mobile)"]:::external

    %% API Hosting & Configuration
    subgraph "API Hosting & Configuration"
        direction TB
        ProgramNode["Program.cs \n(Kestrel Host & DI Setup)"]:::runtime
        LaunchSettings["launchSettings.json"]:::runtime
        AppSettings["appsettings.json / appsettings.Development.json"]:::runtime
    end

    %% Controllers Layer
    subgraph "Controllers"
        direction TB
        UCtrl["UserController"]:::runtime
        ACtrl["AccountController"]:::runtime
        TCtrl["TransactionController"]:::runtime
    end

    %% Services Layer
    subgraph "Services"
        direction TB
        USvc["UserServices"]:::runtime
        ASvc["AccountServices"]:::runtime
        TSvc["TransactionServices"]:::runtime
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        DC["DataContext (EF Core)"]:::persistence
    end

    %% Persistence
    DB["SQLite Database\nBanca.sqlite"]:::persistence

    %% Test Project
    Test["API_Banca.Tests\n(Unit Tests)"]:::external

    %% Connections: Client to Host to Controllers
    Client -->|"HTTP Request"| ProgramNode
    ProgramNode -->|"Route to Controller"| UCtrl
    ProgramNode -->|"Route to Controller"| ACtrl
    ProgramNode -->|"Route to Controller"| TCtrl

    %% Controllers to Services via DI
    UCtrl -->|"IUserService → UserServices"| USvc
    ACtrl -->|"IAccountService → AccountServices"| ASvc
    TCtrl -->|"ITransactionService → TransactionServices"| TSvc

    %% Services to DataContext
    USvc -->|"Use DataContext"| DC
    ASvc -->|"Use DataContext"| DC
    TSvc -->|"Use DataContext"| DC

    %% DataContext to Database
    DC -->|"EF Core SQL Queries"| DB
    DB -->|"Query Results"| DC

    %% Return path
    DC --> USvc
    USvc --> UCtrl
    ACtrl --> ProgramNode
    TCtrl --> ProgramNode
    ProgramNode -->|"HTTP Response"| Client

    %% Unit tests invoking services
    Test -.->|"Invokes Services"| USvc
    Test -.->|"Invokes DataContext Helpers"| DC

    %% Click Events
    click ProgramNode "https://github.com/rocafi/api_banca/blob/master/API_Banca/Program.cs"
    click LaunchSettings "https://github.com/rocafi/api_banca/blob/master/API_Banca/Properties/launchSettings.json"
    click AppSettings "https://github.com/rocafi/api_banca/blob/master/API_Banca/appsettings.json"
    click UCtrl "https://github.com/rocafi/api_banca/blob/master/API_Banca/Controllers/UserController.cs"
    click ACtrl "https://github.com/rocafi/api_banca/blob/master/API_Banca/Controllers/AccountController.cs"
    click TCtrl "https://github.com/rocafi/api_banca/blob/master/API_Banca/Controllers/TransactionController.cs"
    click USvc "https://github.com/rocafi/api_banca/blob/master/API_Banca/Services/UserServices.cs"
    click ASvc "https://github.com/rocafi/api_banca/blob/master/API_Banca/Services/AccountServices.cs"
    click TSvc "https://github.com/rocafi/api_banca/blob/master/API_Banca/Services/TransactionServices.cs"
    click DC "https://github.com/rocafi/api_banca/blob/master/API_Banca/Data/DataContext.cs"
    click DB "https://github.com/rocafi/api_banca/blob/master/API_Banca/Banca.sqlite"
    click Test "https://github.com/rocafi/api_banca/blob/master/API_Banca.Tests/API_Banca.Tests.csproj"

    %% Styles
    classDef runtime fill:#D0E8FF,stroke:#057BFF,color:#000
    classDef persistence fill:#E0FFE0,stroke:#00A000,color:#000
    classDef external fill:#FFE8D0,stroke:#FF7800,color:#000
```
