How shriram28baskar/route-resilience works
1. System shape
Route Resilience is a two-tier application: a Python FastAPI backend that performs geospatial ML, graph analysis, and simulation, and a Next.js frontend that presents maps, metrics, scenario controls, and report/copot interactions. The backend is the computational core; the frontend is a thin interactive client.
2. Primary data flow
The main pipeline starts with satellite or map imagery and road-related geodata, passes through road segmentation, then graph construction, then criticality and resilience analysis, and finally feeds simulation outputs into the dashboard, evacuation planner, and PDF report generator. This is the core architecture to draw: imagery → mask → graph → analytics/simulations → UI outputs.
3. Backend API boundary
backend/app/api/ exposes distinct domain endpoints: segmentation, graph building, simulation, reports, Bhuvan integration, accessibility analytics, and copilot queries. This separation is important because each endpoint maps to a subsystem rather than a generic monolith. The backend’s main.py is the FastAPI composition point.
4. ML and image understanding subsystem
backend/app/ml/ handles the raster-side intelligence: model definition, inference, augmentation-based occlusion robustness, change detection, explainability, and training. This layer turns image tiles into road masks and confidence/explanation artifacts. It is the entry point for the “occlusion-robust road extraction” part of the product.
5. Graph construction and topology subsystem
backend/app/graph_pipeline/ converts masks into road graphs and repairs topology. The key stages are skeletonization, graph building, centrality analysis, MST-based healing, and metrics extraction. This is where pixel outputs become a network representation that can support junction criticality, connectivity, and partition analysis.
6. Simulation and resilience subsystem
backend/app/simulation/ contains the scenario engine: cascade failure, ablation, evacuation routing, resilience scoring, equity impact, fragility, traffic impact, temporal degradation, and topography/flood-related effects. These modules consume the graph and its attributes, then produce scenario-specific outputs such as failed nodes, impacted population, route detours, and resilience indices.
7. External data and mapping integrations
backend/app/integrations/ wraps outside services used by the system: ISRO Bhuvan for map layers and road/context overlays, Overpass and Nominatim for open geodata lookups, and Groq for the AI copilot. These integrations are important architectural boundaries because they augment local computation with live geospatial data and LLM-driven assistance.
8. Reporting layer
backend/app/reports/generator.py produces situation reports from the computed analytics and simulations. In the architecture, this is a downstream consumer of all prior subsystems, turning technical outputs into a decision-support artifact suitable for NDMA/operations-style sharing.
9. Frontend application structure
The Next.js app in frontend/app/ is organized by task: map, analytics, simulate, reports, explain, and copilot pages. Shared UI components such as RoadMap, SplitMapView, EvacuationPanel, and metric cards render the geospatial outputs and scenario controls. The frontend does not perform heavy computation; it orchestrates backend calls and visualization.
10. Client-server interaction pattern
frontend/lib/api.ts is the client-side API boundary. UI pages request segmentation results, graphs, simulation outcomes, and reports from the backend, then render them as maps, charts, and scenario panels. This makes the frontend a presentation and interaction layer rather than a data-processing layer.
11. Persistent assets and offline data
backend/data/graphs/ stores prebuilt graph artifacts, and backend/cache/ stores cached computation results. The presence of scripts/download_data.py and scripts/rasterize_masks.py shows that some data preparation happens offline or ahead of runtime, reducing repeated processing during demos or API calls.
12. Operational packaging
The repo is designed for local development and Docker-based deployment. docker-compose.yml, backend/frontend Dockerfiles, and the startup scripts imply a reproducible full-stack environment where the frontend and backend run as separate services. The backend is Python 3.11/FastAPI; the frontend is React/Next.js 14 with TypeScript and Leaflet-style mapping.
13. Validation and experimentation boundary
The notebooks/ directory and backend/tests/test_analytics.py indicate an analytical/experimental workflow alongside the product code. Notebooks are for exploration, model evaluation, graph validation, and QA of assumptions; tests cover analytics behavior at least at a unit/integration level.
14. What to show in an architecture diagram
A clear diagram should show: external inputs from satellite tiles, road data, and map services; the backend as a pipeline of ML → graph → simulation → reporting; the frontend as a separate presentation shell; and external services like Bhuvan, Overpass/Nominatim, and Groq connected only through integration modules. The main trust boundary is between the browser UI and the backend API, and the main compute boundary is between geospatial ML/analysis and the interactive dashboard.
Main entry points: main.py Main API · integrations Integrations · components UI Shell · simulation Simulation Core
Components 22
Backend
FastAPI geospatial computation and API surface
- Main API · Composes the backend service and mounts domain routes
backend/app/main.py - Segmentation · Image-to-mask endpoint for road extraction
backend/app/api/segmentation.py - Graph API · Endpoints for building and inspecting road graphs
backend/app/api/graph.py - Simulation API · Scenario execution and resilience outputs
backend/app/api/simulation.py - Reports API · Report generation and export endpoint
backend/app/api/reports.py - Accessibility API · Accessibility and reachability analytics endpoint
backend/app/api/accessibility.py - Bhuvan API · Geospatial layer and overlay integration endpoint
backend/app/api/bhuvan.py - Copilot API · LLM-assisted query and guidance endpoint
backend/app/api/copilot.py - Road ML · Model inference, augmentation, change detection, and explainability
backend/app/ml - Graph Pipeline · Skeletonizes masks and builds connected road graphs
backend/app/graph_pipeline - Simulation Core · Runs failure, evacuation, traffic, and resilience scenarios
backend/app/simulation - Report Generator · Formats analytics and scenarios into decision reports
backend/app/reports/generator.py - Integrations · Wrappers for map, geodata, and AI services
backend/app/integrations
Frontend
Next.js presentation and interaction layer
- App Pages · Map, analytics, simulate, reports, explain, and copilot screens
frontend/app - UI Shell · Shared map and control components for geospatial interaction
frontend/components - Client API · Typed frontend boundary for backend requests
frontend/lib/api.ts
External
Third-party data and AI services
- Bhuvan · Satellite and contextual map layers
- Overpass · OpenStreetMap-style road and place lookups
- Nominatim · Address and place geocoding service
- Groq · AI backend used for copilot responses
Assets
Precomputed data and cached artifacts
- Graph Cache · Prebuilt graphs and cached computation outputs
backend/data/graphs - Runtime Cache · Serialized API and analysis cache files
backend/cache
Connections 29
- App Pages → UI Shell: renders · Pages compose shared map and control widgets
- App Pages → Client API: calls · UI requests backend data and scenario results
- Client API → Main API: HTTP API · Client-server boundary into the FastAPI app
- Main API → Segmentation: mounts · Registers segmentation endpoints
- Main API → Graph API: mounts · Registers graph endpoints
- Main API → Simulation API: mounts · Registers simulation endpoints
- Main API → Reports API: mounts · Registers reporting endpoints
- Main API → Accessibility API: mounts · Registers accessibility endpoints
- Main API → Bhuvan API: mounts · Registers Bhuvan integration endpoints
- Main API → Copilot API: mounts · Registers copilot endpoints
- Segmentation → Road ML: runs · Segmentation routes invoke raster ML
- Road ML → Graph Pipeline: emits masks · Model outputs feed topology reconstruction
- Graph Pipeline → Graph API: serves graphs · Graph products are exposed through the API
- Graph Pipeline → Simulation Core: feeds · Topology metrics become scenario inputs
- Simulation API → Simulation Core: executes · Scenario endpoints dispatch the simulation core
- Simulation Core → Report Generator: produces outputs · Scenario results are packaged for reporting
- Report Generator → Reports API: exposes · Report generator is served through the API
- Bhuvan API → Integrations: adapts · Bhuvan-specific wrapper layer
- Copilot API → Integrations: adapts · Copilot endpoint uses integration clients
- Integrations → Bhuvan: uses · Fetches satellite and overlay data
- Integrations → Overpass: uses · Queries open road and place data
- Integrations → Nominatim: uses · Resolves locations and addresses
- Integrations → Groq: uses · Delegates LLM copilot calls
- Graph API → Graph Cache: reads · Graph endpoints can reuse prebuilt artifacts
- Road ML → Runtime Cache: reads/writes · Inference and analysis may persist cached results
- Simulation Core → Runtime Cache: reads/writes · Scenario outputs may be cached for reuse
- UI Shell → Simulation API: drives · Evacuation and scenario controls trigger simulation runs
- UI Shell → Graph API: visualizes · Map views render graph and topology data
- UI Shell → Reports API: downloads · Report views fetch generated documents