Predictive traffic intelligence dashboard for event-driven congestion β forecasts gridlock impact and recommends resource deployment before it happens.
Live Demo: traffi-sense-ai-neon.vercel.app
API Docs: traffisense-ai-2.onrender.com/docs (Bare API root / returns {"status": "ok", "service": "TraffiSense AI backend"})
Planned events (concerts, matches, rallies) and unplanned incidents (accidents, waterlogging, breakdowns) create localized traffic breakdowns across a city. Today, that impact is rarely quantified in advance β resource deployment (officers, barricades, diversions) is largely experience-driven, with no systematic post-event learning loop.
TraffiSense AI predicts how long an incident will block traffic, how far the congestion is likely to ripple, and exactly what resources a precinct should deploy β using a machine learning model trained on historical Bengaluru traffic-event data coupled with an IRC:SP:55/MoRTH-aligned fuzzy decision engine.
flowchart LR
A[Incident Input] --> B[ML Duration Prediction]
A --> C[Fuzzy Resourcing Engine]
B --> C
C --> D[Personnel & Barricade Plan]
B --> E[Congestion Radius & Impact]
A --> F[OSRM Routing Client]
F --> G[Interactive Leaflet Map]
D --> H[One-Click Public Advisory]
G --> H
H --> I[Deployment Log]
I --> J[Feedback & Auto-Retraining]
J --> B
- Event Input β an operator logs an incident: cause, location coordinates, corridor, vehicle type, priority, crowd size, and description.
- ML Inference β a Scikit-Learn
GradientBoostingRegressor, trained on historical resolution times, predicts expected clearance duration from the event's spatial, temporal, and categorical features. - Fuzzy Logic Resourcing β the predicted duration, corridor priority, severity score, and crowd size are run through a
scikit-fuzzycontrol system to derive personnel and barricade counts. - Spatial Analytics β DBSCAN clustering surfaces recurring incident hotspots and corridor-level hourly patterns from the historical dataset, computed live and filterable by hour and month.
- Diversion Routing & Mapping β a driving route around the incident is fetched from OSRM and rendered on an interactive Leaflet/OpenStreetMap view, along with a congestion-radius overlay.
- Automated Advisory β one click generates a pre-formatted public advisory ready to post to WhatsApp or X (Twitter).
- Feedback Loop β resolved deployments are logged with actual outcomes, triggering automated background model retraining with validation and rollback support.
| Layer | Technologies |
|---|---|
| Frontend | React 19, Vite 6, Tailwind CSS v4, Leaflet, React-Leaflet, Recharts, Axios, Oxlint |
| Backend | FastAPI, Python 3.11+, Uvicorn, Pydantic V2 |
| ML & Analytics | Scikit-Learn (GradientBoostingRegressor), Scikit-Fuzzy, Pandas, NumPy, SciPy (ConvexHull, DBSCAN, BallTree) |
| Database | SQLAlchemy, PostgreSQL (production), SQLite (local development) |
| Routing | OSRM (Open Source Routing Machine API client with caching & fallback) |
| Infrastructure | Vercel (Frontend), Render (Backend + Managed Postgres), GitHub Actions (CI/CD) |
TraffiSense-AI/
βββ .github/
β βββ workflows/
β βββ ci.yml # Backend & ML CI test pipeline
β βββ frontend.yml # Frontend build validation
β βββ pr-check.yml # Pull request unit tests & build checks
β βββ codeql.yml # CodeQL static security analysis
βββ backend/
β βββ main.py # FastAPI application, route handlers, DBSCAN & analytics
β βββ ml_model.py # GradientBoostingRegressor training, validation & promotion
β βββ fuzzy_engine.py # IRC:SP:55 / MoRTH-aligned fuzzy logic control system
β βββ data_pipeline.py # Dataset cleaning, feature extraction & spatial imputation
β βββ db.py # SQLAlchemy storage (PostgreSQL/SQLite) & retraining lock
β βββ routing.py # Resilient OSRM diversion routing client with caching
β βββ requirements.txt # Production dependencies
β βββ requirements_train.txt # Training & test dependencies (pytest, httpx)
β βββ README.md # Backend-specific architecture & API guide
βββ frontend/
β βββ index.html # Single page application entry point
β βββ package.json # Frontend scripts & dependencies
β βββ vite.config.js # Vite configuration with Tailwind CSS v4
β βββ vercel.json # Vercel deployment & rewrite configuration
β βββ src/
β β βββ App.jsx # Layout controller & view state management
β β βββ LeafletMap.jsx # Interactive Leaflet map (routes, markers, radius)
β β βββ Analytics.jsx # City-wide charts & KPI visualizer
β β βββ GridMap.jsx # 0.5 kmΒ² density grid map & DBSCAN polygon layers
β β βββ Feedback.jsx # Deployment tracking & post-event feedback modal
β β βββ constants.js # Shared enums, bounds, and API configuration
β β βββ utils/fixLeafletIcons.js # Leaflet marker asset resolver
β β βββ components/
β β βββ Header.jsx # Navigation bar & platform features modal
β β βββ LandingPage.jsx # Scenario starters & control center entry
β β βββ LiveFeeds.jsx # Simulated live event feed aggregator
β β βββ SidebarForm.jsx # Incident parameter entry panel
β β βββ ResultsPanel.jsx # Prediction metrics, ROI, map & advisory modal
β βββ README.md # Frontend-specific architecture & component guide
βββ ml/
β βββ model.joblib # Trained GradientBoostingRegressor artifact
β βββ feature_importance.csv # Extracted feature importance scores
β βββ feature_importance.png # Feature importance visualization plot
βββ tests/
β βββ test_backend.py # API request validation & police station tests
β βββ test_fuzzy_engine.py # Scikit-fuzzy resourcing & FAM rule tests
β βββ test_ml.py # ML artifact presence tests
β βββ test_retraining.py # Retraining pipeline, locking & feedback tests
β βββ test_routing.py # OSRM routing resilience & cache tests
βββ dataset.csv # Historical Bengaluru traffic-event dataset
βββ docker-compose.osrm.yml # Self-hosted OSRM container stack
βββ render.yaml # Render deployment blueprint
βββ README.md # Project documentation
- Predictive Clearance Modeling β Estimates incident clearance duration based on historical patterns, spatial coordinates, road closures, and severity keywords.
- Fuzzy Logic Resource Allocation β Derives precise officer headcounts and barricade counts using a 4-variable fuzzy associative memory control system.
- Dynamic DBSCAN Spatial Clustering β Auto-discovers recurring risk zones using haversine metric (500m radius, min 10 points) rendered with convex hulls.
- 0.5 kmΒ² Grid Density Analytics β Explores traffic breakdown densities across Bengaluru with interactive hour-of-day and month-of-year filters.
- Live Diversion Mapping β Generates turn-by-turn street diversion routes via OSRM with automatic caching and simulated fallback.
- ROI & Delay Savings β Quantifies commuter time saved with AI-assisted response vs. unmanaged gridlock.
- One-Click Public Advisory β Auto-generates hashtag-ready broadcast copy for WhatsApp channels and X (Twitter).
- Continuous Feedback Loop & Safe Retraining β Resolves active incidents with real-world outcomes, safely evaluating and promoting new model weights in the background.
- Node.js 18+ and npm 9+
- Python 3.11+
-
Navigate to the backend directory and set up a virtual environment:
cd backend python -m venv venv -
Activate the virtual environment:
- Windows (PowerShell):
.\venv\Scripts\Activate.ps1
- Windows (Command Prompt):
venv\Scripts\activate.bat
- Linux / macOS:
source venv/bin/activate
- Windows (PowerShell):
-
Install dependencies:
pip install -r requirements.txt -r requirements_train.txt
-
Train and prepare the ML model artifact:
python ml_model.py # Copy artifact to the backend directory: # On Windows (PowerShell): Copy-Item ..\ml\model.joblib .\model.joblib # On Linux / macOS: cp ../ml/model.joblib ./model.joblib
-
Start the FastAPI server:
uvicorn main:app --reload --port 8000
- API Root:
http://127.0.0.1:8000 - Interactive Swagger Docs:
http://127.0.0.1:8000/docs - ReDoc:
http://127.0.0.1:8000/redoc
- API Root:
-
Navigate to the frontend directory:
cd frontend -
Install Node dependencies:
npm install
-
Start the development server:
npm run dev
The dashboard will be available at
http://localhost:5173.
Run all unit and integration tests across tests/ and backend/:
# From repository root:
pytest tests backend/ -vcd frontend
npm run lint
npm run buildDiversion routes are generated by calling an OSRM-compatible routing service (backend/routing.py). By default, it targets the public OSRM demo server (router.project-osrm.org) for zero-configuration local development.
| Variable | Default | Description |
|---|---|---|
OSRM_BASE_URL |
http://router.project-osrm.org |
Base URL of the routing service. |
OSRM_PROFILE |
driving |
Routing profile (driving / walking / cycling). |
OSRM_TIMEOUT_SECONDS |
1.2 |
Per-request timeout in seconds. |
OSRM_MAX_RETRIES |
1 |
Number of retry attempts on network / 5xx errors. |
OSRM_RETRY_BACKOFF_SECONDS |
0.1 |
Base backoff interval between retries. |
ROUTE_CACHE_TTL_SECONDS |
300 |
In-memory cache TTL for diversion routes. |
ROUTE_CACHE_MAX_SIZE |
500 |
Maximum cached route entries. |
To run a dedicated, high-performance OSRM instance for Bengaluru/Karnataka:
docker compose -f docker-compose.osrm.yml up -dThen configure the backend to use your self-hosted instance:
export OSRM_BASE_URL=http://localhost:5000This project is architected for continuous deployment:
- Frontend (Vercel): Configured via
frontend/vercel.json. SetVITE_API_URLto your production backend URL. - Backend (Render): Configured via
render.yaml. Provisions a Python web service and a managed PostgreSQL database.
This project is licensed under the MIT License.