# sujith123143/bank- architecture

> Architecture diagram of the GitHub repository sujith123143/bank-, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sujith123143/bank-
- Repository: https://github.com/sujith123143/bank-

## Overview

#### Purpose and Entry Points
NexBank is a Flask-based bank-management system exposing a REST API and serving an interactive browser dashboard. Runtime startup is `run.py`; application construction and route/middleware registration are centered in `app/main.py`. The static dashboard assets are `index.html`, `script.js`, and `style.css`.

#### HTTP API Boundary
API controllers are partitioned by banking capability: authentication, accounts, customers, cards, loans, transactions, reporting, employee operations, and administration. Controllers form the request boundary and should delegate domain work rather than access storage directly.
- `app/api/auth.py`
- `app/api/accounts.py`
- `app/api/transactions.py`
- `app/api/admin.py`
- `app/api/loans.py`

#### Request Security and Authorization
Requests pass through authentication/error middleware, JWT session handling, and role-based permission checks. Password and PIN protection are separate concerns: bcrypt-style password handling, PBKDF2 PIN hashing, and encryption utilities protect sensitive data. This boundary determines identity and allowed operations before service execution.
- `app/middleware/auth_middleware.py`
- `app/middleware/error_middleware.py`
- `app/authentication/jwt.py`
- `app/authentication/password.py`
- `app/authorization/rbac.py`

#### Business-Service Layer
Services implement core banking use cases, notably login/session behavior, account lifecycle operations, and transaction execution. They mediate between API schemas/validation and persistence repositories, making them the primary location for transactional business rules.
- `app/services/auth_service.py`
- `app/services/account_service.py`
- `app/services/transaction_service.py`
- `app/dependencies/deps.py`

#### Persistence and Domain Model Boundary
Repositories isolate database operations behind account and transaction access abstractions; models represent persisted banking entities. Database setup selects SQLite or MySQL support, with the checked-in SQLite database operating in WAL mode (`nexbank.db`, `nexbank.db-wal`).
- `app/repositories/base_repository.py`
- `app/repositories/account_repository.py`
- `app/repositories/transaction_repository.py`
- `app/database/connection.py`
- `app/database/init_db.py`
- `app/models/account.py`
- `app/models/transaction.py`

#### Data and Control Flow
The primary flow is: dashboard or API client → Flask controller → middleware/JWT/RBAC → validation/schema handling → service → repository → SQLite/MySQL → normalized JSON response. Error middleware and custom exceptions provide a cross-cutting failure boundary, while response schemas standardize API output.
- `app/schemas/response.py`
- `app/validators/input_validators.py`
- `app/exceptions/custom_exceptions.py`
- `app/constants/status_codes.py`

#### Operations and Supporting Infrastructure
Configuration is environment-driven, seeded data can initialize usable banking records, and application logging provides operational visibility. External/runtime dependencies are Python/Flask, SQLite or MySQL, JWT-based clients, and the browser frontend.
- `app/config/settings.py`
- `.env.example`
- `scripts/seed_data.py`
- `app/logging/logger.py`
- `requirements.txt`

