# ninostephen/egov architecture

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

- Interactive diagram: https://gitdiagram.com/ninostephen/egov
- Repository: https://github.com/ninostephen/egov

## Overview

##### Project type and purpose
- This is a proof-of-concept full-stack web application (“Blockchain based E-Governance”) that demonstrates how a private blockchain can manage everyday governance workflows (user requests, official approvals, admin oversight).

##### File structure
- Top-level Python scripts:
- app.py – the Flask web server entry point and HTTP routing layer
- blockchain.py, blockCrypto.py – blockchain ledger and cryptographic utilities
- Persistence assets:
- chain/chain.json, chain/backup.json – the JSON-based blockchain ledger
- database.sql – schema for the relational user/role data store
- Key management:
- keys/ – PEM key pairs organized by admin, official, and user roles
- Frontend assets:
- static/ – CSS, JS, images for three role-based sub-directories (admin, official, user)
- templates/ – Jinja2 HTML templates, organized by role (admin, official, user) plus shared includes and layout

##### README
- Confirms PoC objective: leverage blockchain for e-governance transactions.

##### Main components and interactions
a. Components
- Web Client (Browser) – renders UI for admin, official, or user roles
- Flask App Server (app.py) – HTTP endpoints, authentication, view rendering
- Blockchain Service (blockchain.py, blockCrypto.py) – block creation/validation, cryptography
- Relational Database (database.sql) – stores user accounts, role data, request metadata
- Blockchain Ledger (chain/chain.json + backup.json) – stores the immutable chain of governance transactions
- Key Store (keys/) – holds private/public key pairs for signing and verification
b. Relationships and data flow
1. Browser sends HTTP(S) requests to Flask controllers
2. Flask routes invoke:
– Database layer for user/role/auth data
– Blockchain Service to record or verify a transaction
3. Blockchain Service
– Uses keys from Key Store to sign new blocks (blockCrypto.py)
– Appends blocks to chain.json, then backs up to backup.json
4. Flask returns HTML pages (via Jinja2 templates) or JSON responses to client
c. Architectural patterns and design principles
– Monolithic MVC style:
- Model: database.sql + JSON chain files
- View: Jinja2 templates in templates/ + static assets
- Controller: Flask app.py routes
– Layered separation: UI layer ↔ service layer (Flask+blockchain) ↔ persistence layers (DB, JSON ledger)
– Role-based access control enforced at controller layer
d. Key technologies and frameworks
– Python & Flask for web server and routing
– Jinja2 templating engine for HTML
– JSON file store as blockchain ledger
– SQL (SQLite/MySQL) for relational data
– Python cryptography for digital signatures

##### Detail
- Three role flows separately (user applies, official approves, admin oversees)
- Backup path from chain.json to backup.json
- Configuration files (e.g., database.sql) and where they load on startup

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Layer
    subgraph "Frontend Layer"
        direction TB
        Browser["Browser (User/Official/Admin)"]:::frontend
        Static["Static Assets"]:::frontend
        Templates["Jinja2 Templates"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        direction TB
        Flask["Flask App Server"]:::compute
        subgraph "Blockchain Service"
            direction TB
            LedgerLogic["blockchain.py"]:::compute
            Crypto["blockCrypto.py"]:::compute
        end
    end

    %% Persistence Layer
    subgraph "Persistence Layer"
        direction TB
        DB["Relational DB"]:::persistence
        Chain["Chain JSON"]:::persistence
        Backup["Backup JSON"]:::persistence
        Keys["Key Store"]:::keystore
    end

    %% Connections
    Browser -->|"HTTP Request/Response"| Flask
    Flask -->|"SQL Queries"| DB
    Flask -->|"Invoke Transaction/Verify"| LedgerLogic
    LedgerLogic -->|"Sign/Verify Block"| Keys
    Crypto -->|"Uses Keys"| Keys
    LedgerLogic -->|"Append Block"| Chain
    Chain -->|"Backup"| Backup
    Flask -->|"Render Views via Jinja2"| Templates
    Browser -->|"Loads Static Assets"| Static

    %% Click Events
    click Static "https://github.com/ninostephen/egov/tree/master/static/"
    click Templates "https://github.com/ninostephen/egov/tree/master/templates/"
    click Flask "https://github.com/ninostephen/egov/blob/master/app.py"
    click LedgerLogic "https://github.com/ninostephen/egov/blob/master/blockchain.py"
    click Crypto "https://github.com/ninostephen/egov/blob/master/blockCrypto.py"
    click DB "https://github.com/ninostephen/egov/blob/master/database.sql"
    click Chain "https://github.com/ninostephen/egov/blob/master/chain/chain.json"
    click Backup "https://github.com/ninostephen/egov/blob/master/chain/backup.json"
    click Keys "https://github.com/ninostephen/egov/tree/master/keys/"

    %% Styles
    classDef frontend fill:#cccccc,stroke:#333,stroke-width:1px
    classDef compute fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef persistence fill:#90EE90,stroke:#333,stroke-width:1px
    classDef keystore fill:#FFFFE0,stroke:#333,stroke-width:1px
```
