How alexnoning/offline-payment-solution-for-enaira-transactions works
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)