Real-time monitoring and AI-powered insights for rural development projects
Features β’ Installation β’ AI RAG System β’ Architecture β’ Demo
RuraLens is a cutting-edge village digital twin platform that combines real-time IoT monitoring, 3D visualization, and AI-powered Retrieval-Augmented Generation (RAG) to provide intelligent insights for rural development schemes. The platform enables administrators, field workers, and citizens to ask natural language questions and receive accurate, citation-backed answers from government documents and live data.
Rural development projects often suffer from:
- β Information scattered across multiple documents
- β Lack of real-time visibility into scheme progress
- β Difficulty identifying discrepancies and delays
- β Limited citizen engagement and feedback
- β AI-Powered Q&A: Ask questions in plain language, get instant answers
- β Smart Citations: Every answer backed by verifiable document sources
- β Real-Time Monitoring: Live IoT sensor data and scheme tracking
- β Automated Compliance: AI analyzes vendor reports vs government plans
- β Interactive 3D Maps: Visualize projects and sensor locations
The crown jewel of RuraLens - an intelligent question-answering system that understands context and provides accurate, sourced answers.
User Question β RAG Backend β Pathway MCP β Document Store
β β β
PII Filter Vector Search Embeddings
β β β
Rate Limit LLM Processing Knowledge Base
β β β
Cache Check β Answer Generated β Top Results
β
Citation Enrichment (Geo + Metadata)
β
Frontend Display with Map Integration
| Feature | Description |
|---|---|
| π Natural Language Queries | Ask questions like "Why is Swachh Bharat delayed?" |
| π Multi-Source Knowledge | Searches schemes, reports, sensor data, citizen feedback |
| π― Smart Citations | Every answer includes source documents with relevance scores |
| πΊοΈ Map Integration | Click citations to view locations on 3D map |
| β‘ Lightning Fast | 120-second cache, sub-second responses |
| π PII Protection | Auto-redacts sensitive information (Aadhaar, PAN, emails) |
| π Geo-Aware | Citations include precise coordinates with 4-level fallback |
Advanced infrastructure failure prediction using Graph Neural Networks to simulate cascading impacts across village infrastructure.
| Feature | Description |
|---|---|
| π Real Infrastructure Network | Auto-generates graph from water tanks, pumps, power nodes, buildings |
| π₯ Failure Simulation | Click any infrastructure node to trigger realistic failures |
| π Cascading Impact | AI predicts how failures propagate through connected infrastructure |
| π Impact Visualization | Color-coded nodes show damage levels (green β yellow β orange β red) |
| β Dynamic Node Addition | Right-click map to add new infrastructure nodes with auto-connections |
| π Smart Edge Generation | Nodes automatically connect based on type and proximity |
| π Accumulated Damage | Multiple failures compound damage realistically |
| πΊοΈ Interactive 3D Map | View entire infrastructure network on MapLibre GL with smooth animations |
Infrastructure Node Selected β Trigger Failure
β
GNN API Analysis (or Local Simulation)
β
Calculate Impact Propagation via Edges
β
Score Each Connected Node (0-100%)
β
Update Map Visualization
β
Display in InfoPanel with Details
- View Network: Navigate to "Village Analyzer" from sidebar
- Explore Map: All infrastructure appears as labeled nodes on 3D map
- Trigger Failure: Click any node β Select failure type and severity
- Watch Propagation: See impacts spread through network in real-time
- Add Nodes: Right-click map β Add new infrastructure β Auto-connects
Scenario 1: Water Pump Failure
- Main Pump Station fails β
- Connected pipes show 60% impact β
- Hospital, School lose water supply (80% impact) β
- Consumer areas show reduced service (40-70%)
Scenario 2: Power Transformer Failure
- Transformer fails β
- All pumps lose power (90% impact) β
- Entire water system compromised β
- Critical buildings affected
Scenario 3: Multiple Cascading Failures
- First failure: Pump at 50% damage
- Second failure: Same pump now 56% damage (accumulated)
- Third failure: Pump cascades to failure (>90%)
Enhanced Visual Experience:
- Opaque Popups: Beautiful gradient backgrounds (slate-900 β slate-800) with glowing borders
- Color-Coded Infrastructure: Green (healthy) β Yellow (impacted) β Orange (severe) β Red (failed)
- Smooth Animations: Pulsing failed nodes, glowing impacts
- Detailed Tooltips: Hover over nodes to see health, type, and impact details
- Map Controls: Zoom, pitch, rotation, fullscreen, reset view
- Dual-Mode Display: Normal monitoring + Failure simulation modes
- Live Dashboard: Water quality, power consumption, scheme progress
- Alert System: Automatic notifications for critical infrastructure issues
- Citizen Feedback: Anonymous report system with GPS tracking
- Government Schemes: Track budget, timeline, and completion status
Q: "What water problems are reported in Zone B?"
A: Citizens report water pressure issues in Zone B, particularly during peak hours
(7-9 AM) affecting approximately 45 households. Sensor data confirms 30% pressure
drop during these times.
π Citations: [Sensor-042 (89% match), Citizen Report #127 (75% match)]
Q: "Why is MGNREGA road scheme delayed?"
A: The MGNREGA Rural Road Development is delayed by 14 days due to monsoon weather
impact and labor shortage. Vendor reported 40% workforce availability in October.
π Citations: [Vendor Report Phase-2 (92% match), Weather Log (78% match)]
Q: "Show me all schemes with budget overruns"
A: 2 schemes show budget variance: S-123 (+12% due to material cost increase),
S-456 (+8% from scope expansion approved in review).
π Citations: [Financial Report Q3 (94% match), Budget Analysis (81% match)]
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Frontend (React) β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββββββββ β
β β Dashboard β β RAG Modal β β 3D Map Viewer β β
β β Components β β with β β (MapLibre GL) β β
β β β β Citations β β + GNN Viz β β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββββββββ β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββββββββ β
β β Impact β β Failure β β Node Addition β β
β β Predictor β β Popups β β Interface β β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Backend (Node.js/Express) β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββββββββ β
β β RAG Router β β PII Filter β β Cache Manager β β
β β + Auth β β Sanitizer β β (120s TTL) β β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββββββββ β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββββββββ β
β β Citation β β Geo Fallbackβ β Audit Logger β β
β β Enrichment β β 4-Level β β + Trace IDs β β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββββββββ β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββββββββ β
β β GNN Proxy β β Infrastructureβ β Schemes API β β
β β Client β β Graph Store β β Routes β β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β AI Services Layer β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Pathway MCP Server (Python/Rust) β β
β β β’ DocumentStore: Schemes, Reports, Sensors, Feedback β β
β β β’ VectorSearch: Embedding-based semantic search β β
β β β’ LLM: OpenAI/Gemini for answer generation β β
β β β’ REST API: /v1/pw_ai_answer endpoint β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β GNN Service (Python) β β
β β β’ Graph Neural Network for impact prediction β β
β β β’ Node embedding and feature extraction β β
β β β’ Cascading failure simulation β β
β β β’ REST API: /api/gnn/predict-structured endpoint β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β MongoDB Database β
β Collections: schemes, users, vendorReports, citizenReports, β
β feedback, gnnNodes, gnnEdges, infrastructureGraph β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Frontend:
- βοΈ React 18 with TypeScript
- π¨ Tailwind CSS for styling
- πΊοΈ MapLibre GL for 3D maps
- π WebSocket for real-time updates
- π± Capacitor for mobile apps
- π Lucide React for icons
Backend:
- π’ Node.js with Express
- π JWT authentication
- πΎ MongoDB with Mongoose
- π€ Gemini AI for document analysis
- π WebSocket server for live data
AI/RAG Layer:
- π Python Pathway framework
- π¦ Rust-powered vector search
- π§ OpenAI GPT-4 / Google Gemini
- π Document embeddings & semantic search
# Required
Node.js >= 18.x
Python >= 3.11
MongoDB >= 6.0
Git
# Optional (for production RAG)
WSL2 (Windows) or Linux
Docker (for containerized deployment)# 1. Clone repository
git clone https://github.com/Abhishekmishra2808/village-digital-twin.git
cd village-digital-twin
# 2. Install frontend dependencies
npm install
# 3. Install backend dependencies
cd backend
npm install
# 4. Set up environment variables
cp .env.example .env
# Edit .env with your MongoDB URI, API keys, etc.
# 5. Start development servers
npm run dev # Frontend (Port 3000)
npm start # Backend (Port 3001, from backend folder)For immediate testing without full Pathway setup:
# 1. Install Flask
pip install flask
# 2. Start mock Pathway server
cd llm-app/templates/question_answering_rag
python mock_pathway_server.py
# Server runs on http://localhost:8080
# 3. Backend .env should have:
PATHWAY_MCP_URL=http://localhost:8080/v1/pw_ai_answer
PATHWAY_MCP_TOKEN=mock_token_for_developmentFor production with real Pathway server:
# On Linux/WSL2:
cd llm-app/templates/question_answering_rag
bash setup-wsl.sh
# Configure with your LLM API key
export OPENAI_API_KEY=your_key_here
# or
export GEMINI_API_KEY=your_key_here
# Run Pathway server
source pathway-env/bin/activate
python app.pyThe "Ask AI" button appears in:
- π Admin Dashboard - Top right corner
- π₯ Citizen Dashboard - Top right corner
- π Schemes View - Header toolbar
Access from the sidebar menu β "Village Analyzer"
Features:
- π View Infrastructure Network: Automatically loaded from real village data
- πΊοΈ Interactive 3D Map: All infrastructure nodes displayed with labels and icons
- π₯ Trigger Failures: Click any node β Select failure type and severity
- π Watch Impacts: See how failures cascade through the network
- β Add Nodes: Right-click map β Add new infrastructure with auto-connections
- π Reset Network: Clear all failures and return to original state
- π Accumulated Damage: Multiple failures compound realistically
Using the Analyzer:
Step 1: Navigate to "Village Analyzer" from sidebar
Step 2: View the infrastructure network on the map
β’ Green nodes = Healthy (100% operational)
β’ Yellow nodes = Minor impact (30-60% operational)
β’ Orange nodes = Severe impact (10-30% operational)
β’ Red nodes = Failed (<10% operational)
Step 3: Click any infrastructure node to trigger a failure
ββββββββββββββββββββββββββββββββββββ
β β οΈ Trigger Failure β β
ββββββββββββββββββββββββββββββββββββ€
β Main Pump Station β
β pump β’ Health: 100% β
β β
β Failure Type: [Supply Disruption]β
β Severity: [Low][Medium][High] β
β β
β [π₯ Trigger Failure] β
ββββββββββββββββββββββββββββββββββββ
Step 4: Watch the impact propagate
β’ GNN calculates impact on connected nodes
β’ Map updates with color-coded damage levels
β’ InfoPanel shows detailed impact analysis
Step 5: Add more infrastructure (Optional)
β’ Right-click anywhere on the map
β’ Enter node name and select type
β’ Node auto-connects based on proximity and type
Step 6: Trigger multiple failures to see accumulated damage
β’ Each failure adds to existing damage
β’ Nodes above 90% damage cascade to failure
Click "Ask AI" button β Modal opens:
ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β π€ Ask AI about Schemes β β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β What water problems are reported in Zone B? β
β ββββββββββββββββββββββββββββββββββββββββββββββ β
β β β β
β ββββββββββββββββββββββββββββββββββββββββββββββ β
β [Ask AI] β
β β
β π‘ Example questions: β
β β’ Why is Swachh Bharat scheme delayed? β
β β’ Show budget status of MGNREGA project β
β β’ What are citizen complaints in Zone A? β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Answer: β
β βββββββββββββββββββββββββββββββββββββββββββββββ β
β Citizens report low water pressure in Zone B, β
β particularly during morning hours (7-9 AM). β
β Sensor data confirms 30% pressure drop. β
β β
β π Citations (2): β
β ββββββββββββββββββββββββββββββββββββββββββββββ β
β β π Sensor Report 89% β β
β β "Sensor-042 recorded pressure drops..." β β
β β [Show on Map] [View Document] β β
β ββββββββββββββββββββββββββββββββββββββββββββββ β
β ββββββββββββββββββββββββββββββββββββββββββββββ β
β β π¬ Citizen Report 75% β β
β β "Multiple complaints from Zone B..." β β
β β [Show on Map] [View Document] β β
β ββββββββββββββββββββββββββββββββββββββββββββββ β
β β
β π Trace ID: trace_1763664692_2300 β’ Cached β β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
- Show on Map: Pans to citation location with highlight
- View Document: Opens full source document
- Relevance Score: Shows AI confidence (0-100%)
| Feature | Implementation |
|---|---|
| π PII Sanitization | Auto-redacts Aadhaar, PAN, emails, phones before LLM |
| π« JWT Authentication | All RAG queries require valid user token |
| β±οΈ Rate Limiting | 10 queries/minute per user to prevent abuse |
| π Service-to-Service Auth | Backend β Pathway uses PATHWAY_MCP_TOKEN |
| π Audit Logging | Every query logged with trace_id, user, latency |
| π« Fail-Open Policy | Returns graceful errors if Pathway unavailable |
// Example: PII auto-redacted before sending to LLM
Input: "Contact John at john@example.com, Aadhaar: 1234-5678-9012"
Output: "Contact John at [EMAIL_REDACTED], Aadhaar: [AADHAAR_REDACTED]"POST /api/rag-query
Content-Type: application/json
Authorization: Bearer <JWT_TOKEN>{
"question": "Why is Swachh Bharat scheme delayed?",
"scheme_id": "S-123", // Optional: filter by scheme
"bbox": [77.5, 28.4, 77.6, 28.5], // Optional: geographic filter
"max_citations": 5 // Optional: limit citations (default 5)
}{
"answer": "The Swachh Bharat Mission is delayed by 14 days due to monsoon weather...",
"citations": [
{
"doc_id": "vendor-report-VR-2024-001",
"type": "vendor_report",
"snippet": "Weather delays in October pushed timeline by 3 weeks...",
"score": 0.92,
"timestamp": "2024-10-15T10:30:00Z",
"geo": {
"lat": 28.4595,
"lon": 77.0266
}
},
{
"doc_id": "scheme-S-123",
"type": "scheme",
"snippet": "Phase 2 originally scheduled for October completion...",
"score": 0.87,
"timestamp": "2024-09-01T00:00:00Z",
"geo": {
"lat": 28.4612,
"lon": 77.0312
}
}
],
"trace_id": "trace_1763664729_8574",
"cached": false,
"processing_time_ms": 612
}| Code | Description |
|---|---|
400 |
Invalid request (missing question, malformed bbox) |
401 |
Unauthorized (invalid/missing JWT token) |
429 |
Rate limit exceeded (>10 queries/min) |
502 |
RAG service temporarily unavailable |
500 |
Internal server error |
cd backend
powershell -File test-rag.ps1Expected output:
=== Testing RAG Feature ===
1. Logging in...
β
Login successful!
2. Sending RAG query...
β
RAG query successful!
Answer: Multiple schemes are experiencing delays...
Citations: 2 (scores: 0.9, 0.82)
Cached: False
- Open http://localhost:3000
- Login with:
admin@village.com/admin123 - Click "Ask AI" button (blue gradient)
- Type:
"Why is MGNREGA delayed?" - Verify:
- β Answer appears within 1 second
- β Citations show with scores
- β "Show on Map" buttons work
- β Cached indicator on repeat query
π Project Root
βββ π README.md (this file)
βββ π docs/
β βββ π README_RAG.md (detailed RAG setup)
βββ π backend/
β βββ π routes/
β β βββ π§ rag.js (RAG endpoint)
β βββ π utils/
β β βββ π§ pathwayClient.js (MCP client)
β β βββ π§ piiSanitizer.js (privacy filter)
β β βββ π§ ragCache.js (response cache)
β βββ π test-rag.ps1 (test script)
βββ π src/
β βββ π components/
β β βββ π Rag/
β β βββ π¨ RagQueryModal.tsx (UI component)
β βββ π hooks/
β β βββ π§ useRagQuery.ts (React hook)
β βββ π utils/
β βββ π§ mapHighlighter.ts (map integration)
βββ π llm-app/
βββ π templates/question_answering_rag/
βββ π app.py (Pathway server)
βββ π mock_pathway_server.py (dev mock)
βββ π setup-wsl.sh (Linux setup)
- π Pathway Documentation
- π RAG Setup Guide
- π API Reference
The RAG feature is integrated across the platform:
1. Admin Dashboard
- Click "Ask AI" in top-right corner
- Query about scheme status, delays, budget
- View citations with geo-coordinates
2. Schemes View
- "Ask AI" button in toolbar
- Ask about specific schemes
- Citations link to scheme details
3. Citizen Dashboard
- Public-facing AI assistant
- Simplified query interface
- Helps citizens track projects
We welcome contributions! Please see our Contributing Guide for details.
- π§ AI/ML: Improve RAG accuracy, add new LLM providers
- π¨ UI/UX: Enhance modal design, add voice input
- π Analytics: Query insights, popular questions dashboard
- π i18n: Multi-language support for queries
- π± Mobile: Optimize RAG UI for mobile devices
This project is licensed under the MIT License - see LICENSE file.
Developed by: Village Digital Twin Team
Contact: abhishekmishra8770@gmail.com
GitHub: @Abhishekmishra2808
- Pathway - For the amazing RAG framework
- OpenAI/Google - For LLM APIs
- MongoDB - For flexible document storage
- React Community - For excellent UI libraries
β Star this repo if you find it useful!
Made with β€οΈ for rural development