# xpnsn/banking-app architecture

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

- Interactive diagram: https://gitdiagram.com/xpnsn/banking-app
- Repository: https://github.com/xpnsn/banking-app

## Overview

##### Main components
a. External Actors:
- User (web or mobile client)
- Admin user
b. Infrastructure Services:
- API‐Gateway (Spring Cloud Gateway or Zuul)
- Eureka Server (service registry)
c. Microservices:
- Security Service (authentication, authorization, JWT issuance)
- Accounts Service (account CRUD, balance operations)
- Transactions Service (recording credits/debits, transfers)
- Notifications Service (email/SMS alerts)
d. Data Stores:
- One database per microservice (e.g., PostgreSQL/MySQL instances)
e. (Optional) Shared Components:

##### Relationships & data flow
a. Client → API‐Gateway: all incoming HTTP(S) requests pass through the gateway.
b. API‐Gateway ↔ Eureka: the gateway queries Eureka to discover the addresses of the downstream microservices.
c. API‐Gateway → Security Service: login/registration flows are forwarded to the Security Service.
d. Security Service → Database: persists user credentials & roles.
e. API‐Gateway → Accounts & Transactions Services: after validating JWT, routes incoming account/transaction API calls.
f. Accounts & Transactions Services → Security Service: use Feign clients + interceptor to validate tokens and fetch user details (via internal calls).
g. Accounts Service → Database (A): stores account entities, statuses, types.
h. Transactions Service → Database (T): stores transaction records, statuses.
i. Accounts ↔ Transactions: Transactions Service may call Accounts Service (Feign) to retrieve account details or check balances before posting transactions.
j. Notifications Service: invoked either synchronously by other services after a transaction/account event, or asynchronously via an event broker (if extended). It pushes out notifications to users.
k. Notifications Service → Database (N): logs sent notifications (if required).

##### Architectural patterns & principles
- Microservices decomposition: each bounded context (security, accounts, transactions, notifications) lives in its own Spring Boot project.
- Service discovery: Eureka server for dynamic registration/resolution.
- API gateway: single entry point, cross‐cutting concerns (authentication filter, request routing).
- Feign HTTP clients + interceptors: for inter-service calls with token propagation.
- Per-service data persistence: loose coupling, data autonomy.
- Centralized exception handling and DTO mapping: consistent API contracts.

## Diagram (Mermaid)

