# refathasanabir/traffic-monitor architecture

> Architecture diagram of the GitHub repository refathasanabir/traffic-monitor, 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/refathasanabir/traffic-monitor
- Repository: https://github.com/refathasanabir/traffic-monitor

## Overview

Traffic-Monitor is a Streamlit application for vehicle detection and congestion prediction. Users upload an image for detection and counts, or a video for tracked vehicle counts, annotated-video download, and a Random Forest traffic prediction. A separate training script builds the Random Forest from the traffic dataset. The runtime is concentrated in app.py; the graph separates its main stages for clarity. Relationships are based on the shown app.py and train.py excerpts; other runtime wiring was not inspected.

Main entry points: [`app.py`](https://github.com/refathasanabir/traffic-monitor/blob/main/app.py) (Streamlit interface), [`train.py`](https://github.com/refathasanabir/traffic-monitor/blob/main/train.py) (Classifier training), [`model/traffic_rf_model.pkl`](https://github.com/refathasanabir/traffic-monitor/blob/main/model/traffic_rf_model.pkl) (Random Forest model), [`model/best.pt`](https://github.com/refathasanabir/traffic-monitor/blob/main/model/best.pt) (YOLO weights)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["User interface"]
  node_streamlit_ui["Streamlit interface<br/>[app.py]"]
  node_video_download["Video download<br/>[app.py]"]
end

subgraph group_vision["Vehicle vision"]
  node_image_detection["Image detection<br/>[app.py]"]
  node_video_processing["Video processing<br/>[app.py]"]
  node_vehicle_tracking["Vehicle tracking<br/>[app.py]"]
  node_annotation["Frame annotation<br/>[app.py]"]
  node_yolo_weights["YOLO weights<br/>[best.pt]"]
end

subgraph group_analysis["Traffic analysis"]
  node_vehicle_counting["Vehicle counting<br/>[app.py]"]
  node_traffic_prediction["Traffic prediction<br/>[app.py]"]
  node_traffic_visualization["Traffic chart<br/>[app.py]"]
  node_rf_model["Random Forest model"]
end

subgraph group_training["Model training"]
  node_training["Classifier training<br/>[train.py]"]
  node_traffic_dataset[("Traffic dataset<br/>[traffic_data.csv]")]
end

node_user(("Uploader"))

node_user -->|"uploads media"| node_streamlit_ui
node_streamlit_ui -->|"runs image"| node_image_detection
node_streamlit_ui -->|"processes video"| node_video_processing
node_streamlit_ui -->|"loads weights"| node_yolo_weights
node_streamlit_ui -->|"loads classifier"| node_rf_model
node_image_detection -->|"counts detections"| node_vehicle_counting
node_image_detection -->|"annotates detections"| node_annotation
node_video_processing -->|"tracks frames"| node_vehicle_tracking
node_video_processing -->|"annotates frames"| node_annotation
node_video_processing -->|"counts frames"| node_vehicle_counting
node_video_processing -->|"returns counts"| node_streamlit_ui
node_streamlit_ui -->|"predicts traffic"| node_traffic_prediction
node_streamlit_ui -->|"plots frame counts"| node_traffic_visualization
node_streamlit_ui -->|"offers output"| node_video_download
node_training -->|"reads data"| node_traffic_dataset
node_training -->|"saves classifier"| node_rf_model

click node_streamlit_ui "https://github.com/refathasanabir/traffic-monitor/blob/main/app.py"
click node_image_detection "https://github.com/refathasanabir/traffic-monitor/blob/main/app.py"
click node_video_processing "https://github.com/refathasanabir/traffic-monitor/blob/main/app.py"
click node_vehicle_tracking "https://github.com/refathasanabir/traffic-monitor/blob/main/app.py"
click node_annotation "https://github.com/refathasanabir/traffic-monitor/blob/main/app.py"
click node_vehicle_counting "https://github.com/refathasanabir/traffic-monitor/blob/main/app.py"
click node_traffic_prediction "https://github.com/refathasanabir/traffic-monitor/blob/main/app.py"
click node_traffic_visualization "https://github.com/refathasanabir/traffic-monitor/blob/main/app.py"
click node_video_download "https://github.com/refathasanabir/traffic-monitor/blob/main/app.py"
click node_yolo_weights "https://github.com/refathasanabir/traffic-monitor/blob/main/model/best.pt"
click node_rf_model "https://github.com/refathasanabir/traffic-monitor/blob/main/model/traffic_rf_model.pkl"
click node_training "https://github.com/refathasanabir/traffic-monitor/blob/main/train.py"
click node_traffic_dataset "https://github.com/refathasanabir/traffic-monitor/blob/main/dataset/traffic_data.csv"

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_streamlit_ui,node_video_download toneBlue
class node_image_detection,node_video_processing,node_vehicle_tracking,node_annotation,node_yolo_weights toneAmber
class node_vehicle_counting,node_traffic_prediction,node_traffic_visualization,node_rf_model toneMint
class node_training,node_traffic_dataset toneRose
class node_user toneIndigo
```

## Components

### User interface

- [Streamlit interface](https://github.com/refathasanabir/traffic-monitor/blob/main/app.py): `app.py`
- [Video download](https://github.com/refathasanabir/traffic-monitor/blob/main/app.py): `app.py`

### Vehicle vision

- [Image detection](https://github.com/refathasanabir/traffic-monitor/blob/main/app.py): `app.py`
- [Video processing](https://github.com/refathasanabir/traffic-monitor/blob/main/app.py): `app.py`
- [Vehicle tracking](https://github.com/refathasanabir/traffic-monitor/blob/main/app.py): `app.py`
- [Frame annotation](https://github.com/refathasanabir/traffic-monitor/blob/main/app.py): `app.py`
- [YOLO weights](https://github.com/refathasanabir/traffic-monitor/blob/main/model/best.pt): `model/best.pt`

### Traffic analysis

- [Vehicle counting](https://github.com/refathasanabir/traffic-monitor/blob/main/app.py): `app.py`
- [Traffic prediction](https://github.com/refathasanabir/traffic-monitor/blob/main/app.py): `app.py`
- [Traffic chart](https://github.com/refathasanabir/traffic-monitor/blob/main/app.py): `app.py`
- [Random Forest model](https://github.com/refathasanabir/traffic-monitor/blob/main/model/traffic_rf_model.pkl): `model/traffic_rf_model.pkl`

### Model training

- [Classifier training](https://github.com/refathasanabir/traffic-monitor/blob/main/train.py): `train.py`
- [Traffic dataset](https://github.com/refathasanabir/traffic-monitor/blob/main/dataset/traffic_data.csv): `dataset/traffic_data.csv`

### Other components

- **Uploader**

## Connections

- Uploader → Streamlit interface: uploads media (evidence: `app.py`)
- Streamlit interface → Image detection: runs image (evidence: `app.py`)
- Streamlit interface → Video processing: processes video (evidence: `app.py`)
- Streamlit interface → YOLO weights: loads weights (evidence: `app.py`)
- Streamlit interface → Random Forest model: loads classifier (evidence: `app.py`)
- Image detection → Vehicle counting: counts detections (evidence: `app.py`)
- Image detection → Frame annotation: annotates detections (evidence: `app.py`)
- Video processing → Vehicle tracking: tracks frames (evidence: `app.py`)
- Video processing → Frame annotation: annotates frames (evidence: `app.py`)
- Video processing → Vehicle counting: counts frames (evidence: `app.py`)
- Video processing → Streamlit interface: returns counts (evidence: `app.py`)
- Streamlit interface → Traffic prediction: predicts traffic (evidence: `app.py`)
- Streamlit interface → Traffic chart: plots frame counts (evidence: `app.py`)
- Streamlit interface → Video download: offers output (evidence: `app.py`)
- Classifier training → Traffic dataset: reads data (evidence: `train.py`)
- Classifier training → Random Forest model: saves classifier (evidence: `train.py`)
