# sakshamsk2409-sys/road-risk-detection architecture

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

- Interactive diagram: https://gitdiagram.com/sakshamsk2409-sys/road-risk-detection
- Repository: https://github.com/sakshamsk2409-sys/road-risk-detection

## Overview

This repository is a Streamlit ADAS prototype that turns uploaded or sample dashcam video into annotated playback, telemetry, and advisory risk alerts. The primary runtime path is dashboard → video processor → perception, motion/spatial analysis, risk assessment, and rendered output. README capabilities preserve the rider filter, metric distance estimation, cut-in/blind-spot reasoning, and safety guardrails. Training and model evaluation are supporting product capabilities. Some detailed wiring is documented only in the README or SOURCE INDEX; unverified connections are omitted.

Main entry points: [`src/pipeline/video_processor.py`](https://github.com/sakshamsk2409-sys/road-risk-detection/blob/main/src/pipeline/video_processor.py) (Video processor and HUD), [`app.py`](https://github.com/sakshamsk2409-sys/road-risk-detection/blob/main/app.py) (Streamlit dashboard), [`src/risk_engine/train_risk_model.py`](https://github.com/sakshamsk2409-sys/road-risk-detection/blob/main/src/risk_engine/train_risk_model.py) (Risk model training), [`src/perception/detector.py`](https://github.com/sakshamsk2409-sys/road-risk-detection/blob/main/src/perception/detector.py) (YOLO detection and rider filter)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["Dashboard"]
  node_dashboard["Streamlit dashboard<br/>[app.py]"]
end

subgraph group_processing["Video processing"]
  node_samples["Sample video source<br/>[sample_data.py]"]
  node_processor["Video processor and HUD<br/>[video_processor.py]"]
  node_result["Annotated video and safety telemetry"]
end

subgraph group_perception["Road perception"]
  node_detector["YOLO detection and rider filter<br/>[detector.py]"]
  node_tracker["Tracking and TTC<br/>[tracker.py]"]
  node_distance["Monocular distance<br/>[depth_estimator.py]"]
  node_zones["Lane and cut-in analysis<br/>[lane_detector.py]"]
end

subgraph group_risk["Risk intelligence"]
  node_features["Risk feature extraction"]
  node_classifier["ML risk and guardrails<br/>[classifier.py]"]
  node_training["Risk model training"]
  node_evaluation["Model evaluation analytics<br/>[evaluator.py]"]
end

subgraph group_models["Model assets"]
  node_config["Camera and risk configuration<br/>[config.py]"]
  node_weights["YOLO weights<br/>[yolo11n.pt]"]
  node_riskmodel["Trained risk model"]
  node_trainingdata[("Driving risk dataset")]
  node_metrics["Model comparison metrics"]
end

node_driver(("Driver"))

node_driver -->|"selects video"| node_dashboard
node_dashboard -->|"offers samples"| node_samples
node_dashboard -->|"starts analysis"| node_processor
node_processor -->|"detects objects"| node_detector
node_processor -->|"tracks detections"| node_tracker
node_processor -->|"estimates range"| node_distance
node_processor -->|"analyzes zones"| node_zones
node_processor -->|"evaluates risk"| node_classifier
node_classifier -->|"extracts features"| node_features
node_processor -->|"renders HUD"| node_result
node_dashboard -->|"presents playback"| node_result
node_dashboard -->|"shows metrics"| node_evaluation
node_detector -->|"loads weights"| node_weights
node_detector -->|"uses thresholds"| node_config
node_distance -->|"uses calibration"| node_config
node_zones -->|"uses boundaries"| node_config
node_classifier -->|"loads model"| node_riskmodel
node_training -->|"trains on scenes"| node_trainingdata
node_training -->|"uses feature vector"| node_features
node_training -->|"saves selected model"| node_riskmodel
node_training -->|"records benchmarks"| node_metrics
node_evaluation -->|"loads comparisons"| node_metrics

click node_dashboard "https://github.com/sakshamsk2409-sys/road-risk-detection/blob/main/app.py"
click node_samples "https://github.com/sakshamsk2409-sys/road-risk-detection/blob/main/src/pipeline/sample_data.py"
click node_processor "https://github.com/sakshamsk2409-sys/road-risk-detection/blob/main/src/pipeline/video_processor.py"
click node_detector "https://github.com/sakshamsk2409-sys/road-risk-detection/blob/main/src/perception/detector.py"
click node_tracker "https://github.com/sakshamsk2409-sys/road-risk-detection/blob/main/src/perception/tracker.py"
click node_distance "https://github.com/sakshamsk2409-sys/road-risk-detection/blob/main/src/perception/depth_estimator.py"
click node_zones "https://github.com/sakshamsk2409-sys/road-risk-detection/blob/main/src/perception/lane_detector.py"
click node_features "https://github.com/sakshamsk2409-sys/road-risk-detection/blob/main/src/risk_engine/feature_extractor.py"
click node_classifier "https://github.com/sakshamsk2409-sys/road-risk-detection/blob/main/src/risk_engine/classifier.py"
click node_training "https://github.com/sakshamsk2409-sys/road-risk-detection/blob/main/src/risk_engine/train_risk_model.py"
click node_evaluation "https://github.com/sakshamsk2409-sys/road-risk-detection/blob/main/src/evaluation/evaluator.py"
click node_config "https://github.com/sakshamsk2409-sys/road-risk-detection/blob/main/config/config.py"
click node_weights "https://github.com/sakshamsk2409-sys/road-risk-detection/blob/main/yolo11n.pt"
click node_riskmodel "https://github.com/sakshamsk2409-sys/road-risk-detection/blob/main/data/models/best_risk_model.joblib"
click node_trainingdata "https://github.com/sakshamsk2409-sys/road-risk-detection/blob/main/data/training_data/driving_risk_dataset.csv"
click node_metrics "https://github.com/sakshamsk2409-sys/road-risk-detection/blob/main/data/models/model_comparison.json"

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_dashboard toneBlue
class node_samples,node_processor,node_result toneAmber
class node_detector,node_tracker,node_distance,node_zones toneMint
class node_features,node_classifier,node_training,node_evaluation toneRose
class node_config,node_weights,node_riskmodel,node_trainingdata,node_metrics,node_driver toneIndigo
```

## Components

### Dashboard

- [Streamlit dashboard](https://github.com/sakshamsk2409-sys/road-risk-detection/blob/main/app.py): `app.py`

### Video processing

- [Sample video source](https://github.com/sakshamsk2409-sys/road-risk-detection/blob/main/src/pipeline/sample_data.py): `src/pipeline/sample_data.py`
- [Video processor and HUD](https://github.com/sakshamsk2409-sys/road-risk-detection/blob/main/src/pipeline/video_processor.py): `src/pipeline/video_processor.py`
- **Annotated video and safety telemetry**

### Road perception

- [YOLO detection and rider filter](https://github.com/sakshamsk2409-sys/road-risk-detection/blob/main/src/perception/detector.py): `src/perception/detector.py`
- [Tracking and TTC](https://github.com/sakshamsk2409-sys/road-risk-detection/blob/main/src/perception/tracker.py): `src/perception/tracker.py`
- [Monocular distance](https://github.com/sakshamsk2409-sys/road-risk-detection/blob/main/src/perception/depth_estimator.py): `src/perception/depth_estimator.py`
- [Lane and cut-in analysis](https://github.com/sakshamsk2409-sys/road-risk-detection/blob/main/src/perception/lane_detector.py): `src/perception/lane_detector.py`

### Risk intelligence

- [Risk feature extraction](https://github.com/sakshamsk2409-sys/road-risk-detection/blob/main/src/risk_engine/feature_extractor.py): `src/risk_engine/feature_extractor.py`
- [ML risk and guardrails](https://github.com/sakshamsk2409-sys/road-risk-detection/blob/main/src/risk_engine/classifier.py): `src/risk_engine/classifier.py`
- [Risk model training](https://github.com/sakshamsk2409-sys/road-risk-detection/blob/main/src/risk_engine/train_risk_model.py): `src/risk_engine/train_risk_model.py`
- [Model evaluation analytics](https://github.com/sakshamsk2409-sys/road-risk-detection/blob/main/src/evaluation/evaluator.py): `src/evaluation/evaluator.py`

### Model assets

- [Camera and risk configuration](https://github.com/sakshamsk2409-sys/road-risk-detection/blob/main/config/config.py): `config/config.py`
- [YOLO weights](https://github.com/sakshamsk2409-sys/road-risk-detection/blob/main/yolo11n.pt): `yolo11n.pt`
- [Trained risk model](https://github.com/sakshamsk2409-sys/road-risk-detection/blob/main/data/models/best_risk_model.joblib): `data/models/best_risk_model.joblib`
- [Driving risk dataset](https://github.com/sakshamsk2409-sys/road-risk-detection/blob/main/data/training_data/driving_risk_dataset.csv): `data/training_data/driving_risk_dataset.csv`
- [Model comparison metrics](https://github.com/sakshamsk2409-sys/road-risk-detection/blob/main/data/models/model_comparison.json): `data/models/model_comparison.json`

### Other components

- **Driver**

## Connections

- Driver → Streamlit dashboard: selects video (evidence: `README.md`)
- Streamlit dashboard → Sample video source: offers samples (evidence: `app.py`)
- Streamlit dashboard → Video processor and HUD: starts analysis (evidence: `README.md`)
- Video processor and HUD → YOLO detection and rider filter: detects objects (evidence: `README.md`)
- Video processor and HUD → Tracking and TTC: tracks detections (evidence: `README.md`)
- Video processor and HUD → Monocular distance: estimates range (evidence: `README.md`)
- Video processor and HUD → Lane and cut-in analysis: analyzes zones (evidence: `README.md`)
- Video processor and HUD → ML risk and guardrails: evaluates risk (evidence: `src/pipeline/video_processor.py`)
- ML risk and guardrails → Risk feature extraction: extracts features (evidence: `src/risk_engine/classifier.py`)
- Video processor and HUD → Annotated video and safety telemetry: renders HUD (evidence: `README.md`)
- Streamlit dashboard → Annotated video and safety telemetry: presents playback (evidence: `README.md`)
- Streamlit dashboard → Model evaluation analytics: shows metrics (evidence: `app.py`)
- YOLO detection and rider filter → YOLO weights: loads weights (evidence: `README.md`)
- YOLO detection and rider filter → Camera and risk configuration: uses thresholds (evidence: `src/perception/detector.py`)
- Monocular distance → Camera and risk configuration: uses calibration (evidence: `src/perception/depth_estimator.py`)
- Lane and cut-in analysis → Camera and risk configuration: uses boundaries (evidence: `src/perception/lane_detector.py`)
- ML risk and guardrails → Trained risk model: loads model (evidence: `src/risk_engine/classifier.py`)
- Risk model training → Driving risk dataset: trains on scenes (evidence: `README.md`)
- Risk model training → Risk feature extraction: uses feature vector (evidence: `src/risk_engine/train_risk_model.py`)
- Risk model training → Trained risk model: saves selected model (evidence: `README.md`)
- Risk model training → Model comparison metrics: records benchmarks (evidence: `README.md`)
- Model evaluation analytics → Model comparison metrics: loads comparisons (evidence: `src/evaluation/evaluator.py`)
