# sbathina/bankapp architecture

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

- Interactive diagram: https://gitdiagram.com/sbathina/bankapp
- Repository: https://github.com/sbathina/bankapp

## Overview

##### Project Type and Purpose
- This is a backend‐only RESTful banking application built with Java 8 and Spring Boot.
- It simulates simple banking operations (CRUD for customers/accounts, deposits, withdrawals, internal transfers) using an in-memory H2 database.

##### File Structure Analysis
- src/main/java/com/coding/exercise/bankapp
- config – Spring configuration and security setup (ApplicationConfig, SecurityConfig)
- controller – REST controllers (AccountController, CustomerController)
- service – Business logic interfaces and implementations (BankingService, BankingServiceImpl, helper)
- repository – Spring Data JPA repositories (AccountRepository, CustomerRepository, TransactionRepository, etc.)
- model – JPA entity classes mapping to database tables (Customer, Account, Transaction, etc.)
- domain – DTOs used to carry payloads in/out of the API (CustomerDetails, TransactionDetails, TransferDetails, etc.)
- BankingApplication.java – Spring Boot application entry point
- src/main/resources/application.yml – configuration properties (port, datasource URL, etc.)
- pom.xml – declares dependencies: Spring Boot starters (web, data-jpa, security, actuator), H2, Lombok, Swagger

##### Key Insights from README
- Exposes REST endpoints (base path: /bank-api) secured via Spring Security
- In-memory H2 DB, with console and Swagger UI paths under /bank-api
- Uses Lombok to reduce boilerplate; Maven as build tool

##### Main Components
a. Client (browser/Postman/Swagger UI)
b. Spring Security filter chain (authentication/authorization)
c. REST Layer – Controllers (AccountController, CustomerController)
d. Service Layer – BankingServiceImpl (business rules, validation, helper classes)
e. Data Layer – Spring Data JPA Repositories
f. Persistence – H2 In-Memory Database (testdb)
g. Supporting Components – Swagger UI, H2 Console, Actuator

##### Relationships and Data Flow
1. Client sends HTTP request →
2. Spring Security filter intercepts →
3. Controller receives request →
4. Controller calls Service layer →
5. Service performs business logic, may call helper →
6. Service calls Repository →
7. Repository reads/writes to H2 DB →
8. Service returns domain/DTO to Controller →
9. Controller returns HTTP response to Client

##### Architectural Patterns & Principles
- Layered Architecture (Controller → Service → Repository)
- Dependency Injection (Spring IoC)
- DAO pattern via Spring Data JPA
- DTO mapping between domain (JPA entities) and API payloads
- Configuration segregation (ApplicationConfig vs. SecurityConfig)