```mermaid
graph TB
    %% External Actors
    User["User (Web/Mobile)"]:::external
    Admin["Admin User"]:::external

    %% Infrastructure
    subgraph "Infrastructure"
        direction TB
        ApiGateway["API Gateway"]:::gateway
        Eureka["Eureka Server"]:::registry
    end

    %% Microservices
    subgraph "Services"
        direction TB

        subgraph "Security Service"
            direction TB
            SecController["Controller"]:::component
            SecConfig["Config"]:::component
            SecServiceLayer["Service Layer"]:::component
            SecRepo["Repository"]:::component
            SecurityDB["Database (Security)"]:::database
        end

        subgraph "Accounts Service"
            direction TB
            AccController["Controller"]:::component
            AccConfig["SecurityConfig"]:::component
            AccServiceLayer["Service Layer"]:::component
            AccRepo["Repository"]:::component
            AccFeign["Feign Client"]:::component
            AccInterceptor["Interceptor"]:::component
            AccountsDB["Database (Accounts)"]:::database
        end

        subgraph "Transactions Service"
            direction TB
            TxController["Controller"]:::component
            TxConfig["SecurityConfig"]:::component
            TxServiceLayer["Service Layer"]:::component
            TxRepo["Repository"]:::component
            TxFeign["Feign Clients"]:::component
            TxInterceptor["Interceptor"]:::component
            TransactionsDB["Database (Transactions)"]:::database
        end

        subgraph "Notifications Service"
            direction TB
            NotifApp["Main Application"]:::component
            NotifConfig["application.properties"]:::component
            NotificationsDB["Database (Notifications)"]:::database
        end
    end

    %% Flows
    User -->|"HTTP(S) Requests"| ApiGateway
    Admin -->|"HTTP(S) Requests"| ApiGateway
    ApiGateway -->|"Service Discovery"| Eureka
    ApiGateway -->|"REST: Auth Requests"| SecController
    ApiGateway -->|"REST: Account APIs"| AccController
    ApiGateway -->|"REST: Transaction APIs"| TxController

    SecController -->|"CRUD Credentials"| SecRepo
    SecController -->|"Business Logic"| SecServiceLayer
    SecServiceLayer -->|"Persist Data"| SecurityDB

    AccController -->|"Business Logic"| AccServiceLayer
    AccServiceLayer -->|"Persist Data"| AccountsDB
    AccServiceLayer -->|"Validate Token / User Details (Feign)"| SecServiceLayer
    AccServiceLayer -->|"FeignClientInterceptor"| AccInterceptor
    AccServiceLayer -->|"SecurityConfig"| AccConfig
    AccServiceLayer -->|"SecurityFeignClient"| AccFeign

    TxController -->|"Business Logic"| TxServiceLayer
    TxServiceLayer -->|"Persist Data"| TransactionsDB
    TxServiceLayer -->|"Get Account Details (Feign)"| AccServiceLayer
    TxServiceLayer -->|"Validate Token / User Details (Feign)"| SecServiceLayer
    TxServiceLayer -->|"FeignClientInterceptor"| TxInterceptor
    TxServiceLayer -->|"SecurityConfig"| TxConfig
    TxServiceLayer -->|"Transactions Feign Clients"| TxFeign

    AccServiceLayer -->|"Sync Notification"| NotifApp
    TxServiceLayer -->|"Sync Notification"| NotifApp
    NotifApp -->|"Log Notification"| NotificationsDB

    %% Click Events
    click ApiGateway "https://github.com/xpnsn/banking-app/tree/main/SafeVault/Api-Gateway"
    click Eureka "https://github.com/xpnsn/banking-app/tree/main/SafeVault/Eureka-server"
    click SecController "https://github.com/xpnsn/banking-app/tree/main/SafeVault/Security/src/main/java/com/safevault/security/controller"
    click SecConfig "https://github.com/xpnsn/banking-app/tree/main/SafeVault/Security/src/main/java/com/safevault/security/config"
    click SecServiceLayer "https://github.com/xpnsn/banking-app/tree/main/SafeVault/Security/src/main/java/com/safevault/security/service"
    click SecRepo "https://github.com/xpnsn/banking-app/tree/main/SafeVault/Security/src/main/java/com/safevault/security/repository"
    click AccController "https://github.com/xpnsn/banking-app/tree/main/SafeVault/Accounts/src/main/java/com/safevault/accounts/controller"
    click AccConfig "https://github.com/xpnsn/banking-app/blob/main/SafeVault/Accounts/src/main/java/com/safevault/accounts/config/SecurityConfig.java"
    click AccServiceLayer "https://github.com/xpnsn/banking-app/tree/main/SafeVault/Accounts/src/main/java/com/safevault/accounts/service"
    click AccRepo "https://github.com/xpnsn/banking-app/tree/main/SafeVault/Accounts/src/main/java/com/safevault/accounts/repository"
    click AccFeign "https://github.com/xpnsn/banking-app/blob/main/SafeVault/Accounts/src/main/java/com/safevault/accounts/feignClient/SecurityFeignClient.java"
    click AccInterceptor "https://github.com/xpnsn/banking-app/blob/main/SafeVault/Accounts/src/main/java/com/safevault/accounts/interceptor/FeignClientInterceptor.java"
    click TxController "https://github.com/xpnsn/banking-app/tree/main/SafeVault/Transactions/src/main/java/com/safevault/transactions/controller"
    click TxConfig "https://github.com/xpnsn/banking-app/blob/main/SafeVault/Transactions/src/main/java/com/safevault/transactions/config/SecurityConfig.java"
    click TxServiceLayer "https://github.com/xpnsn/banking-app/tree/main/SafeVault/Transactions/src/main/java/com/safevault/transactions/service"
    click TxRepo "https://github.com/xpnsn/banking-app/tree/main/SafeVault/Transactions/src/main/java/com/safevault/transactions/repository"
    click TxFeign "https://github.com/xpnsn/banking-app/tree/main/SafeVault/Transactions/src/main/java/com/safevault/transactions/feignclient"
    click TxInterceptor "https://github.com/xpnsn/banking-app/blob/main/SafeVault/Transactions/src/main/java/com/safevault/transactions/interceptor/FeignClientInterceptor.java"
    click NotifApp "https://github.com/xpnsn/banking-app/blob/main/SafeVault/Notifications/src/main/java/com/safevault/notifications/NotificationsApplication.java"
    click NotifConfig "https://github.com/xpnsn/banking-app/blob/main/SafeVault/Notifications/src/main/resources/application.properties"

    %% Styles
    classDef external fill:#f9f,stroke:#333,stroke-width:1px
    classDef gateway fill:#aaffee,stroke:#333,stroke-width:1px
    classDef registry fill:#ddaaff,stroke:#333,stroke-width:1px
    classDef component fill:#bbddff,stroke:#333,stroke-width:1px
    classDef database fill:#ffeeaa,stroke:#333,stroke-width:1px
```
