# harpreetvirkk/hypervoter architecture

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

- Interactive diagram: https://gitdiagram.com/harpreetvirkk/hypervoter
- Repository: https://github.com/harpreetvirkk/hypervoter

## Overview

##### Project type and purpose
- This is a blockchain-based E-Voting application built on Hyperledger Fabric.
- It comprises two main parts:
- Chaincode (the “smart contract” in Fabric) under chaincode/hypervoter/javascript
- A Node.js application serving static HTML/JS frontends (EC dashboard, voter dashboard, public bulletin)

##### File structure
- Top-level directories:
- chaincode/hypervoter/javascript – Fabric chaincode implementing vote asset logic
- hypervoter/javascript – Node.js “client” application using Fabric SDK, serves UI
- Shell scripts in hypervoter/ start and teardown the Fabric test network (“basic-network”)
- Static HTML under hypervoter/javascript/public for three user‐facing apps:
– EC-dashboard (Election Commission interface)
– voter-dashboard (voter registration & voting)
– public-bulletin (view results)
- Config files: package.json for npm, ESLint, EditorConfig, .gitignore, .sh for network orchestration

##### README for additional insights
- HyperLedger Fabric v1.4.6, “basic-network” with:
1. Orderer
2. Certificate Authority
3. 1 Org (org1) with 1 peer
4. CouchDB state database
5. CLI container for admin tasks
- Asset model: voteID→{ownerId, hasVoted}
- Endpoints invoked via Fabric SDK to submit/query transactions

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Browser Clients
    subgraph "Browser Clients"
        direction TB
        EC["EC Dashboard"]:::browser
        Voter["Voter Dashboard"]:::browser
        Public["Public Bulletin"]:::browser
    end

    %% Node.js Backend
    subgraph "Node.js Backend" 
        direction TB
        AppServer["Express Server (app.js)"]:::backend
        Enroll["enrollAdmin.js"]:::script
        Query["query.js"]:::script
        Candidates["candidates.json"]:::data
        Voters["voters.json"]:::data
        BackendPkg["package.json"]:::config
        ESLintClient[".eslintrc.js/.eslintignore/.editorconfig/.gitignore"]:::config
    end

    %% Chaincode
    subgraph "Chaincode (Smart Contract)" 
        direction TB
        CCIndex["index.js"]:::chaincode
        CCLib["lib/hypervoter.js"]:::chaincode
        CCPkg["package.json"]:::config
    end

    %% Fabric Network
    subgraph "Fabric Network" 
        direction TB
        CA["Certificate Authority"]:::blockchain
        Orderer["Orderer"]:::blockchain
        Peer["Peer0.org1"]:::blockchain
        CouchDB["CouchDB"]:::blockchain
        CLI["CLI Admin"]:::blockchain
    end

    %% Interactions
    EC -->|"HTTP Request"| AppServer
    Voter -->|"HTTP Request"| AppServer
    Public -->|"HTTP Request"| AppServer

    AppServer -->|"Enroll/Admin via SDK"| Enroll
    Enroll -->|"Enrolls with"| CA

    AppServer -->|"Query Ledger"| Query
    Query -->|"Calls Peer"| Peer

    AppServer -->|"Submit TX Proposal"| Peer
    Peer -->|"Endorsement"| AppServer

    AppServer -->|"Send Proposal to Orderer"| Orderer
    Orderer -->|"Broadcast Block"| Peer
    Peer -->|"Execute Chaincode"| CCIndex
    CCIndex -->|"Logic in"| CCLib
    CCIndex -->|"Update State"| CouchDB

    Peer -->|"Query World State"| CouchDB

    Peer -->|"Admin Tasks"| CLI

    %% Click events
    click CCIndex "https://github.com/harpreetvirkk/hypervoter/blob/master/chaincode/hypervoter/javascript/index.js"
    click CCLib "https://github.com/harpreetvirkk/hypervoter/blob/master/chaincode/hypervoter/javascript/lib/hypervoter.js"
    click CCPkg "https://github.com/harpreetvirkk/hypervoter/blob/master/chaincode/hypervoter/javascript/package.json"
    click AppServer "https://github.com/harpreetvirkk/hypervoter/blob/master/hypervoter/javascript/app.js"
    click Enroll "https://github.com/harpreetvirkk/hypervoter/blob/master/hypervoter/javascript/enrollAdmin.js"
    click Query "https://github.com/harpreetvirkk/hypervoter/blob/master/hypervoter/javascript/query.js"
    click Candidates "https://github.com/harpreetvirkk/hypervoter/blob/master/hypervoter/javascript/candidates.json"
    click Voters "https://github.com/harpreetvirkk/hypervoter/blob/master/hypervoter/javascript/voters.json"
    click BackendPkg "https://github.com/harpreetvirkk/hypervoter/blob/master/hypervoter/javascript/package.json"
    click ESLintClient "https://github.com/harpreetvirkk/hypervoter/blob/master/hypervoter/javascript/.eslintrc.js"
    click EC "https://github.com/harpreetvirkk/hypervoter/blob/master/hypervoter/javascript/public/EC-dashboard/ec-dashboard.html"
    click Voter "https://github.com/harpreetvirkk/hypervoter/blob/master/hypervoter/javascript/public/voter-dashboard/voter-dashboard.html"
    click Public "https://github.com/harpreetvirkk/hypervoter/blob/master/hypervoter/javascript/public/public-bulletin/index.html"
    click CA "https://github.com/harpreetvirkk/hypervoter/blob/master/hypervoter/startHyperVoter.sh"
    click CLI "https://github.com/harpreetvirkk/hypervoter/blob/master/hypervoter/teardownHyperVoter.sh"

    %% Styles
    classDef browser fill:#f9f,stroke:#333,stroke-width:1px
    classDef backend fill:#f96,stroke:#333,stroke-width:1px
    classDef script fill:#ccc,stroke:#333,stroke-width:1px
    classDef data fill:#ff9,stroke:#333,stroke-width:1px
    classDef config fill:#ddd,stroke:#333,stroke-width:1px
    classDef chaincode fill:#9f9,stroke:#333,stroke-width:1px
    classDef blockchain fill:#9ef,stroke:#333,stroke-width:1px
```
