# rishavsvault/road-accident-severity-and-hotspot-analysis architecture

> Architecture diagram of the GitHub repository rishavsvault/road-accident-severity-and-hotspot-analysis, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rishavsvault/road-accident-severity-and-hotspot-analysis
- Repository: https://github.com/rishavsvault/road-accident-severity-and-hotspot-analysis

## Overview

This is a synthetic-data prototype for explainable road-accident severity and hotspot analysis for Kolkata/KMDA. The principal workflow is pipeline execution: generate or load crash, road-network, and weather inputs; spatially align crashes; build features; rank hotspots; train and evaluate severity models; then explain risks and recommend engineering interventions. A Streamlit dashboard presents hotspot exploration, segment deep dives, counterfactual simulation, and policy briefs; the repository also includes an API. Pipeline-stage links are supported by the README and the run_pipeline.py reference index. Some internal calls and dashboard data wiring were not sampled, so those links are omitted.

Main entry points: [`run_pipeline.py`](https://github.com/rishavsvault/road-accident-severity-and-hotspot-analysis/blob/main/run_pipeline.py) (Pipeline runner), [`dashboard/app.py`](https://github.com/rishavsvault/road-accident-severity-and-hotspot-analysis/blob/main/dashboard/app.py) (Streamlit dashboard), [`src/features/build_features.py`](https://github.com/rishavsvault/road-accident-severity-and-hotspot-analysis/blob/main/src/features/build_features.py) (Feature matrix), [`src/explainability/intervention_engine.py`](https://github.com/rishavsvault/road-accident-severity-and-hotspot-analysis/blob/main/src/explainability/intervention_engine.py) (Intervention advice)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingestion["Input and alignment"]
  node_pipeline["Pipeline runner<br/>[run_pipeline.py]"]
  node_synthetic["Synthetic crashes"]
  node_cleaner["Crash cleaning<br/>[crash_cleaner.py]"]
  node_osm["Road network<br/>[osm_loader.py]"]
  node_weather["Weather loading<br/>[weather_loader.py]"]
  node_snapper["Spatial snapping<br/>[spatial_snapper.py]"]
end

subgraph group_analysis["Risk analysis"]
  node_features["Feature matrix<br/>[build_features.py]"]
  node_roadfeatures["Road features<br/>[road_features.py]"]
  node_temporalfeatures["Temporal features"]
  node_weatherfeatures["Weather features"]
  node_netkde["Network KDE<br/>[network_kde.py]"]
  node_spatialstats["Spatial statistics<br/>[spatial_stats.py]"]
  node_ranker["Segment ranking<br/>[segment_ranker.py]"]
end

subgraph group_decision["Model and decisions"]
  node_trainer["Severity training<br/>[xgboost_trainer.py]"]
  node_spatialcv["Spatial validation<br/>[spatial_cv.py]"]
  node_evaluation["Model evaluation<br/>[evaluate.py]"]
  node_shap["SHAP explanations<br/>[shap_explainer.py]"]
  node_interventions["Intervention advice"]
end

subgraph group_interfaces["User interfaces"]
  node_dashboard["Streamlit dashboard<br/>[app.py]"]
  node_hotspotpage["Hotspot explorer"]
  node_deeppage["Segment deep dive"]
  node_simulator["What-if simulator"]
  node_policy["KMDA policy brief"]
  node_api["Analysis API<br/>[main.py]"]
end

node_user(("KMDA analyst"))

node_user -->|"runs pipeline"| node_pipeline
node_pipeline -->|"generates inputs"| node_synthetic
node_pipeline -->|"cleans crashes"| node_cleaner
node_pipeline -->|"loads roads"| node_osm
node_pipeline -->|"loads weather"| node_weather
node_pipeline -->|"aligns crashes"| node_snapper
node_pipeline -->|"builds features"| node_features
node_features -->|"uses"| node_roadfeatures
node_features -->|"uses"| node_temporalfeatures
node_features -->|"uses"| node_weatherfeatures
node_pipeline -->|"computes density"| node_netkde
node_pipeline -->|"tests clusters"| node_spatialstats
node_pipeline -->|"ranks segments"| node_ranker
node_pipeline -->|"trains severity model"| node_trainer
node_trainer -->|"uses folds"| node_spatialcv
node_trainer -->|"evaluates predictions"| node_evaluation
node_pipeline -->|"exports metrics"| node_evaluation
node_pipeline -->|"explains predictions"| node_shap
node_pipeline -->|"recommends fixes"| node_interventions
node_user -->|"opens dashboard"| node_dashboard
node_dashboard -.->|"presents page"| node_deeppage
node_dashboard -.->|"presents page"| node_hotspotpage
node_dashboard -.->|"presents page"| node_simulator
node_dashboard -.->|"presents page"| node_policy
node_deeppage -->|"uses explanations"| node_shap
node_deeppage -->|"uses recommendations"| node_interventions
node_simulator -->|"uses recommendations"| node_interventions
node_api -->|"uses recommendations"| node_interventions
node_api -->|"uses statistics"| node_spatialstats

click node_pipeline "https://github.com/rishavsvault/road-accident-severity-and-hotspot-analysis/blob/main/run_pipeline.py"
click node_synthetic "https://github.com/rishavsvault/road-accident-severity-and-hotspot-analysis/blob/main/src/data/mock_data_generator.py"
click node_cleaner "https://github.com/rishavsvault/road-accident-severity-and-hotspot-analysis/blob/main/src/data/crash_cleaner.py"
click node_osm "https://github.com/rishavsvault/road-accident-severity-and-hotspot-analysis/blob/main/src/data/osm_loader.py"
click node_weather "https://github.com/rishavsvault/road-accident-severity-and-hotspot-analysis/blob/main/src/data/weather_loader.py"
click node_snapper "https://github.com/rishavsvault/road-accident-severity-and-hotspot-analysis/blob/main/src/data/spatial_snapper.py"
click node_features "https://github.com/rishavsvault/road-accident-severity-and-hotspot-analysis/blob/main/src/features/build_features.py"
click node_roadfeatures "https://github.com/rishavsvault/road-accident-severity-and-hotspot-analysis/blob/main/src/features/road_features.py"
click node_temporalfeatures "https://github.com/rishavsvault/road-accident-severity-and-hotspot-analysis/blob/main/src/features/temporal_features.py"
click node_weatherfeatures "https://github.com/rishavsvault/road-accident-severity-and-hotspot-analysis/blob/main/src/features/weather_features.py"
click node_netkde "https://github.com/rishavsvault/road-accident-severity-and-hotspot-analysis/blob/main/src/hotspots/network_kde.py"
click node_spatialstats "https://github.com/rishavsvault/road-accident-severity-and-hotspot-analysis/blob/main/src/hotspots/spatial_stats.py"
click node_ranker "https://github.com/rishavsvault/road-accident-severity-and-hotspot-analysis/blob/main/src/hotspots/segment_ranker.py"
click node_trainer "https://github.com/rishavsvault/road-accident-severity-and-hotspot-analysis/blob/main/src/models/xgboost_trainer.py"
click node_spatialcv "https://github.com/rishavsvault/road-accident-severity-and-hotspot-analysis/blob/main/src/models/spatial_cv.py"
click node_evaluation "https://github.com/rishavsvault/road-accident-severity-and-hotspot-analysis/blob/main/src/models/evaluate.py"
click node_shap "https://github.com/rishavsvault/road-accident-severity-and-hotspot-analysis/blob/main/src/explainability/shap_explainer.py"
click node_interventions "https://github.com/rishavsvault/road-accident-severity-and-hotspot-analysis/blob/main/src/explainability/intervention_engine.py"
click node_dashboard "https://github.com/rishavsvault/road-accident-severity-and-hotspot-analysis/blob/main/dashboard/app.py"
click node_hotspotpage "https://github.com/rishavsvault/road-accident-severity-and-hotspot-analysis/blob/main/dashboard/pages/1_Hotspot_Explorer.py"
click node_deeppage "https://github.com/rishavsvault/road-accident-severity-and-hotspot-analysis/blob/main/dashboard/pages/2_Segment_Deep_Dive.py"
click node_simulator "https://github.com/rishavsvault/road-accident-severity-and-hotspot-analysis/blob/main/dashboard/pages/3_What_If_Simulator.py"
click node_policy "https://github.com/rishavsvault/road-accident-severity-and-hotspot-analysis/blob/main/dashboard/pages/4_KMDA_Policy_Brief.py"
click node_api "https://github.com/rishavsvault/road-accident-severity-and-hotspot-analysis/blob/main/src/api/main.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_pipeline,node_synthetic,node_cleaner,node_osm,node_weather,node_snapper toneBlue
class node_features,node_roadfeatures,node_temporalfeatures,node_weatherfeatures,node_netkde,node_spatialstats,node_ranker toneAmber
class node_trainer,node_spatialcv,node_evaluation,node_shap,node_interventions toneMint
class node_dashboard,node_hotspotpage,node_deeppage,node_simulator,node_policy,node_api toneRose
class node_user toneIndigo
```

## Components

### Input and alignment

- [Pipeline runner](https://github.com/rishavsvault/road-accident-severity-and-hotspot-analysis/blob/main/run_pipeline.py): `run_pipeline.py`
- [Synthetic crashes](https://github.com/rishavsvault/road-accident-severity-and-hotspot-analysis/blob/main/src/data/mock_data_generator.py): `src/data/mock_data_generator.py`
- [Crash cleaning](https://github.com/rishavsvault/road-accident-severity-and-hotspot-analysis/blob/main/src/data/crash_cleaner.py): `src/data/crash_cleaner.py`
- [Road network](https://github.com/rishavsvault/road-accident-severity-and-hotspot-analysis/blob/main/src/data/osm_loader.py): `src/data/osm_loader.py`
- [Weather loading](https://github.com/rishavsvault/road-accident-severity-and-hotspot-analysis/blob/main/src/data/weather_loader.py): `src/data/weather_loader.py`
- [Spatial snapping](https://github.com/rishavsvault/road-accident-severity-and-hotspot-analysis/blob/main/src/data/spatial_snapper.py): `src/data/spatial_snapper.py`

### Risk analysis

- [Feature matrix](https://github.com/rishavsvault/road-accident-severity-and-hotspot-analysis/blob/main/src/features/build_features.py): `src/features/build_features.py`
- [Road features](https://github.com/rishavsvault/road-accident-severity-and-hotspot-analysis/blob/main/src/features/road_features.py): `src/features/road_features.py`
- [Temporal features](https://github.com/rishavsvault/road-accident-severity-and-hotspot-analysis/blob/main/src/features/temporal_features.py): `src/features/temporal_features.py`
- [Weather features](https://github.com/rishavsvault/road-accident-severity-and-hotspot-analysis/blob/main/src/features/weather_features.py): `src/features/weather_features.py`
- [Network KDE](https://github.com/rishavsvault/road-accident-severity-and-hotspot-analysis/blob/main/src/hotspots/network_kde.py): `src/hotspots/network_kde.py`
- [Spatial statistics](https://github.com/rishavsvault/road-accident-severity-and-hotspot-analysis/blob/main/src/hotspots/spatial_stats.py): `src/hotspots/spatial_stats.py`
- [Segment ranking](https://github.com/rishavsvault/road-accident-severity-and-hotspot-analysis/blob/main/src/hotspots/segment_ranker.py): `src/hotspots/segment_ranker.py`

### Model and decisions

- [Severity training](https://github.com/rishavsvault/road-accident-severity-and-hotspot-analysis/blob/main/src/models/xgboost_trainer.py): `src/models/xgboost_trainer.py`
- [Spatial validation](https://github.com/rishavsvault/road-accident-severity-and-hotspot-analysis/blob/main/src/models/spatial_cv.py): `src/models/spatial_cv.py`
- [Model evaluation](https://github.com/rishavsvault/road-accident-severity-and-hotspot-analysis/blob/main/src/models/evaluate.py): `src/models/evaluate.py`
- [SHAP explanations](https://github.com/rishavsvault/road-accident-severity-and-hotspot-analysis/blob/main/src/explainability/shap_explainer.py): `src/explainability/shap_explainer.py`
- [Intervention advice](https://github.com/rishavsvault/road-accident-severity-and-hotspot-analysis/blob/main/src/explainability/intervention_engine.py): `src/explainability/intervention_engine.py`

### User interfaces

- [Streamlit dashboard](https://github.com/rishavsvault/road-accident-severity-and-hotspot-analysis/blob/main/dashboard/app.py): `dashboard/app.py`
- [Hotspot explorer](https://github.com/rishavsvault/road-accident-severity-and-hotspot-analysis/blob/main/dashboard/pages/1_Hotspot_Explorer.py): `dashboard/pages/1_Hotspot_Explorer.py`
- [Segment deep dive](https://github.com/rishavsvault/road-accident-severity-and-hotspot-analysis/blob/main/dashboard/pages/2_Segment_Deep_Dive.py): `dashboard/pages/2_Segment_Deep_Dive.py`
- [What-if simulator](https://github.com/rishavsvault/road-accident-severity-and-hotspot-analysis/blob/main/dashboard/pages/3_What_If_Simulator.py): `dashboard/pages/3_What_If_Simulator.py`
- [KMDA policy brief](https://github.com/rishavsvault/road-accident-severity-and-hotspot-analysis/blob/main/dashboard/pages/4_KMDA_Policy_Brief.py): `dashboard/pages/4_KMDA_Policy_Brief.py`
- [Analysis API](https://github.com/rishavsvault/road-accident-severity-and-hotspot-analysis/blob/main/src/api/main.py): `src/api/main.py`

### Other components

- **KMDA analyst**

## Connections

- KMDA analyst → Pipeline runner: runs pipeline
- Pipeline runner → Synthetic crashes: generates inputs (evidence: `run_pipeline.py`)
- Pipeline runner → Crash cleaning: cleans crashes (evidence: `run_pipeline.py`)
- Pipeline runner → Road network: loads roads (evidence: `run_pipeline.py`)
- Pipeline runner → Weather loading: loads weather (evidence: `run_pipeline.py`)
- Pipeline runner → Spatial snapping: aligns crashes (evidence: `run_pipeline.py`)
- Pipeline runner → Feature matrix: builds features (evidence: `run_pipeline.py`)
- Feature matrix → Road features: uses (evidence: `src/features/build_features.py`)
- Feature matrix → Temporal features: uses (evidence: `src/features/build_features.py`)
- Feature matrix → Weather features: uses (evidence: `src/features/build_features.py`)
- Pipeline runner → Network KDE: computes density (evidence: `run_pipeline.py`)
- Pipeline runner → Spatial statistics: tests clusters (evidence: `run_pipeline.py`)
- Pipeline runner → Segment ranking: ranks segments (evidence: `run_pipeline.py`)
- Pipeline runner → Severity training: trains severity model (evidence: `run_pipeline.py`)
- Severity training → Spatial validation: uses folds (evidence: `src/models/xgboost_trainer.py`)
- Severity training → Model evaluation: evaluates predictions (evidence: `src/models/xgboost_trainer.py`)
- Pipeline runner → Model evaluation: exports metrics (evidence: `run_pipeline.py`)
- Pipeline runner → SHAP explanations: explains predictions (evidence: `run_pipeline.py`)
- Pipeline runner → Intervention advice: recommends fixes (evidence: `run_pipeline.py`)
- KMDA analyst → Streamlit dashboard: opens dashboard
- Streamlit dashboard → Segment deep dive: presents page
- Streamlit dashboard → Hotspot explorer: presents page
- Streamlit dashboard → What-if simulator: presents page
- Streamlit dashboard → KMDA policy brief: presents page
- Segment deep dive → SHAP explanations: uses explanations (evidence: `dashboard/pages/2_Segment_Deep_Dive.py`)
- Segment deep dive → Intervention advice: uses recommendations (evidence: `dashboard/pages/2_Segment_Deep_Dive.py`)
- What-if simulator → Intervention advice: uses recommendations (evidence: `dashboard/pages/3_What_If_Simulator.py`)
- Analysis API → Intervention advice: uses recommendations (evidence: `src/api/main.py`)
- Analysis API → Spatial statistics: uses statistics (evidence: `src/api/main.py`)
