# ashraf-io/hybrid-trust-evoting architecture

> Architecture diagram of the GitHub repository ashraf-io/hybrid-trust-evoting, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ashraf-io/hybrid-trust-evoting
- Repository: https://github.com/ashraf-io/hybrid-trust-evoting

## Overview

1. **Overall shape**
   - This is a **Node.js backend for a blockchain-based voting system**.
   - The repo is organized around three main concerns: **HTTP API**, **application services**, and **infrastructure adapters** for **database** and **Ethereum/Hardhat blockchain**.

2. **API boundary**
   - `backend/api/server.js` is the entry point for the backend server.
   - Route modules split the HTTP surface by concern:
     - `votingRoutes.js` for vote-related actions
     - `voterRoutes.js` for voter/identity-related actions
     - `blockchainRoutes.js` for blockchain/contract status or admin-style operations
   - This suggests a classic request flow: **client → route → service layer**.

3. **Application/service layer**
   - `backend/services/votingService.js` is the main orchestration layer for the voting workflow.
   - `backend/services/blockchainService.js` wraps blockchain-specific operations so the rest of the app does not talk directly to Web3/contract code.
   - `backend/services/identityService.js` handles voter identity or eligibility logic and likely mediates access to voting actions.
   - These services form the core business boundary and coordinate database checks plus blockchain writes.

4. **Database subsystem**
   - `backend/database/db.js` manages database connectivity.
   - `backend/database/schema.js` defines the persisted data structure.
   - `backend/database/voterModel.js` represents voter records in the database.
   - This layer appears to store **voter metadata / registration state / identity-related records**, separate from vote execution on-chain.

5. **Blockchain integration boundary**
   - `backend/blockchain/provider.js` abstracts the blockchain connection provider.
   - `backend/blockchain/contractService.js` encapsulates smart contract access and deployment/runtime interaction details.
   - This is the isolation layer between Node code and the chain, which keeps contract calls centralized and easier to test.

6. **Smart contract and deployment**
   - `contracts/` holds the Solidity contract source.
   - `hardhat.config.js` and `scripts/deploy.js` indicate a **Hardhat-managed Ethereum development workflow**.
   - `scripts/deployed_address.txt` stores the deployed contract address, which is then consumed by backend blockchain code.
   - That means the backend depends on a separately deployed contract instance rather than embedding contract details directly.

7. **Data flow for a vote**
   - A vote request likely enters through `votingRoutes.js`.
   - `votingService.js` probably checks voter eligibility via `identityService.js`, consults or updates the database, and then calls `blockchainService.js`.
   - `blockchainService.js` forwards the transaction to `contractService.js`, which uses the provider to submit/read from the contract.
   - Result: the backend coordinates **off-chain identity/state** with **on-chain vote execution**.

8. **Data flow for voter management**
   - Voter-related operations likely come through `voterRoutes.js`.
   - Those route handlers use `identityService.js` and database models to register, verify, or query voters.
   - This subsystem is the off-chain control plane for ensuring only eligible participants can interact with the voting contract.

9. **Testing and validation**
   - The repo is unusually test-heavy for a backend-only project.
   - Tests cover isolated layers and end-to-end behavior:
     - `tests/databaseTest.js`
     - `tests/identityServiceTest.js`
     - `tests/blockchainServiceTest.js`
     - `tests/votingServiceTest.js`
     - `tests/apiVotingTest.js`
     - `tests/systemIntegrationTest.js`
     - `tests/securityEvaluation.js`
   - This indicates the architecture is intended to be validated at multiple boundaries: database, service, API, and full system.

10. **Performance and evaluation**
   - `benchmarks/performanceBenchmark.js` and `benchmarks/statisticalBenchmark.js` suggest the system measures throughput/latency or execution consistency, likely around voting operations or contract interactions.
   - `results/performance.csv` stores benchmark output, so performance is treated as a first-class concern.

11. **Operational/docs boundary**
   - `docs/` contains deployment, environment, API, troubleshooting, and system-test documentation.
   - `scripts/deploy.js` plus the deployed address file imply a manual or scripted deployment workflow for the contract and backend integration.
   - The docs and scripts together define the operational path from local development to deployed contract-backed service.

