# rkt973/multi-hazard-detection architecture

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

- Interactive diagram: https://gitdiagram.com/rkt973/multi-hazard-detection
- Repository: https://github.com/rkt973/multi-hazard-detection

## Overview

This repository is a multi-hazard monitoring application: vision models classify fire, smoke, and water leakage, while sensor intelligence and decision fusion contribute to hazard alerts shown on a live dashboard. The documented runtime flow runs from camera and ESP32 readings through the Flask backend to dashboard status, history, and audio warnings. Separate scripts prepare data, train models, and evaluate checkpoints. The README documents the system-level workflow; unsampled backend and frontend details limit confirmation of some specific runtime connections.

Main entry points: [`app.py`](https://github.com/rkt973/multi-hazard-detection/blob/main/app.py) (Flask API and fusion), [`Fire detection CV/dataset`](https://github.com/rkt973/multi-hazard-detection/tree/main/Fire%20detection%20CV/dataset) (Fire dataset), [`Smoke detection CV/smoke_dataset`](https://github.com/rkt973/multi-hazard-detection/tree/main/Smoke%20detection%20CV/smoke_dataset) (Smoke dataset), [`Water Leakage CV/leak_dataset`](https://github.com/rkt973/multi-hazard-detection/tree/main/Water%20Leakage%20CV/leak_dataset) (Leak dataset)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_vision["Vision models"]
  node_fire_data[("Fire dataset")]
  node_fire_prepare["Prepare fire data<br/>[prepare_dataset.py]"]
  node_fire_train["Train fire model<br/>[train.py]"]
  node_fire_eval["Evaluate fire model<br/>[evaluate.py]"]
  node_fire_infer["Fire inference<br/>[infer.py]"]
  node_smoke_data[("Smoke dataset")]
  node_smoke_prepare["Prepare smoke data"]
  node_smoke_train["Train smoke model<br/>[train_smoke.py]"]
  node_smoke_eval["Evaluate smoke model<br/>[evaluate_smoke.py]"]
  node_smoke_infer["Smoke inference<br/>[infer_smoke.py]"]
  node_leak_data[("Leak dataset")]
  node_leak_prepare["Prepare leak data"]
  node_leak_train["Train leak model<br/>[train_leak.py]"]
  node_leak_eval["Evaluate leak model<br/>[evaluate_leak.py]"]
  node_leak_infer["Leak inference<br/>[infer_leak.py]"]
end

subgraph group_ml["Sensor intelligence"]
  node_sensor["Sensor classifier<br/>[hazard_ml.py]"]
  node_sensor_train["Train sensor model"]
end

subgraph group_backend["Hazard backend"]
  node_backend["Flask API and fusion<br/>[app.py]"]
end

subgraph group_ui["Monitoring dashboard"]
  node_dashboard["Dashboard UI<br/>[app.js]"]
  node_history_ui["Event history<br/>[history.js]"]
  node_dashboard_data["Dashboard data<br/>[data.js]"]
  node_audio["Audio alerts<br/>[app.js]"]
end

subgraph group_device["IoT device"]
  node_esp32["ESP32 firmware<br/>[IDP-PROJECT-3.ino]"]
end

node_camera(("Camera"))

node_fire_prepare -->|"writes splits"| node_fire_data
node_fire_data -->|"trains on"| node_fire_train
node_fire_train -->|"saves checkpoint"| node_fire_eval
node_fire_data -->|"evaluates split"| node_fire_eval
node_camera -->|"provides frames"| node_fire_infer
node_smoke_prepare -->|"writes splits"| node_smoke_data
node_smoke_data -->|"trains on"| node_smoke_train
node_smoke_train -->|"saves checkpoint"| node_smoke_eval
node_smoke_data -->|"evaluates split"| node_smoke_eval
node_camera -->|"provides frames"| node_smoke_infer
node_leak_prepare -->|"writes splits"| node_leak_data
node_leak_data -->|"trains on"| node_leak_train
node_leak_train -->|"saves checkpoint"| node_leak_eval
node_leak_data -->|"evaluates split"| node_leak_eval
node_camera -->|"provides frames"| node_leak_infer
node_sensor_train -->|"produces model"| node_sensor
node_esp32 -->|"sends readings"| node_backend
node_camera -->|"captures frames"| node_backend
node_sensor -->|"predicts sensor risk"| node_backend
node_backend -->|"serves live status"| node_dashboard
node_backend -->|"serves event history"| node_history_ui
node_dashboard -->|"updates display"| node_dashboard_data
node_dashboard -->|"plays warnings"| node_audio

click node_fire_data "https://github.com/rkt973/multi-hazard-detection/tree/main/Fire%20detection%20CV/dataset"
click node_fire_prepare "https://github.com/rkt973/multi-hazard-detection/blob/main/Fire%20detection%20CV/prepare_dataset.py"
click node_fire_train "https://github.com/rkt973/multi-hazard-detection/blob/main/Fire%20detection%20CV/train.py"
click node_fire_eval "https://github.com/rkt973/multi-hazard-detection/blob/main/Fire%20detection%20CV/evaluate.py"
click node_fire_infer "https://github.com/rkt973/multi-hazard-detection/blob/main/Fire%20detection%20CV/infer.py"
click node_smoke_data "https://github.com/rkt973/multi-hazard-detection/tree/main/Smoke%20detection%20CV/smoke_dataset"
click node_smoke_prepare "https://github.com/rkt973/multi-hazard-detection/blob/main/Smoke%20detection%20CV/prepare_smoke_dataset.py"
click node_smoke_train "https://github.com/rkt973/multi-hazard-detection/blob/main/Smoke%20detection%20CV/train_smoke.py"
click node_smoke_eval "https://github.com/rkt973/multi-hazard-detection/blob/main/Smoke%20detection%20CV/evaluate_smoke.py"
click node_smoke_infer "https://github.com/rkt973/multi-hazard-detection/blob/main/Smoke%20detection%20CV/infer_smoke.py"
click node_leak_data "https://github.com/rkt973/multi-hazard-detection/tree/main/Water%20Leakage%20CV/leak_dataset"
click node_leak_prepare "https://github.com/rkt973/multi-hazard-detection/blob/main/Water%20Leakage%20CV/prepare_leak_dataset.py"
click node_leak_train "https://github.com/rkt973/multi-hazard-detection/blob/main/Water%20Leakage%20CV/train_leak.py"
click node_leak_eval "https://github.com/rkt973/multi-hazard-detection/blob/main/Water%20Leakage%20CV/evaluate_leak.py"
click node_leak_infer "https://github.com/rkt973/multi-hazard-detection/blob/main/Water%20Leakage%20CV/infer_leak.py"
click node_sensor "https://github.com/rkt973/multi-hazard-detection/blob/main/hazard_ml.py"
click node_sensor_train "https://github.com/rkt973/multi-hazard-detection/blob/main/train_hazard_model.py"
click node_esp32 "https://github.com/rkt973/multi-hazard-detection/blob/main/IDP-PROJECT-3/IDP-PROJECT-3.ino"
click node_backend "https://github.com/rkt973/multi-hazard-detection/blob/main/app.py"
click node_dashboard "https://github.com/rkt973/multi-hazard-detection/blob/main/app.js"
click node_history_ui "https://github.com/rkt973/multi-hazard-detection/blob/main/history.js"
click node_dashboard_data "https://github.com/rkt973/multi-hazard-detection/blob/main/data.js"
click node_audio "https://github.com/rkt973/multi-hazard-detection/blob/main/app.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_fire_data,node_fire_prepare,node_fire_train,node_fire_eval,node_fire_infer,node_smoke_data,node_smoke_prepare,node_smoke_train,node_smoke_eval,node_smoke_infer,node_leak_data,node_leak_prepare,node_leak_train,node_leak_eval,node_leak_infer toneBlue
class node_sensor,node_sensor_train toneAmber
class node_backend toneMint
class node_dashboard,node_history_ui,node_dashboard_data,node_audio toneRose
class node_esp32,node_camera toneIndigo
```

## Components

### Vision models

- [Fire dataset](https://github.com/rkt973/multi-hazard-detection/tree/main/Fire%20detection%20CV/dataset): `Fire detection CV/dataset`
- [Prepare fire data](https://github.com/rkt973/multi-hazard-detection/blob/main/Fire%20detection%20CV/prepare_dataset.py): `Fire detection CV/prepare_dataset.py`
- [Train fire model](https://github.com/rkt973/multi-hazard-detection/blob/main/Fire%20detection%20CV/train.py): `Fire detection CV/train.py`
- [Evaluate fire model](https://github.com/rkt973/multi-hazard-detection/blob/main/Fire%20detection%20CV/evaluate.py): `Fire detection CV/evaluate.py`
- [Fire inference](https://github.com/rkt973/multi-hazard-detection/blob/main/Fire%20detection%20CV/infer.py): `Fire detection CV/infer.py`
- [Smoke dataset](https://github.com/rkt973/multi-hazard-detection/tree/main/Smoke%20detection%20CV/smoke_dataset): `Smoke detection CV/smoke_dataset`
- [Prepare smoke data](https://github.com/rkt973/multi-hazard-detection/blob/main/Smoke%20detection%20CV/prepare_smoke_dataset.py): `Smoke detection CV/prepare_smoke_dataset.py`
- [Train smoke model](https://github.com/rkt973/multi-hazard-detection/blob/main/Smoke%20detection%20CV/train_smoke.py): `Smoke detection CV/train_smoke.py`
- [Evaluate smoke model](https://github.com/rkt973/multi-hazard-detection/blob/main/Smoke%20detection%20CV/evaluate_smoke.py): `Smoke detection CV/evaluate_smoke.py`
- [Smoke inference](https://github.com/rkt973/multi-hazard-detection/blob/main/Smoke%20detection%20CV/infer_smoke.py): `Smoke detection CV/infer_smoke.py`
- [Leak dataset](https://github.com/rkt973/multi-hazard-detection/tree/main/Water%20Leakage%20CV/leak_dataset): `Water Leakage CV/leak_dataset`
- [Prepare leak data](https://github.com/rkt973/multi-hazard-detection/blob/main/Water%20Leakage%20CV/prepare_leak_dataset.py): `Water Leakage CV/prepare_leak_dataset.py`
- [Train leak model](https://github.com/rkt973/multi-hazard-detection/blob/main/Water%20Leakage%20CV/train_leak.py): `Water Leakage CV/train_leak.py`
- [Evaluate leak model](https://github.com/rkt973/multi-hazard-detection/blob/main/Water%20Leakage%20CV/evaluate_leak.py): `Water Leakage CV/evaluate_leak.py`
- [Leak inference](https://github.com/rkt973/multi-hazard-detection/blob/main/Water%20Leakage%20CV/infer_leak.py): `Water Leakage CV/infer_leak.py`

### Sensor intelligence

- [Sensor classifier](https://github.com/rkt973/multi-hazard-detection/blob/main/hazard_ml.py): `hazard_ml.py`
- [Train sensor model](https://github.com/rkt973/multi-hazard-detection/blob/main/train_hazard_model.py): `train_hazard_model.py`

### Hazard backend

- [Flask API and fusion](https://github.com/rkt973/multi-hazard-detection/blob/main/app.py): `app.py`

### Monitoring dashboard

- [Dashboard UI](https://github.com/rkt973/multi-hazard-detection/blob/main/app.js): `app.js`
- [Event history](https://github.com/rkt973/multi-hazard-detection/blob/main/history.js): `history.js`
- [Dashboard data](https://github.com/rkt973/multi-hazard-detection/blob/main/data.js): `data.js`
- [Audio alerts](https://github.com/rkt973/multi-hazard-detection/blob/main/app.js): `app.js`

### IoT device

- [ESP32 firmware](https://github.com/rkt973/multi-hazard-detection/blob/main/IDP-PROJECT-3/IDP-PROJECT-3.ino): `IDP-PROJECT-3/IDP-PROJECT-3.ino`

### Other components

- **Camera**

## Connections

- Prepare fire data → Fire dataset: writes splits (evidence: `Fire detection CV/prepare_dataset.py`)
- Fire dataset → Train fire model: trains on (evidence: `Fire detection CV/train.py`)
- Train fire model → Evaluate fire model: saves checkpoint (evidence: `Fire detection CV/evaluate.py`)
- Fire dataset → Evaluate fire model: evaluates split (evidence: `Fire detection CV/evaluate.py`)
- Camera → Fire inference: provides frames (evidence: `README.md`)
- Prepare smoke data → Smoke dataset: writes splits (evidence: `Smoke detection CV/prepare_smoke_dataset.py`)
- Smoke dataset → Train smoke model: trains on (evidence: `Smoke detection CV/train_smoke.py`)
- Train smoke model → Evaluate smoke model: saves checkpoint (evidence: `Smoke detection CV/evaluate_smoke.py`)
- Smoke dataset → Evaluate smoke model: evaluates split (evidence: `Smoke detection CV/evaluate_smoke.py`)
- Camera → Smoke inference: provides frames (evidence: `README.md`)
- Prepare leak data → Leak dataset: writes splits (evidence: `Water Leakage CV/prepare_leak_dataset.py`)
- Leak dataset → Train leak model: trains on (evidence: `Water Leakage CV/train_leak.py`)
- Train leak model → Evaluate leak model: saves checkpoint (evidence: `Water Leakage CV/evaluate_leak.py`)
- Leak dataset → Evaluate leak model: evaluates split (evidence: `Water Leakage CV/evaluate_leak.py`)
- Camera → Leak inference: provides frames (evidence: `README.md`)
- Train sensor model → Sensor classifier: produces model (evidence: `train_hazard_model.py`)
- ESP32 firmware → Flask API and fusion: sends readings (evidence: `README.md`)
- Camera → Flask API and fusion: captures frames (evidence: `README.md`)
- Sensor classifier → Flask API and fusion: predicts sensor risk (evidence: `README.md`)
- Flask API and fusion → Dashboard UI: serves live status (evidence: `README.md`)
- Flask API and fusion → Event history: serves event history (evidence: `README.md`)
- Dashboard UI → Dashboard data: updates display (evidence: `app.js`)
- Dashboard UI → Audio alerts: plays warnings (evidence: `app.js`)