##### Technologies / Frameworks to Highlight
- Spring Boot (auto-configuration, embedded server)
- Spring Security (filter chain, HTTP basic or JWT)
- Spring Data JPA (CRUD Repositories)
- H2 In-Memory DB (persistence)
- Lombok (getters/setters, builders)
- Swagger (REST documentation)
- Maven (build and dependency management)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Clients
    subgraph "External Clients"
        direction TB
        Postman["Postman"]:::client
        Browser["Browser"]:::client
        SwaggerUI["Swagger UI"]:::client
        H2Console["H2 Console"]:::client
    end

    %% Configuration and Entry Point
    subgraph "Configuration"
        direction TB
        BankingApp["BankingApplication"]:::config
        AppConfig["ApplicationConfig"]:::config
        SecConfig["SecurityConfig"]:::config
    end

    %% Security Layer
    SecurityFilter["Spring Security Filter Chain"]:::security

    %% REST Layer
    subgraph "Controllers"
        direction TB
        AccountCtrl["AccountController"]:::controller
        CustomerCtrl["CustomerController"]:::controller
    end

    %% Service Layer
    subgraph "Services"
        direction TB
        ServiceIntf["BankingService"]:::service
        ServiceImpl["BankingServiceImpl"]:::service
        ServiceHelper["BankingServiceHelper"]:::service
    end

    %% Data Access Layer
    subgraph "Repositories"
        direction TB
        AccountRepo["AccountRepository"]:::repository
        CustomerRepo["CustomerRepository"]:::repository
        TransactionRepo["TransactionRepository"]:::repository
        XRefRepo["CustomerAccountXRefRepository"]:::repository
    end

    %% Persistence
    H2DB["H2 In-Memory Database"]:::database

    %% Arrows and Data Flow
    Postman -- "HTTP Request" --> SecurityFilter
    Browser -- "HTTP Request" --> SecurityFilter
    SwaggerUI -- "UI/API Docs" --> SecurityFilter
    H2Console -- "H2 Console Access" --> SecurityFilter

    BankingApp --> AppConfig
    BankingApp --> SecConfig

    SecurityFilter --> AccountCtrl
    SecurityFilter --> CustomerCtrl

    AccountCtrl -- "calls service()" --> ServiceImpl
    CustomerCtrl -- "calls service()" --> ServiceImpl

    ServiceImpl --> ServiceIntf
    ServiceImpl --> ServiceHelper

    ServiceImpl -- "save/find/update" --> AccountRepo
    ServiceImpl -- "save/find/update" --> CustomerRepo
    ServiceImpl -- "save/find/update" --> TransactionRepo
    ServiceImpl -- "save/find/update" --> XRefRepo

    AccountRepo -- "JDBC" --> H2DB
    CustomerRepo -- "JDBC" --> H2DB
    TransactionRepo -- "JDBC" --> H2DB
    XRefRepo -- "JDBC" --> H2DB

    H2DB --> AccountRepo
    H2DB --> CustomerRepo

    AccountRepo --> ServiceImpl
    CustomerRepo --> ServiceImpl
    TransactionRepo --> ServiceImpl
    XRefRepo --> ServiceImpl

    ServiceImpl --> AccountCtrl
    ServiceImpl --> CustomerCtrl

    AccountCtrl --> Postman
    CustomerCtrl --> Postman
    AccountCtrl --> Browser
    CustomerCtrl --> Browser

    %% Click Events
    click BankingApp "https://github.com/sbathina/bankapp/blob/master/src/main/java/com/coding/exercise/bankapp/BankingApplication.java"
    click AppConfig "https://github.com/sbathina/bankapp/blob/master/src/main/java/com/coding/exercise/bankapp/config/ApplicationConfig.java"
    click SecConfig "https://github.com/sbathina/bankapp/blob/master/src/main/java/com/coding/exercise/bankapp/config/SecurityConfig.java"
    click AccountCtrl "https://github.com/sbathina/bankapp/blob/master/src/main/java/com/coding/exercise/bankapp/controller/AccountController.java"
    click CustomerCtrl "https://github.com/sbathina/bankapp/blob/master/src/main/java/com/coding/exercise/bankapp/controller/CustomerController.java"
    click ServiceIntf "https://github.com/sbathina/bankapp/blob/master/src/main/java/com/coding/exercise/bankapp/service/BankingService.java"
    click ServiceImpl "https://github.com/sbathina/bankapp/blob/master/src/main/java/com/coding/exercise/bankapp/service/BankingServiceImpl.java"
    click ServiceHelper "https://github.com/sbathina/bankapp/blob/master/src/main/java/com/coding/exercise/bankapp/service/helper/BankingServiceHelper.java"
    click AccountRepo "https://github.com/sbathina/bankapp/blob/master/src/main/java/com/coding/exercise/bankapp/repository/AccountRepository.java"
    click CustomerRepo "https://github.com/sbathina/bankapp/blob/master/src/main/java/com/coding/exercise/bankapp/repository/CustomerRepository.java"
    click TransactionRepo "https://github.com/sbathina/bankapp/blob/master/src/main/java/com/coding/exercise/bankapp/repository/TransactionRepository.java"
    click XRefRepo "https://github.com/sbathina/bankapp/blob/master/src/main/java/com/coding/exercise/bankapp/repository/CustomerAccountXRefRepository.java"
    click H2DB "https://github.com/sbathina/bankapp/blob/master/src/main/resources/application.yml"

    %% Styles
    classDef client fill:#D8B4FE,stroke:#8B5CF6,color:#111;
    classDef config fill:#FEF3C7,stroke:#FBBF24,color:#111;
    classDef security fill:#FCA5A5,stroke:#EF4444,color:#111;
    classDef controller fill:#BFDBFE,stroke:#3B82F6,color:#111;
    classDef service fill:#BBF7D0,stroke:#10B981,color:#111;
    classDef repository fill:#FED7AA,stroke:#F59E0B,color:#111;
    classDef database fill:#E5E7EB,stroke:#6B7280,color:#111;
```
