How navyaaasingh/electionmanagement works
1. Repository shape
This is a multi-surface election platform monorepo. The main runtime subsystems are: backend API, Hyperledger Fabric blockchain, IoT voting terminal, ML fraud detection service, and frontend UIs. Supporting layers include PostgreSQL/MongoDB/Redis/Kafka, Kubernetes/Docker deployment, and CI/testing scripts.
2. Primary end-to-end flow
A vote starts at the IoT terminal or voter-facing UI, is authenticated by the backend, persisted in operational databases, written to the Fabric ledger, and emitted as telemetry onto Kafka. From there, the ML service analyzes events and the observer/admin dashboards receive live updates over WebSocket.
3. Backend is the orchestration hub
backend/src is a Node.js/Express service organized by controllers, routes, services, middleware, models, and context-specific modules. It is the central integration point for authentication, voting, results, auditing, and operational workflows.
4. Backend boundaries and cross-cutting controls
The backend enforces security and policy through middleware for auth, CSRF, rate limiting, and MAC filtering. It also includes services for biometric auth, encryption, ZKP, Fabric integration, IoT, Kafka production, observability, results, and reconciliation/saga processing.
5. Data layer and workflow state
The backend models show a split between transactional and audit/async state: students, voters, elections, candidates, admin users, audit logs, disputes, passkeys, vote nonces, voting records, outbox events, dead-letter events, and saga status. This suggests a design that combines synchronous API writes with asynchronous, recoverable workflows.
6. Eventing and live operations
Kafka is used as the event backbone for telemetry and downstream analysis. WebSocket support is present for pushing live status to dashboards. Redis appears as supporting infrastructure for session/rate-limit style operational state.
7. Blockchain subsystem
blockchain/chaincode/voting contains the Hyperledger Fabric smart contract in Go, with its own test file and chaincode structs. The blockchain/network configs and shell scripts define the Fabric network topology and lifecycle. The ledger is the immutable enforcement boundary for vote validity and recording.
8. Edge voting terminal
iot-terminal combines ESP32 firmware/C++ and a Python runtime layer for the terminal’s operational logic. It includes biometric handling, offline cache, tamper detection, MQTT connectivity, and VVPAT printing, making it the resilience layer for disconnected or partially connected voting sites.
9. Fraud detection and monitoring
ml-service is a Python analytics service centered on stream processing and anomaly detection. The README indicates an ensemble approach; the repo contains API, consumer, alerting, fraud detection, and monitoring notebooks/scripts. It subscribes to vote/event streams rather than serving the main voting path.
10. Frontend surfaces
The root frontend/ directory is the main React + Vite unified shell for multiple roles, with API clients and components for admin, voter, observer, verification, and public pages. There are also separate admin-portal, observer-dashboard, and voter-ui directories, which look like role-specific UI variants or earlier/smaller shells. shared-ui/tokens.css provides common styling tokens.
11. Infrastructure and deployment
infrastructure/ defines both Docker images and Kubernetes manifests. The K8s layer includes backend, ML, monitoring, Kafka, MongoDB, Postgres, Redis, ingress, secrets, HPA, and a reconciliation saga worker. Monitoring is built around Prometheus and Grafana dashboards/rules.
12. Quality, simulation, and operations
The repo includes CI/CD workflows, security tests, load tests, chaos drills, and simulation scripts. These are not part of the runtime path, but they matter architecturally because they validate the vote pipeline, fraud flow, and failure recovery behavior under load and fault injection.
13. Documentation as architecture contract
The docs/ tree is unusually central: it defines API contracts, data model, blockchain schema, lifecycle/roles, threat model, deployment, monitoring, and user guides. For diagramming, these docs are effectively the authoritative boundaries and responsibilities of each subsystem.
Main entry points: server.js API server · services Core services · kubernetes Kubernetes · scripts Ops scripts
Components 24
Backend
Node/Express orchestration hub with domain contexts, policy controls, persistence, and workflow services.
- API server · Main backend entrypoint wiring routes, middleware, contexts, and services.
backend/src/server.js - Contexts · Election, vote, and voter bounded-context services that organize core business logic.
backend/src/contexts - Policy guards · Auth, CSRF, rate limiting, and MAC filtering controls.
backend/src/middleware - Core services · Biometric auth, encryption, Fabric, IoT, Kafka, observability, results, ZKP, and saga coordination.
backend/src/services - Data models · Transactional, audit, outbox, and saga state for voters, elections, and voting workflows.
backend/src/models - API routes · Authentication, election, vote, terminal, results, audit, and operations endpoints.
backend/src/routes - Saga worker · Asynchronous reconciliation and recovery processor for long-running workflows.
backend/src/workers/reconciliationSagaWorker.js
Blockchain
Hyperledger Fabric smart contract and network lifecycle for immutable vote recording.
- Voting contract · Go smart contract enforcing vote validity and ledger writes.
blockchain/chaincode/voting/voting.go - Fabric network · Topology, crypto material, and lifecycle scripts for the blockchain network.
blockchain/network
Edge terminal
IoT voting terminal firmware and runtime for disconnected or assisted voting sites.
- Terminal runtime · Python-side terminal control flow for device operation and voting interactions.
iot-terminal/src/terminal_main.py - Firmware · Embedded firmware handling biometric input, offline cache, tamper detection, and networking.
iot-terminal/firmware/main.cpp - VVPAT printer · Paper verification output for voter-verified audit trail.
iot-terminal/src/printer/vvpat_printer.py
ML service
Streaming fraud detection, alerting, and monitoring analytics.
- ML API · Service entrypoint for fraud analysis and operational exposure.
ml-service/api.py - Stream consumer · Consumes event streams for telemetry, detection, and downstream processing.
ml-service/kafka_consumer.py - Fraud detector · Ensemble fraud detection and monitoring logic.
ml-service/fraud_detector.py - Alerting · Produces fraud and monitoring alerts from analytic signals.
ml-service/alert_service.py
Frontend surfaces
Role-based web UIs and shared client-side presentation layer.
- Web shell · Unified React/Vite client shell with shared APIs and role-specific pages.
frontend/src/App.jsx - Shared UI · Common socket, snapshot, and styling primitives used across web surfaces.
shared-ui/tokens.css - Admin portal · Administrative dashboard for election operations and monitoring.
admin-portal/src/pages/MonitoringDashboard.jsx - Observer dashboard · Live observer surface for election visibility and status.
observer-dashboard/src/App.jsx - Voter UI · Voter-facing interface including biometric authentication.
voter-ui/src/App.jsx
Infrastructure
Container, Kubernetes, and monitoring deployment assets.
- Kubernetes · Cluster manifests for backend, ML, databases, Kafka, ingress, secrets, and reconciliation worker.
infrastructure/kubernetes - Monitoring · Prometheus scrape config, alert rules, and Grafana dashboards.
infrastructure/monitoring
Operations
Simulation, testing, and chaos scripts that validate the end-to-end election pipeline.
- Ops scripts · Load tests, chaos drills, and simulation harnesses for end-to-end verification.
scripts
Connections 30
- Voter UI → API server: auth/vote API · Voter actions are submitted to the backend for authentication and voting.
- Terminal runtime → API server: terminal API · The edge terminal exchanges operational and voting requests with the backend.
- API server → Policy guards: enforces · Requests pass through security and policy middleware.
- API server → Contexts: dispatches · Domain contexts implement vote, election, and voter workflow logic.
- API server → API routes: serves · The server exposes the REST surface through route modules.
- API server → Core services: coordinates · Core services handle encryption, Fabric, Kafka, WebSocket, and reconciliation.
- API server → Data models: persists · Business operations store transactional and audit state in the model layer.
- Core services → Voting contract: writes ledger · Fabric integration submits validated vote records to chaincode.
- Core services → Stream consumer: publishes telemetry · Kafka event production feeds downstream analytics and monitoring.
- Core services → Observer dashboard: live updates · WebSocket services push operational status to dashboards.
- Core services → Saga worker: reconciles · Saga coordination is completed by a background worker.
- Data models → Saga worker: async state · Outbox, dead-letter, and saga models support recoverable processing.
- Fabric network → Voting contract: hosts · The network config and scripts deploy and run the chaincode.
- Firmware → Terminal runtime: boots device · Embedded firmware provides the device-level runtime.
- Terminal runtime → VVPAT printer: prints receipt · The terminal produces voter verification output through the printer layer.
- Stream consumer → Fraud detector: analyzes · Streamed events are scored for anomalies and fraud patterns.
- Fraud detector → Alerting: triggers · Detections create alerts and monitoring events.
- ML API → Fraud detector: serves analysis · The API exposes fraud detection capabilities.
- Web shell → Shared UI: uses · Shared client-side tokens and socket helpers support the unified shell.
- Admin portal → API server: admin API · Admin and monitoring pages consume backend endpoints.
- Observer dashboard → API server: observer API · Observer dashboard reads election status and operational endpoints.
- Voter UI → API server: voter API · Voter UI exchanges account, election, and vote actions with the backend.
- Kubernetes → API server: deploys · Cluster manifests run the backend service.
- Kubernetes → ML API: deploys · Cluster manifests run the ML service.
- Kubernetes → Fabric network: orchestrates · Infrastructure includes blockchain-related runtime components.
- Kubernetes → Saga worker: deploys · The reconciliation worker is managed as a separate workload.
- Monitoring → Core services: observes · Prometheus and Grafana track backend health and workflow metrics.
- Ops scripts → API server: tests · Load and security scripts exercise the backend pipeline.
- Ops scripts → Stream consumer: simulates · Traffic simulation drives the fraud detection stream.
- Ops scripts → Fabric network: drills · Chaos drills validate blockchain and recovery behavior.