# bisiolayemi/finpay architecture

> Architecture diagram of the GitHub repository bisiolayemi/finpay, 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/bisiolayemi/finpay
- Repository: https://github.com/bisiolayemi/finpay

## Overview

##### Main System Components
- NestJS Server Setup: Represent the application’s entry point (src/main.ts) that bootstraps the application.
- Modules: Each module in src/modules (accounts, auth, deposits, invoices, payments, transactions, users, virtual-cards, withdrawals) should be depicted as an independent component. This establishes the modular architecture that encapsulates its controllers, services, and data entities.
- Common Infrastructure: Include components for common utilities like authentication (auth strategies, guards), exception handling (HTTP exception filters), logging interceptors, and decorators—all used across modules.
- Configuration: A separate component/block representing configuration settings (JWT, database, environment, Swagger, validation) found in src/config.
- External Services and Gateways: Highlight external integrations like the Stripe payment gateway (located in src/modules/payments/gateways/stripe.gateway.ts) which connects the internal system with external payment processing.

##### Relationships and Interactions
- Controller-Service Communication: Illustrate that controllers pass client requests to the corresponding service layer within each module.
- Service Persistence: Represent how services interact with data entities and the database (configured via src/config/database.config.ts) to persist or retrieve information.
- Cross-Cutting Concerns: Show that requests can be intercepted by guards (authentication/authorization), filters (global error handling), and interceptors (logging) defined in the “common” directory.
- External API Communications: For modules that rely on external services (like the payments module using a Stripe gateway), indicate the connection to external APIs.
- Configuration Management: Indicate that configuration settings (from src/config) are “injected” into various modules for uniform behavior and environment handling.

##### Architectural Patterns and Design Principles
- Modularity: Emphasize the modular nature that allows each feature to be developed, maintained, and replaced independently.

##### Relevant Technologies and Framework-Specific Elements
- NestJS Framework: Clearly state that the application is built on NestJS.
- TypeScript: As this project is written in TypeScript (as evidenced by the tsconfig files), note that this typing system helps maintain code quality.
- Testing Infrastructure: Optionally represent the existence of unit and end-to-end tests (under the test directory) to indicate robust testing practices.
- Tools/Libraries: Mention supporting libraries and configurations such as ESLint, Prettier, Swagger (for API docs), and authentication strategies (JWT & local).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% API Layer
    HTTP["HTTP Request"]:::api
    Entry["NestJS Entry Point (main.ts)"]:::api
    HTTP -->|"routes"| Entry

    %% Modules Subgraph
    subgraph "Modules"
        Accounts["Accounts Module"]:::module
        Auth["Auth Module"]:::module
        Deposits["Deposits Module"]:::module
        Invoices["Invoices Module"]:::module
        Payments["Payments Module"]:::module
        Transactions["Transactions Module"]:::module
        Users["Users Module"]:::module
        VirtualCards["Virtual Cards Module"]:::module
        Withdrawals["Withdrawals Module"]:::module
    end

    Entry --> Accounts
    Entry --> Auth
    Entry --> Deposits
    Entry --> Invoices
    Entry --> Payments
    Entry --> Transactions
    Entry --> Users
    Entry --> VirtualCards
    Entry --> Withdrawals

    %% Payments Integration Subgraph
    subgraph "Payments Integration"
        StripeGateway["Stripe Gateway"]:::module
    end
    Payments -->|"uses_gateway"| StripeGateway
    StripeGateway -->|"external_call"| ExternalStripe["External Payment API (Stripe)"]:::external

    %% Infrastructure & Cross-Cutting Subgraph
    subgraph "Infrastructure & Cross-Cutting"
        CommonInfra["Common Infrastructure"]:::infra
        Config["Configuration Settings"]:::infra
        Shared["Shared Resources"]:::infra
    end

    %% Link Modules to Infrastructure
    Accounts --- CommonInfra
    Auth --- CommonInfra
    Deposits --- CommonInfra
    Invoices --- CommonInfra
    Payments --- CommonInfra
    Transactions --- CommonInfra
    Users --- CommonInfra
    VirtualCards --- CommonInfra
    Withdrawals --- CommonInfra

    Accounts --- Config
    Auth --- Config
    Deposits --- Config
    Invoices --- Config
    Payments --- Config
    Transactions --- Config
    Users --- Config
    VirtualCards --- Config
    Withdrawals --- Config

    Accounts --- Shared
    Auth --- Shared
    Deposits --- Shared
    Invoices --- Shared
    Payments --- Shared
    Transactions --- Shared
    Users --- Shared
    VirtualCards --- Shared
    Withdrawals --- Shared

    %% Click Events
    click Entry "https://github.com/bisiolayemi/finpay/blob/main/src/main.ts"
    click Accounts "https://github.com/bisiolayemi/finpay/tree/main/src/modules/accounts"
    click Auth "https://github.com/bisiolayemi/finpay/tree/main/src/modules/auth"
    click Deposits "https://github.com/bisiolayemi/finpay/tree/main/src/modules/deposits"
    click Invoices "https://github.com/bisiolayemi/finpay/tree/main/src/modules/invoices"
    click Payments "https://github.com/bisiolayemi/finpay/tree/main/src/modules/payments"
    click StripeGateway "https://github.com/bisiolayemi/finpay/blob/main/src/modules/payments/gateways/stripe.gateway.ts"
    click Transactions "https://github.com/bisiolayemi/finpay/tree/main/src/modules/transactions"
    click Users "https://github.com/bisiolayemi/finpay/tree/main/src/modules/users"
    click VirtualCards "https://github.com/bisiolayemi/finpay/tree/main/src/modules/virtual-cards"
    click Withdrawals "https://github.com/bisiolayemi/finpay/tree/main/src/modules/withdrawals"
    click CommonInfra "https://github.com/bisiolayemi/finpay/tree/main/src/common"
    click Config "https://github.com/bisiolayemi/finpay/tree/main/src/config"
    click Shared "https://github.com/bisiolayemi/finpay/tree/main/src/shared"

    %% Styles
    classDef api fill:#f9e79f,stroke:#b9770e,stroke-width:2px;
    classDef module fill:#aed6f1,stroke:#2874a6,stroke-width:2px;
    classDef infra fill:#d5f5e3,stroke:#28b463,stroke-width:2px;
    classDef external fill:#f5b7b1,stroke:#c0392b,stroke-width:2px;
```
