# kaivals/the-chronobank architecture

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

- Interactive diagram: https://gitdiagram.com/kaivals/the-chronobank
- Repository: https://github.com/kaivals/the-chronobank

## Overview

##### Project Type and Purpose
- The-ChronoBank is a monolithic Flask-based full-stack web app where “time” is the currency.
- Frontend: HTML templates (served by Flask), plus static assets (packaged in `static.zip`, `admin.zip`).
- Backend: Python, employing MVC-style separation via route modules and rich domain/service layer.
- Integrations: A blockchain network (`blockchain.py`) and a legacy banking system adapter (`adapter_legacy_system.py`).

##### Main Components
A. Client / Presentation Layer
- Web Browsers
- HTML templates (e.g. `index.html`, `login.html`, `dashboard.html`, etc.)
- Static assets (CSS/JS) unpacked from `static.zip`
B. Web Server / Controllers
- `app.py` (Flask entry point)
- Route modules:
– `banking_routes.py`
– `alert_routes.py`
– `goal_routes.py`
– `strategy_routes.py`
– Others: `apply_loan.py`, `transactions.py`, etc.
C. Business / Domain Layer
- Account management:
– `account_factory.py` (Factory pattern)
– `account_state.py` (State pattern)
– `account_status.html` (UI view)
- Loan & repayment:
– `apply_loan.py`
– `repayment_strategy.py` (Strategy pattern)
– `repay.py`, `repayment_success.html`
- Goals & commands:
– `goal_base.html`, `goal_command.py`, `goal_models.py`
- Transactions:
– `transactions.py`, `view_transactions.html`, `money_time_transactions.py`
- Account customization:
– `customize_account.py`, `customize_account_builder.py` (Builder pattern)
- Alerts & notifications:
– `alert_routes.py`, `alerts.html`
D. Integration & Infrastructure Layer
- `singleton_db.py` (Singleton DB connection, uses scripts in `sql.zip`)
- Adapter patterns:
– `adapter.py` (generic)
– `adapter_legacy_system.py`
- Facade: `facade.py` (simplify complex subsystems)
- Observer: `observer.py` (event subscription for alerts)
- Blockchain integration: `blockchain.py`
E. External Systems
- Decentralized blockchain network
- Legacy banking system

##### Relationships & Data Flow
- Client → HTTP request → Flask (`app.py`)
- Flask routes invoke Controllers → Domain services
- Domain services coordinate via design patterns (Factory, Strategy, Command, Observer, Builder, Facade)
- Services read/write via `singleton_db.py` (persistent store)
- Certain services call out to:
- Blockchain network (`blockchain.py`)
- Legacy system via adapter (`adapter_legacy_system.py`)
- Responses flow back through Controllers → Templates → Client

