# pshkarsngh/saferoute-ai-project architecture

> Architecture diagram of the GitHub repository pshkarsngh/saferoute-ai-project, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/pshkarsngh/saferoute-ai-project
- Repository: https://github.com/pshkarsngh/saferoute-ai-project

## Overview

SafeRoute AI accepts a place or coordinates, obtains candidate routes, assesses permitted imagery for hazards, computes deterministic risk and route comparisons, and returns a grounded explanation. Separate API capabilities provide geocoding, persisted analysis records, and nearby facilities; dataset governance and detector evaluation support the model lifecycle. Relationships are limited to the sampled excerpts, SOURCE INDEX references, and README; unsampled provider wiring is not inferred.

Main entry points: [`src/api/pipeline.py`](https://github.com/pshkarsngh/saferoute-ai-project/blob/main/src/api/pipeline.py) (Analysis Orchestrator), [`src/api/app.py`](https://github.com/pshkarsngh/saferoute-ai-project/blob/main/src/api/app.py) (HTTP API), [`src/detection/detector.py`](https://github.com/pshkarsngh/saferoute-ai-project/blob/main/src/detection/detector.py) (Hazard Detection), [`src/routing/adapter.py`](https://github.com/pshkarsngh/saferoute-ai-project/blob/main/src/routing/adapter.py) (Route Selection)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and Records"]
  node_http["HTTP API<br/>[app.py]"]
  node_settings["Runtime Settings<br/>[settings.py]"]
  node_store[("Analysis Store<br/>[store.py]")]
end

subgraph group_analysis["Safety Analysis"]
  node_pipeline["Analysis Orchestrator<br/>[pipeline.py]"]
  node_routing["Route Selection<br/>[adapter.py]"]
  node_imagery["Imagery Retrieval<br/>[adapter.py]"]
  node_detection["Hazard Detection<br/>[detector.py]"]
  node_preprocess["Image Preprocessing<br/>[pipeline.py]"]
  node_aggregation["Hazard Aggregation<br/>[aggregate.py]"]
  node_risk["Deterministic Risk<br/>[engine.py]"]
  node_comparison["Route Comparison<br/>[comparison.py]"]
  node_explanation["Grounded Explanation<br/>[explainer.py]"]
end

subgraph group_providers["External Providers"]
  node_geocoder["Geocoding<br/>[nominatim.py]"]
  node_router["OSRM and Valhalla<br/>[multi_adapter.py]"]
  node_mapillary["Mapillary Imagery"]
  node_facilities["Nearby Facilities<br/>[service.py]"]
end

subgraph group_quality["Data and Evaluation"]
  node_acquisition["Image Acquisition<br/>[acquisition.py]"]
  node_freeze["Dataset Freeze<br/>[freeze.py]"]
  node_evaluation["Detector Evaluation<br/>[evaluator.py]"]
end

node_user(("Traveler"))

node_user -->|"submits analysis"| node_http
node_http -->|"runs analysis"| node_pipeline
node_http -->|"persists records"| node_store
node_http -->|"geocodes query"| node_geocoder
node_pipeline -->|"requests routes"| node_routing
node_pipeline -->|"retrieves imagery"| node_imagery
node_pipeline -->|"detects hazards"| node_detection
node_detection -->|"prepares images"| node_preprocess
node_pipeline -->|"aggregates detections"| node_aggregation
node_pipeline -->|"computes risk"| node_risk
node_pipeline -->|"compares routes"| node_comparison
node_pipeline -->|"requests explanation"| node_explanation
node_routing -.->|"dispatches routing"| node_router
node_imagery -.->|"selects imagery"| node_mapillary
node_http -.->|"serves lookup"| node_facilities
node_acquisition -->|"supplies dataset"| node_freeze
node_evaluation -->|"evaluates serving path"| node_detection

click node_http "https://github.com/pshkarsngh/saferoute-ai-project/blob/main/src/api/app.py"
click node_settings "https://github.com/pshkarsngh/saferoute-ai-project/blob/main/src/config/settings.py"
click node_store "https://github.com/pshkarsngh/saferoute-ai-project/blob/main/src/api/store.py"
click node_pipeline "https://github.com/pshkarsngh/saferoute-ai-project/blob/main/src/api/pipeline.py"
click node_routing "https://github.com/pshkarsngh/saferoute-ai-project/blob/main/src/routing/adapter.py"
click node_imagery "https://github.com/pshkarsngh/saferoute-ai-project/blob/main/src/imagery/adapter.py"
click node_detection "https://github.com/pshkarsngh/saferoute-ai-project/blob/main/src/detection/detector.py"
click node_preprocess "https://github.com/pshkarsngh/saferoute-ai-project/blob/main/src/preprocessing/pipeline.py"
click node_aggregation "https://github.com/pshkarsngh/saferoute-ai-project/blob/main/src/risk/aggregate.py"
click node_risk "https://github.com/pshkarsngh/saferoute-ai-project/blob/main/src/risk/engine.py"
click node_comparison "https://github.com/pshkarsngh/saferoute-ai-project/blob/main/src/risk/comparison.py"
click node_explanation "https://github.com/pshkarsngh/saferoute-ai-project/blob/main/src/llm/explainer.py"
click node_geocoder "https://github.com/pshkarsngh/saferoute-ai-project/blob/main/src/geocoding/nominatim.py"
click node_router "https://github.com/pshkarsngh/saferoute-ai-project/blob/main/src/routing/multi_adapter.py"
click node_mapillary "https://github.com/pshkarsngh/saferoute-ai-project/blob/main/src/imagery/mapillary_provider.py"
click node_facilities "https://github.com/pshkarsngh/saferoute-ai-project/blob/main/src/facilities/service.py"
click node_acquisition "https://github.com/pshkarsngh/saferoute-ai-project/blob/main/src/datasets/acquisition.py"
click node_freeze "https://github.com/pshkarsngh/saferoute-ai-project/blob/main/src/datasets/freeze.py"
click node_evaluation "https://github.com/pshkarsngh/saferoute-ai-project/blob/main/src/evaluation/evaluator.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_http,node_settings,node_store toneBlue
class node_pipeline,node_routing,node_imagery,node_detection,node_preprocess,node_aggregation,node_risk,node_comparison,node_explanation toneAmber
class node_geocoder,node_router,node_mapillary,node_facilities toneMint
class node_acquisition,node_freeze,node_evaluation toneRose
class node_user toneIndigo
```

## Components

### API and Records

- [HTTP API](https://github.com/pshkarsngh/saferoute-ai-project/blob/main/src/api/app.py): `src/api/app.py`
- [Runtime Settings](https://github.com/pshkarsngh/saferoute-ai-project/blob/main/src/config/settings.py): `src/config/settings.py`
- [Analysis Store](https://github.com/pshkarsngh/saferoute-ai-project/blob/main/src/api/store.py): `src/api/store.py`

### Safety Analysis

- [Analysis Orchestrator](https://github.com/pshkarsngh/saferoute-ai-project/blob/main/src/api/pipeline.py): `src/api/pipeline.py`
- [Route Selection](https://github.com/pshkarsngh/saferoute-ai-project/blob/main/src/routing/adapter.py): `src/routing/adapter.py`
- [Imagery Retrieval](https://github.com/pshkarsngh/saferoute-ai-project/blob/main/src/imagery/adapter.py): `src/imagery/adapter.py`
- [Hazard Detection](https://github.com/pshkarsngh/saferoute-ai-project/blob/main/src/detection/detector.py): `src/detection/detector.py`
- [Image Preprocessing](https://github.com/pshkarsngh/saferoute-ai-project/blob/main/src/preprocessing/pipeline.py): `src/preprocessing/pipeline.py`
- [Hazard Aggregation](https://github.com/pshkarsngh/saferoute-ai-project/blob/main/src/risk/aggregate.py): `src/risk/aggregate.py`
- [Deterministic Risk](https://github.com/pshkarsngh/saferoute-ai-project/blob/main/src/risk/engine.py): `src/risk/engine.py`
- [Route Comparison](https://github.com/pshkarsngh/saferoute-ai-project/blob/main/src/risk/comparison.py): `src/risk/comparison.py`
- [Grounded Explanation](https://github.com/pshkarsngh/saferoute-ai-project/blob/main/src/llm/explainer.py): `src/llm/explainer.py`

### External Providers

- [Geocoding](https://github.com/pshkarsngh/saferoute-ai-project/blob/main/src/geocoding/nominatim.py): `src/geocoding/nominatim.py`
- [OSRM and Valhalla](https://github.com/pshkarsngh/saferoute-ai-project/blob/main/src/routing/multi_adapter.py): `src/routing/multi_adapter.py`
- [Mapillary Imagery](https://github.com/pshkarsngh/saferoute-ai-project/blob/main/src/imagery/mapillary_provider.py): `src/imagery/mapillary_provider.py`
- [Nearby Facilities](https://github.com/pshkarsngh/saferoute-ai-project/blob/main/src/facilities/service.py): `src/facilities/service.py`

### Data and Evaluation

- [Image Acquisition](https://github.com/pshkarsngh/saferoute-ai-project/blob/main/src/datasets/acquisition.py): `src/datasets/acquisition.py`
- [Dataset Freeze](https://github.com/pshkarsngh/saferoute-ai-project/blob/main/src/datasets/freeze.py): `src/datasets/freeze.py`
- [Detector Evaluation](https://github.com/pshkarsngh/saferoute-ai-project/blob/main/src/evaluation/evaluator.py): `src/evaluation/evaluator.py`

### Other components

- **Traveler**

## Connections

- Traveler → HTTP API: submits analysis
- HTTP API → Analysis Orchestrator: runs analysis (evidence: `src/api/app.py`)
- HTTP API → Analysis Store: persists records (evidence: `src/api/app.py`)
- HTTP API → Geocoding: geocodes query (evidence: `src/api/app.py`)
- Analysis Orchestrator → Route Selection: requests routes (evidence: `src/api/pipeline.py`)
- Analysis Orchestrator → Imagery Retrieval: retrieves imagery (evidence: `src/api/pipeline.py`)
- Analysis Orchestrator → Hazard Detection: detects hazards (evidence: `src/api/pipeline.py`)
- Hazard Detection → Image Preprocessing: prepares images (evidence: `src/detection/detector.py`)
- Analysis Orchestrator → Hazard Aggregation: aggregates detections (evidence: `src/api/pipeline.py`)
- Analysis Orchestrator → Deterministic Risk: computes risk (evidence: `src/api/pipeline.py`)
- Analysis Orchestrator → Route Comparison: compares routes (evidence: `src/api/pipeline.py`)
- Analysis Orchestrator → Grounded Explanation: requests explanation (evidence: `src/api/pipeline.py`)
- Route Selection → OSRM and Valhalla: dispatches routing
- Imagery Retrieval → Mapillary Imagery: selects imagery
- HTTP API → Nearby Facilities: serves lookup
- Image Acquisition → Dataset Freeze: supplies dataset (evidence: `src/datasets/freeze.py`)
- Detector Evaluation → Hazard Detection: evaluates serving path (evidence: `src/evaluation/evaluator.py`)
