# sreeharshit/smart-traffic-management-ai architecture

> Architecture diagram of the GitHub repository sreeharshit/smart-traffic-management-ai, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sreeharshit/smart-traffic-management-ai
- Repository: https://github.com/sreeharshit/smart-traffic-management-ai

## Overview

Smart Traffic Management AI processes video frames into tracked vehicle detections, traffic decisions and signal state, then presents an annotated live view and analytics through Flask. The main web workflow and detection/rendering calls are visible in app.py; main.py also provides a separate OpenCV desktop runner. Emergency priority and violation detection are handled in the web frame workflow. Some app.py frame-processing calls are in omitted excerpts, so those links are marked unverified rather than asserted as inspected.

Main entry points: [`app.py`](https://github.com/sreeharshit/smart-traffic-management-ai/blob/main/app.py) (Flask service), [`main.py`](https://github.com/sreeharshit/smart-traffic-management-ai/blob/main/main.py) (Desktop runner), [`detector.py`](https://github.com/sreeharshit/smart-traffic-management-ai/blob/main/detector.py) (Vehicle detection), [`traffic_light.py`](https://github.com/sreeharshit/smart-traffic-management-ai/blob/main/traffic_light.py) (Signal control)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Traffic Runtime"]
  node_video[("Demo videos")]
  node_detector["Vehicle detection<br/>[detector.py]"]
  node_model["YOLO model<br/>[yolov8n.pt]"]
  node_config["Runtime settings<br/>[config.py]"]
  node_desktop["Desktop runner<br/>[main.py]"]
end

subgraph group_web["Web Experience"]
  node_webapp["Flask service<br/>[app.py]"]
  node_dashboard["Frame dashboard<br/>[dashboard.py]"]
  node_analytics["Analytics endpoint<br/>[app.py]"]
  node_page["Traffic page<br/>[index.html]"]
  node_liveclient["Live controls<br/>[script.js]"]
  node_analyticsclient["Analytics charts<br/>[analytics.js]"]
end

subgraph group_policy["Traffic Policy"]
  node_analysis["Traffic analysis"]
  node_signal["Signal control<br/>[traffic_light.py]"]
  node_emergency["Emergency priority<br/>[app.py]"]
  node_violations["Violation detection<br/>[app.py]"]
end

node_operator(("Traffic operator"))
node_browser(("Browser"))

node_operator -->|"views"| node_browser
node_browser -->|"requests pages"| node_webapp
node_webapp -->|"renders"| node_page
node_webapp -->|"reads demo"| node_video
node_webapp -->|"detects vehicles"| node_detector
node_detector -->|"loads model"| node_model
node_detector -->|"reads settings"| node_config
node_analysis -->|"reads thresholds"| node_config
node_signal -->|"reads timing"| node_config
node_dashboard -->|"reads display settings"| node_config
node_webapp -.->|"analyzes detections"| node_analysis
node_webapp -.->|"updates signal"| node_signal
node_webapp -->|"checks emergency vehicles"| node_emergency
node_emergency -.->|"prioritizes direction"| node_signal
node_webapp -->|"checks crossings"| node_violations
node_webapp -->|"draws frame"| node_dashboard
node_webapp -->|"serves statistics"| node_analytics
node_browser -->|"uses controls"| node_liveclient
node_liveclient -->|"switches demo"| node_webapp
node_browser -->|"views charts"| node_analyticsclient
node_analyticsclient -->|"fetches stats"| node_analytics
node_desktop -->|"detects vehicles"| node_detector
node_desktop -->|"analyzes detections"| node_analysis
node_desktop -->|"updates signal"| node_signal
node_desktop -->|"draws frame"| node_dashboard

click node_webapp "https://github.com/sreeharshit/smart-traffic-management-ai/blob/main/app.py"
click node_video "https://github.com/sreeharshit/smart-traffic-management-ai/tree/main/videos"
click node_detector "https://github.com/sreeharshit/smart-traffic-management-ai/blob/main/detector.py"
click node_model "https://github.com/sreeharshit/smart-traffic-management-ai/blob/main/yolov8n.pt"
click node_analysis "https://github.com/sreeharshit/smart-traffic-management-ai/blob/main/traffic_controller.py"
click node_signal "https://github.com/sreeharshit/smart-traffic-management-ai/blob/main/traffic_light.py"
click node_emergency "https://github.com/sreeharshit/smart-traffic-management-ai/blob/main/app.py"
click node_violations "https://github.com/sreeharshit/smart-traffic-management-ai/blob/main/app.py"
click node_config "https://github.com/sreeharshit/smart-traffic-management-ai/blob/main/config.py"
click node_dashboard "https://github.com/sreeharshit/smart-traffic-management-ai/blob/main/dashboard.py"
click node_analytics "https://github.com/sreeharshit/smart-traffic-management-ai/blob/main/app.py"
click node_page "https://github.com/sreeharshit/smart-traffic-management-ai/blob/main/templates/index.html"
click node_liveclient "https://github.com/sreeharshit/smart-traffic-management-ai/blob/main/static/script.js"
click node_analyticsclient "https://github.com/sreeharshit/smart-traffic-management-ai/blob/main/static/analytics.js"
click node_desktop "https://github.com/sreeharshit/smart-traffic-management-ai/blob/main/main.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_video,node_detector,node_model,node_config,node_desktop,node_browser toneBlue
class node_webapp,node_dashboard,node_analytics,node_page,node_liveclient,node_analyticsclient toneAmber
class node_analysis,node_signal,node_emergency,node_violations toneMint
class node_operator toneIndigo
```

## Components

### Traffic Runtime

- [Demo videos](https://github.com/sreeharshit/smart-traffic-management-ai/tree/main/videos): `videos`
- [Vehicle detection](https://github.com/sreeharshit/smart-traffic-management-ai/blob/main/detector.py): `detector.py`
- [YOLO model](https://github.com/sreeharshit/smart-traffic-management-ai/blob/main/yolov8n.pt): `yolov8n.pt`
- [Runtime settings](https://github.com/sreeharshit/smart-traffic-management-ai/blob/main/config.py): `config.py`
- [Desktop runner](https://github.com/sreeharshit/smart-traffic-management-ai/blob/main/main.py): `main.py`

### Web Experience

- [Flask service](https://github.com/sreeharshit/smart-traffic-management-ai/blob/main/app.py): `app.py`
- [Frame dashboard](https://github.com/sreeharshit/smart-traffic-management-ai/blob/main/dashboard.py): `dashboard.py`
- [Analytics endpoint](https://github.com/sreeharshit/smart-traffic-management-ai/blob/main/app.py): `app.py`
- [Traffic page](https://github.com/sreeharshit/smart-traffic-management-ai/blob/main/templates/index.html): `templates/index.html`
- [Live controls](https://github.com/sreeharshit/smart-traffic-management-ai/blob/main/static/script.js): `static/script.js`
- [Analytics charts](https://github.com/sreeharshit/smart-traffic-management-ai/blob/main/static/analytics.js): `static/analytics.js`

### Traffic Policy

- [Traffic analysis](https://github.com/sreeharshit/smart-traffic-management-ai/blob/main/traffic_controller.py): `traffic_controller.py`
- [Signal control](https://github.com/sreeharshit/smart-traffic-management-ai/blob/main/traffic_light.py): `traffic_light.py`
- [Emergency priority](https://github.com/sreeharshit/smart-traffic-management-ai/blob/main/app.py): `app.py`
- [Violation detection](https://github.com/sreeharshit/smart-traffic-management-ai/blob/main/app.py): `app.py`

### Other components

- **Traffic operator**
- **Browser**

## Connections

- Traffic operator → Browser: views (evidence: `README.md`)
- Browser → Flask service: requests pages (evidence: `README.md`)
- Flask service → Traffic page: renders (evidence: `app.py`)
- Flask service → Demo videos: reads demo
- Flask service → Vehicle detection: detects vehicles (evidence: `app.py`)
- Vehicle detection → YOLO model: loads model (evidence: `detector.py`)
- Vehicle detection → Runtime settings: reads settings (evidence: `detector.py`)
- Traffic analysis → Runtime settings: reads thresholds (evidence: `traffic_controller.py`)
- Signal control → Runtime settings: reads timing (evidence: `traffic_light.py`)
- Frame dashboard → Runtime settings: reads display settings (evidence: `dashboard.py`)
- Flask service → Traffic analysis: analyzes detections (evidence: `app.py`)
- Flask service → Signal control: updates signal (evidence: `app.py`)
- Flask service → Emergency priority: checks emergency vehicles (evidence: `app.py`)
- Emergency priority → Signal control: prioritizes direction (evidence: `app.py`)
- Flask service → Violation detection: checks crossings (evidence: `app.py`)
- Flask service → Frame dashboard: draws frame (evidence: `app.py`)
- Flask service → Analytics endpoint: serves statistics (evidence: `app.py`)
- Browser → Live controls: uses controls (evidence: `static/script.js`)
- Live controls → Flask service: switches demo (evidence: `static/script.js`)
- Browser → Analytics charts: views charts (evidence: `static/analytics.js`)
- Analytics charts → Analytics endpoint: fetches stats (evidence: `static/analytics.js`)
- Desktop runner → Vehicle detection: detects vehicles (evidence: `main.py`)
- Desktop runner → Traffic analysis: analyzes detections (evidence: `main.py`)
- Desktop runner → Signal control: updates signal (evidence: `main.py`)
- Desktop runner → Frame dashboard: draws frame (evidence: `main.py`)
