CivicBrain.AI is a state-of-the-art interactive platform designed to modernize civic learning. It combines a stunning 3D interactive interface with the power of Google's Gemini AI to create an engaging, gamified learning experience.
CivicBrain.AI was born from a simple but powerful idea: Empowerment through Education. In a world of complex election cycles and misinformation, our platform serves as a "GPS for Democracy."
- Objective: To bridge the gap between complex legal/electoral processes and the average citizen.
- Problem Statement: Traditional civic education is often dry, inaccessible, and static. Young voters lack engaging tools to understand the why and how of their democratic rights.
- Our Solution: A hybrid AI platform that provides instant clarity (Aura AI), visualizes history (Election Timeline), and rewards participation (Gamified Dashboard).
- π€ Aura AI Assistant: A fully integrated Gemini AI proxy that answers civic-related questions with context awareness.
- πΊοΈ 3D Interactive Map: A beautiful Three.js powered interactive map displaying real-time data for locations like Hyderabad, India.
- π Dynamic Theming: Seamless global Dark and Light (Professional) modes using custom CSS variables.
- π Secure Backend Proxy: API keys are never exposed to the browser. All AI requests route securely through a custom Express server.
- π Gamified Learning & Dashboard: Track student progress with a persistent data layer (Firebase/Supabase), earning XP and badges for completing learning milestones.
- π Election Timeline: An interactive horizontal timeline that traces the historical journey of democratic elections.
- π AI-driven Quiz Generator: Automatically generates civic-focused quizzes using Gemini AI to test user knowledge dynamically.
- π± Progressive Web App (PWA): Installable on mobile and desktop for offline-ready access.
- React 19 & TypeScript: Builds the dynamic, component-based user interface with strict type-safety for a robust codebase.
- Vite: An ultra-fast build tool used to compile and bundle the frontend application for production.
- Node.js & Express 5: Acts as the backend server. It serves the static frontend and acts as a secure proxy for the Gemini API, ensuring API keys are never exposed to the client.
- Google Gemini AI (2.5 & Flash): The brain behind the Aura AI Assistant and dynamic Quiz Generator, providing real-time, context-aware civic knowledge.
- Three.js & React Three Fiber: Renders the stunning, interactive 3D elements, including the real-time globe and location maps.
- Firebase / Supabase: Provides the persistent data layer for user authentication, tracking student progress, XP, and earning badges.
- Google Cloud Run & Docker: Containerizes the entire application and deploys it to a serverless, highly scalable environment.
- Vanilla CSS & Variables: Powers the glassmorphism aesthetics and the seamless global Dark/Light mode toggle.
CivicBrain.AI is built as a Progressive Web App (PWA), meaning it can work even without an internet connection. Here's how:
| Technology | Role |
|---|---|
vite-plugin-pwa |
Automatically generates a Service Worker at build time, handling all caching strategies without manual configuration. |
| Service Worker | A background script that intercepts network requests. When offline, it serves cached pages and assets instantly instead of showing a browser error. |
| Cache API | Stores all static assets (HTML, CSS, JS, images) locally on the user's device after the first visit, so subsequent loads are instant. |
Web App Manifest (manifest.json) |
Defines the app's name, icons, theme color, and display mode. This enables the browser's "Install App" prompt on mobile and desktop. |
| localStorage | Persists user preferences (like the Dark/Light theme toggle) across sessions, even when offline. |
| Qwen 2.5 0.5B (via WebLLM) | Google's lightweight open-source AI model that runs entirely inside the browser using WebGPU. When the user goes offline, the Aura AI Assistant automatically switches from cloud-based Gemini to the local Qwen model, so AI chat continues to work without internet. |
@mlc-ai/web-llm |
The Machine Learning Compilation engine that loads and runs the Gemma 2B model directly in the browser using WebGPU acceleration β no server needed. |
How it works in practice:
- The user visits the site for the first time β the Service Worker caches all assets in the background.
- On the next visit (even without internet), the cached version loads instantly.
- When online β the AI Assistant uses Gemini (Cloud) for fast, powerful responses.
- When offline β the AI Assistant automatically falls back to Qwen 2.5 (Local), running entirely in the browser via WebGPU β no internet required for AI chat!
This project uses a hybrid Server-Side + Static Frontend architecture optimized for containerized environments like Google Cloud Run.
- Frontend: React + Vite (Compiled into static HTML/CSS/JS in the
dist/folder). - Backend Server: Node.js + Express (
server.js). This server acts as the entry point. It serves the static frontend files and provides the secure/api/geminiproxy for AI requests. - Deployment: Docker container (
Dockerfile) configured to skip heavy builds in the cloud and instantly serve the pre-built application.
Follow these exact steps to run CivicBrain.AI on your local machine.
- Node.js (v20 or higher recommended)
- Git
- A Gemini API Key from Google AI Studio
Open your terminal and install all required Node modules:
npm installCreate a file named .env in the root folder (next to package.json) and add your Gemini API Key and other required variables:
# AI Integration
GEMINI_API_KEY=your_actual_gemini_api_key_here
# Firebase/Supabase Configs (if applicable)
VITE_SUPABASE_URL=...
VITE_SUPABASE_ANON_KEY=...To run the app locally with hot-reloading (for making frontend changes):
npm run devThe app will be available at http://localhost:5173.
We have perfectly optimized this project to be deployed flawlessly on Google Cloud Run without hitting memory limits.
Because cloud environments have strict memory limits, we build the heavy React code on your local computer first:
npm run buildThis generates a dist/ folder containing your optimized production website.
Make sure you have the Google Cloud CLI installed and you are logged in (gcloud auth login).
Run the deployment command:
gcloud run deploy civicbrain --source . --region us-central1 --allow-unauthenticatedWhat happens here?
- Google Cloud reads the
Dockerfile. - The
.gcloudignorefile ensures thenode_modulesfolder is skipped. - The
dist/folder is uploaded directly. - Only lightweight production dependencies are installed (
npm install --omit=dev --legacy-peer-deps).
Your live website does not automatically read your local .env file for the Gemini API Key. You must add it manually to Google Cloud:
- Go to the Google Cloud Run Console.
- Click on the
civicbrainservice. - Click Edit & Deploy New Revision.
- Go to the Variables & Secrets tab.
- Click Add Variable and create a variable named
GEMINI_API_KEY. Paste your key as the value. - Click Deploy.
π¦ Civicbrain.ai
β£ π dist/ # Compiled frontend code (Generated after build)
β£ π public/ # Static assets (images, icons)
β£ π src/ # React Source Code
β β£ π components/ # Reusable UI components
β β£ π pages/ # Application views (Dashboard, Admin, Assistant)
β β£ π App.tsx # Main application routing and theme logic
β β£ π index.css # Global CSS containing Light/Dark theme variables
β β π main.tsx # React DOM entry point
β£ π .env # Local environment secrets (DO NOT COMMIT)
β£ π .gcloudignore # Google Cloud build exclusion rules
β£ π Dockerfile # Cloud Run container configuration
β£ π package.json # Dependencies and scripts
β π server.js # Express Backend & API Proxy
Built with β€οΈ for Civic Education.