How ashraf-io/hybrid-trust-evoting works
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: server.js API Server · votingService.js Voting Service · contractService.js Contract Service · tests Test Suite
Components 19
Backend
Node.js API, services, database, and blockchain adapter layers
- API Server · Backend server entry point and request dispatcher
backend/api/server.js - Voting Routes · Vote submission and voting workflow endpoints
backend/api/votingRoutes.js - Voter Routes · Voter identity and registration endpoints
backend/api/voterRoutes.js - Chain Routes · Blockchain status and admin-style endpoints
backend/api/blockchainRoutes.js - Voting Service · Coordinates voting workflow across identity, database, and chain
backend/services/votingService.js - Identity Service · Handles voter identity, registration, and eligibility checks
backend/services/identityService.js - Blockchain Service · Application-facing wrapper for blockchain operations
backend/services/blockchainService.js - Database · Database connectivity and persistence boundary
backend/database/db.js - Schema · Persisted data definitions for voter records
backend/database/schema.js - Voter Model · Database model for voter records and state
backend/database/voterModel.js - Provider · Blockchain connection abstraction
backend/blockchain/provider.js - Contract Service · Centralized access to deployed smart contract functions
backend/blockchain/contractService.js
Chain
Hardhat-managed contract and deployment artifacts
- Smart Contract · On-chain voting contract source and runtime logic
contracts - Deploy Script · Deployment workflow for the contract instance
scripts/deploy.js - Deployed Address · Stored address of the deployed contract instance
scripts/deployed_address.txt
Quality
Tests and benchmarks that validate behavior and performance
- Test Suite · Layered tests across database, services, API, and integration
tests - Benchmarks · Performance and statistical measurement scripts
benchmarks
Ops
Deployment and project documentation
- Docs · Deployment, environment, API, troubleshooting, and system test docs
docs
Other components
- HTTP Client · External caller of the backend API
Connections 26
- 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