# oscargps/bank-aseessment-back architecture

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

- Interactive diagram: https://gitdiagram.com/oscargps/bank-aseessment-back
- Repository: https://github.com/oscargps/bank-aseessment-back

## Overview

##### Main Components
- API Gateway / Entry Point: Represent the main.ts file as the application bootstrap.
- Module Structure: Separate modules such as “bank-store” (which includes sub-modules for deliveries, products, and transactions) and “core” (which handles database and health-check functionality).
- Common Components: Include the “common” directory for middleware like the API key middleware.
- Database Layer: Highlight components under “src/modules/core/database” which include entities, migrations, and seeds that handle data persistence using TypeORM and PostgreSQL.
- External Services: Note the integration points for external APIs (for example, WOMPI and Bank APIs) as mentioned in the environment variables and service files.
- Testing: Include a note about tests (Jest specs) to indicate supporting components for verifying functionality.

##### Relationships and Interactions
- Flow from the client making an HTTP request to the API, which is handled by controllers in different modules (deliveries.controller, products.controller, transactions.controller, health-check.controller).
- That controllers delegate business logic to their corresponding services in the “infrastructure/services” directories.
- Connection between the domain layer (DTOs and business logic) and the persistence layer (entities defined in the “core/database/domain/entities”).

##### Architectural Patterns and Design Principles
- Layered Architecture: Demonstrate separation between the API layer (controllers), business logic (services, mappers, and utilities), and data persistence (repositories/entities).
- Dependency Injection: Emphasize that each module (and even middleware) leverages NestJS’s DI container to manage service dependencies.
- Clean Separation of Concerns: Each module (e.g., transactions, deliveries, products) has its own substructure dividing domain types, controllers, and services.

##### Specify Technologies & Frameworks
- NestJS for the API framework
- TypeScript for static typing and modern JavaScript features
- TypeORM for Data Access and ORM
- PostgreSQL as the database engine
- Jest for testing and Swagger/OpenAPI for documentation

##### Detailing the Essential Elements
- Connecting lines to represent that controllers in each module depend on service layers, which in turn interact with the database layer.

## Diagram (Mermaid)

```mermaid
flowchart TD
    Client["Client"]:::external
    API_Gateway["API Gateway (Bootstrap)"]:::apigateway
    Common_MW["Common Middleware (API Key)"]:::middleware
    DI_Container["NestJS DI Container"]:::di

    Client -->|"HTTP_Request"| API_Gateway
    API_Gateway -->|"Init"| Common_MW

    subgraph "Bank Store Module"
        BankStore_Module["Bank Store Module"]:::module
        Deliveries["Deliveries Module\n(Controllers, DTOs, Services)"]:::module
        Products["Products Module\n(Controllers, Services)"]:::module
        Transactions["Transactions Module\n(Business Logic, Mappers, DTOs)"]:::module
        BankStore_Module --> Deliveries
        BankStore_Module --> Products
        BankStore_Module --> Transactions
    end

    subgraph "Core Modules"
        Core_DB["Core Database\n(Entities, Migrations, Seeds)"]:::database
        HealthCheck["Health Check Module\n(Controllers, Services)"]:::module
    end

    Common_MW -->|"Route_Request"| BankStore_Module
    Common_MW -->|"HealthCheck_Request"| HealthCheck

    Deliveries -->|"DB_Query"| Core_DB
    Products -->|"DB_Query"| Core_DB
    Transactions -->|"DB_Query"| Core_DB
    Transactions -->|"API_Call"| External_Bank

    BankStore_Module ---|"Injects_Services"| DI_Container
    HealthCheck ---|"Injects_Services"| DI_Container
    Core_DB ---|"Managed_by"| DI_Container

    External_Bank["External Bank API Integration"]:::external

    click API_Gateway "https://github.com/oscargps/bank-aseessment-back/blob/main/src/main.ts"
    click BankStore_Module "https://github.com/oscargps/bank-aseessment-back/tree/main/src/modules/bank-store"
    click Deliveries "https://github.com/oscargps/bank-aseessment-back/tree/main/src/modules/bank-store/deliveries"
    click Products "https://github.com/oscargps/bank-aseessment-back/tree/main/src/modules/bank-store/products"
    click Transactions "https://github.com/oscargps/bank-aseessment-back/tree/main/src/modules/bank-store/transactions"
    click Core_DB "https://github.com/oscargps/bank-aseessment-back/tree/main/src/modules/core/database"
    click HealthCheck "https://github.com/oscargps/bank-aseessment-back/tree/main/src/modules/core/health-check"
    click Common_MW "https://github.com/oscargps/bank-aseessment-back/blob/main/src/common/middleware/api-key.middleware.ts"
    click External_Bank "https://github.com/oscargps/bank-aseessment-back/blob/main/src/modules/bank-store/transactions/infrastructure/services/bank.service.ts"

    classDef apigateway fill:#d1c4e9,stroke:#4a148c,color:#000;
    classDef middleware fill:#ffe0b2,stroke:#ef6c00,color:#000;
    classDef module fill:#bbdefb,stroke:#0d47a1,color:#000;
    classDef database fill:#c8e6c9,stroke:#2e7d32,color:#000;
    classDef external fill:#ffcdd2,stroke:#c62828,color:#000;
    classDef di fill:#dcedc8,stroke:#558b2f,color:#000;
```
