Namma AI helps Bengaluru Traffic Police shift from reactive patrol to proactive, data-driven enforcement. It predicts incident severity and road-closure probability using a CatBoost ML model, recommends officer and barricade deployment, generates diversion routes, surfaces hotspots on a live heatmap, and lets citizens report incidents directly to authorities.
Next.js 14 · FastAPI · PostgreSQL · CatBoost
| Metric | Value |
|---|---|
| ML inference latency | < 5 ms per prediction |
| Diversion route computation | < 3 s |
| Incident telemetry | Real-time via WebSocket |
| Authentication | JWT-based |
| Access control | Role-based (Citizen / Personnel / Authority) |
| API | REST, with auto-generated Swagger documentation |
| Layer | Technology |
|---|---|
| Frontend | Next.js 14, TypeScript, Tailwind CSS, Leaflet (OpenStreetMap), Recharts |
| Backend | FastAPI, Pydantic v2, SQLAlchemy |
| Database | PostgreSQL |
| ML | CatBoost (closure probability + priority ranking), DBSCAN (hotspot clustering) |
| Routing | OSRM public server + custom diversion engine |
| Maps & weather | OpenStreetMap tiles, Open-Meteo API (both free, no key needed) |
namma-traffic/
├── backend/ # FastAPI app, models, routers, ML inference
│ ├── models/ # CatBoost + DBSCAN model artifacts
│ ├── routers/ # API route handlers
│ └── main.py
├── frontend/ # Next.js 14 app (citizen + authority views)
│ ├── app/
│ └── components/
├── docs/ # Screenshots, logo, hero images
└── README.md
- Python 3.12+ — tick "Add python.exe to PATH"
- Node.js LTS
- PostgreSQL 14+
createdb traffic_dbOpen a terminal in the project root:
# Windows (PowerShell)
cd backend
py -3.12 -m venv venv
venv\Scripts\Activate.ps1
pip install -r requirements.txt
uvicorn main:app --reload# Mac / Linux
cd backend
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
uvicorn main:app --reloadIf PowerShell blocks script execution, run once:
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned
Backend: http://localhost:8000 · Swagger docs: http://localhost:8000/docs
The schema (all tables and columns) is created automatically on first start.
Create backend/.env:
DATABASE_URL=postgresql://user:pass@localhost:5432/traffic_db
JWT_SECRET_KEY=any-random-string-here
# Optional — only needed for Gemini advisory and Cloudinary photo upload
GEMINI_API_KEY=
CLOUDINARY_CLOUD_NAME=
CLOUDINARY_API_KEY=
CLOUDINARY_API_SECRET=Open a second terminal:
cd frontend # or: cd namma-traffic/frontend
npm install
npm run dev- Open http://localhost:3000
- Seed data — click "I'm an Authority" → log in (admin / admin123) → Dashboard → expand Admin Tools → click Generate demo data
- Citizen view — go back to home → click "I'm a Citizen" → try Safe Route Finder and Live Heatmap
- Report an incident — Citizen → Report Incident → fill form → submit → copy tracking ID
- Verify it — Authority → Verify Reports → approve the report → watch it appear on the dashboard live
- Resource planning — Authority → Deployment → see per-incident officer and barricade recommendations
- Diversion — Authority → Diversion Plans → click "Diversion plan" on any incident
| Role | How to access | Credentials |
|---|---|---|
| Citizen | Home → "I'm a Citizen" | No login needed |
| Traffic Personnel | Home → "I'm Traffic Personnel" | Register or use demo login |
| Authority | Home → "I'm an Authority" → Login | admin / admin123 |
| Route | Who | Description |
|---|---|---|
/ |
Public | Landing + role selection |
/citizen/report |
Citizen | Submit incident report |
/citizen/heatmap |
Citizen | Live incident map + hotspots |
/citizen/route |
Citizen | Incident-aware safe route planner |
/authority/login |
Authority | JWT login |
/authority/dashboard |
Authority | Live KPIs + priority incidents |
/authority/predict |
Authority | ML closure probability + priority ranking |
/authority/analytics |
Authority | Incident trends (charts from live DB) |
/authority/resources |
Authority | Per-incident deployment recommendations |
/authority/diversion |
Authority | Auto-generated diversion routes |
/authority/verify |
Authority | Approve / reject citizen reports |
POST /api/predict — returns road-closure probability and priority ranking for an incident.
Request:
{
"incident_type": "accident",
"location": {
"lat": 12.9716,
"lng": 77.5946
},
"severity": "moderate",
"weather": "rain",
"time_of_day": "peak_hour",
"road_type": "arterial"
}Response:
{
"closure_probability": 0.72,
"priority_score": 8.4,
"recommended_officers": 3,
"recommended_barricades": 2,
"estimated_clearance_minutes": 35
}Full interactive docs for all endpoints are available at /docs (Swagger UI) once the backend is running.
- Backend → Render: New Web Service · root
backend· start commanduvicorn main:app --host 0.0.0.0 --port $PORT· set env vars in Render dashboard - Frontend → Vercel: Import repo · root
frontend· setNEXT_PUBLIC_API_URLto your Render backend URL
Namma Traffic · Smarter Roads. Safer Journeys.
BIT Mesra

