Skip to content

Abhishekmishra2808/village-digital-twin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

64 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🏘️ RuraLens - AI-Powered Village Digital Twin

Version Node React License

Real-time monitoring and AI-powered insights for rural development projects

Features β€’ Installation β€’ AI RAG System β€’ Architecture β€’ Demo


πŸ“‹ Overview

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.

🎯 Problem Solved

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

✨ RuraLens Solution

  • βœ… 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

πŸš€ Key Features

πŸ€– AI RAG System (Retrieval-Augmented Generation)

The crown jewel of RuraLens - an intelligent question-answering system that understands context and provides accurate, sourced answers.

How It Works:

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

RAG Features:

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

🧠 GNN Impact Predictor (Graph Neural Network)

Advanced infrastructure failure prediction using Graph Neural Networks to simulate cascading impacts across village infrastructure.

GNN Features:

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

How GNN Works:

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

GNN Usage:

  1. View Network: Navigate to "Village Analyzer" from sidebar
  2. Explore Map: All infrastructure appears as labeled nodes on 3D map
  3. Trigger Failure: Click any node β†’ Select failure type and severity
  4. Watch Propagation: See impacts spread through network in real-time
  5. Add Nodes: Right-click map β†’ Add new infrastructure β†’ Auto-connects

Example Scenarios:

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%)

πŸ—ΊοΈ Interactive 3D Map View

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

πŸ“Š Real-Time Analytics & Monitoring

  • 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

Example Queries:

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)]

πŸ—οΈ Architecture

System Components

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                        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  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Technology Stack

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

⚑ Quick Start

Prerequisites

# Required
Node.js >= 18.x
Python >= 3.11
MongoDB >= 6.0
Git

# Optional (for production RAG)
WSL2 (Windows) or Linux
Docker (for containerized deployment)

Installation

# 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)

Quick RAG Setup (Mock Mode)

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_development

Production RAG Setup

For 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.py

🎨 Using the Platform

1. AI RAG Feature - "Ask AI"

The "Ask AI" button appears in:

  • πŸ“Š Admin Dashboard - Top right corner
  • πŸ‘₯ Citizen Dashboard - Top right corner
  • πŸ“‹ Schemes View - Header toolbar

2. Village Analyzer (GNN Impact Predictor)

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

3. Ask AI Questions

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?       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

3. View Results

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  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 βœ“    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

4. Explore Citations

  • Show on Map: Pans to citation location with highlight
  • View Document: Opens full source document
  • Relevance Score: Shows AI confidence (0-100%)

πŸ” Security Features

RAG-Specific Security

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

Privacy Protection

// 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]"

πŸ“Š RAG API Reference

Endpoint

POST /api/rag-query
Content-Type: application/json
Authorization: Bearer <JWT_TOKEN>

Request Body

{
  "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)
}

Response

{
  "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
}

Error Codes

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

πŸ§ͺ Testing the RAG Feature

Backend Test

cd backend
powershell -File test-rag.ps1

Expected 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

Frontend Test

  1. Open http://localhost:3000
  2. Login with: admin@village.com / admin123
  3. Click "Ask AI" button (blue gradient)
  4. Type: "Why is MGNREGA delayed?"
  5. Verify:
    • βœ… Answer appears within 1 second
    • βœ… Citations show with scores
    • βœ… "Show on Map" buttons work
    • βœ… Cached indicator on repeat query

πŸ“š Documentation

Key Files

πŸ“ 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)

Further Reading


🌟 Demo

Screenshots

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

🀝 Contributing

We welcome contributions! Please see our Contributing Guide for details.

Areas for Contribution

  • 🧠 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

πŸ“ License

This project is licensed under the MIT License - see LICENSE file.


πŸ‘₯ Team

Developed by: Village Digital Twin Team
Contact: abhishekmishra8770@gmail.com
GitHub: @Abhishekmishra2808


πŸ™ Acknowledgments

  • 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

Report Bug β€’ Request Feature

About

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors