The radmm/nagarikdesu repository contains the source code for NagarikAI, a civic advocacy platform designed to bridge the gap between citizens and municipal authorities in Bengaluru, India. The application's primary function is to transform informal citizen complaints (submitted via text or voice) into professionally formatted, legally-coded formal letters addressed to specific government departments.
At its core, the project acts as an automated legal drafting engine. When a user describes a public hazard; such as a pothole, a water main burst, or an illegal dumping site; the system uses Large Language Models (LLMs) to:
- Categorize the issue into specific domains like "Roads & Infrastructure" or "Public Safety & Law."
- Assess Urgency (Routine, Medium, Urgent, or Critical).
- Route the complaint to the correct authority, such as the BBMP (Bruhat Bengaluru Mahanagara Palike) or BESCOM (Bangalore Electricity Supply Company).
- Generate a Formal Letter that references relevant municipal codes or statutory duties of care, making the complaint more actionable for officials.
The repository includes a full-stack implementation featuring a React-based frontend for reporting and tracking, and a Node.js/Express backend that integrates with Google's Gemini AI for natural language processing.
The architecture is a classic client-server model with an external AI integration. The frontend is a Single Page Application (SPA) that manages user state, multi-language support (English, Kannada, Hindi), and geographic visualization. The backend serves both as an API for AI analysis and as a static file server for the production build.
- Intake: The user interacts with
src/components/NewReport.tsx. They can type a description or use a simulated voice input. - Location Sensing: The application uses the browser's Geolocation API to pinpoint coordinates, then performs reverse geocoding via OpenStreetMap (Nominatim) to identify the specific ward or zone.
- Analysis Request: The frontend calls the
/api/analyze-reportendpoint on the Express server (server.ts). - AI Inference: The server sends a structured prompt to the Google Gemini API. The prompt, defined in
server.ts, instructs the AI to act as a "legal-expert civic advocacy agent." - Schema Enforcement: The AI returns a JSON object following a strict schema defined in the backend, ensuring consistent data for the frontend (title, category, urgency, department, and the formal letter text).
- Persistence: The frontend receives the analysis, creates a new
CivicReportobject (defined insrc/types.ts), and saves it to the browser'slocalStoragefor persistence across sessions.
graph TD
User["Citizen (UI)"] -->|"Submit Complaint"| NewReport["src/components/NewReport.tsx"]
NewReport -->|"POST /api/analyze-report"| Express["server.ts (Express)"]
subgraph Backend
Express -->|"Auth & Initialize"| GenAI["@google/genai SDK"]
GenAI -->|"Analyze & Draft Letter"| Gemini["Google Gemini 3.5 Flash"]
Gemini -->|"Structured JSON"| Express
end
Express -->|"Analysis Results"| App["src/App.tsx"]
App -->|"Sync State"| LocalStorage[("Browser localStorage")]
App -->|"Display Details"| CaseDetails["src/components/CaseDetails.tsx"]
Dashboard["src/components/Dashboard.tsx"] -->|"Read Stats"| App
Heatmap["src/components/Heatmap.tsx"] -->|"Visualize Coordinates"| App
nagarikdesu/
├── assets/
│ └── .aistudio/
├── package.json
├── server.ts
├── src/
│ ├── App.tsx
│ ├── components/
│ │ ├── Authorities.tsx
│ │ ├── BottomNav.tsx
│ │ ├── CaseDetails.tsx
│ │ ├── CaseList.tsx
│ │ ├── Dashboard.tsx
│ │ ├── Heatmap.tsx
│ │ ├── NewReport.tsx
│ │ ├── NotificationsScreen.tsx
│ │ └── Sidebar.tsx
│ ├── data.ts
│ ├── index.css
│ ├── main.tsx
│ ├── translations.ts
│ └── types.ts
├── tsconfig.json
├── vite.config.ts
├── .env.example
├── index.html
└── README.mda. Wireframe / Mock Diagram
+---------------------------------------------------------------------------------+
| [ Logo: Nagarikdesu ] [ Motto: Voice for Bengaluru ] [ EN | ಕನ್ನಡ | हिंदी ] |
+---------------------------------------------------------------------------------+
| Sidebar (Desktop) | Main Content Area |
| | |
| [ ] Dashboard | +-------------------+ +-------------------+ |
| [ ] Heatmap | | Total Cases: 12 | | Pressure Score: 85 | |
| [ ] My Cases | +-------------------+ +-------------------+ |
| [ ] Authorities | |
| [ ] Notifications | +-------------------------------------------------------+ |
| | | [ Button: + Report New Issue ] | |
| | +-------------------------------------------------------+ |
| | |
| | +-------------------------------------------------------+ |
| | | Active Reports Feed | |
| | | > #REP-001: Pothole at Indiranagar (Urgent) | |
| | | > #REP-002: Water Leakage at Koramangala | |
| | +-------------------------------------------------------+ |
| | |
+-------------------+-------------------------------------------------------------+
| Bottom Nav (Mobile): [ Dashboard ] [ Map ] [ + ] [ Cases ] [ Alerts ] |
+---------------------------------------------------------------------------------+
b. Architecture Diagram
The system architecture follows a request-response flow centered around AI-driven analysis.
graph TD
User["Citizen (UI)"] -->|"Submit Complaint"| NewReport["src/components/NewReport.tsx"]
NewReport -->|"POST /api/analyze-report"| Express["server.ts (Express)"]
subgraph Backend
Express -->|"Auth & Initialize"| GenAI["@google/genai SDK"]
GenAI -->|"Analyze & Draft Letter"| Gemini["Google Gemini 3.5 Flash"]
Gemini -->|"Structured JSON"| Express
end
Express -->|"Analysis Results"| App["src/App.tsx"]
App -->|"Sync State"| LocalStorage[("Browser localStorage")]
App -->|"Display Details"| CaseDetails["src/components/CaseDetails.tsx"]
Dashboard["src/components/Dashboard.tsx"] -->|"Read Stats"| App
Heatmap["src/components/Heatmap.tsx"] -->|"Visualize Coordinates"| App
c. Key Architectural Details
Frontend (React/Vite):
Located in src/. Uses a single-page architecture where the tab state in src/App.tsx controls which component is rendered. Styles are managed via Tailwind CSS with a dark-mode "glassmorphism" aesthetic. Backend (Express):
Defined in server.ts. Acts as a bridge to the Gemini AI API to prevent exposing API keys on the frontend. Includes a Graceful Fallback: If the Gemini API fails or no key is provided, the server returns a pre-defined mock response (mockFallbackResponse) so the app remains functional for testing. AI Engine:
The backend uses a system prompt that instructs Gemini to act as a legal-expert civic advocacy agent. It enforces a strict JSON schema requiring a title, category, urgency, department assignment, and a formal legal letter referencing municipal codes. Persistence:
There is no external database (like PostgreSQL or MongoDB). All user reports are persisted locally in the user's browser using localStorage (managed in src/App.tsx).
- Frontend Framework: React 19 with TypeScript.
- Build Tooling: Vite 6 for the frontend development and HMR, and
esbuildfor bundling theserver.tsinto a production-ready CJS file (dist/server.cjs). - Styling: Tailwind CSS (using the
@tailwindcss/viteplugin) for a modern, high-contrast "dark mode" aesthetic with significant use of backdrop blurs and ambient glow effects. - AI Integration:
@google/genaiSDK targeting thegemini-3.5-flashmodel. - Icons:
@phosphor-icons/reactandlucide-react. - Mapping: Leaflet (
leaflet) for the interactive heatmap and issue density visualization. - Animations: Framer Motion (
motion) for smooth transitions between dashboard tabs.
- Localization:
src/translations.tsprovides a comprehensive mapping for English, Kannada, and Hindi. The system doesn't just translate UI labels; it provides a framework for the AI to understand and generate content relevant to the local context. - Prompt Engineering: In
server.ts, the system uses a sophisticated system prompt that defines available departments (BBMP, BWSSB, BESCOM, Police) and specific statutory duties. It includes logic to set aneedsHumanReviewflag if the input is ambiguous or contains swearing. - Graceful Fallbacks: The
server.tsfile includes amockFallbackResponse. If theGEMINI_API_KEYis missing or the API call fails, the system still returns a functional, Bengaluru-specific response to allow for development and testing without active API credits. - Bento-style Dashboard:
src/components/Dashboard.tsximplements a modern grid layout displaying "Community Pressure" scores (a simulated metric of how many citizens support a specific case) and "Priority Indexes."
To run the project, developers need to configure environment variables as shown in .env.example:
GEMINI_API_KEY: A valid API key from Google AI Studio.APP_URL: The base URL for the application.
Commands:
npm install: Install dependencies.npm run dev: Starts the server usingtsx(TypeScript Execute) which runsserver.ts. The server then handles both the API and the Vite middleware for the frontend.npm run build: Compiles the frontend via Vite and the backend viaesbuild.
