# balaragavesh/dynamic-traffic-control architecture

> Architecture diagram of the GitHub repository balaragavesh/dynamic-traffic-control, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/balaragavesh/dynamic-traffic-control
- Repository: https://github.com/balaragavesh/dynamic-traffic-control

## Overview

##### Project Type and Purpose
- This is a computer vision–based, full-stack traffic control application.
- It integrates deep learning detection (via YOLOv5 models), real-time analytics, and a custom dynamic signal adjustment algorithm to prioritize ambulances.

##### Main Architectural Components and Their Subdivisions
a. Data and Configuration Layer:
- The data folder holds dataset YAML files (e.g., ImageNet, VOC, coco variants), augmentation/hyperparameter (hyps) configurations, and useful scripts for downloading or manipulating datasets.
- This layer is responsible for input configuration to both train and inference pipelines.

b. Models and Detection Module:
- The models directory contains various YOLOv5 (and segmentation) model configurations and implementations.
- Files like detect.py, train.py, export.py, and specific model YAML files (yolov5s.yaml to yolov5x.yaml) define the core deep learning components.
- This module handles object detection (vehicles, ambulances) and segmentation, feeding into the decision module.

c. Inference and Post-Processing Pipelines:
- The classify and segment folders house scripts and notebooks that relate to running predictions, validations, and tutorials.
- These components are crucial when testing or tuning model behavior (e.g., prediction accuracy in a live traffic scenario).

d. Traffic Control Decision Engine:
- The custom dynamic signal control algorithm is implemented in files such as dynamic_signal_switching.py.
- This component takes in the outputs (detection results) of the YOLO module and applies logic to adjust the traffic light durations prioritizing ambulances.

e. Utility and Integration Modules:
- The utils directory contains support modules for logging (with integrations to ClearML, comet, wandb), augmentations, data loading, and common operations across the project.
- Additionally, the presence of a flask_rest_api under utils implies that a web service interface might be used to expose APIs for sending commands or accessing model outputs.
- Dockerfiles and other deployment configuration files (under utils/docker and utils/google_app_engine) indicate containerized deployment options.

## Diagram (Mermaid)

```mermaid
flowchart TD
    E["External Live Feed"]
    DC["Datasets & Config (data/)"]:::config
    YDL["YOLO Detection (models/)"]:::ai
    CL["Classification (classify/)"]:::ai
    SG["Segmentation (segment/)"]:::ai
    DS["Dynamic Signal Control (dynamic_signal_switching.py)"]:::decision
    TA["Traffic Signal Actuation (Physical/Simulated)"]:::actuation

    subgraph "Integration & Utilities"
        API["Flask REST API (utils/flask_rest_api)"]:::integration
        DEP_DOCKER["Docker Deployment (utils/docker)"]:::integration
        DEP_GAE["Google App Engine (utils/google_app_engine)"]:::integration
        IL["Logging Modules (utils/loggers)"]:::integration
    end

    %% Main Data Flow
    E -->|"ingests"| DC
    DC -->|"provides config"| YDL
    YDL -->|"detection output"| DS
    YDL -->|"classification"| CL
    YDL -->|"segmentation"| SG
    CL -->|"inference output"| DS
    SG -->|"inference output"| DS
    DS -->|"control signals"| TA

    %% Integration connections (dashed arrows)
    YDL ---|"monitoring"| API
    DS ---|"reporting"| API
    API ---|"logs to"| IL
    API -->|"deployment trigger"| DEP_DOCKER
    API -->|"deployment trigger"| DEP_GAE

    %% Click Events
    click DC "https://github.com/balaragavesh/dynamic-traffic-control/tree/main/data/"
    click YDL "https://github.com/balaragavesh/dynamic-traffic-control/tree/main/models/"
    click CL "https://github.com/balaragavesh/dynamic-traffic-control/tree/main/classify/"
    click SG "https://github.com/balaragavesh/dynamic-traffic-control/tree/main/segment/"
    click DS "https://github.com/balaragavesh/dynamic-traffic-control/blob/main/dynamic_signal_switching.py"
    click API "https://github.com/balaragavesh/dynamic-traffic-control/tree/main/utils/flask_rest_api"
    click DEP_DOCKER "https://github.com/balaragavesh/dynamic-traffic-control/tree/main/utils/docker"
    click DEP_GAE "https://github.com/balaragavesh/dynamic-traffic-control/tree/main/utils/google_app_engine"
    click IL "https://github.com/balaragavesh/dynamic-traffic-control/tree/main/utils/loggers"

    %% Styles
    classDef config fill:#FFFFCC,stroke:#333,stroke-width:2px;
    classDef ai fill:#E6FFE6,stroke:#333,stroke-width:2px;
    classDef decision fill:#FFE6E6,stroke:#333,stroke-width:2px;
    classDef actuation fill:#FFEDCC,stroke:#333,stroke-width:2px;
    classDef integration fill:#E6F7FF,stroke:#333,stroke-width:2px;
```
