# ismael-asensio/pjcuentabancaria architecture

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

- Interactive diagram: https://gitdiagram.com/ismael-asensio/pjcuentabancaria
- Repository: https://github.com/ismael-asensio/pjcuentabancaria

## Overview

##### Project Type and Purpose
- This project is a RESTful API built in .NET 8 designed for managing bank accounts including creating customers, managing monetary transactions (deposits and withdrawals), and retrieving account balances and transaction histories.
- The README emphasizes API endpoints for clients, bank accounts, and transactions, and it also indicates the use of an In-Memory database for simplicity during development/testing.

##### File Structure
- The top-level solution is represented by "pjCuentaBancaria.sln" and includes the main project directory (pjCuentaBancaria) and a test project (TestBanco).
- Within the main project directory, you have a clear layered structure:
- Controllers – Implements the API endpoints (BankAccountController, CustomerController, TransactionController).
- Models – Defines the entities (BankAccount, Customer, Transaction) used throughout the API.
- Data – Contains the ApplicationDbContext and configuration for the In-Memory database.
- Repositories – Contains repository interfaces and implementations (such as IBankAccountRepository and its implementation). This layer abstracts data access.
- Services – Contains business logic and service interfaces with concrete implementations (BankAccountService, CustomerService, TransactionService). Services act as intermediaries between controllers and repositories.
- The test project (TestBanco) contains unit tests that verify the functionality of services, repositories, and controllers.
- Configuration files (appsettings.json and appsettings.Development.json) guide deployment-specific settings.

##### Key Architectural Elements
a. Main Components:
- API Controllers: Gateway for client requests.
- Services: Business logic processing.
- Repositories: Data persistence abstraction.
- Data Layer: EF Core ApplicationDbContext, using an In-Memory database.
- Models: Domain entities representing customers, bank accounts, and transactions.
- Test Suite: Ensures proper functionality of individual layers.

b. Relationships and Interactions:
- Clients interact with API endpoints exposed by Controllers.
- Controllers delegate requests to Services.
- Services use Repositories to perform CRUD operations on Models.
- Repository layer interacts with the EF Core data context that accesses the In-Memory database.
- The test project simulates interactions and validates functionality over these layers.

c. Architectural Patterns and Design Principles:
- Layered Architecture: Clear separation between Controllers (presentation), Services (business logic), and Repositories/Data Access.
- Repository Pattern: Abstracts and encapsulates database access logic.
- Dependency Injection: Likely used for injecting services and repositories (as is common in .NET projects).
- Clean Code and Separation of Concerns: Data models, business logic, and API controllers are each in distinct folders.

