# subhajitbadhuk/smarttrafficmanagement architecture

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

- Interactive diagram: https://gitdiagram.com/subhajitbadhuk/smarttrafficmanagement
- Repository: https://github.com/subhajitbadhuk/smarttrafficmanagement

## Overview

Smart Traffic Management accepts four lane images, lets users mark lane regions, and processes the images through a Flask/YOLO backend. The backend filters detections to each region, counts vehicles, creates annotated images, and selects the lane with the highest total for green; the live page displays the results and cycles lane signals using weighted counts. The README also describes vehicle detection, lane-wise counting, ROI selection, and future ambulance priority. Unsampled page and styling files are represented only where their role is documented; the graph focuses on relationships visible in the excerpts.

Main entry points: [`backend/main.py`](https://github.com/subhajitbadhuk/smarttrafficmanagement/blob/main/backend/main.py) (Flask routes), [`frontend/live.js`](https://github.com/subhajitbadhuk/smarttrafficmanagement/blob/main/frontend/live.js) (Live dashboard), [`frontend/script.js`](https://github.com/subhajitbadhuk/smarttrafficmanagement/blob/main/frontend/script.js) (Image and ROI UI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Traffic interface"]
  node_upload_ui["Image and ROI UI<br/>[script.js]"]
  node_live_ui["Live dashboard<br/>[live.js]"]
end

subgraph group_backend["Image processing"]
  node_flask["Flask routes<br/>[main.py]"]
  node_uploads[("Uploaded lane images<br/>[main.py]")]
  node_vehicle_detection["Vehicle detection<br/>[main.py]"]
  node_roi_counting["ROI filtering and counts<br/>[main.py]"]
  node_annotated_images[("Annotated lane images<br/>[main.py]")]
  node_lane_results["Lane results<br/>[main.py]"]
end

subgraph group_signals["Signal management"]
  node_signal_selection["Green lane selection<br/>[main.py]"]
  node_signal_cycle["Weighted signal cycle<br/>[live.js]"]
  node_ambulance_priority["Ambulance priority"]
end

node_operator(("Traffic operator"))

node_operator -->|"selects lanes"| node_upload_ui
node_upload_ui -->|"uploads images"| node_flask
node_flask -->|"saves images"| node_uploads
node_upload_ui -->|"submits ROIs"| node_flask
node_flask -->|"reads images"| node_uploads
node_flask -->|"runs detection"| node_vehicle_detection
node_flask -->|"filters detections"| node_roi_counting
node_roi_counting -->|"counts vehicles"| node_vehicle_detection
node_flask -->|"writes images"| node_annotated_images
node_flask -->|"returns results"| node_lane_results
node_flask -->|"selects green lane"| node_signal_selection
node_live_ui -->|"loads stored results"| node_lane_results
node_live_ui -->|"loads images"| node_annotated_images
node_live_ui -->|"starts cycle"| node_signal_cycle
node_signal_cycle -->|"shows lane status"| node_operator
node_ambulance_priority -.->|"may prioritize"| node_signal_cycle

click node_upload_ui "https://github.com/subhajitbadhuk/smarttrafficmanagement/blob/main/frontend/script.js"
click node_live_ui "https://github.com/subhajitbadhuk/smarttrafficmanagement/blob/main/frontend/live.js"
click node_flask "https://github.com/subhajitbadhuk/smarttrafficmanagement/blob/main/backend/main.py"
click node_uploads "https://github.com/subhajitbadhuk/smarttrafficmanagement/blob/main/backend/main.py"
click node_vehicle_detection "https://github.com/subhajitbadhuk/smarttrafficmanagement/blob/main/backend/main.py"
click node_roi_counting "https://github.com/subhajitbadhuk/smarttrafficmanagement/blob/main/backend/main.py"
click node_annotated_images "https://github.com/subhajitbadhuk/smarttrafficmanagement/blob/main/backend/main.py"
click node_lane_results "https://github.com/subhajitbadhuk/smarttrafficmanagement/blob/main/backend/main.py"
click node_signal_selection "https://github.com/subhajitbadhuk/smarttrafficmanagement/blob/main/backend/main.py"
click node_signal_cycle "https://github.com/subhajitbadhuk/smarttrafficmanagement/blob/main/frontend/live.js"

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_upload_ui,node_live_ui toneBlue
class node_flask,node_uploads,node_vehicle_detection,node_roi_counting,node_annotated_images,node_lane_results toneAmber
class node_signal_selection,node_signal_cycle,node_ambulance_priority toneMint
class node_operator toneIndigo
```

## Components

### Traffic interface

- [Image and ROI UI](https://github.com/subhajitbadhuk/smarttrafficmanagement/blob/main/frontend/script.js): `frontend/script.js`
- [Live dashboard](https://github.com/subhajitbadhuk/smarttrafficmanagement/blob/main/frontend/live.js): `frontend/live.js`

### Image processing

- [Flask routes](https://github.com/subhajitbadhuk/smarttrafficmanagement/blob/main/backend/main.py): `backend/main.py`
- [Uploaded lane images](https://github.com/subhajitbadhuk/smarttrafficmanagement/blob/main/backend/main.py): `backend/main.py`
- [Vehicle detection](https://github.com/subhajitbadhuk/smarttrafficmanagement/blob/main/backend/main.py): `backend/main.py`
- [ROI filtering and counts](https://github.com/subhajitbadhuk/smarttrafficmanagement/blob/main/backend/main.py): `backend/main.py`
- [Annotated lane images](https://github.com/subhajitbadhuk/smarttrafficmanagement/blob/main/backend/main.py): `backend/main.py`
- [Lane results](https://github.com/subhajitbadhuk/smarttrafficmanagement/blob/main/backend/main.py): `backend/main.py`

### Signal management

- [Green lane selection](https://github.com/subhajitbadhuk/smarttrafficmanagement/blob/main/backend/main.py): `backend/main.py`
- [Weighted signal cycle](https://github.com/subhajitbadhuk/smarttrafficmanagement/blob/main/frontend/live.js): `frontend/live.js`
- **Ambulance priority**

### Other components

- **Traffic operator**

## Connections

- Traffic operator → Image and ROI UI: selects lanes (evidence: `README.md`)
- Image and ROI UI → Flask routes: uploads images (evidence: `frontend/script.js`)
- Flask routes → Uploaded lane images: saves images (evidence: `backend/main.py`)
- Image and ROI UI → Flask routes: submits ROIs (evidence: `frontend/script.js`)
- Flask routes → Uploaded lane images: reads images (evidence: `backend/main.py`)
- Flask routes → Vehicle detection: runs detection (evidence: `backend/main.py`)
- Flask routes → ROI filtering and counts: filters detections (evidence: `backend/main.py`)
- ROI filtering and counts → Vehicle detection: counts vehicles (evidence: `backend/main.py`)
- Flask routes → Annotated lane images: writes images (evidence: `backend/main.py`)
- Flask routes → Lane results: returns results (evidence: `backend/main.py`)
- Flask routes → Green lane selection: selects green lane (evidence: `backend/main.py`)
- Live dashboard → Lane results: loads stored results (evidence: `frontend/live.js`)
- Live dashboard → Annotated lane images: loads images (evidence: `frontend/live.js`)
- Live dashboard → Weighted signal cycle: starts cycle (evidence: `frontend/live.js`)
- Weighted signal cycle → Traffic operator: shows lane status (evidence: `frontend/live.js`)
- Ambulance priority → Weighted signal cycle: may prioritize (evidence: `README.md`)
