Building CivicGemma: A Tamper-Evident E-Voting Microservices Platform with Gemma 4 ๐ณ๏ธ
๐ TL;DR During Hacktoberfest Hack Day Bhubaneswar ร DatrixLabs, I built CivicGemma โ an open-source, full-stack microservices e-voting pilot system designed specifically for local body elections (Panchayats, Municipali
๐ TL;DR
During Hacktoberfest Hack Day Bhubaneswar ร DatrixLabs, I built CivicGemma โ an open-source, full-stack microservices e-voting pilot system designed specifically for local body elections (Panchayats, Municipalities, and Wards).
It combines Java 21 & Spring Boot 3.4 microservices, Angular 22, and Gemma 4 multimodal AI to deliver double-voting prevention, cryptographic SHA-256 ballot sealing, and multilingual voter assistance.
๐ก The Problem: Why Local Body Elections?
Grassroots democracy is where policy directly impacts daily life โ from local roads to sanitation and water supply. However, local body elections face unique logistical hurdles:
- Paper Ballot Inefficiencies & Fraud: High printing costs, slow manual counting, and vulnerability to tampering.
- Double-Voting Risks: Malicious voters registered across adjacent wards attempting multiple ballots.
- Information Asymmetry: Citizens often don't know who their ward candidates are or what their local manifestos promise.
We asked: Can we build a transparent, auditable, and accessible digital voting platform that guarantees ballot integrity while empowering voters with AI?
That was the birth of CivicGemma.
๐๏ธ System Architecture: The Microservices Ecosystem
Rather than building a monolithic prototype, we architected CivicGemma around the Database-per-Service pattern using Spring Cloud 2024 and Spring Boot 3.4.2:
โโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Angular 22 Frontend โ
โโโโโโโโโโโโโโฌโโโโโโโโโโโโโ
โ HTTP / REST
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Spring Cloud Gateway โ (Port 8080)
โโโโโโโโโโโโโโฌโโโโโโโโโโโโโ
โ lb://
โโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโผโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโ
โผ โผ โผ โผ โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ Auth Service โโVoter ServiceโโVoting ServiceโResult ServiceโAudit Serviceโ โ (Port 8086) โโ (Port 8081) โโ (Port 8084) โโ (Port 8085) โโ (Port 8087) โ โโโโโโโโฌโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโฌโโโโโโโ โ โ โ โ โ [Auth DB] [Voter DB] [Voting DB] [Result DB] [Audit DB]
Key Components:
- Eureka Discovery Server (8761): Dynamic registry enabling microservices to locate each other without hardcoded IPs.
- Spring Cloud API Gateway (8080): Reverse proxy handling routing, CORS policies, and centralized security.
-
7 Domain Services:
Auth,Voter,Election,Candidate,Voting,Result, andAudit. - Database-per-Service: Each microservice has its own isolated MySQL database schema to ensure zero tight coupling.
๐ก๏ธ Core Innovation #1: Unbreakable Double-Voting Defense
In electronic voting, preventing race conditions (e.g., clicking "Vote" simultaneously across multiple tabs) is paramount. We implemented a three-tier defense:
- Application Layer Check:
if (voteRepository.existsByElectionIdAndVoterId(dto.getElectionId(), dto.getVoterId())) {
throw new IllegalStateException("Voter has already cast a ballot.");
}
Database Engine Constraint (The Hard Wall): We enforce a compound unique index constraint at the database level:
ALTER TABLE votes ADD CONSTRAINT uk_election_voter UNIQUE (election_id, voter_id);
Cryptographic SHA-256 Ballot Sealing: Every ballot generates a tamper-evident digital seal returned to the voter as a verifiable receipt:
String rawData = voterId + ":" + electionId + ":" + candidateId + ":" + timestamp + ":" + UUID.randomUUID();
MessageDigest digest = MessageDigest.getInstance("SHA-256");
byte[] hashBytes = digest.digest(rawData.getBytes(StandardCharsets.UTF_8));
// Returns 64-character hexadecimal receipt hash
๐ค Core Innovation #2: Gemma 4 Multimodal Civic AI
We leveraged Google's open-weights Gemma 4 model to solve two real-world accessibility challenges:
1. Multimodal Voter ID (EPIC) Verification
Elderly or rural voters can upload an image of their Electors Photo Identity Card (EPIC). Gemma 4's vision capabilities inspect the card, verify document legibility, extract the identifier, and cross-validate with the voter-service registry.
2. Multilingual Manifesto Explainer
Local voters can ask natural language questions in English, Hindi, or Odia:
"Who is running in Ward 12?"
"Summarize Candidate Arjun Sharma's key promises in 3 bullet points."
"Which candidate has promised better water drainage?"
Gemma parses structured candidate manifestos and delivers impartial, concise summaries.
๐ ๏ธ The Tech Stack
Domain Technologies
Backend Java 21 LTS, Spring Boot 3.4.2, Spring Cloud 2024 (Eureka, Gateway, OpenFeign)
Frontend Angular 22 (Standalone Components, SSR, Tailwind CSS)
Databases MySQL (Isolated schema per microservice)
AI / ML Google Gemma 4 / Gemini API
Security Stateless JWT (HMAC-SHA256), BCrypt, SHA-256
DevOps Maven Multi-Module, Automated Batch Launchers (start-all.bat)
๐ง Challenges Faced & Lessons Learned
1. The JDK Compiler vs. Lombok Dilemma
During compilation, we hit a compiler error:
Fatal error compiling: java.lang.ExceptionInInitializerError: com.sun.tools.javac.code.TypeTag :: UNKNOWN
We discovered that the host environment was compiling with bleeding-edge JDK 25/26, which introduced breaking internal changes to com.sun.tools.javac.code.TypeTag that broke annotation processors like Lombok. We diagnosed and resolved this by pinning our toolchain to Eclipse Temurin JDK 21 LTS, restoring clean, reproducible builds.
2. Distributed State vs. Network Partitions
When voting-service records a ballot, it must sync hasVoted = true with voter-service. While OpenFeign handles synchronous calls gracefully, a network partition requires resilience. We architected fallback exception handlers and designed the schema so that the ballot ledger remains authoritative even if the voter metadata service experiences latency.
๐ฎ What's Next for CivicGemma?
Zero-Knowledge Proofs (ZKP): Implementing zk-SNARKs to achieve complete ballot unlinkability while mathematically guaranteeing eligibility.
Consortium Blockchain (Hyperledger Fabric): Moving the audit log service onto a distributed ledger so no single administrative authority can modify election logs.
Offline Polling Station Sync: Edge-caching for rural booths with intermittent connectivity.
๐ Acknowledgements
Huge thanks to Major League Hacking (MLH), DatrixLabs, and the Hacktoberfest community for organizing this hackathon!
GitHub Repository: https://github.com/hira8969/E-Voting-Pilot-System-for-Local-Body-Elections
Live Demo Video / Project Link: https://lnkd.in/p/dKgcisNt
Drop a โค๏ธ if you found this interesting, and leave your thoughts on digital voting in the comments!
---
### 4. Optional Polish:
- **Cover Image:** You can click the **โจ Generate Image** button at the top to let DEV generate an AI cover banner for your post.
- **Preview:** Click the **Preview** tab next to "Edit" to see how clean the article looks before publishing.
- Click **Publish** (blue button at the bottom left) when you're ready!
Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes โ full credit and traffic to the original publisher.