# hoanglayor/fireeye-smart-system architecture

> Architecture diagram of the GitHub repository hoanglayor/fireeye-smart-system, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hoanglayor/fireeye-smart-system
- Repository: https://github.com/hoanglayor/fireeye-smart-system

## Overview

##### Project Type and Purpose
- This is an ML-powered fire and smoke detection system combining a training pipeline, a model repository, and a real-time inference/alerting pipeline.
- Purpose: train YOLOv8/v10 models on a curated fire-smoke dataset, then run inference on camera feeds to trigger alarms and send notifications.

##### Main Architectural Components
a. Data Ingestion & Preparation
- Data folder & data.yaml: holds raw images and annotations.
- prepare_data.py / DownloadFireDataset.py / GetDatasetStatistics.py: scripts to fetch, preprocess and analyze the dataset.

b. Model Training Pipeline
- train.py & train_v8s.ipynb: launch YOLO training (v8s for speed, v10m for accuracy).
- W&B integration: logs metrics and training events.
- model/yolov10m: stores trained weights (best.pt, last.pt) and args.yaml.

c. Model Registry / Storage
- model/ directory: versioned subfolders (e.g., yolov10m) for organizing checkpoints and metadata.

d. Inference & Alerting Pipeline
- inference.py: loads a selected model, processes frames (images or live video), runs detection.
- telegram_message.py: sends alert messages via Telegram API when fire/smoke is detected.
- alarm_sound.wav: local audio alert played on detection.

e. External Services
- Telegram API: push notifications to users/devices.
- (Optional) Roboflow: original dataset hosting.
- W&B (Weights & Biases): experiment tracking.

##### Component Interactions & Data Flow
1) Data Preparation
[Raw Images + Annotations] → prepare_data.py → [Formatted Dataset + data.yaml]
2) Training
[Formatted Dataset] → train.py → [Trained YOLO Model + Logs to W&B] → model/
3) Inference
[Camera Feed / Test Images] → inference.py (loads model/) → [Detections]
4) Alerting
If detection →
- Play alarm_sound.wav → local speaker
- Invoke telegram_message.py → HTTP request → Telegram API → user device

##### Architectural Patterns & Principles
- Modular separation: data layer, training layer, inference/alert layer.
- Single responsibility: one script per task (prepare, train, infer, notify).
- Externalized configuration: data.yaml, args.yaml, .env for secrets (e.g., Telegram token).
- Versioning of artifacts: model weights in dedicated folders, results in versioned subfolders.