d. Relevant Technologies and Frameworks:
- .NET 8 for API and application framework.
- Entity Framework Core with an In-Memory provider for data persistence.
- Testing frameworks integrated with .NET (via dotnet test).
- Tools such as Visual Studio or VSCode for development and debugging.
- Postman/Swagger for API testing.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global Entities
    Client["External Client (Postman/Swagger)"]:::client

    %% API Layer (Controllers)
    subgraph "API Layer (Controllers)"
        BAController["BankAccountController"]:::controller
        CustController["CustomerController"]:::controller
        TransController["TransactionController"]:::controller
    end

    %% Business Layer (Services)
    subgraph "Business Layer (Services)"
        BAService["BankAccountService"]:::service
        CustService["CustomerService"]:::service
        TransService["TransactionService"]:::service
    end

    %% Data Access Layer
    subgraph "Data Access Layer"
        subgraph "Repositories"
            IBankRepo["IBankAccountRepository"]:::repository
            ICustomerRepo["ICustomerRepository"]:::repository
            ITransactionRepo["ICustomerRepository"]:::repository
            BankRepo["BankAccountRepository"]:::repository
            CustomerRepo["CustomerRepository"]:::repository
            TransactionRepo["TransactionRepository"]:::repository
        end
        DbContext["ApplicationDbContext (In-Memory DB)"]:::database
    end

    %% Domain Models
    subgraph "Domain Models"
        BankModel["BankAccount"]:::model
        CustomerModel["Customer"]:::model
        TransactionModel["Transaction"]:::model
    end

    %% Testing (Unit Tests)
    subgraph "Testing (Unit Tests)"
        BAServiceTest["BankAccountServiceTests"]:::test
        CustServiceTest["CustomerServiceTests"]:::test
        TransServiceTest["TransactionServiceTests"]:::test
    end

    %% Connections from Client to Controllers
    Client -->|"calls"| BAController
    Client -->|"calls"| CustController
    Client -->|"calls"| TransController

    %% Controllers delegate to Services
    BAController -->|"delegates"| BAService
    CustController -->|"delegates"| CustService
    TransController -->|"delegates"| TransService

    %% Services use Repository interfaces
    BAService -->|"uses"| IBankRepo
    CustService -->|"uses"| ICustomerRepo
    TransService -->|"uses"| ITransactionRepo

    %% Interfaces implemented by Repositories
    IBankRepo -->|"implementedBy"| BankRepo
    ICustomerRepo -->|"implementedBy"| CustomerRepo
    ITransactionRepo -->|"implementedBy"| TransactionRepo

    %% Repositories access Data Persistence
    BankRepo -->|"accesses"| DbContext
    CustomerRepo -->|"accesses"| DbContext
    TransactionRepo -->|"accesses"| DbContext

    %% Data context maps to Domain Models
    DbContext -->|"mapsTo"| BankModel
    DbContext -->|"mapsTo"| CustomerModel
    DbContext -->|"mapsTo"| TransactionModel

    %% Unit Tests validate Services
    BAServiceTest -->|"tests"| BAService
    CustServiceTest -->|"tests"| CustService
    TransServiceTest -->|"tests"| TransService

    %% Click Events for API Controllers
    click BAController "https://github.com/ismael-asensio/pjcuentabancaria/blob/main/pjCuentaBancaria/Controllers/BankAccountController.cs"
    click CustController "https://github.com/ismael-asensio/pjcuentabancaria/blob/main/pjCuentaBancaria/Controllers/CustomerController.cs"
    click TransController "https://github.com/ismael-asensio/pjcuentabancaria/blob/main/pjCuentaBancaria/Controllers/TransactionController.cs"
    
    %% Click Events for Business Services
    click BAService "https://github.com/ismael-asensio/pjcuentabancaria/blob/main/pjCuentaBancaria/Services/BankAccountService.cs"
    click CustService "https://github.com/ismael-asensio/pjcuentabancaria/blob/main/pjCuentaBancaria/Services/CustomerService.cs"
    click TransService "https://github.com/ismael-asensio/pjcuentabancaria/blob/main/pjCuentaBancaria/Services/TransactionService.cs"

    %% Click Events for Repository Interfaces and Implementations
    click IBankRepo "https://github.com/ismael-asensio/pjcuentabancaria/blob/main/pjCuentaBancaria/Repositories/IBankAccountRepository.cs"
    click ICustomerRepo "https://github.com/ismael-asensio/pjcuentabancaria/blob/main/pjCuentaBancaria/Repositories/ICustomerRepository.cs"
    click ITransactionRepo "https://github.com/ismael-asensio/pjcuentabancaria/blob/main/pjCuentaBancaria/Repositories/ITransactionRepository.cs"
    click BankRepo "https://github.com/ismael-asensio/pjcuentabancaria/blob/main/pjCuentaBancaria/Repositories/BankAccountRepository.cs"
    click CustomerRepo "https://github.com/ismael-asensio/pjcuentabancaria/blob/main/pjCuentaBancaria/Repositories/CustomerRepository.cs"
    click TransactionRepo "https://github.com/ismael-asensio/pjcuentabancaria/blob/main/pjCuentaBancaria/Repositories/TransactionRepository.cs"

    %% Click Event for Data Persistence
    click DbContext "https://github.com/ismael-asensio/pjcuentabancaria/blob/main/pjCuentaBancaria/Data/ApplicationDbContext.cs"

    %% Click Events for Domain Models
    click BankModel "https://github.com/ismael-asensio/pjcuentabancaria/blob/main/pjCuentaBancaria/Models/BankAccount.cs"
    click CustomerModel "https://github.com/ismael-asensio/pjcuentabancaria/blob/main/pjCuentaBancaria/Models/Customer.cs"
    click TransactionModel "https://github.com/ismael-asensio/pjcuentabancaria/blob/main/pjCuentaBancaria/Models/Transaction.cs"

    %% Click Events for Testing
    click BAServiceTest "https://github.com/ismael-asensio/pjcuentabancaria/blob/main/TestBanco/Test/BankAccountServiceTests.cs"
    click CustServiceTest "https://github.com/ismael-asensio/pjcuentabancaria/blob/main/TestBanco/Test/CustomerServiceTests.cs"
    click TransServiceTest "https://github.com/ismael-asensio/pjcuentabancaria/blob/main/TestBanco/Test/TransactionServiceTests.cs"

    %% Styles
    classDef client fill:#FFD700,stroke:#DAA520,stroke-width:2px;
    classDef controller fill:#ADD8E6,stroke:#0000FF,stroke-width:2px;
    classDef service fill:#90EE90,stroke:#008000,stroke-width:2px;
    classDef repository fill:#FFA07A,stroke:#FF4500,stroke-width:2px;
    classDef database fill:#D3D3D3,stroke:#696969,stroke-width:2px;
    classDef model fill:#E6E6FA,stroke:#800080,stroke-width:2px;
    classDef test fill:#F0E68C,stroke:#BDB76B,stroke-width:2px;
```
