# riya-joshi-401/ethereum-blockchain-based-electronic-voting-system architecture

> Architecture diagram of the GitHub repository riya-joshi-401/ethereum-blockchain-based-electronic-voting-system, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-10-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/riya-joshi-401/ethereum-blockchain-based-electronic-voting-system
- Repository: https://github.com/riya-joshi-401/ethereum-blockchain-based-electronic-voting-system

## Overview

##### Project Type and Purpose
- This is a full‐stack decentralized application (DApp) for electronic voting.
- Purpose: Allow users to authenticate via Aadhaar, view candidates, cast a vote through a web portal, and record that vote immutably on a blockchain (Ethereum via Ganache).

##### Main Architectural Components
a. Frontend (React.js SPA)
- ui/src/components (App.js, Auth.js, Voting.js, Loading.js)
- Redux state management (ui/src/redux.js)
- Service worker (ui/src/serviceWorkerRegistration.js, service-worker.js)
- Asset pipeline (ui/src/assets, public folder)
b. Web3 Layer
- Web3.js integration to communicate with smart contracts
- MetaMask as the injected provider for transaction signing
c. Smart Contracts & Blockchain
- Solidity contracts in contracts/ (Voting.sol, Migrations.sol implied)
- Truffle migrations (migrations/1_initial_migration.js, 2_deploy_voting.js)
- Local blockchain (Ganache) configured via truffle-config.js
d. External Services
- Aadhaar authentication API (out-of-band, not in code but called from Auth.js)
- MetaMask wallet extension
e. Development & Testing
- Truffle CLI for compile/migrate/test
- JavaScript tests in test/
- init.sh for environment setup

##### Relationships & Data Flow
1. User opens browser → React App served from ui/public/index.html
2. React App dispatches login action → calls Aadhaar API for OTP and Aadhar validation
3. On success, App requests MetaMask to connect accounts (Web3 provider)
4. User selects candidate → App invokes web3.eth.sendTransaction to Voting smart contract
5. MetaMask prompts user to sign and broadcast transaction to Ganache network
6. Ganache (Ethereum VM) executes contract, state (vote count) updates
7. Frontend polls or listens to contract events to display updated vote counts

##### Architectural Patterns & Principles
- Separation of concerns: UI components vs. blockchain integration vs. smart contracts
- Single-page App with Redux for predictable state
- Smart contract as the sole source of truth for votes (immutability)
- Infrastructure as code: truffle-config.js and migration scripts to automate deployment