- Left: Data Preparation (data folder, prepare scripts)
- Center: Model Training (train.py, W&B, model repository)
- Right: Inference & Alerting (inference.py, alarm_sound, telegram_message)
c. Overlay “External Services” above or aside, linking W&B to training, Telegram to alerting, Roboflow to data.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Data Preparation
    subgraph "Data Preparation"
        direction TB
        RawData(("data/")):::data
        DataConfig["data.yaml"]:::data
        PrepScript["prepare_data.py"]:::data
        DownloadScript["DownloadFireDataset.py"]:::data
        StatsScript["GetDatasetStatistics.py"]:::data
    end

    %% Training Pipeline
    subgraph "Model Training Pipeline"
        direction TB
        TrainScript["train.py"]:::train
        Notebook["train_v8s.ipynb"]:::train
        EnvConfig[".env"]:::train
        ModelRegistry(("model/yolov10m/")):::storage
        ArgsFile["args.yaml"]:::storage
        EventsFile["events.out.tfevents.*"]:::storage
        ResultsFile["results.csv"]:::storage
        BestWeights["best.pt"]:::storage
        LastWeights["last.pt"]:::storage
    end

    %% Inference & Alerting
    subgraph "Inference & Alerting"
        direction TB
        InferenceScript["inference.py"]:::infer
        AlarmSound["alarm_sound.wav"]:::alert
        TelegramModule["telegram_message.py"]:::alert
        ResultV1(("results/v1.0/")):::storage
        ResultV2(("results/v2.0/")):::storage
    end

    %% External Services
    subgraph "External Services"
        direction TB
        Roboflow((Cloud Roboflow)):::external
        WandB((Cloud W&B)):::external
        TelegramAPI((Cloud Telegram API)):::external
    end

    %% Connections
    RawData -->|provides raw images| PrepScript
    PrepScript -->|outputs formatted dataset| ModelRegistry
    DownloadScript --> PrepScript
    StatsScript --> PrepScript
    DataConfig --> PrepScript

    ModelRegistry -->|loads dataset| TrainScript
    Notebook --> TrainScript
    EnvConfig --> TrainScript
    TrainScript -->|stores model artifacts| ModelRegistry
    TrainScript -->|logs metrics| WandB

    ModelRegistry --> InferenceScript
    InferenceScript -->|on detection| AlarmSound
    InferenceScript -->|on detection| TelegramModule
    TelegramModule -->|sends HTTP request| TelegramAPI
    InferenceScript --> ResultV1
    InferenceScript --> ResultV2

    Roboflow --> PrepScript
    WandB --> TrainScript
    TelegramAPI --> TelegramModule

    %% Click Events
    click RawData "https://github.com/hoanglayor/fireeye-smart-system/tree/main/data/"
    click DataConfig "https://github.com/hoanglayor/fireeye-smart-system/blob/main/data.yaml"
    click PrepScript "https://github.com/hoanglayor/fireeye-smart-system/blob/main/prepare_data.py"
    click DownloadScript "https://github.com/hoanglayor/fireeye-smart-system/blob/main/NEWFireSmokeDataset_YoloModels/DownloadFireDataset.py"
    click StatsScript "https://github.com/hoanglayor/fireeye-smart-system/blob/main/NEWFireSmokeDataset_YoloModels/GetDatasetStatistics.py"
    click TrainScript "https://github.com/hoanglayor/fireeye-smart-system/blob/main/train.py"
    click Notebook "https://github.com/hoanglayor/fireeye-smart-system/blob/main/train_v8s.ipynb"
    click EnvConfig "https://github.com/hoanglayor/fireeye-smart-system/blob/main/.env"
    click ModelRegistry "https://github.com/hoanglayor/fireeye-smart-system/tree/main/model/yolov10m/"
    click ArgsFile "https://github.com/hoanglayor/fireeye-smart-system/blob/main/model/yolov10m/args.yaml"
    click EventsFile "https://github.com/hoanglayor/fireeye-smart-system/blob/main/model/yolov10m/events.out.tfevents.*"
    click ResultsFile "https://github.com/hoanglayor/fireeye-smart-system/blob/main/model/yolov10m/results.csv"
    click BestWeights "https://github.com/hoanglayor/fireeye-smart-system/blob/main/model/yolov10m/weights/best.pt"
    click LastWeights "https://github.com/hoanglayor/fireeye-smart-system/blob/main/model/yolov10m/weights/last.pt"
    click InferenceScript "https://github.com/hoanglayor/fireeye-smart-system/blob/main/inference.py"
    click AlarmSound "https://github.com/hoanglayor/fireeye-smart-system/blob/main/alarm_sound.wav"
    click TelegramModule "https://github.com/hoanglayor/fireeye-smart-system/blob/main/telegram_message.py"
    click ResultV1 "https://github.com/hoanglayor/fireeye-smart-system/tree/main/results/v1.0/"
    click ResultV2 "https://github.com/hoanglayor/fireeye-smart-system/tree/main/results/v2.0/"

    %% Styles
    classDef data fill:#D0E8FF,stroke:#0366d6,color:#0366d6;
    classDef train fill:#DFFFE0,stroke:#28a745,color:#28a745;
    classDef storage fill:#FFF5BA,stroke:#c17c00,color:#c17c00;
    classDef infer fill:#FFE8C0,stroke:#e69500,color:#e69500;
    classDef alert fill:#FFCCCC,stroke:#d73a49,color:#d73a49;
    classDef external fill:#EAEAEA,stroke:#6a737d,color:#6a737d;
```