Main entry points: [`app/api/accounts.py`](https://github.com/sujith123143/bank-/blob/main/app/api/accounts.py) (Banking controllers), [`app/repositories/base_repository.py`](https://github.com/sujith123143/bank-/blob/main/app/repositories/base_repository.py) (Account & transaction repositories), [`app/middleware/auth_middleware.py`](https://github.com/sujith123143/bank-/blob/main/app/middleware/auth_middleware.py) (Auth & error middleware), [`app/services/auth_service.py`](https://github.com/sujith123143/bank-/blob/main/app/services/auth_service.py) (Authentication service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime &amp; UI"]
  node_startup(("Flask startup<br/>entrypoint<br/>[run.py]"))
  node_app["Application factory<br/>Flask app<br/>[main.py]"]
  node_dashboard["Browser dashboard<br/>static frontend<br/>[index.html]"]
  node_operations["Configuration &amp; operations<br/>runtime support<br/>[settings.py]"]
end

subgraph group_api["API Boundary"]
  node_controllers["Banking controllers<br/>REST controllers<br/>[accounts.py]"]
  node_validation["Input validation<br/>validators"]
  node_responses["Response schemas<br/>API schemas<br/>[response.py]"]
end

subgraph group_security["Security"]
  node_auth_middleware["Auth &amp; error middleware<br/>Flask middleware<br/>[auth_middleware.py]"]
  node_jwt["JWT sessions<br/>authentication<br/>[jwt.py]"]
  node_rbac["Role permissions<br/>authorization<br/>[rbac.py]"]
  node_credentials["Password &amp; PIN protection<br/>credential security<br/>[password.py]"]
end

subgraph group_domain["Banking Services"]
  node_auth_service["Authentication service<br/>banking service<br/>[auth_service.py]"]
  node_account_service["Account service<br/>banking service<br/>[account_service.py]"]
  node_transaction_service["Transaction service<br/>banking service"]
end

subgraph group_data["Persistence"]
  node_repositories["Account &amp; transaction repositories<br/>repository layer<br/>[base_repository.py]"]
  node_models["Banking models<br/>persisted models<br/>[account.py]"]
  node_database[("SQLite / MySQL<br/>database backend<br/>[connection.py]")]
  node_database_init["Database initialization<br/>database setup<br/>[init_db.py]"]
end

node_startup -->|"starts"| node_app
node_dashboard -->|"API requests"| node_controllers
node_app -->|"registers"| node_auth_middleware
node_auth_middleware -->|"validates session"| node_jwt
node_auth_middleware -->|"checks role"| node_rbac
node_auth_middleware -->|"authorizes request"| node_controllers
node_controllers -->|"validates input"| node_validation
node_controllers -->|"authentication use cases"| node_auth_service
node_controllers -->|"account use cases"| node_account_service
node_controllers -->|"transaction use cases"| node_transaction_service
node_controllers -->|"returns JSON"| node_responses
node_auth_service -->|"protects credentials"| node_credentials
node_auth_service -->|"persists identity data"| node_repositories
node_account_service -->|"account access"| node_repositories
node_transaction_service -->|"transaction access"| node_repositories
node_repositories -->|"maps entities"| node_models
node_repositories -->|"reads and writes"| node_database
node_database_init -->|"initializes"| node_database
node_operations -.->|"configures runtime"| node_app

click node_startup "https://github.com/sujith123143/bank-/blob/main/run.py"
click node_app "https://github.com/sujith123143/bank-/blob/main/app/main.py"
click node_dashboard "https://github.com/sujith123143/bank-/blob/main/index.html"
click node_controllers "https://github.com/sujith123143/bank-/blob/main/app/api/accounts.py"
click node_validation "https://github.com/sujith123143/bank-/blob/main/app/validators/input_validators.py"
click node_responses "https://github.com/sujith123143/bank-/blob/main/app/schemas/response.py"
click node_auth_middleware "https://github.com/sujith123143/bank-/blob/main/app/middleware/auth_middleware.py"
click node_jwt "https://github.com/sujith123143/bank-/blob/main/app/authentication/jwt.py"
click node_rbac "https://github.com/sujith123143/bank-/blob/main/app/authorization/rbac.py"
click node_credentials "https://github.com/sujith123143/bank-/blob/main/app/authentication/password.py"
click node_auth_service "https://github.com/sujith123143/bank-/blob/main/app/services/auth_service.py"
click node_account_service "https://github.com/sujith123143/bank-/blob/main/app/services/account_service.py"
click node_transaction_service "https://github.com/sujith123143/bank-/blob/main/app/services/transaction_service.py"
click node_repositories "https://github.com/sujith123143/bank-/blob/main/app/repositories/base_repository.py"
click node_models "https://github.com/sujith123143/bank-/blob/main/app/models/account.py"
click node_database "https://github.com/sujith123143/bank-/blob/main/app/database/connection.py"
click node_database_init "https://github.com/sujith123143/bank-/blob/main/app/database/init_db.py"
click node_operations "https://github.com/sujith123143/bank-/blob/main/app/config/settings.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_startup,node_app,node_dashboard,node_operations toneBlue
class node_controllers,node_validation,node_responses toneAmber
class node_auth_middleware,node_jwt,node_rbac,node_credentials toneMint
class node_auth_service,node_account_service,node_transaction_service toneRose
class node_repositories,node_models,node_database,node_database_init toneIndigo
```

## Components

### Runtime & UI

- [Flask startup](https://github.com/sujith123143/bank-/blob/main/run.py): entrypoint · `run.py`
- [Application factory](https://github.com/sujith123143/bank-/blob/main/app/main.py): Flask app · Registers routes and middleware. · `app/main.py`
- [Browser dashboard](https://github.com/sujith123143/bank-/blob/main/index.html): static frontend · `index.html`
- [Configuration & operations](https://github.com/sujith123143/bank-/blob/main/app/config/settings.py): runtime support · Environment settings, seed data, and application logging. · `app/config/settings.py`

### API Boundary

- [Banking controllers](https://github.com/sujith123143/bank-/blob/main/app/api/accounts.py): REST controllers · Auth, accounts, transactions, admin, and loans endpoints. · `app/api/accounts.py`
- [Input validation](https://github.com/sujith123143/bank-/blob/main/app/validators/input_validators.py): validators · `app/validators/input_validators.py`
- [Response schemas](https://github.com/sujith123143/bank-/blob/main/app/schemas/response.py): API schemas · Normalizes JSON responses. · `app/schemas/response.py`

### Security

- [Auth & error middleware](https://github.com/sujith123143/bank-/blob/main/app/middleware/auth_middleware.py): Flask middleware · Authenticates requests and maps failures. · `app/middleware/auth_middleware.py`
- [JWT sessions](https://github.com/sujith123143/bank-/blob/main/app/authentication/jwt.py): authentication · `app/authentication/jwt.py`
- [Role permissions](https://github.com/sujith123143/bank-/blob/main/app/authorization/rbac.py): authorization · `app/authorization/rbac.py`
- [Password & PIN protection](https://github.com/sujith123143/bank-/blob/main/app/authentication/password.py): credential security · Uses password hashing, PBKDF2 PIN hashing, and encryption utilities. · `app/authentication/password.py`

### Banking Services

- [Authentication service](https://github.com/sujith123143/bank-/blob/main/app/services/auth_service.py): banking service · Handles login and session behavior. · `app/services/auth_service.py`
- [Account service](https://github.com/sujith123143/bank-/blob/main/app/services/account_service.py): banking service · Owns account lifecycle rules. · `app/services/account_service.py`
- [Transaction service](https://github.com/sujith123143/bank-/blob/main/app/services/transaction_service.py): banking service · Executes transactional banking rules. · `app/services/transaction_service.py`

### Persistence

- [Account & transaction repositories](https://github.com/sujith123143/bank-/blob/main/app/repositories/base_repository.py): repository layer · Isolates database access abstractions. · `app/repositories/base_repository.py`
- [Banking models](https://github.com/sujith123143/bank-/blob/main/app/models/account.py): persisted models · Account and transaction entities. · `app/models/account.py`
- [SQLite / MySQL](https://github.com/sujith123143/bank-/blob/main/app/database/connection.py): database backend · SQLite is checked in and operates in WAL mode; MySQL is also supported. · `app/database/connection.py`
- [Database initialization](https://github.com/sujith123143/bank-/blob/main/app/database/init_db.py): database setup · Selects and initializes the configured backend. · `app/database/init_db.py`

## Connections

- Flask startup → Application factory: starts
- Browser dashboard → Banking controllers: API requests
- Application factory → Auth & error middleware: registers
- Auth & error middleware → JWT sessions: validates session
- Auth & error middleware → Role permissions: checks role
- Auth & error middleware → Banking controllers: authorizes request
- Banking controllers → Input validation: validates input
- Banking controllers → Authentication service: authentication use cases
- Banking controllers → Account service: account use cases
- Banking controllers → Transaction service: transaction use cases
- Banking controllers → Response schemas: returns JSON
- Authentication service → Password & PIN protection: protects credentials
- Authentication service → Account & transaction repositories: persists identity data
- Account service → Account & transaction repositories: account access
- Transaction service → Account & transaction repositories: transaction access
- Account & transaction repositories → Banking models: maps entities
- Account & transaction repositories → SQLite / MySQL: reads and writes
- Database initialization → SQLite / MySQL: initializes
- Configuration & operations → Application factory: configures runtime