12. **How to diagram it**
   - The clean diagram should show:
     - **HTTP clients** entering the **Node.js API server**
     - the server dispatching to **route modules**
     - routes calling **service modules**
     - services depending on two adapters: **database** and **blockchain**
     - blockchain adapter connecting to **Hardhat-deployed smart contract**
     - database adapter persisting **voter/identity state**
   - The key architectural idea is that **votes are executed on-chain, while voter identity and service coordination remain off-chain**.

Main entry points: [`backend/api/server.js`](https://github.com/ashraf-io/hybrid-trust-evoting/blob/main/backend/api/server.js) (API Server), [`backend/services/votingService.js`](https://github.com/ashraf-io/hybrid-trust-evoting/blob/main/backend/services/votingService.js) (Voting Service), [`backend/blockchain/contractService.js`](https://github.com/ashraf-io/hybrid-trust-evoting/blob/main/backend/blockchain/contractService.js) (Contract Service), [`tests`](https://github.com/ashraf-io/hybrid-trust-evoting/tree/main/tests) (Test Suite)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_g_backend["Backend"]
  node_n_server["API Server<br/>express entrypoint<br/>[server.js]"]
  node_n_voting_routes["Voting Routes<br/>http routes<br/>[votingRoutes.js]"]
  node_n_voter_routes["Voter Routes<br/>http routes<br/>[voterRoutes.js]"]
  node_n_blockchain_routes["Chain Routes<br/>http routes"]
  node_n_voting_service["Voting Service<br/>orchestrator<br/>[votingService.js]"]
  node_n_identity_service["Identity Service<br/>eligibility logic<br/>[identityService.js]"]
  node_n_blockchain_service["Blockchain Service<br/>chain facade"]
  node_n_db[("Database<br/>sqlite/postgres adapter<br/>[db.js]")]
  node_n_schema["Schema<br/>[schema.js]"]
  node_n_voter_model["Voter Model<br/>data model<br/>[voterModel.js]"]
  node_n_provider["Provider<br/>[provider.js]"]
  node_n_contract_service["Contract Service<br/>contract wrapper<br/>[contractService.js]"]
end

subgraph group_g_chain["Chain"]
  node_n_contracts{{"Smart Contract<br/>solidity contract"}}
  node_n_deploy["Deploy Script<br/>hardhat deploy<br/>[deploy.js]"]
  node_n_address["Deployed Address<br/>deployment artifact"]
end

subgraph group_g_quality["Quality"]
  node_n_tests["Test Suite<br/>validation"]
  node_n_benchmarks["Benchmarks<br/>performance eval"]
end

subgraph group_g_ops["Ops"]
  node_n_docs["Docs<br/>documentation"]
end

node_n_client(("HTTP Client<br/>requester"))

node_n_client -->|"HTTP requests"| node_n_server
node_n_server -->|"mounts"| node_n_voting_routes
node_n_server -->|"mounts"| node_n_voter_routes
node_n_server -->|"mounts"| node_n_blockchain_routes
node_n_voting_routes -->|"delegates"| node_n_voting_service
node_n_voter_routes -->|"delegates"| node_n_identity_service
node_n_blockchain_routes -->|"delegates"| node_n_blockchain_service
node_n_voting_service -->|"checks eligibility"| node_n_identity_service
node_n_voting_service -->|"submits vote"| node_n_blockchain_service
node_n_identity_service -->|"reads/writes"| node_n_db
node_n_identity_service -->|"uses model"| node_n_voter_model
node_n_db -->|"implements"| node_n_schema
node_n_blockchain_service -->|"forwards"| node_n_contract_service
node_n_contract_service -->|"connects via"| node_n_provider
node_n_contract_service -->|"calls"| node_n_contracts
node_n_deploy -->|"deploys"| node_n_contracts
node_n_deploy -->|"writes"| node_n_address
node_n_address -.->|"configures"| node_n_contract_service
node_n_tests -.->|"validates"| node_n_db
node_n_tests -.->|"validates"| node_n_voting_service
node_n_tests -.->|"validates"| node_n_blockchain_service
node_n_tests -.->|"validates"| node_n_server
node_n_benchmarks -.->|"measures"| node_n_voting_service
node_n_benchmarks -.->|"measures"| node_n_contract_service
node_n_docs -.->|"documents"| node_n_deploy
node_n_docs -.->|"documents"| node_n_server

click node_n_server "https://github.com/ashraf-io/hybrid-trust-evoting/blob/main/backend/api/server.js"
click node_n_voting_routes "https://github.com/ashraf-io/hybrid-trust-evoting/blob/main/backend/api/votingRoutes.js"
click node_n_voter_routes "https://github.com/ashraf-io/hybrid-trust-evoting/blob/main/backend/api/voterRoutes.js"
click node_n_blockchain_routes "https://github.com/ashraf-io/hybrid-trust-evoting/blob/main/backend/api/blockchainRoutes.js"
click node_n_voting_service "https://github.com/ashraf-io/hybrid-trust-evoting/blob/main/backend/services/votingService.js"
click node_n_identity_service "https://github.com/ashraf-io/hybrid-trust-evoting/blob/main/backend/services/identityService.js"
click node_n_blockchain_service "https://github.com/ashraf-io/hybrid-trust-evoting/blob/main/backend/services/blockchainService.js"
click node_n_db "https://github.com/ashraf-io/hybrid-trust-evoting/blob/main/backend/database/db.js"
click node_n_schema "https://github.com/ashraf-io/hybrid-trust-evoting/blob/main/backend/database/schema.js"
click node_n_voter_model "https://github.com/ashraf-io/hybrid-trust-evoting/blob/main/backend/database/voterModel.js"
click node_n_provider "https://github.com/ashraf-io/hybrid-trust-evoting/blob/main/backend/blockchain/provider.js"
click node_n_contract_service "https://github.com/ashraf-io/hybrid-trust-evoting/blob/main/backend/blockchain/contractService.js"
click node_n_contracts "https://github.com/ashraf-io/hybrid-trust-evoting/tree/main/contracts"
click node_n_deploy "https://github.com/ashraf-io/hybrid-trust-evoting/blob/main/scripts/deploy.js"
click node_n_address "https://github.com/ashraf-io/hybrid-trust-evoting/blob/main/scripts/deployed_address.txt"
click node_n_tests "https://github.com/ashraf-io/hybrid-trust-evoting/tree/main/tests"
click node_n_benchmarks "https://github.com/ashraf-io/hybrid-trust-evoting/tree/main/benchmarks"
click node_n_docs "https://github.com/ashraf-io/hybrid-trust-evoting/tree/main/docs"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_n_server,node_n_voting_routes,node_n_voter_routes,node_n_blockchain_routes,node_n_voting_service,node_n_identity_service,node_n_blockchain_service,node_n_db,node_n_schema,node_n_voter_model,node_n_provider,node_n_contract_service toneBlue
class node_n_contracts,node_n_deploy,node_n_address toneAmber
class node_n_tests,node_n_benchmarks toneMint
class node_n_docs toneRose
class node_n_client toneNeutral
```

## Components

### Backend

Node.js API, services, database, and blockchain adapter layers

- [API Server](https://github.com/ashraf-io/hybrid-trust-evoting/blob/main/backend/api/server.js): express entrypoint · Backend server entry point and request dispatcher · `backend/api/server.js`
- [Voting Routes](https://github.com/ashraf-io/hybrid-trust-evoting/blob/main/backend/api/votingRoutes.js): http routes · Vote submission and voting workflow endpoints · `backend/api/votingRoutes.js`
- [Voter Routes](https://github.com/ashraf-io/hybrid-trust-evoting/blob/main/backend/api/voterRoutes.js): http routes · Voter identity and registration endpoints · `backend/api/voterRoutes.js`
- [Chain Routes](https://github.com/ashraf-io/hybrid-trust-evoting/blob/main/backend/api/blockchainRoutes.js): http routes · Blockchain status and admin-style endpoints · `backend/api/blockchainRoutes.js`
- [Voting Service](https://github.com/ashraf-io/hybrid-trust-evoting/blob/main/backend/services/votingService.js): orchestrator · Coordinates voting workflow across identity, database, and chain · `backend/services/votingService.js`
- [Identity Service](https://github.com/ashraf-io/hybrid-trust-evoting/blob/main/backend/services/identityService.js): eligibility logic · Handles voter identity, registration, and eligibility checks · `backend/services/identityService.js`
- [Blockchain Service](https://github.com/ashraf-io/hybrid-trust-evoting/blob/main/backend/services/blockchainService.js): chain facade · Application-facing wrapper for blockchain operations · `backend/services/blockchainService.js`
- [Database](https://github.com/ashraf-io/hybrid-trust-evoting/blob/main/backend/database/db.js): sqlite/postgres adapter · Database connectivity and persistence boundary · `backend/database/db.js`
- [Schema](https://github.com/ashraf-io/hybrid-trust-evoting/blob/main/backend/database/schema.js): data schema · Persisted data definitions for voter records · `backend/database/schema.js`
- [Voter Model](https://github.com/ashraf-io/hybrid-trust-evoting/blob/main/backend/database/voterModel.js): data model · Database model for voter records and state · `backend/database/voterModel.js`
- [Provider](https://github.com/ashraf-io/hybrid-trust-evoting/blob/main/backend/blockchain/provider.js): web3 provider · Blockchain connection abstraction · `backend/blockchain/provider.js`
- [Contract Service](https://github.com/ashraf-io/hybrid-trust-evoting/blob/main/backend/blockchain/contractService.js): contract wrapper · Centralized access to deployed smart contract functions · `backend/blockchain/contractService.js`

### Chain

Hardhat-managed contract and deployment artifacts

- [Smart Contract](https://github.com/ashraf-io/hybrid-trust-evoting/tree/main/contracts): solidity contract · On-chain voting contract source and runtime logic · `contracts`
- [Deploy Script](https://github.com/ashraf-io/hybrid-trust-evoting/blob/main/scripts/deploy.js): hardhat deploy · Deployment workflow for the contract instance · `scripts/deploy.js`
- [Deployed Address](https://github.com/ashraf-io/hybrid-trust-evoting/blob/main/scripts/deployed_address.txt): deployment artifact · Stored address of the deployed contract instance · `scripts/deployed_address.txt`

### Quality

Tests and benchmarks that validate behavior and performance

- [Test Suite](https://github.com/ashraf-io/hybrid-trust-evoting/tree/main/tests): validation · Layered tests across database, services, API, and integration · `tests`
- [Benchmarks](https://github.com/ashraf-io/hybrid-trust-evoting/tree/main/benchmarks): performance eval · Performance and statistical measurement scripts · `benchmarks`

### Ops

Deployment and project documentation

- [Docs](https://github.com/ashraf-io/hybrid-trust-evoting/tree/main/docs): documentation · Deployment, environment, API, troubleshooting, and system test docs · `docs`

### Other components

- **HTTP Client**: requester · External caller of the backend API

## Connections

- HTTP Client → API Server: HTTP requests · Clients call the backend entrypoint
- API Server → Voting Routes: mounts · Server exposes vote-related endpoints
- API Server → Voter Routes: mounts · Server exposes voter-related endpoints
- API Server → Chain Routes: mounts · Server exposes blockchain-related endpoints
- Voting Routes → Voting Service: delegates · Vote requests are handled by the voting service
- Voter Routes → Identity Service: delegates · Voter management routes use identity logic
- Chain Routes → Blockchain Service: delegates · Blockchain endpoints use the blockchain service
- Voting Service → Identity Service: checks eligibility · Voting workflow verifies voter identity and eligibility
- Voting Service → Blockchain Service: submits vote · Voting workflow sends on-chain actions through blockchain service
- Identity Service → Database: reads/writes · Identity logic persists and queries voter state
- Identity Service → Voter Model: uses model · Identity logic relies on the voter data model
- Database → Schema: implements · Database connectivity uses the persisted schema
- Blockchain Service → Contract Service: forwards · Application layer forwards chain operations to contract wrapper
- Contract Service → Provider: connects via · Contract wrapper uses the blockchain provider
- Contract Service → Smart Contract: calls · Wrapper interacts with deployed contract logic
- Deploy Script → Smart Contract: deploys · Deploy script produces the contract instance
- Deploy Script → Deployed Address: writes · Deployment stores the deployed address artifact
- Deployed Address → Contract Service: configures · Backend chain adapter consumes the deployed address
- Test Suite → Database: validates · Database tests cover persistence behavior
- Test Suite → Voting Service: validates · Service tests cover voting orchestration
- Test Suite → Blockchain Service: validates · Tests cover blockchain integration boundary
- Test Suite → API Server: validates · API and system tests exercise the server
- Benchmarks → Voting Service: measures · Benchmarks likely target core voting flow
- Benchmarks → Contract Service: measures · Benchmarks likely include chain interaction cost
- Docs → Deploy Script: documents · Docs describe the deployment workflow
- Docs → API Server: documents · Docs cover backend API and operating procedures
