# Building CivicGemma: A Tamper-Evident E-Voting Microservices Platform with Gemma 4 🗳️

> Source: <https://dev.to/amlan24/building-civicgemma-a-tamper-evident-e-voting-microservices-platform-with-gemma-4-188o>
> Published: 2026-10-31 07:41:07+00:00

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.

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:

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**.

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]

`Auth`, `Voter`, `Election`, `Candidate`, `Voting`, `Result`, and `Audit`.
In electronic voting, preventing race conditions (e.g., clicking "Vote" simultaneously across multiple tabs) is paramount. We implemented a **three-tier defense**:

```
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!
```


