How penquinz01/gridlock-2.0 works
Purpose and entry points
ARES is a Bengaluru Traffic Police incident-response decision-support system. The FastAPI application starts at backend/app/main.py (uvicorn app.main:app) and exposes REST endpoints, chiefly POST /api/report, plus analysis, routing, map, hotspot, and station-portal APIs. The optional Vite/React operator UI starts from frontend/src/main.jsx and frontend/src/App.jsx.
API composition
Route modules are the HTTP boundary and delegate business work to services: backend/app/routes/report.py, backend/app/routes/analyze.py, and backend/app/routes/station_portal.py. backend/app/main.py composes these routers. The report route is the primary orchestration entry point for a minimally specified incident; specialized routes expose individual capabilities such as risk, recommendations, diversions, similarities, and maps.
Incident enrichment and inference
Incident coordinates, cause, and timestamp are normalized into model-ready fields. Location resolution maps coordinates to corridor and station, with local nearest-data lookup and optional Mappls live-place lookup: backend/app/services/location_service.py, backend/app/services/map_service.py, backend/app/utils/mappings.py. Time-derived features and inferred event/vehicle properties form the boundary between user input and analytics.
ML prediction and historical data
Pretrained scikit-learn Random Forest artifacts predict priority and road-closure needs: backend/models/priority_model.pkl, backend/models/road_closure_model.pkl. Historical feature data is held in backend/preprocessed_data/preprocessed_data.csv; it supports KNN-based similar-incident retrieval through backend/app/services/similarity_service.py. Model training/preprocessing is offline, represented by backend/jupyter_files/data_preprocess.ipynb and model notebooks, rather than a runtime training path.
Deterministic operational decisions
Predictions feed rule-based risk scoring and resource deployment recommendations. Risk combines priority, closure prediction, timing, incident type, and vehicle factors; recommendation logic converts the resulting level into officers, barricades, escalation, and recovery requirements. Core boundaries are backend/app/services/risk_service.py, backend/app/rules/risk_rules.py, backend/app/services/recommendation_service.py, and backend/app/rules/recommendation_rules.py.
Diversion, routing, and spatial analytics
The system generates interactive Folium diversion-map HTML around an incident and corridor warnings, while routing/diversion services provide operational route alternatives. Hotspot processing aggregates frequent/high-risk locations for corridor-level views. Components: backend/app/services/diversion_service.py, backend/app/services/routing_service.py, backend/app/services/hotspot_service.py, and backend/app/routes/map.py. These outputs are visualization/operational artifacts downstream of inference, not inputs to model scoring.
Persistence, portal, and external integration
SQLite persistence uses raw SQL through backend/app/database.py; it records incidents and resolution feedback. The station portal authenticates station-code users, authorizes queues, and closes incidents with actual outcome labels via backend/app/services/auth_service.py and backend/app/routes/station_portal.py. Feedback creates the learning-data boundary for future offline retraining. Runtime infrastructure is Python 3.10+, FastAPI/Uvicorn, SQLite, scikit-learn/joblib, and Folium; Mappls/MapmyIndia is an optional credential-driven external service configured through backend/app/config.py.
Components 20
Interfaces
- FastAPI application · Composes REST routers.
backend/app/main.py - Report API · Primary minimally specified incident entry point.
backend/app/routes/report.py - Analysis API
backend/app/routes/analyze.py - Station portal API
backend/app/routes/station_portal.py - Operator UI · Optional Vite operator interface.
frontend/src/App.jsx
Inference & Decisions
- Location resolution · Maps coordinates to corridors and stations.
backend/app/services/location_service.py - Mappls lookup · Optional live-place enrichment.
backend/app/services/map_service.py - Priority & closure models · Random Forest inference for priority and closure.
backend/models/priority_model.pkl - Risk scoring · Combines predictions with incident factors.
backend/app/services/risk_service.py - Risk rules
backend/app/rules/risk_rules.py - Resource recommendations · Produces deployment and recovery requirements.
backend/app/services/recommendation_service.py - Recommendation rules
backend/app/rules/recommendation_rules.py - Similar incidents
backend/app/services/similarity_service.py
Operations & Data
- Historical features · Supports similarity retrieval and offline training.
backend/preprocessed_data/preprocessed_data.csv - Incident database · Stores incidents and resolution feedback.
backend/app/database.py - Station authentication · Authenticates station-code users and queues.
backend/app/services/auth_service.py - Routing & diversion · Provides route alternatives and corridor warnings.
backend/app/services/diversion_service.py - Diversion maps · Interactive incident-area visualization.
backend/app/routes/map.py - Hotspot analytics · Builds corridor-level frequent and high-risk views.
backend/app/services/hotspot_service.py - Offline preprocessing · Prepares data and trains runtime artifacts offline.
backend/jupyter_files/data_preprocess.ipynb
Connections 23
- Operator UI → FastAPI application: REST calls
- FastAPI application → Report API: mounts
- FastAPI application → Analysis API: mounts
- FastAPI application → Station portal API: mounts
- Report API → Location resolution: enriches incident
- Location resolution → Mappls lookup: optional lookup
- Report API → Priority & closure models: predicts
- Priority & closure models → Risk scoring: priority and closure
- Location resolution → Risk scoring: normalized features
- Risk rules → Risk scoring: applies
- Risk scoring → Resource recommendations: risk level
- Recommendation rules → Resource recommendations: applies
- Analysis API → Similar incidents: queries
- Historical features → Similar incidents: KNN corpus
- Report API → Incident database: records incident
- Station portal API → Station authentication: authenticates
- Station portal API → Incident database: closes and records outcome
- Risk scoring → Routing & diversion: operational context
- Routing & diversion → Diversion maps: map content
- Incident database → Hotspot analytics: incident history
- Historical features → Offline preprocessing: training input
- Offline preprocessing → Priority & closure models: produces artifacts
- Incident database → Offline preprocessing: resolution feedback