{"slug": "building-civicgemma-a-tamper-evident-e-voting-microservices-platform-with-gemma", "title": "Building CivicGemma: A Tamper-Evident E-Voting Microservices Platform with Gemma 4 🗳️", "summary": "A developer built CivicGemma, an open-source microservices e-voting pilot for local body elections, combining Java 21 and Spring Boot 3.4.2 services, an Angular 22 frontend, and Google's open-weights Gemma 4 multimodal model. The platform uses a database-per-service architecture with a compound unique index and SHA-256 ballot sealing to prevent double voting and produce tamper-evident receipts, while Gemma 4 handles voter ID image verification and multilingual manifesto summaries in English, Hindi, and Odia.", "body_md": "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). \n\nIt 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.\n\nGrassroots democracy is where policy directly impacts daily life — from local roads to sanitation and water supply. However, local body elections face unique logistical hurdles:\n\nWe asked: *Can we build a transparent, auditable, and accessible digital voting platform that guarantees ballot integrity while empowering voters with AI?*\n\nThat was the birth of **CivicGemma**.\n\nRather than building a monolithic prototype, we architected CivicGemma around the **Database-per-Service pattern** using **Spring Cloud 2024** and **Spring Boot 3.4.2**:\n\n```\n             ┌─────────────────────────┐\n               │  Angular 22 Frontend    │\n               └────────────┬────────────┘\n                            │ HTTP / REST\n                            ▼\n               ┌─────────────────────────┐\n               │   Spring Cloud Gateway  │ (Port 8080)\n               └────────────┬────────────┘\n                            │ lb://\n```\n\n┌──────────────┬─────────────┼─────────────┬──────────────┐\n\n   ▼              ▼             ▼             ▼              ▼\n\n┌──────────────┐┌────────────┐┌────────────┐┌────────────┐┌────────────┐ │ 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]\n\n`Auth`, `Voter`, `Election`, `Candidate`, `Voting`, `Result`, and `Audit`.\nIn electronic voting, preventing race conditions (e.g., clicking \"Vote\" simultaneously across multiple tabs) is paramount. We implemented a **three-tier defense**:\n\n```\nif (voteRepository.existsByElectionIdAndVoterId(dto.getElectionId(), dto.getVoterId())) {\n    throw new IllegalStateException(\"Voter has already cast a ballot.\");\n}\n\nDatabase Engine Constraint (The Hard Wall): We enforce a compound unique index constraint at the database level:\n```\n\nALTER TABLE votes ADD CONSTRAINT uk_election_voter UNIQUE (election_id, voter_id);\n\n```\nCryptographic SHA-256 Ballot Sealing: Every ballot generates a tamper-evident digital seal returned to the voter as a verifiable receipt:\n```\n\nString rawData = voterId + \":\" + electionId + \":\" + candidateId + \":\" + timestamp + \":\" + UUID.randomUUID();\n\nMessageDigest digest = MessageDigest.getInstance(\"SHA-256\");\n\nbyte[] hashBytes = digest.digest(rawData.getBytes(StandardCharsets.UTF_8));\n\n// Returns 64-character hexadecimal receipt hash\n\n```\n🤖 Core Innovation #2: Gemma 4 Multimodal Civic AI\n\nWe leveraged Google's open-weights Gemma 4 model to solve two real-world accessibility challenges:\n\n1. Multimodal Voter ID (EPIC) Verification\n\nElderly 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.\n\n2. Multilingual Manifesto Explainer\n\nLocal voters can ask natural language questions in English, Hindi, or Odia:\n\n\"Who is running in Ward 12?\"\n\"Summarize Candidate Arjun Sharma's key promises in 3 bullet points.\"\n\"Which candidate has promised better water drainage?\"\n\nGemma parses structured candidate manifestos and delivers impartial, concise summaries.\n\n🛠️ The Tech Stack\nDomain  Technologies\nBackend Java 21 LTS, Spring Boot 3.4.2, Spring Cloud 2024 (Eureka, Gateway, OpenFeign)\nFrontend    Angular 22 (Standalone Components, SSR, Tailwind CSS)\nDatabases   MySQL (Isolated schema per microservice)\nAI / ML Google Gemma 4 / Gemini API\nSecurity    Stateless JWT (HMAC-SHA256), BCrypt, SHA-256\nDevOps  Maven Multi-Module, Automated Batch Launchers (start-all.bat)\n\n🧗 Challenges Faced & Lessons Learned\n1. The JDK Compiler vs. Lombok Dilemma\n\nDuring compilation, we hit a compiler error:\n```\n\nFatal error compiling: java.lang.ExceptionInInitializerError: com.sun.tools.javac.code.TypeTag :: UNKNOWN\n\n```\nWe 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.\n\n2. Distributed State vs. Network Partitions\n\nWhen 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.\n\n🔮 What's Next for CivicGemma?\nZero-Knowledge Proofs (ZKP): Implementing zk-SNARKs to achieve complete ballot unlinkability while mathematically guaranteeing eligibility.\nConsortium Blockchain (Hyperledger Fabric): Moving the audit log service onto a distributed ledger so no single administrative authority can modify election logs.\nOffline Polling Station Sync: Edge-caching for rural booths with intermittent connectivity.\n🙏 Acknowledgements\n\nHuge thanks to Major League Hacking (MLH), DatrixLabs, and the Hacktoberfest community for organizing this hackathon!\n\nGitHub Repository: https://github.com/hira8969/E-Voting-Pilot-System-for-Local-Body-Elections\nLive Demo Video / Project Link: https://lnkd.in/p/dKgcisNt\n\nDrop a ❤️ if you found this interesting, and leave your thoughts on digital voting in the comments!\n\n---\n\n### 4. Optional Polish:\n- **Cover Image:** You can click the **✨ Generate Image** button at the top to let DEV generate an AI cover banner for your post.\n- **Preview:** Click the **Preview** tab next to \"Edit\" to see how clean the article looks before publishing.\n- Click **Publish** (blue button at the bottom left) when you're ready!\n```\n\n", "url": "https://wpnews.pro/news/building-civicgemma-a-tamper-evident-e-voting-microservices-platform-with-gemma", "canonical_source": "https://dev.to/amlan24/building-civicgemma-a-tamper-evident-e-voting-microservices-platform-with-gemma-4-188o", "published_at": "2026-10-31 07:41:07+00:00", "updated_at": "2026-10-31 07:49:25.667680+00:00", "lang": "en", "topics": ["ai-products", "generative-ai", "computer-vision", "ai-tools"], "entities": ["CivicGemma", "Gemma 4", "Google", "Spring Boot", "Angular", "Hacktoberfest", "DatrixLabs"], "also_reported_by": [], "alternates": {"html": "https://wpnews.pro/news/building-civicgemma-a-tamper-evident-e-voting-microservices-platform-with-gemma", "markdown": "https://wpnews.pro/news/building-civicgemma-a-tamper-evident-e-voting-microservices-platform-with-gemma.md", "text": "https://wpnews.pro/news/building-civicgemma-a-tamper-evident-e-voting-microservices-platform-with-gemma.txt", "jsonld": "https://wpnews.pro/news/building-civicgemma-a-tamper-evident-e-voting-microservices-platform-with-gemma.jsonld"}}