# alexnoning/offline-payment-solution-for-enaira-transactions architecture

> Architecture diagram of the GitHub repository alexnoning/offline-payment-solution-for-enaira-transactions, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-10-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/alexnoning/offline-payment-solution-for-enaira-transactions
- Repository: https://github.com/alexnoning/offline-payment-solution-for-enaira-transactions

## Overview

##### Project Type & Purpose
- Full-stack, offline-first digital wallet simulator.
- Provides USSD-style web interface (and CLI) for transactions, stores them encrypted locally, then syncs online.

##### Main Components
a. Presentation Layer
- Web UI: templates/index.html served by Flask (app.py)
- CLI Simulator: run_post.py for command-line USSD flows
b. Application Layer
- Flask Server (app.py): HTTP endpoints handling USSD menu navigation and API calls
c. Domain & Business Logic
- Transaction services (inside app.py)
- PIN validation & menu state
d. Crypto Module
- crypto.py: encrypt/decrypt transaction JSON payloads
e. Persistence Layer
- database.py: SQLite operations for balances, ledger
- Local “data/” directory: encrypted JSON queue
- enaira.db: main SQLite file (git-ignored)
f. External Integration
- Sync service (could be an external REST API endpoint)

##### Relationships & Data Flows
- User → (Web UI / CLI) → Flask endpoints
- Flask → invokes crypto.py for encrypt/decrypt
- Flask → calls database.py for reads/writes to SQLite
- New transactions → written as encrypted JSON to data/
- Sync action → reads encrypted JSON, decrypts, packages & POSTs to external service
- External response → update local SQLite and/or delete queued JSON

##### Architectural Patterns & Principles
- Layered architecture: presentation ↔ application ↔ domain ↔ persistence
- Separation of concerns: crypto logic factored out; DB logic in its own module
- Offline-first queue pattern (local JSON queue + eventual sync)
- MVC-style templating (Flask + Jinja2)

##### Technologies & Frameworks
- Python 3.x, Flask (web framework)
- Jinja2 templates (index.html)
- SQLite (database.py)
- Standard library JSON & File I/O (data/ queue)
- Pytest (tests/test_app.py)

##### Detail Level
- Break each module into sub-components if needed (e.g., “Menu Handler” in app.py)

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Presentation Layer"
        WebUI["Web UI<br>(templates/index.html)"]:::presentation
        CLI["CLI Simulator<br>(run_post.py)"]:::presentation
    end

    subgraph "Application & Domain"
        Flask["Flask Server<br>(app.py)"]:::app
        Crypto["Crypto Module<br>(crypto.py)"]:::app
    end

    subgraph "Persistence Layer"
        Database["SQLite DB<br>(enaira.db)"]:::persistence
        JSONQueue["Encrypted JSON Queue<br>(data/)"]:::persistence
    end

    SyncService["Sync Endpoint"]:::external
    TestSuite["Pytest Suite<br>(tests/test_app.py)"]:::app

    WebUI -->|"HTTP GET/POST"| Flask
    CLI -->|"USSD CLI Flow"| Flask

    Flask -->|"AES-Encrypt/Decrypt"| Crypto
    Flask -->|"SQL INSERT/SELECT"| Database
    Flask -->|"Write Encrypted JSON"| JSONQueue

    JSONQueue -->|"Read & Decrypt"| Crypto
    Crypto -->|"POST JSON"| SyncService

    SyncService -->|"Response Update"| Database
    SyncService -->|"Delete JSON"| JSONQueue

    TestSuite -->|"runs tests on"| Flask

    click WebUI "https://github.com/alexnoning/offline-payment-solution-for-enaira-transactions/blob/main/templates/index.html"
    click CLI "https://github.com/alexnoning/offline-payment-solution-for-enaira-transactions/blob/main/run_post.py"
    click Flask "https://github.com/alexnoning/offline-payment-solution-for-enaira-transactions/blob/main/app.py"
    click Crypto "https://github.com/alexnoning/offline-payment-solution-for-enaira-transactions/blob/main/crypto.py"
    click Database "https://github.com/alexnoning/offline-payment-solution-for-enaira-transactions/blob/main/database.py"
    click JSONQueue "https://github.com/alexnoning/offline-payment-solution-for-enaira-transactions/tree/main/data/"
    click TestSuite "https://github.com/alexnoning/offline-payment-solution-for-enaira-transactions/blob/main/tests/test_app.py"

    classDef presentation fill:#9f6,stroke:#333,color:#000
    classDef app fill:#6cf,stroke:#333,color:#000
    classDef persistence fill:#f96,stroke:#333,color:#000
    classDef external fill:#f66,stroke:#333,color:#000
```
