# kartik1502/spring-boot-microservices-banking-application architecture

> Architecture diagram of the GitHub repository kartik1502/spring-boot-microservices-banking-application, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-09-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kartik1502/spring-boot-microservices-banking-application
- Repository: https://github.com/kartik1502/spring-boot-microservices-banking-application

## Overview

##### Project type and purpose
- This is a Spring-Boot Microservices Banking Application. It uses Spring Cloud for service discovery (Eureka), an API Gateway for routing and security, and independent microservices for user management, accounts, fund transfers, and transactions. Each microservice uses its own MySQL database and communicates via Feign clients and service discovery.

##### Main components
a. Clients (Web/Mobile)
b. API Gateway (Spring Cloud Gateway)
c. Service Registry (Eureka)
d. Authentication & Authorization (Keycloak)
e. Microservices:
- User Service
- Account Service
- Fund Transfer Service
- Transaction Service
- Sequence Generator Service
f. Databases (one per microservice; e.g., MySQL instances)
g. External systems (if any—here Keycloak and potentially email/SMS for future notifications)

##### Relationships and data flows
1. Client sends request → API Gateway
2. API Gateway authenticates/authorizes via Keycloak
3. API Gateway looks up service instances in Service Registry and forwards request to the appropriate microservice
4. Microservices call other microservices using Feign clients (through the gateway or via service discovery)
5. Microservices persist data to their own databases
6. For ID generation, microservices call the Sequence Generator Service

##### Architectural patterns and design principles
- Microservice per bounded context (User, Account, Fund Transfer, Transaction, Sequence Generator)
- Database per service (isolated schemas, independent scaling)
- Service Discovery (Eureka) prevents hard-coding endpoints
- API Gateway centralizes routing, authentication, rate limiting, and cross-cutting concerns
- Feign clients for declarative inter-service calls
- Keycloak for centralized auth (OAuth2/OpenID Connect)
- Exception handling and DTO mapping layers inside each service

##### Technology stack
- Spring Boot (each service)
- Spring Cloud Netflix Eureka (Service Registry)
- Spring Cloud Gateway (API Gateway)
- Spring Security + Keycloak adapter
- Spring Data JPA + MySQL
- OpenFeign for inter-service communication
- Maven for build management
- Dockerfile in User-Service for containerization
- Postman collection for API testing

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Clients Layer
    subgraph "Clients"
        direction TB
        Web["Web Client"]:::clients
        Mobile["Mobile Client"]:::clients
    end

    %% API Gateway Layer
    APIGateway{"API Gateway"}:::gateway

    %% Authentication
    Keycloak["Keycloak (Auth Server)"]:::auth

    %% Service Registry
    Eureka["Eureka Service Registry"]:::registry

    %% Services Layer
    subgraph "Microservices"
        direction TB
        UserSvc["User Service"]:::user
        AccountSvc["Account Service"]:::account
        FundTransferSvc["Fund Transfer Service"]:::fund
        TransactionSvc["Transaction Service"]:::transaction
        SeqGenSvc["Sequence Generator Service"]:::sequence
    end

    %% Databases
    UserDB["User DB (MySQL)"]:::db
    AccountDB["Account DB (MySQL)"]:::db
    FundTransferDB["FundTransfer DB (MySQL)"]:::db
    TransactionDB["Transaction DB (MySQL)"]:::db
    SeqGenDB["SeqGen DB (MySQL)"]:::db

    %% Flows
    Web -->|API Request| APIGateway
    Mobile -->|API Request| APIGateway

    APIGateway -->|Validate Token| Keycloak
    Keycloak -->|Token OK| APIGateway

    APIGateway -->|Route to Service| UserSvc
    APIGateway -->|Route to Service| AccountSvc
    APIGateway -->|Route to Service| FundTransferSvc
    APIGateway -->|Route to Service| TransactionSvc

    %% Service Discovery
    APIGateway -->|Discovery Lookup| Eureka
    UserSvc -->|Register| Eureka
    AccountSvc -->|Register| Eureka
    FundTransferSvc -->|Register| Eureka
    TransactionSvc -->|Register| Eureka
    SeqGenSvc -->|Register| Eureka

    %% Service to DB
    UserSvc -->|CRUD| UserDB
    AccountSvc -->|CRUD| AccountDB
    FundTransferSvc -->|CRUD| FundTransferDB
    TransactionSvc -->|CRUD| TransactionDB
    SeqGenSvc -->|CRUD| SeqGenDB

    %% Inter-service Calls
    AccountSvc -->|Feign call:/generateSequence| SeqGenSvc
    FundTransferSvc -->|Feign call:/generateSequence| SeqGenSvc
    TransactionSvc -->|Feign call:/generateSequence| SeqGenSvc

    %% Optional External
    FundTransferSvc -.->|Future: Notify| NotificationSystem[(Notifications)]:::external

    %% Click Events
    click APIGateway "https://github.com/kartik1502/spring-boot-microservices-banking-application/tree/main/API-Gateway/"
    click Eureka "https://github.com/kartik1502/spring-boot-microservices-banking-application/tree/main/Service-Registry/"
    click Keycloak "https://github.com/kartik1502/spring-boot-microservices-banking-application/blob/main/User-Service/src/main/java/org/training/user/service/config/KeyCloakManager.java"
    click UserSvc "https://github.com/kartik1502/spring-boot-microservices-banking-application/tree/main/User-Service/"
    click AccountSvc "https://github.com/kartik1502/spring-boot-microservices-banking-application/tree/main/Account-Service/"
    click FundTransferSvc "https://github.com/kartik1502/spring-boot-microservices-banking-application/tree/main/Fund-Transfer/"
    click TransactionSvc "https://github.com/kartik1502/spring-boot-microservices-banking-application/tree/main/Transaction-Service/"
    click SeqGenSvc "https://github.com/kartik1502/spring-boot-microservices-banking-application/tree/main/Sequence-Generator/"

    %% Styles
    classDef clients fill:#E8F0FE,stroke:#1E88E5,color:#1E88E5;
    classDef gateway fill:#D1C4E9,stroke:#5E35B1,color:#5E35B1;
    classDef auth fill:#FFCDD2,stroke:#E53935,color:#E53935;
    classDef registry fill:#C8E6C9,stroke:#43A047,color:#43A047;
    classDef user fill:#BBDEFB,stroke:#1E88E5,color:#0D47A1;
    classDef account fill:#C8E6C9,stroke:#43A047,color:#1B5E20;
    classDef fund fill:#FFE0B2,stroke:#FB8C00,color:#E65100;
    classDef transaction fill:#D1C4E9,stroke:#8E24AA,color:#4A148C;
    classDef sequence fill:#B2DFDB,stroke:#00796B,color:#004D40;
    classDef db fill:#FFF9C4,stroke:#FDD835,color:#F57F17;
    classDef external stroke-dasharray: 5 5,fill:none,color:#9E9E9E;
```
