- SDG 2: Zero Hunger — Prevents farmer distress by enabling early intervention
- SDG 3: Good Health and Well-being — Reduces farmer suicides through mental health alerts
Farmer distress in Vidarbha, Maharashtra leads to debt cycles, crop failures, and rising suicide rates. Authorities lack a real-time system to identify at-risk districts and deploy preventive measures.
An AI-powered early warning system that:
- Computes a Crop Distress Index (CDI) using 6 features (price volatility, rainfall, NDVI, groundwater, debt, historical base rate)
- Generates PDF distress reports with SHAP explainability for authorities
- Displays a real-time heatmap of all 10 Vidarbha districts
- Provides history replay via daily snapshots
| Layer | Technology |
|---|---|
| Frontend | React 18, Vite, TypeScript, Leaflet, Recharts |
| Backend (ML) | Django 5, DRF, scikit-learn, XGBoost, SHAP |
| Ingestion | Go 1.22 (worker pool, cron, WebSocket) |
| Database | PostgreSQL / SQLite |
| WeasyPrint |
┌─────────────────────────────────────────────────────────────────────────┐
│ LAYER 1 — REACT DASHBOARD (Port 3000) │
│ │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ ┌────────────┐ │
│ │ MapView │ │DistrictDetail│ │ CDITrend │ │AlertPanel │ │
│ │ (Leaflet) │ │(SHAP bar) │ │ (Recharts) │ │(Realtime) │ │
│ └──────┬───────┘ └──────┬───────┘ └──────┬───────┘ └─────┬──────┘ │
│ ┌──────┴───────┐ ┌──────┴───────┐ ┌──────┴───────┐ ┌─────┴──────┐ │
│ │ Notifications│ │ History │ │ Header │ │ Layout │ │
│ │ (PDF mgmt) │ │(snap replay) │ │(logo, WS) │ │(tabs,dark) │ │
│ └──────────────┘ └──────────────┘ └──────────────┘ └────────────┘ │
└───────────────────────────────────┬─────────────────────────────────────┘
│
┌───────────┴───────────┐
│ REST API (JSON) │
│ /api/v1/cdi/* │
│ /api/v1/notifications │
│ /api/v1/snapshots/* │
└───────────┬───────────┘
▼
┌─────────────────────────────────────────────────────────────────────────┐
│ LAYER 2 — DJANGO ML API (Port 8000) │
│ │
│ ┌────────────────────┐ ┌────────────────────┐ ┌───────────────────┐ │
│ │ CDI Engine │ │ SHAP Explainer │ │ Feature Pipeline │ │
│ │ Ensemble Model │ │ Feature Contrib. │ │ Price Volatility │ │
│ │ RF + XGBoost + LR │ │ Waterfall Chart │ │ Rainfall Dev. │ │
│ └─────────┬──────────┘ └─────────┬──────────┘ │ NDVI Anomaly │ │
│ ┌─────────┴──────────┐ ┌─────────┴──────────┐ │ Groundwater Dep. │ │
│ │ Notification Sys. │ │ Snapshot Engine │ │ Debt Exposure │ │
│ │ PDF (WeasyPrint) │ │ Daily JSON State │ │ Historical Base │ │
│ └─────────┬──────────┘ └─────────┬──────────┘ └───────────────────┘ │
│ ┌─────────┴──────────┐ ┌─────────┴──────────┐ │
│ │ DRF REST Views │ │ Celery Workers │ │
│ │ 7 API Endpoints │ │ (async inference) │ │
│ └────────────────────┘ └────────────────────┘ │
└───────────────────────────────────┬─────────────────────────────────────┘
│
┌───────────┴───────────┐
│ Django ORM / SQL │
└───────────┬───────────┘
▼
┌─────────────────────────────────────────────────────────────────────────┐
│ LAYER 3 — POSTGRESQL + TIMESCALEDB (Port 5432) │
│ │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ ┌────────────┐ │
│ │ Crop Prices │ │ Weather Data │ │ Suicide │ │ Groundwater│ │
│ │ (hypertable) │ │ (hypertable) │ │ History (dim)│ │ (hypertable)│ │
│ ├──────────────┤ ├──────────────┤ ├──────────────┤ ├────────────┤ │
│ │NDVI Index │ │Loan Default │ │ CDI Scores │ │ Alerts │ │
│ │(hypertable) │ │(hypertable) │ │ (hypertable) │ │ (hypertable)│ │
│ └──────────────┘ └──────────────┘ └──────────────┘ └────────────┘ │
│ TimescaleDB: auto-partitioned by time, continuous aggregates, │
│ compression policies for efficient storage │
└───────────────────────────────────┬─────────────────────────────────────┘
│
┌───────────┴───────────┐
│ Read by ML API │
│ Written by Go Ingest│
└───────────┬───────────┘
▼
┌─────────────────────────────────────────────────────────────────────────┐
│ LAYER 4 — GO INGESTION (Port 8080) │
│ │
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌────────────────────────┐ │
│ │AgMarknet │ │ IMD API │ │ NASA │ │ India Data Portal │ │
│ │ Fetcher │ │ Fetcher │ │ MODIS │ │ Loan Default Fetch │ │
│ │ │ │ │ │ Fetcher │ │ │ │
│ └────┬─────┘ └────┬─────┘ └────┬─────┘ └───────────┬───────────┘ │
│ │ │ │ │ │
│ └─────────────┴─────────────┴─────────────────────┘ │
│ │ 5-goroutine worker pool │
│ ┌───────┴───────┐ │
│ │ Go Router │ (Chi/Gin) + Cron Scheduler │
│ │ (6h/24h) │ + WebSocket Broadcaster │
│ └───────┬───────┘ │
└──────────────────────┼─────────────────────────────────────────────────┘
│
┌───────────┴───────────┐
│ Write to TimescaleDB │
│ Push alerts via WS │
└───────────────────────┘
▼
┌─────────────────────────────────────────────────────────────────────────┐
│ LAYER 5 — ALERTING & NOTIFICATION │
│ │
│ CDI Thresholds: │
│ Critical (>=70) → DBT Transfer + Loan Moratorium + SMS │
│ High (50-69) → Dashboard Alert + Email + This-week Visit │
│ Medium (30-49) → Dashboard Highlight + Monitoring │
│ Low (<30) → Routine Monitoring │
│ │
│ • WebSocket push → Dashboard real-time alert panel │
│ • PDF report generation → A4 report with SHAP + trend + actions │
│ • Daily snapshots → JSON state capture for history replay │
│ • Bhashini API → Hindi/Marathi alert text generation │
└─────────────────────────────────────────────────────────────────────────┘
- Data Ingestion — Go service fetches govt APIs (AgMarknet, IMD, NASA) via 5-goroutine worker pool on cron schedule
- CDI Computation — Django ML API fetches metrics, runs ensemble model (RF+XGB+LR), computes SHAP values, stores CDIRecords
- Dashboard Visualization — React polls REST API, renders Leaflet heatmap, displays SHAP breakdown
- Notification Pipeline — Click "Send" → Django renders A4 PDF via WeasyPrint → saves to MEDIA_ROOT → creates Notification record
- History Snapshots — Daily snapshots serialize full CDI + alerts state → stored in CDISnapshot → replay any date
- Real-time Alerts — Go polls every 15s → WebSocket push → Dashboard AlertPanel updates live
| Concern | Go (ingest/) | Python (ml/) |
|---|---|---|
| Data Fetching | 5 goroutines, 15s polling | N/A |
| ML / AI | N/A | scikit-learn, XGBoost, SHAP |
| PDF Generation | N/A | WeasyPrint (Django template) |
| Concurrency | Native goroutines + channels | Celery (optional) |
| Scheduling | Cron (native Go) | APScheduler / Celery Beat |
# ML API
cd ml
python3 -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt
python manage.py migrate
python manage.py runserver 0.0.0.0:8000 --noreload
# Dashboard
cd dashboard
npm install
npm run devGET /api/v1/cdi/rankings— All districts ranked by CDIGET /api/v1/notifications— List notification historyPOST /api/v1/notifications/generate— Generate distress PDFGET /api/v1/snapshots— List history snapshotsPOST /api/v1/snapshots/generate— Create daily snapshot
This project was built as the Artificial Intelligence Final Project for the course Build a Solution for a Sustainable Development Goal (SDG).