# anmolrawat990/road-hazard-detection architecture

> Architecture diagram of the GitHub repository anmolrawat990/road-hazard-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/anmolrawat990/road-hazard-detection
- Repository: https://github.com/anmolrawat990/road-hazard-detection

## Overview

Road Hazard Detection combines PHP session-based account access with a Flask video-analysis service. A signed-in user uploads a video from the dashboard; Flask saves it, processes frames with the custom YOLO weights, and exposes an MJPEG stream and current-frame detections for the dashboard to display. Users can pause and resume processing, and high-confidence detections trigger Windows audio alerts. The README also describes MySQL authentication and sample videos. Source excerpts do not show database use beyond account handling, or any persistent video/detection history.

Main entry points: [`dashboard.php`](https://github.com/anmolrawat990/road-hazard-detection/blob/main/dashboard.php) (Detection Dashboard), [`app.py`](https://github.com/anmolrawat990/road-hazard-detection/blob/main/app.py) (Frame Processor), [`index.php`](https://github.com/anmolrawat990/road-hazard-detection/blob/main/index.php) (Login and Signup), [`logout.php`](https://github.com/anmolrawat990/road-hazard-detection/blob/main/logout.php) (Session Logout)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_access["Account Access"]
  node_login["Login and Signup<br/>[index.php]"]
  node_authdb[("MySQL Accounts<br/>[db_config.php]")]
  node_logout["Session Logout<br/>[logout.php]"]
end

subgraph group_interface["Dashboard Interface"]
  node_dashboard["Detection Dashboard<br/>[dashboard.php]"]
end

subgraph group_vision["Video Detection"]
  node_upload["Video Upload API<br/>[app.py]"]
  node_video["Uploaded Video<br/>[app.py]"]
  node_processor["Frame Processor<br/>[app.py]"]
  node_capture["OpenCV Capture<br/>[app.py]"]
  node_detector["YOLO Inference<br/>[app.py]"]
  node_weights["Custom YOLO Weights<br/>[best.pt]"]
  node_pause["Pause Control<br/>[app.py]"]
  node_alerts["Audio Alerts<br/>[app.py]"]
end

subgraph group_delivery["Live Results"]
  node_frame_state["Current Frame State<br/>[app.py]"]
  node_stream["MJPEG Stream<br/>[app.py]"]
  node_alert_api["Detection Status API<br/>[app.py]"]
end

node_user(("Driver"))
node_sound["Windows System Sound"]

node_user -->|"signs in"| node_login
node_login -->|"queries accounts"| node_authdb
node_login -->|"redirects after login"| node_dashboard
node_dashboard -->|"opens logout"| node_logout
node_logout -->|"redirects to"| node_login
node_user -->|"uploads video"| node_dashboard
node_dashboard -->|"posts video"| node_upload
node_upload -->|"saves upload"| node_video
node_upload -->|"starts thread"| node_processor
node_processor -->|"opens video"| node_capture
node_processor -->|"runs inference"| node_detector
node_detector -->|"loads model"| node_weights
node_processor -->|"writes annotated frame"| node_frame_state
node_processor -->|"waits on event"| node_pause
node_processor -->|"triggers on confidence"| node_alerts
node_alerts -->|"plays beep"| node_sound
node_dashboard -->|"requests stream"| node_stream
node_stream -->|"reads frames"| node_frame_state
node_dashboard -->|"polls detections"| node_alert_api
node_alert_api -->|"reads detection state"| node_frame_state
node_dashboard -->|"toggles processing"| node_pause

click node_login "https://github.com/anmolrawat990/road-hazard-detection/blob/main/index.php"
click node_authdb "https://github.com/anmolrawat990/road-hazard-detection/blob/main/db_config.php"
click node_logout "https://github.com/anmolrawat990/road-hazard-detection/blob/main/logout.php"
click node_dashboard "https://github.com/anmolrawat990/road-hazard-detection/blob/main/dashboard.php"
click node_upload "https://github.com/anmolrawat990/road-hazard-detection/blob/main/app.py"
click node_video "https://github.com/anmolrawat990/road-hazard-detection/blob/main/app.py"
click node_processor "https://github.com/anmolrawat990/road-hazard-detection/blob/main/app.py"
click node_capture "https://github.com/anmolrawat990/road-hazard-detection/blob/main/app.py"
click node_detector "https://github.com/anmolrawat990/road-hazard-detection/blob/main/app.py"
click node_weights "https://github.com/anmolrawat990/road-hazard-detection/blob/main/best.pt"
click node_pause "https://github.com/anmolrawat990/road-hazard-detection/blob/main/app.py"
click node_alerts "https://github.com/anmolrawat990/road-hazard-detection/blob/main/app.py"
click node_frame_state "https://github.com/anmolrawat990/road-hazard-detection/blob/main/app.py"
click node_stream "https://github.com/anmolrawat990/road-hazard-detection/blob/main/app.py"
click node_alert_api "https://github.com/anmolrawat990/road-hazard-detection/blob/main/app.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_login,node_authdb,node_logout toneBlue
class node_dashboard toneAmber
class node_upload,node_video,node_processor,node_capture,node_detector,node_weights,node_pause,node_alerts toneMint
class node_frame_state,node_stream,node_alert_api toneRose
class node_user,node_sound toneIndigo
```

## Components

### Account Access

- [Login and Signup](https://github.com/anmolrawat990/road-hazard-detection/blob/main/index.php): `index.php`
- [MySQL Accounts](https://github.com/anmolrawat990/road-hazard-detection/blob/main/db_config.php): `db_config.php`
- [Session Logout](https://github.com/anmolrawat990/road-hazard-detection/blob/main/logout.php): `logout.php`

### Dashboard Interface

- [Detection Dashboard](https://github.com/anmolrawat990/road-hazard-detection/blob/main/dashboard.php): `dashboard.php`

### Video Detection

- [Video Upload API](https://github.com/anmolrawat990/road-hazard-detection/blob/main/app.py): `app.py`
- [Uploaded Video](https://github.com/anmolrawat990/road-hazard-detection/blob/main/app.py): `app.py`
- [Frame Processor](https://github.com/anmolrawat990/road-hazard-detection/blob/main/app.py): `app.py`
- [OpenCV Capture](https://github.com/anmolrawat990/road-hazard-detection/blob/main/app.py): `app.py`
- [YOLO Inference](https://github.com/anmolrawat990/road-hazard-detection/blob/main/app.py): `app.py`
- [Custom YOLO Weights](https://github.com/anmolrawat990/road-hazard-detection/blob/main/best.pt): `best.pt`
- [Pause Control](https://github.com/anmolrawat990/road-hazard-detection/blob/main/app.py): `app.py`
- [Audio Alerts](https://github.com/anmolrawat990/road-hazard-detection/blob/main/app.py): `app.py`

### Live Results

- [Current Frame State](https://github.com/anmolrawat990/road-hazard-detection/blob/main/app.py): `app.py`
- [MJPEG Stream](https://github.com/anmolrawat990/road-hazard-detection/blob/main/app.py): `app.py`
- [Detection Status API](https://github.com/anmolrawat990/road-hazard-detection/blob/main/app.py): `app.py`

### Other components

- **Driver**
- **Windows System Sound**

## Connections

- Driver → Login and Signup: signs in (evidence: `README.md`)
- Login and Signup → MySQL Accounts: queries accounts (evidence: `index.php`)
- Login and Signup → Detection Dashboard: redirects after login (evidence: `index.php`)
- Detection Dashboard → Session Logout: opens logout (evidence: `dashboard.php`)
- Session Logout → Login and Signup: redirects to (evidence: `logout.php`)
- Driver → Detection Dashboard: uploads video (evidence: `README.md`)
- Detection Dashboard → Video Upload API: posts video (evidence: `dashboard.php`)
- Video Upload API → Uploaded Video: saves upload (evidence: `app.py`)
- Video Upload API → Frame Processor: starts thread (evidence: `app.py`)
- Frame Processor → OpenCV Capture: opens video (evidence: `app.py`)
- Frame Processor → YOLO Inference: runs inference (evidence: `app.py`)
- YOLO Inference → Custom YOLO Weights: loads model (evidence: `app.py`)
- Frame Processor → Current Frame State: writes annotated frame (evidence: `app.py`)
- Frame Processor → Pause Control: waits on event (evidence: `app.py`)
- Frame Processor → Audio Alerts: triggers on confidence (evidence: `app.py`)
- Audio Alerts → Windows System Sound: plays beep (evidence: `app.py`)
- Detection Dashboard → MJPEG Stream: requests stream (evidence: `dashboard.php`)
- MJPEG Stream → Current Frame State: reads frames (evidence: `app.py`)
- Detection Dashboard → Detection Status API: polls detections (evidence: `dashboard.php`)
- Detection Status API → Current Frame State: reads detection state (evidence: `app.py`)
- Detection Dashboard → Pause Control: toggles processing (evidence: `dashboard.php`)
