How padmaganesh14/grievancepilot works
1. Purpose and topology
GrievancePilot AI is a municipal grievance-management and officer decision-support system. Citizens submit and track civic issues; officers review AI-derived classification, priority, routing, funding/budget context, patterns, and workforce assignments. It is split into a React frontend and Node/Express backend:
• frontend/src/router.tsx
• backend/src/app.ts
• backend/src/server.ts
2. Frontend entry points and user surfaces
The frontend is a TypeScript React application with route-driven citizen and officer experiences. Public routes cover landing, submission, and tracking; protected-style officer routes expose operational dashboards and detail views.
• frontend/src/routes/citizen.index.tsx
• frontend/src/routes/track.tsx
• frontend/src/routes/officer.index.tsx
Officer UI is organized around a shared portal shell and specialized pages for grievances, prioritization, patterns, budgets, funding, recommendations, maps, and workforce.
• frontend/src/components/officer/OfficerPortalShell.tsx
• frontend/src/components/officer/pages/GrievanceIntelligence.tsx
• frontend/src/components/officer/pages/WorkforceManagement.tsx
3. API boundary, identity, and request handling
Express exposes API and auth route groups, with controllers as the backend application boundary. Authentication middleware protects authorized operations; upload middleware supports complaint attachments or documents.
• backend/src/routes/api.ts
• backend/src/routes/authRoutes.ts
• backend/src/middleware/authMiddleware.ts
Core request orchestration is controller-based for complaints, officer operations, workflow callbacks, patterns, and AI assistance.
• backend/src/controllers/complaintController.ts
• backend/src/controllers/officerController.ts
• backend/src/controllers/workflowController.ts
4. Grievance lifecycle and decision flow
The central flow is complaint creation/update → AI/workflow analysis → category, department, severity, and priority persistence → officer review/assignment → progress toward resolution. Complaint records are the primary operational aggregate; workflows preserve AI or process state; users represent citizens/officers.
• backend/src/models/Complaint.ts
• backend/src/models/Workflow.ts
• backend/src/models/User.ts
The decision engine is the domain layer for prioritization and allocation-oriented decisions, separated from HTTP controllers.
• backend/src/services/decisionEngine.ts
• backend/src/controllers/complaintController.ts
5. AI and automation integration
n8n is the explicit external orchestration boundary for AI/LLM analysis and callbacks. Backend services invoke or interpret n8n workflow responses, while the frontend also has an n8n-facing service. The AI assistant controller supports an officer-facing copilot surface.
• backend/src/services/n8nService.ts
• backend/src/controllers/workflowController.ts
• frontend/src/services/n8n.ts
Operational scripts indicate support for replaying missing AI analysis, probing n8n responses, and repairing workflow/assignment state.
• backend/src/scripts/reprocessMissingAI.ts
• backend/src/scripts/probeN8NResponse.ts
6. Municipal intelligence data domains
Budget and funding are modeled separately from grievances, enabling contextual funding eligibility, transaction approval, and budget intelligence. A supplied municipal budget PDF can be imported into these records.
• backend/src/models/BudgetDocument.ts
• backend/src/models/BudgetProject.ts
• backend/src/models/FundingTransaction.ts
Workforce records support assignment capacity; pattern records and clustering utilities support hotspot/recurrence analysis and department resolution.
• backend/src/models/Workforce.ts
• backend/src/models/PatternRecord.ts
• backend/src/utils/clusteringEngine.ts
7. Runtime and infrastructure
Backend is TypeScript on Node.js/Express with a database adapter/configuration layer; README identifies PostgreSQL or MongoDB as intended persistence options. Frontend is React/TypeScript built through Vite, with a server/start entry path. Environment templates define deployment-time secrets and external endpoints.
• backend/src/config/db.ts
• backend/.env.example
• frontend/src/start.ts
Main entry points: complaintController.ts Request controllers · api.ts API and auth routes · router.tsx Route surfaces · n8nService.ts Workflow integration
Components 19
React frontend
- Frontend startup
frontend/src/start.ts - Route surfaces · Citizen submission/tracking and officer routes.
frontend/src/router.tsx - Citizen experience · Landing, submission, and tracking.
frontend/src/routes/citizen.index.tsx - Officer portal · Shared operational dashboard shell.
frontend/src/components/officer/OfficerPortalShell.tsx - Officer intelligence · Grievance intelligence and workforce management.
frontend/src/components/officer/pages/GrievanceIntelligence.tsx - n8n client
frontend/src/services/n8n.ts
Express backend
- Server bootstrap
backend/src/server.ts - Express application
backend/src/app.ts - API and auth routes
backend/src/routes/api.ts - Authorization
backend/src/middleware/authMiddleware.ts - Request controllers · Complaint, officer, and workflow operations.
backend/src/controllers/complaintController.ts - Workflow integration · Invokes and interprets automation responses.
backend/src/services/n8nService.ts
Municipal domain
- Decision engine · Prioritization and allocation decisions.
backend/src/services/decisionEngine.ts - Complaints · Primary grievance lifecycle record.
backend/src/models/Complaint.ts - Workflow state · Persists AI and process state.
backend/src/models/Workflow.ts - Municipal intelligence · Budgets, funding, workforce, and patterns.
backend/src/models/BudgetDocument.ts - Pattern clustering · Supports hotspot and department analysis.
backend/src/utils/clusteringEngine.ts
External systems
- Persistence adapter · PostgreSQL or MongoDB persistence.
backend/src/config/db.ts - n8n automation · AI/LLM analysis and callbacks.
Connections 24
- Frontend startup → Route surfaces: starts
- Route surfaces → Citizen experience: renders
- Route surfaces → Officer portal: renders
- Officer portal → Officer intelligence: hosts
- Citizen experience → API and auth routes: submits and tracks
- Officer intelligence → API and auth routes: operates through
- n8n client → n8n automation: calls
- Server bootstrap → Express application: boots
- Express application → API and auth routes: mounts
- API and auth routes → Authorization: protects operations
- Authorization → Request controllers: authorizes
- API and auth routes → Request controllers: dispatches
- Request controllers → Decision engine: requests decisions
- Request controllers → Workflow integration: orchestrates analysis
- Workflow integration → n8n automation: invokes
- n8n automation → Request controllers: workflow callbacks
- Request controllers → Complaints: creates and updates
- Decision engine → Complaints: prioritizes
- Decision engine → Municipal intelligence: uses capacity and funding
- Pattern clustering → Municipal intelligence: derives patterns
- Workflow integration → Workflow state: records state
- Complaints → Persistence adapter: persists via
- Workflow state → Persistence adapter: persists via
- Municipal intelligence → Persistence adapter: persists via