# reatmos/savebelt architecture

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

- Interactive diagram: https://gitdiagram.com/reatmos/savebelt
- Repository: https://github.com/reatmos/savebelt

## Overview

##### Main Components

a) Input Layer:
- Multiple Camera Sources (indicated by camera01.py, camera02.py, camera03.py)
- Video/Image Input Processing System

b) Processing Layer:
- Master Node (main.py)
- Slave Nodes (detection workers)
- YOLOv5 Detection System (models directory)
- Grid-based Analysis System

c) Data Management:
- Dataset Management (data directory)
- Weights Management (weights directory)
- Configuration Management (various .yaml files)

d) Output Layer:
- Web Interface (service.html)
- Visualization System (utils/plots.py)

**┌─────────────────────────────────────────────┐**
- Web Interface               │
- ┘
- ↑
**┌─────────────────────────────────────────────┐**
- Master Controller              │
- (main.py)                   │
- ┘
- ↑
- ┌───────────┴───────────┐
**┌───────────────┐      ┌───────────────┐**
- Slave Node 1 │      │  Slave Node 2 │ ...
- (Detection)   │      │ (Detection)   │
- ┘      └───────────────┘
- ↑                     ↑
**┌───────────────┐      ┌───────────────┐**
- Camera 1    │      │   Camera 2    │ ...
- ┘      └───────────────┘

##### Key Interactions to Highlight

a) Data Flow:
- Camera feeds → Slave Nodes
- Slave Nodes → Master Node
- Master Node → Web Interface

b) Control Flow:
- Master Node → Slave Node management
- Configuration management
- Model weight distribution

##### Technical Details

a) Technologies:
- PyTorch (ML Framework)
- YOLOv5 (Detection Model)
- Python 3.8.10 (Runtime)
- CUDA 12.1 (GPU Support)

b) Components:
- Grid-based analysis system
- Crowd density calculation
- Real-time processing pipeline

##### Additional Elements

a) Subsystems:
- Dataset management system
- Model training pipeline
- Logging and monitoring
- Weight management

b) Integration points:
- External APIs
- Storage systems
- Configuration management

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Input
        C1[Camera 1]:::camera
        C2[Camera 2]:::camera
        C3[Camera 3]:::camera
    end

    subgraph Processing
        subgraph Detection
            D1[Detection Worker 1]:::worker
            D2[Detection Worker 2]:::worker
            D3[Detection Worker 3]:::worker
        end

        subgraph Master
            MC[Master Controller]:::master
            GA[Grid Analysis]:::analysis
        end

        subgraph ML
            YM[YOLOv5 Model]:::ml
            TR[Training System]:::ml
        end
    end

    subgraph Data
        DM[Dataset Management]:::data
        WM[Weights Management]:::data
        CM[Configuration Management]:::data
    end

    subgraph Output
        WI[Web Interface]:::output
        VS[Visualization System]:::output
    end

    subgraph Utils
        UD[Datasets Utility]:::util
        UG[General Utility]:::util
        UM[Metrics Utility]:::util
        UT[Torch Utility]:::util
    end

    C1 --> D1
    C2 --> D2
    C3 --> D3

    D1 & D2 & D3 --> MC
    MC --> GA
    GA --> WI
    MC --> VS

    YM --> D1 & D2 & D3
    DM --> TR
    TR --> YM
    WM --> YM
    CM --> MC

    VS --> WI
    UD & UG & UM & UT --> MC

    %% Click Events
    click C1 "https://github.com/reatmos/Savebelt/blob/main/camera01.py"
    click C2 "https://github.com/reatmos/Savebelt/blob/main/camera02.py"
    click C3 "https://github.com/reatmos/Savebelt/blob/main/camera03.py"
    click MC "https://github.com/reatmos/Savebelt/blob/main/main.py"
    click D1 "https://github.com/reatmos/Savebelt/blob/main/detect.py"
    click D2 "https://github.com/reatmos/Savebelt/blob/main/detect02.py"
    click D3 "https://github.com/reatmos/Savebelt/blob/main/detect03.py"
    click YM "https://github.com/reatmos/Savebelt/blob/main/models/yolo.py"
    click DM "https://github.com/reatmos/Savebelt/tree/main/data/custom/"
    click WM "https://github.com/reatmos/Savebelt/blob/main/weights/download_weights.sh"
    click CM "https://github.com/reatmos/Savebelt/blob/main/data/hyp.finetune.yaml"
    click WI "https://github.com/reatmos/Savebelt/blob/main/service.html"
    click VS "https://github.com/reatmos/Savebelt/blob/main/utils/plots.py"
    click GA "https://github.com/reatmos/Savebelt/blob/main/calc.py"
    click TR "https://github.com/reatmos/Savebelt/blob/main/train.py"
    click UD "https://github.com/reatmos/Savebelt/blob/main/utils/datasets.py"
    click UG "https://github.com/reatmos/Savebelt/blob/main/utils/general.py"
    click UM "https://github.com/reatmos/Savebelt/blob/main/utils/metrics.py"
    click UT "https://github.com/reatmos/Savebelt/blob/main/utils/torch_utils.py"

    %% Styles
    classDef camera fill:#3498db,stroke:#2980b9,color:white
    classDef worker fill:#2ecc71,stroke:#27ae60,color:white
    classDef master fill:#e74c3c,stroke:#c0392b,color:white
    classDef analysis fill:#9b59b6,stroke:#8e44ad,color:white
    classDef ml fill:#f1c40f,stroke:#f39c12,color:black
    classDef data fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef output fill:#e67e22,stroke:#d35400,color:white
    classDef util fill:#1abc9c,stroke:#16a085,color:white
```
