# iamrakki/online_voting_system_using_blockchain architecture

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

- Interactive diagram: https://gitdiagram.com/iamrakki/online_voting_system_using_blockchain
- Repository: https://github.com/iamrakki/online_voting_system_using_blockchain

## Overview

##### Project type and purpose
- This is a full-stack web application that uses a private Ethereum‐style blockchain (via Truffle/Ganache) as its persistent store.
- Purpose: provide a secure, transparent, tamper-proof online voting system where votes are cast via a web UI, encrypted, recorded on the chain, and results displayed in real time.

##### File structure
- Top-level blockchain artifacts:
- contracts/           ← Solidity smart-contract source
- migrations/          ← Truffle deployment scripts
- build/contracts/     ← compiled ABIs and JSON definitions
- truffle-config.js    ← network & compiler settings
- Web application server (Node/Express):
- routes/              ← HTTP route handlers for login, registration, dashboard, voting, results
- database.js          ← Web3.js setup & helper functions for contract interaction
- Test suite:
- test/contest.js      ← Mocha/Chai tests against smart contracts
- Auxiliary files:
- bs-config.js         ← Browser-Sync configuration (live reload)
- package.json         ← dependencies, start script (`npm start`)

##### README for additional insights
- Highlights blockchain for immutability, cryptographic vote encryption, and real-time result display.
- Tech stack: Ethereum/Truffle, Web3.js, Node.js/Express, cryptography libraries.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Presentation Layer
    subgraph "Presentation Layer" 
        direction TB
        Browser["Web Browser"]:::frontend
        RegistrationPage["Registration Page"]:::frontend
        LoginPage["Login Page"]:::frontend
        VotingPage["Voting Page"]:::frontend
        DashboardPage["Dashboard Page"]:::frontend
        ResultsPage["Real-Time Results"]:::frontend
    end

    %% Application Layer
    subgraph "Application Layer (Express.js)" 
        direction TB
        AuthSub["User Auth Routes"] 
        RegistrationRoutes["routes/registration-route.js"]:::backend
        LoginRoutes["routes/login-route.js"]:::backend
        LogoutRoutes["routes/logout-route.js"]:::backend
        AdminLogin["routes/admin_login.js"]:::backend
        UserRoutes["routes/user.js"]:::backend

        WorkflowSub["Voting Workflow Routes"]
        FirstPage["routes/first_page.js"]:::backend
        MainVoting["routes/main.js"]:::backend
        DashboardRoutes["routes/dashboard-route.js"]:::backend
        TableView["routes/table_view.js"]:::backend

        DatabaseModule["database.js"]:::backend
    end

    %% Blockchain Layer
    subgraph "Blockchain Layer (Ethereum/Truffle)" 
        direction TB
        GanacheNode["Ganache / Ethereum Node"]:::blockchain
        ContractsSrc["contracts/"]:::blockchain
        ContestSol["Contest.sol"]:::blockchain
        MigrationsSol["Migrations.sol"]:::blockchain
        ABIsSub["Compiled ABIs"] 
        ContestABI["build/contracts/Contest.json"]:::blockchain
        MigrationsABI["build/contracts/Migrations.json"]:::blockchain
        MigrationsSub["Truffle Migrations"] 
        Migration1["migrations/1_initial_migration.js"]:::blockchain
        Migration2["migrations/2_deploy_contacts.js"]:::blockchain
        TruffleConfig["truffle-config.js"]:::blockchain
    end

    %% Tooling & Tests
    subgraph "Tooling & Tests" 
        direction TB
        BrowserSync["bs-config.js"]:::tooling
        PackageMeta["package.json"]:::tooling
        PackageLock["package-lock.json"]:::tooling
        Readme["README.md"]:::tooling
        License["LICENSE"]:::tooling
        TestSuite["test/contest.js"]:::tooling
    end

    %% Client to Server HTTP
    Browser -->|"HTTP(S)"| RegistrationRoutes
    Browser -->|"HTTP(S)"| LoginRoutes
    Browser -->|"HTTP(S)"| LogoutRoutes
    Browser -->|"HTTP(S)"| FirstPage
    Browser -->|"HTTP(S)"| MainVoting
    Browser -->|"HTTP(S)"| DashboardRoutes
    Browser -->|"HTTP(S)"| TableView

    %% Auth routes grouping
    AuthSub --> RegistrationRoutes
    AuthSub --> LoginRoutes
    AuthSub --> LogoutRoutes
    AuthSub --> AdminLogin
    AuthSub --> UserRoutes

    %% Workflow grouping
    WorkflowSub --> FirstPage
    WorkflowSub --> MainVoting
    WorkflowSub --> DashboardRoutes
    WorkflowSub --> TableView

    %% Routes to database module
    RegistrationRoutes -->|"Web3.js calls"| DatabaseModule
    LoginRoutes -->|"Web3.js calls"| DatabaseModule
    LogoutRoutes -->|"Web3.js calls"| DatabaseModule
    FirstPage -->|"Web3.js calls"| DatabaseModule
    MainVoting -->|"Web3.js calls"| DatabaseModule
    DashboardRoutes -->|"Web3.js calls"| DatabaseModule
    TableView -->|"Web3.js calls"| DatabaseModule

    %% Database module to blockchain node
    DatabaseModule -->|"JSON-RPC"| GanacheNode

    %% Blockchain node to contracts
    GanacheNode -->|"deploy tx"| ContractsSrc
    GanacheNode -->|"event logs"| DatabaseModule
    GanacheNode -->|"state queries"| DatabaseModule

    %% Contracts to ABIs
    ContractsSrc --> ContestSol
    ContractsSrc --> MigrationsSol
    ContestSol --> ContestABI
    MigrationsSol --> MigrationsABI

    %% Migrations process
    Migration1 -->|"deploy"| GanacheNode
    Migration2 -->|"deploy"| GanacheNode
    TruffleConfig --> Migration1
    TruffleConfig --> Migration2

    %% Tests
    TestSuite -->|"Mocha/Chai"| ContestSol
    TestSuite -->|"uses Web3.js"| DatabaseModule

    %% Tooling references
    BrowserSync -.-> Browser
    PackageMeta -.-> DatabaseModule
    PackageLock -.-> DatabaseModule
    Readme -.-> PackageMeta
    License -.-> PackageMeta

    %% Click Events
    click ContractsSrc "https://github.com/iamrakki/online_voting_system_using_blockchain/tree/main/contracts/"
    click ContestSol "https://github.com/iamrakki/online_voting_system_using_blockchain/blob/main/contracts/Contest.sol"
    click MigrationsSol "https://github.com/iamrakki/online_voting_system_using_blockchain/blob/main/contracts/Migrations.sol"
    click ContestABI "https://github.com/iamrakki/online_voting_system_using_blockchain/blob/main/build/contracts/Contest.json"
    click MigrationsABI "https://github.com/iamrakki/online_voting_system_using_blockchain/blob/main/build/contracts/Migrations.json"
    click Migration1 "https://github.com/iamrakki/online_voting_system_using_blockchain/blob/main/migrations/1_initial_migration.js"
    click Migration2 "https://github.com/iamrakki/online_voting_system_using_blockchain/blob/main/migrations/2_deploy_contacts.js"
    click TruffleConfig "https://github.com/iamrakki/online_voting_system_using_blockchain/blob/main/truffle-config.js"
    click RegistrationRoutes "https://github.com/iamrakki/online_voting_system_using_blockchain/blob/main/routes/registration-route.js"
    click LoginRoutes "https://github.com/iamrakki/online_voting_system_using_blockchain/blob/main/routes/login-route.js"
    click LogoutRoutes "https://github.com/iamrakki/online_voting_system_using_blockchain/blob/main/routes/logout-route.js"
    click AdminLogin "https://github.com/iamrakki/online_voting_system_using_blockchain/blob/main/routes/admin_login.js"
    click UserRoutes "https://github.com/iamrakki/online_voting_system_using_blockchain/blob/main/routes/user.js"
    click FirstPage "https://github.com/iamrakki/online_voting_system_using_blockchain/blob/main/routes/first_page.js"
    click MainVoting "https://github.com/iamrakki/online_voting_system_using_blockchain/blob/main/routes/main.js"
    click DashboardRoutes "https://github.com/iamrakki/online_voting_system_using_blockchain/blob/main/routes/dashboard-route.js"
    click TableView "https://github.com/iamrakki/online_voting_system_using_blockchain/blob/main/routes/table_view.js"
    click DatabaseModule "https://github.com/iamrakki/online_voting_system_using_blockchain/blob/main/database.js"
    click BrowserSync "https://github.com/iamrakki/online_voting_system_using_blockchain/blob/main/bs-config.js"
    click TestSuite "https://github.com/iamrakki/online_voting_system_using_blockchain/blob/main/test/contest.js"
    click PackageMeta "https://github.com/iamrakki/online_voting_system_using_blockchain/blob/main/package.json"
    click PackageLock "https://github.com/iamrakki/online_voting_system_using_blockchain/blob/main/package-lock.json"
    click Readme "https://github.com/iamrakki/online_voting_system_using_blockchain/blob/main/README.md"
    click License "https://github.com/iamrakki/online_voting_system_using_blockchain/tree/main/LICENSE"

    %% Styles
    classDef frontend fill:#E3F2FD,stroke:#1E88E5,color:#0D47A1
    classDef backend fill:#E8F5E9,stroke:#43A047,color:#1B5E20
    classDef blockchain fill:#FFF3E0,stroke:#FB8C00,color:#E65100
    classDef tooling fill:#ECEFF1,stroke:#607D8B,color:#263238
```
