# susi12300/safeway-road-safety-apk architecture

> Architecture diagram of the GitHub repository susi12300/safeway-road-safety-apk, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-24). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/susi12300/safeway-road-safety-apk
- Repository: https://github.com/susi12300/safeway-road-safety-apk

## Overview

SafeWay is a route-safety application: users enter a trip, receive a route risk assessment, and can view route risk zones or check their current location. The Flask API coordinates routing, weather enrichment, risk scoring, and zone checks; the browser presents results on a map. The excerpts show the route and zone-generation calls, but not all API handler details or model-loading code, so those connections are omitted or marked unverified.

Main entry points: [`app.py`](https://github.com/susi12300/safeway-road-safety-apk/blob/main/app.py) (Flask API), [`frontend/script.js`](https://github.com/susi12300/safeway-road-safety-apk/blob/main/frontend/script.js) (Map and results UI), [`route_service.py`](https://github.com/susi12300/safeway-road-safety-apk/blob/main/route_service.py) (Route analysis), [`weather_service.py`](https://github.com/susi12300/safeway-road-safety-apk/blob/main/weather_service.py) (Route weather)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Browser experience"]
  node_web_ui["Map and results UI<br/>[script.js]"]
end

subgraph group_api["API and risk analysis"]
  node_flask_api["Flask API<br/>[app.py]"]
  node_route_engine["Route analysis<br/>[route_service.py]"]
  node_weather_analysis["Route weather<br/>[weather_service.py]"]
  node_risk_zones["Risk zones<br/>[danger_zone.py]"]
end

subgraph group_integrations["External services"]
  node_geocoder["Nominatim"]
  node_directions["OpenRouteService"]
  node_weather_api["OpenWeather"]
end

subgraph group_modeling["Risk model"]
  node_training["Model training<br/>[train_model.py]"]
  node_accident_data["Accident dataset<br/>[accident_data.csv]"]
  node_risk_model["Trained model"]
end

node_driver(("Driver"))

node_driver -->|"enters trip"| node_web_ui
node_web_ui -->|"requests analysis"| node_flask_api
node_flask_api -->|"gets route"| node_route_engine
node_route_engine -->|"geocodes places"| node_geocoder
node_route_engine -->|"requests directions"| node_directions
node_flask_api -.->|"gets route weather"| node_weather_analysis
node_weather_analysis -->|"fetches conditions"| node_weather_api
node_flask_api -->|"generates zones"| node_risk_zones
node_web_ui -->|"requests zone checks"| node_flask_api
node_flask_api -.->|"checks location"| node_risk_zones
node_accident_data -->|"supplies examples"| node_training
node_training -->|"saves model"| node_risk_model
node_flask_api -.->|"loads for scoring"| node_risk_model

click node_web_ui "https://github.com/susi12300/safeway-road-safety-apk/blob/main/frontend/script.js"
click node_flask_api "https://github.com/susi12300/safeway-road-safety-apk/blob/main/app.py"
click node_route_engine "https://github.com/susi12300/safeway-road-safety-apk/blob/main/route_service.py"
click node_weather_analysis "https://github.com/susi12300/safeway-road-safety-apk/blob/main/weather_service.py"
click node_risk_zones "https://github.com/susi12300/safeway-road-safety-apk/blob/main/danger_zone.py"
click node_training "https://github.com/susi12300/safeway-road-safety-apk/blob/main/train_model.py"
click node_accident_data "https://github.com/susi12300/safeway-road-safety-apk/blob/main/accident_data.csv"
click node_risk_model "https://github.com/susi12300/safeway-road-safety-apk/blob/main/road_risk_model.pkl"

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_web_ui toneBlue
class node_flask_api,node_route_engine,node_weather_analysis,node_risk_zones toneAmber
class node_geocoder,node_directions,node_weather_api toneMint
class node_training,node_accident_data,node_risk_model toneRose
class node_driver toneIndigo
```

## Components

### Browser experience

- [Map and results UI](https://github.com/susi12300/safeway-road-safety-apk/blob/main/frontend/script.js): `frontend/script.js`

### API and risk analysis

- [Flask API](https://github.com/susi12300/safeway-road-safety-apk/blob/main/app.py): `app.py`
- [Route analysis](https://github.com/susi12300/safeway-road-safety-apk/blob/main/route_service.py): `route_service.py`
- [Route weather](https://github.com/susi12300/safeway-road-safety-apk/blob/main/weather_service.py): `weather_service.py`
- [Risk zones](https://github.com/susi12300/safeway-road-safety-apk/blob/main/danger_zone.py): `danger_zone.py`

### External services

- **Nominatim**
- **OpenRouteService**
- **OpenWeather**

### Risk model

- [Model training](https://github.com/susi12300/safeway-road-safety-apk/blob/main/train_model.py): `train_model.py`
- [Accident dataset](https://github.com/susi12300/safeway-road-safety-apk/blob/main/accident_data.csv): `accident_data.csv`
- [Trained model](https://github.com/susi12300/safeway-road-safety-apk/blob/main/road_risk_model.pkl): `road_risk_model.pkl`

### Other components

- **Driver**

## Connections

- Driver → Map and results UI: enters trip (evidence: `frontend/script.js`)
- Map and results UI → Flask API: requests analysis (evidence: `frontend/script.js`)
- Flask API → Route analysis: gets route (evidence: `app.py`)
- Route analysis → Nominatim: geocodes places (evidence: `route_service.py`)
- Route analysis → OpenRouteService: requests directions (evidence: `route_service.py`)
- Flask API → Route weather: gets route weather (evidence: `app.py`)
- Route weather → OpenWeather: fetches conditions (evidence: `weather_service.py`)
- Flask API → Risk zones: generates zones (evidence: `app.py`)
- Map and results UI → Flask API: requests zone checks (evidence: `frontend/script.js`)
- Flask API → Risk zones: checks location (evidence: `app.py`)
- Accident dataset → Model training: supplies examples (evidence: `train_model.py`)
- Model training → Trained model: saves model (evidence: `train_model.py`)
- Flask API → Trained model: loads for scoring
