# wader444/road-accident-hotspot-detection architecture

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

- Interactive diagram: https://gitdiagram.com/wader444/road-accident-hotspot-detection
- Repository: https://github.com/wader444/road-accident-hotspot-detection

## Overview

This is a Python geospatial accident-hotspot analysis project. Its principal workflow extracts a city’s coordinates, clusters them with Haversine DBSCAN, and produces hotspot summaries and visualizations; K-Means provides a separate comparison. The graph also includes documented map serving and pipeline runners. Source excerpts establish the core clustering, preparation, analysis, comparison, and orchestration behavior; some visualization and runner relationships are documented in the README but their implementations were not sampled.

Main entry points: [`run_city.py`](https://github.com/wader444/road-accident-hotspot-detection/blob/main/run_city.py) (City workflow runner), [`outputs`](https://github.com/wader444/road-accident-hotspot-detection/tree/main/outputs) (DBSCAN results), [`main.py`](https://github.com/wader444/road-accident-hotspot-detection/blob/main/main.py) (Downstream runner), [`analyze_hotspots.py`](https://github.com/wader444/road-accident-hotspot-detection/blob/main/analyze_hotspots.py) (Hotspot summary)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingest["Data preparation"]
  node_prepare["City extraction<br/>[prepare_city.py]"]
  node_citydata["Prepared city records"]
end

subgraph group_models["Spatial clustering"]
  node_dbscan["DBSCAN and sweep<br/>[clustering.py]"]
  node_dbresults["DBSCAN results"]
end

subgraph group_insight["Analysis and visualization"]
  node_analysis["Hotspot summary"]
  node_summarydata["Hotspot exports"]
  node_mapview["Interactive map"]
  node_kmeans["K-Means comparison"]
  node_comparisondata["Comparison exports"]
end

subgraph group_workflow["Workflow runners"]
  node_main["Downstream runner<br/>[main.py]"]
  node_cityrunner["City workflow runner<br/>[run_city.py]"]
  node_maprunner["Map server runner<br/>[run_map.py]"]
end

node_rawdata["Raw accident CSV"]
node_user(("Analyst"))

node_rawdata -->|"provides records"| node_prepare
node_prepare -->|"writes records"| node_citydata
node_citydata -->|"loads coordinates"| node_dbscan
node_dbscan -->|"writes labels"| node_dbresults
node_dbresults -->|"loads results"| node_analysis
node_analysis -->|"writes summaries"| node_summarydata
node_dbresults -->|"loads assignments"| node_kmeans
node_kmeans -->|"writes comparison"| node_comparisondata
node_dbresults -.->|"visualizes results"| node_mapview
node_main -->|"calls analysis"| node_analysis
node_main -->|"creates map"| node_mapview
node_main -->|"calls comparison"| node_kmeans
node_cityrunner -->|"runs preparation"| node_prepare
node_cityrunner -->|"runs clustering"| node_dbscan
node_cityrunner -->|"regenerates summaries"| node_analysis
node_cityrunner -->|"creates comparison"| node_kmeans
node_maprunner -->|"serves map"| node_mapview
node_user -->|"selects city"| node_cityrunner
node_user -->|"runs stages"| node_main
node_user -->|"opens map"| node_maprunner

click node_prepare "https://github.com/wader444/road-accident-hotspot-detection/blob/main/prepare_city.py"
click node_citydata "https://github.com/wader444/road-accident-hotspot-detection/tree/main/outputs"
click node_dbscan "https://github.com/wader444/road-accident-hotspot-detection/blob/main/clustering.py"
click node_dbresults "https://github.com/wader444/road-accident-hotspot-detection/tree/main/outputs"
click node_analysis "https://github.com/wader444/road-accident-hotspot-detection/blob/main/analyze_hotspots.py"
click node_summarydata "https://github.com/wader444/road-accident-hotspot-detection/tree/main/outputs"
click node_mapview "https://github.com/wader444/road-accident-hotspot-detection/blob/main/visualize_hotspots.py"
click node_kmeans "https://github.com/wader444/road-accident-hotspot-detection/blob/main/compare_clustering.py"
click node_comparisondata "https://github.com/wader444/road-accident-hotspot-detection/tree/main/outputs"
click node_main "https://github.com/wader444/road-accident-hotspot-detection/blob/main/main.py"
click node_cityrunner "https://github.com/wader444/road-accident-hotspot-detection/blob/main/run_city.py"
click node_maprunner "https://github.com/wader444/road-accident-hotspot-detection/blob/main/run_map.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_prepare,node_citydata toneBlue
class node_dbscan,node_dbresults toneAmber
class node_analysis,node_summarydata,node_mapview,node_kmeans,node_comparisondata toneMint
class node_main,node_cityrunner,node_maprunner toneRose
class node_rawdata,node_user toneIndigo
```

## Components

### Data preparation

- [City extraction](https://github.com/wader444/road-accident-hotspot-detection/blob/main/prepare_city.py): `prepare_city.py`
- [Prepared city records](https://github.com/wader444/road-accident-hotspot-detection/tree/main/outputs): `outputs`

### Spatial clustering

- [DBSCAN and sweep](https://github.com/wader444/road-accident-hotspot-detection/blob/main/clustering.py): `clustering.py`
- [DBSCAN results](https://github.com/wader444/road-accident-hotspot-detection/tree/main/outputs): `outputs`

### Analysis and visualization

- [Hotspot summary](https://github.com/wader444/road-accident-hotspot-detection/blob/main/analyze_hotspots.py): `analyze_hotspots.py`
- [Hotspot exports](https://github.com/wader444/road-accident-hotspot-detection/tree/main/outputs): `outputs`
- [Interactive map](https://github.com/wader444/road-accident-hotspot-detection/blob/main/visualize_hotspots.py): `visualize_hotspots.py`
- [K-Means comparison](https://github.com/wader444/road-accident-hotspot-detection/blob/main/compare_clustering.py): `compare_clustering.py`
- [Comparison exports](https://github.com/wader444/road-accident-hotspot-detection/tree/main/outputs): `outputs`

### Workflow runners

- [Downstream runner](https://github.com/wader444/road-accident-hotspot-detection/blob/main/main.py): `main.py`
- [City workflow runner](https://github.com/wader444/road-accident-hotspot-detection/blob/main/run_city.py): `run_city.py`
- [Map server runner](https://github.com/wader444/road-accident-hotspot-detection/blob/main/run_map.py): `run_map.py`

### Other components

- **Raw accident CSV**
- **Analyst**

## Connections

- Raw accident CSV → City extraction: provides records (evidence: `README.md`)
- City extraction → Prepared city records: writes records (evidence: `prepare_city.py`)
- Prepared city records → DBSCAN and sweep: loads coordinates (evidence: `clustering.py`)
- DBSCAN and sweep → DBSCAN results: writes labels (evidence: `clustering.py`)
- DBSCAN results → Hotspot summary: loads results (evidence: `analyze_hotspots.py`)
- Hotspot summary → Hotspot exports: writes summaries (evidence: `analyze_hotspots.py`)
- DBSCAN results → K-Means comparison: loads assignments (evidence: `compare_clustering.py`)
- K-Means comparison → Comparison exports: writes comparison (evidence: `compare_clustering.py`)
- DBSCAN results → Interactive map: visualizes results
- Downstream runner → Hotspot summary: calls analysis (evidence: `main.py`)
- Downstream runner → Interactive map: creates map (evidence: `main.py`)
- Downstream runner → K-Means comparison: calls comparison (evidence: `main.py`)
- City workflow runner → City extraction: runs preparation (evidence: `README.md`)
- City workflow runner → DBSCAN and sweep: runs clustering (evidence: `README.md`)
- City workflow runner → Hotspot summary: regenerates summaries (evidence: `README.md`)
- City workflow runner → K-Means comparison: creates comparison (evidence: `README.md`)
- Map server runner → Interactive map: serves map (evidence: `README.md`)
- Analyst → City workflow runner: selects city (evidence: `README.md`)
- Analyst → Downstream runner: runs stages (evidence: `README.md`)
- Analyst → Map server runner: opens map (evidence: `README.md`)