##### Architectural Patterns & Principles to Highlight
- Layered architecture: Presentation → Controller → Domain → Data/Infrastructure
- Design patterns ensuring modularity & extensibility:
- Factory (account creation)
- Builder (account customization)
- Strategy (repayment calculations)
- Command (goal operations)
- Observer (alerts)
- Adapter & Facade (external integrations)
- Singleton (database connection)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Presentation Layer
    subgraph "Presentation Layer"
        direction TB
        Browser("Web Browser"):::external
        index["index.html"]:::presentation
        login["login.html"]:::presentation
        dashboard["dashboard.html"]:::presentation
        account_status["account_status.html"]:::presentation
        alerts_ui["alerts.html"]:::presentation
        view_tx["view_transactions.html"]:::presentation
        money_time_tx["money_time_transactions.html"]:::presentation
        goal_base["goal_base.html"]:::presentation
        repayment_success["repayment_success.html"]:::presentation
        create_account["create_account.html"]:::presentation
        customize_account_ui["customize_account.html"]:::presentation
        loan_ui["loan.html"]:::presentation
        loan_eligibility["loan_eligibility.html"]:::presentation
        register["register.html"]:::presentation
        error_page["error.html"]:::presentation
        base_template["base.html"]:::presentation
        banking_ui["banking.html"]:::presentation
        static_assets("static.zip"):::presentation
        admin_assets("admin.zip"):::presentation
    end

    %% Controllers Layer
    subgraph "Controllers Layer"
        direction TB
        app["app.py"]:::controller
        banking_routes["banking_routes.py"]:::controller
        alert_routes["alert_routes.py"]:::controller
        goal_routes["goal_routes.py"]:::controller
        strategy_routes["strategy_routes.py"]:::controller
        apply_loan_ep["apply_loan.py"]:::controller
        transactions_ep["transactions.py"]:::controller
    end

    %% Domain Layer
    subgraph "Domain Layer"
        direction TB
        account_factory["account_factory.py"]:::domain
        account_state["account_state.py"]:::domain
        repayment_strategy["repayment_strategy.py"]:::domain
        money_time_transactions["money_time_transactions.py"]:::domain
        goal_command["goal_command.py"]:::domain
        goal_models["goal_models.py"]:::domain
        customize_account["customize_account.py"]:::domain
        customize_builder["customize_account_builder.py"]:::domain
    end

    %% Infrastructure Layer
    subgraph "Infrastructure Layer"
        direction TB
        singleton_db["singleton_db.py"]:::infrastructure
        sql_scripts("sql.zip"):::infrastructure
        adapter_generic["adapter.py"]:::infrastructure
        adapter_legacy["adapter_legacy_system.py"]:::infrastructure
        facade["facade.py"]:::infrastructure
        observer["observer.py"]:::infrastructure
        blockchain["blockchain.py"]:::infrastructure
    end

    %% External Systems
    subgraph "External Systems"
        direction TB
        blockchain_net("Blockchain Network"):::external
        legacy_system("Legacy Banking System"):::external
    end

    %% Connections
    Browser -->|HTTP Request| app
    app --> banking_routes
    app --> alert_routes
    app --> goal_routes
    app --> strategy_routes
    app --> apply_loan_ep
    app --> transactions_ep

    banking_routes -->|Invokes| account_factory
    banking_routes -->|Invokes| account_state
    banking_routes -->|Invokes| money_time_transactions

    alert_routes -->|Invokes| observer
    alert_routes -->|Renders| alerts_ui

    goal_routes -->|Invokes| goal_command
    goal_routes -->|Reads/Writes| goal_models

    strategy_routes -->|Uses| repayment_strategy

    apply_loan_ep -->|Uses| repayment_strategy
    apply_loan_ep -->|Renders| loan_ui
    apply_loan_ep -->|Renders| loan_eligibility

    transactions_ep -->|Uses| money_time_transactions
    transactions_ep -->|Renders| view_tx
    transactions_ep -->|Renders| money_time_tx

    customize_account -->|Builder Pattern| customize_builder
    banking_routes -->|Invokes| customize_account
    customize_account -->|Renders| customize_account_ui
    banking_routes -->|Renders| create_account

    account_factory --> singleton_db
    account_state --> singleton_db
    money_time_transactions --> singleton_db
    goal_command --> singleton_db
    customize_account --> singleton_db
    repayment_strategy --> singleton_db

    singleton_db --> sql_scripts

    account_factory --> adapter_generic
    adapter_generic --> adapter_legacy
    adapter_legacy --> legacy_system

    facade --> adapter_generic
    facade --> observer

    observer --> alerts_ui

    repayment_strategy --> blockchain
    blockchain --> blockchain_net

    %% Click Events - Presentation
    click index "https://github.com/kaivals/the-chronobank/blob/main//index.html"
    click login "https://github.com/kaivals/the-chronobank/blob/main//login.html"
    click dashboard "https://github.com/kaivals/the-chronobank/blob/main//dashboard.html"
    click account_status "https://github.com/kaivals/the-chronobank/blob/main//account_status.html"
    click alerts_ui "https://github.com/kaivals/the-chronobank/blob/main//alerts.html"
    click view_tx "https://github.com/kaivals/the-chronobank/blob/main//view_transactions.html"
    click money_time_tx "https://github.com/kaivals/the-chronobank/blob/main//money_time_transactions.html"
    click goal_base "https://github.com/kaivals/the-chronobank/blob/main//goal_base.html"
    click repayment_success "https://github.com/kaivals/the-chronobank/blob/main//repayment_success.html"
    click create_account "https://github.com/kaivals/the-chronobank/blob/main//create_account.html"
    click customize_account_ui "https://github.com/kaivals/the-chronobank/blob/main//customize_account.html"
    click loan_ui "https://github.com/kaivals/the-chronobank/blob/main//loan.html"
    click loan_eligibility "https://github.com/kaivals/the-chronobank/blob/main//loan_eligibility.html"
    click register "https://github.com/kaivals/the-chronobank/blob/main//register.html"
    click error_page "https://github.com/kaivals/the-chronobank/blob/main//error.html"
    click base_template "https://github.com/kaivals/the-chronobank/blob/main//base.html"
    click banking_ui "https://github.com/kaivals/the-chronobank/blob/main//banking.html"
    click static_assets "https://github.com/kaivals/the-chronobank/blob/main//static.zip"
    click admin_assets "https://github.com/kaivals/the-chronobank/blob/main//admin.zip"

    %% Click Events - Controllers
    click app "https://github.com/kaivals/the-chronobank/blob/main//app.py"
    click banking_routes "https://github.com/kaivals/the-chronobank/blob/main//banking_routes.py"
    click alert_routes "https://github.com/kaivals/the-chronobank/blob/main//alert_routes.py"
    click goal_routes "https://github.com/kaivals/the-chronobank/blob/main//goal_routes.py"
    click strategy_routes "https://github.com/kaivals/the-chronobank/blob/main//strategy_routes.py"
    click apply_loan_ep "https://github.com/kaivals/the-chronobank/blob/main//apply_loan.py"
    click transactions_ep "https://github.com/kaivals/the-chronobank/blob/main//transactions.py"

    %% Click Events - Domain
    click account_factory "https://github.com/kaivals/the-chronobank/blob/main//account_factory.py"
    click account_state "https://github.com/kaivals/the-chronobank/blob/main//account_state.py"
    click repayment_strategy "https://github.com/kaivals/the-chronobank/blob/main//repayment_strategy.py"
    click money_time_transactions "https://github.com/kaivals/the-chronobank/blob/main//money_time_transactions.py"
    click goal_command "https://github.com/kaivals/the-chronobank/blob/main//goal_command.py"
    click goal_models "https://github.com/kaivals/the-chronobank/blob/main//goal_models.py"
    click customize_account "https://github.com/kaivals/the-chronobank/blob/main//customize_account.py"
    click customize_builder "https://github.com/kaivals/the-chronobank/blob/main//customize_account_builder.py"

    %% Click Events - Infrastructure
    click singleton_db "https://github.com/kaivals/the-chronobank/blob/main//singleton_db.py"
    click sql_scripts "https://github.com/kaivals/the-chronobank/blob/main//sql.zip"
    click adapter_generic "https://github.com/kaivals/the-chronobank/blob/main//adapter.py"
    click adapter_legacy "https://github.com/kaivals/the-chronobank/blob/main//adapter_legacy_system.py"
    click facade "https://github.com/kaivals/the-chronobank/blob/main//facade.py"
    click observer "https://github.com/kaivals/the-chronobank/blob/main//observer.py"
    click blockchain "https://github.com/kaivals/the-chronobank/blob/main//blockchain.py"

    %% Styles
    classDef presentation fill:#cce5ff,stroke:#004085,color:#004085
    classDef controller fill:#d4edda,stroke:#155724,color:#155724
    classDef domain fill:#fff3cd,stroke:#856404,color:#856404
    classDef infrastructure fill:#f8d7da,stroke:#721c24,color:#721c24
    classDef external fill:#e2e3e5,stroke:#6c757d,color:#6c757d
```
