# ramesh-adhikari/e-voting-system-using-blockchain-and-python architecture

> Architecture diagram of the GitHub repository ramesh-adhikari/e-voting-system-using-blockchain-and-python, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ramesh-adhikari/e-voting-system-using-blockchain-and-python
- Repository: https://github.com/ramesh-adhikari/e-voting-system-using-blockchain-and-python

## Overview

##### Main Components
- Frontend Web Application: Represented by “app.py” and the “app” folder containing HTML templates (base.html, index.html) and “views.py” for handling routes and UI logic. This component is responsible for rendering the voting interface and accepting user input (voter ID and selected party).
- Blockchain Node Service: Represented by “service.py” which runs a Flask application that serves as the blockchain node (listening on configurable ports, e.g. 8000, 8001, 8002). This service manages the blockchain ledger, processes new transactions (votes), and handles mining (Proof of Work) and chain synchronization.
- Core Blockchain Logic: Within the blockchain code (class Block, compute_hash method, mining routines, and chain validation), this part encapsulates how blocks are created, chained (through previous_hash), and mined via the nonce to satisfy the hash constraints.
- Network of Nodes: Although it may be started on different ports and even different hosts, conceptually several nodes interact via endpoints such as /register_with and /chain. This forms a distributed network that maintains a synchronized and tamper-proof ledger.
- External References / Documentation: The “reference-paper” folder (with the research paper PDF) supports the design rationale and security choices of the system. While not part of the runtime architecture, it underpins the system’s concepts.

##### Out Relationships and Interactions
- The blockchain node service receives transactions (typically in JSON format) and queues them. It then initiates the mining process which involves computing hashes and updating the blockchain.
- The design must capture that each node functions independently (and in parallel) but uses a consensus algorithm (Proof of Work) to maintain integrity.

##### Architectural Patterns and Design Principles
- Separation of Concerns: The system divides responsibilities between the user interface (voting frontend) and the blockchain ledger management (backend service).
- Decentralization: The distributed nature of the nodes (running on different ports) emphasizes decentralization and fault tolerance.
- Immutable Ledger: The blockchain design illustrates immutability; once a block is mined and linked (via previous_hash), it cannot be altered without invalidating the chain.
- Proof of Work: Indicate the “mining” flow where the nonce is incremented until a hash with the required number of leading zeroes is found, ensuring the block’s validity.

##### Relevant Technologies & Architectural Choices
- Programming Language: Python.
- Framework: Flask (used for both the web frontend and backend service).
- Data Format: JSON (used to store and transmit blockchain transactions).
- Cryptographic Hash: SHA-256 for creating digital fingerprints of blocks.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Section
    subgraph "Frontend"
        FE1["app.py"]:::frontend
        FE2["views.py"]:::frontend
        FE3["templates (HTML)"]:::frontend
    end

    %% Backend / Blockchain Section
    subgraph "Backend / Blockchain"
        BC["Blockchain Core (Block, Mining, PoW)"]:::core
        subgraph "Node Services"
            BN1["Node Service (Port 8000, service.py)"]:::backend
            BN2["Node Service (Port 8001)"]:::backend
            BN3["Node Service (Port 8002)"]:::backend
        end
    end

    %% External Documentation
    ED["Research Paper Documentation"]:::documentation

    %% Interactions
    FE1 -->|"sendsVoteTx"| BN1
    BN1 -->|"initiatesMining"| BC
    BC -->|"propagatesBlock"| BN1
    BC -->|"propagatesBlock"| BN2
    BC -->|"propagatesBlock"| BN3
    BN1 -->|"chainSync"| BN2
    BN1 -->|"chainSync"| BN3
    BN2 -->|"chainSync"| BN3
    ED -->|"supportsDesign"| BC

    %% Click Events
    click FE1 "https://github.com/ramesh-adhikari/e-voting-system-using-blockchain-and-python/blob/master/app.py"
    click FE2 "https://github.com/ramesh-adhikari/e-voting-system-using-blockchain-and-python/blob/master/app/views.py"
    click FE3 "https://github.com/ramesh-adhikari/e-voting-system-using-blockchain-and-python/tree/master/app/templates"
    click BN1 "https://github.com/ramesh-adhikari/e-voting-system-using-blockchain-and-python/blob/master/service.py"
    click ED "https://github.com/ramesh-adhikari/e-voting-system-using-blockchain-and-python/tree/master/reference-paper"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef backend fill:#98FB98,stroke:#000,stroke-width:2px;
    classDef core fill:#FFB6C1,stroke:#000,stroke-width:2px;
    classDef documentation fill:#FFD700,stroke:#000,stroke-width:2px;
```