##### Summary
1. User Interaction Layer (Browser + MetaMask)
2. Frontend Application (React SPA, Redux, Service Worker)
3. Blockchain Interaction Layer (Web3.js, MetaMask Provider)
4. Smart Contract Layer (Voting.sol, Migrations.sol) + Migration Scripts
5. Local Ethereum Network (Ganache)
6. External Identity Service (Aadhaar API)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User & Browser Layer
    subgraph "User & Browser"
        User(("User")):::user
        Browser["Browser UI\n(ui/public/index.html)"]:::browser
        MetaMask["MetaMask\n(Web3 Provider)"]:::external
    end

    %% Frontend Application Layer
    subgraph "Frontend Application Layer"
        App["React App\n(App.js, Auth.js, Voting.js, Loading.js)"]:::ui
        Redux["Redux Store\n(ui/src/redux.js)"]:::ui
        SWReg["Service Worker Registration\n(ui/src/serviceWorkerRegistration.js)"]:::ui
        SW["Service Worker\n(service-worker.js)"]:::ui
        Assets["Asset Pipeline\n(ui/src/assets/, ui/public/)"]:::ui
    end

    %% Blockchain Integration Layer
    subgraph "Blockchain Integration Layer"
        Index["App Init & Web3 Setup\n(ui/src/index.js)"]:::block
        ABIs["Contract ABIs\n(ui/src/contracts/Voting.json, Migrations.json)"]:::block
    end

    %% Smart Contract Layer
    subgraph "Smart Contract Layer"
        Contracts["Solidity Contracts\n(contracts/)"]:::sc
        M1["Initial Migration\n(migrations/1_initial_migration.js)"]:::sc
        M2["Deploy Voting Migration\n(migrations/2_deploy_voting.js)"]:::sc
        Config["Truffle Config\n(truffle-config.js)"]:::sc
    end

    %% Development & Testing
    subgraph "Development & Testing"
        SetupScript["Local Blockchain Setup Script\n(init.sh)"]:::external
        Tests["Automated Tests\n(test/)"]:::external
    end

    %% Local Ethereum Network
    Ganache["Ganache Network\n(Local Ethereum VM)"]:::db

    %% External Service
    Aadhaar["Aadhaar Authentication API"]:::external

    %% Connections
    User --> Browser
    Browser --> App
    Browser --> Assets
    App --> Redux
    App --> SWReg
    App --> SW
    App -->|"dispatch login"| Aadhaar
    Aadhaar -->|"OTP response"| App
    App -->|"connect accounts"| MetaMask
    App --> Index
    Index --> ABIs
    App -->|"select candidate & vote"| Index
    Index --> MetaMask
    MetaMask -->|"sign & broadcast"| Ganache
    Ganache -->|"execute contract"| Contracts
    Config --> Ganache
    M1 --> Ganache
    M2 --> Ganache
    Contracts --> Ganache
    Ganache -->|-- Events --| ABIs
    ABIs -->|-- Events --| App
    SetupScript --> Ganache
    Tests --> Contracts

    %% Click Events
    click App "https://github.com/riya-joshi-401/ethereum-blockchain-based-electronic-voting-system/blob/main/ui/src/components/App.js"
    click App "https://github.com/riya-joshi-401/ethereum-blockchain-based-electronic-voting-system/blob/main/ui/src/components/Auth.js"
    click App "https://github.com/riya-joshi-401/ethereum-blockchain-based-electronic-voting-system/blob/main/ui/src/components/Voting.js"
    click App "https://github.com/riya-joshi-401/ethereum-blockchain-based-electronic-voting-system/blob/main/ui/src/components/Loading.js"
    click Redux "https://github.com/riya-joshi-401/ethereum-blockchain-based-electronic-voting-system/blob/main/ui/src/redux.js"
    click SWReg "https://github.com/riya-joshi-401/ethereum-blockchain-based-electronic-voting-system/blob/main/ui/src/serviceWorkerRegistration.js"
    click SW "https://github.com/riya-joshi-401/ethereum-blockchain-based-electronic-voting-system/blob/main/ui/src/service-worker.js"
    click Assets "https://github.com/riya-joshi-401/ethereum-blockchain-based-electronic-voting-system/tree/main/ui/src/assets/"
    click Assets "https://github.com/riya-joshi-401/ethereum-blockchain-based-electronic-voting-system/tree/main/ui/public/"
    click Index "https://github.com/riya-joshi-401/ethereum-blockchain-based-electronic-voting-system/blob/main/ui/src/index.js"
    click ABIs "https://github.com/riya-joshi-401/ethereum-blockchain-based-electronic-voting-system/blob/main/ui/src/contracts/Voting.json"
    click ABIs "https://github.com/riya-joshi-401/ethereum-blockchain-based-electronic-voting-system/blob/main/ui/src/contracts/Migrations.json"
    click Contracts "https://github.com/riya-joshi-401/ethereum-blockchain-based-electronic-voting-system/tree/main/contracts/"
    click M1 "https://github.com/riya-joshi-401/ethereum-blockchain-based-electronic-voting-system/blob/main/migrations/1_initial_migration.js"
    click M2 "https://github.com/riya-joshi-401/ethereum-blockchain-based-electronic-voting-system/blob/main/migrations/2_deploy_voting.js"
    click Config "https://github.com/riya-joshi-401/ethereum-blockchain-based-electronic-voting-system/blob/main/truffle-config.js"
    click SetupScript "https://github.com/riya-joshi-401/ethereum-blockchain-based-electronic-voting-system/blob/main/init.sh"
    click Tests "https://github.com/riya-joshi-401/ethereum-blockchain-based-electronic-voting-system/tree/main/test/"

    %% Styles
    classDef user fill:#d1d5db,stroke:#000;
    classDef browser fill:#aecbfa,stroke:#000;
    classDef ui fill:#aecbfa,stroke:#000;
    classDef block fill:#a7f3d0,stroke:#000;
    classDef sc fill:#fdba74,stroke:#000;
    classDef db fill:#cbd5e1,stroke:#000;
    classDef external fill:#d1d5db,stroke:#000;
```
