# tonlongthuat/real-time-fall-detection architecture

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

- Interactive diagram: https://gitdiagram.com/tonlongthuat/real-time-fall-detection
- Repository: https://github.com/tonlongthuat/real-time-fall-detection

## Overview

Real-Time Fall Detection is a Flask-based monitoring app: users view a camera feed by registering an ESP32 IP address, or upload a video for processing and playback. Both paths display frames annotated by YOLO fall detection. The README also describes ESP32-CAM capture and multi-person monitoring. `fall_detector.py` contains a separate keypoint pose-and-duration detector, but the sampled runtime does not connect it to the Flask workflow. Relationships below follow sampled calls and README claims; no unsampled implementation links are inferred.

Main entry points: [`main.py`](https://github.com/tonlongthuat/real-time-fall-detection/blob/main/main.py) (Flask routes), [`video.py`](https://github.com/tonlongthuat/real-time-fall-detection/blob/main/video.py) (Live video streamer), [`esp32cam_streamer.py`](https://github.com/tonlongthuat/real-time-fall-detection/blob/main/esp32cam_streamer.py) (Camera frame capture), [`templates/index.html`](https://github.com/tonlongthuat/real-time-fall-detection/blob/main/templates/index.html) (Monitoring interface)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web monitoring"]
  node_flask["Flask routes<br/>[main.py]"]
  node_webui["Monitoring interface<br/>[index.html]"]
end

subgraph group_ingest["Frame sources"]
  node_esp32["ESP32-CAM<br/>[esp32_stream.ino]"]
  node_httpcapture["Camera frame capture"]
  node_upload["Video upload<br/>[main.py]"]
  node_uploadedvideo["Uploaded video"]
end

subgraph group_analysis["Fall analysis"]
  node_yolo["YOLO frame processing<br/>[video.py]"]
  node_pose["Keypoint fall detector<br/>[fall_detector.py]"]
  node_model["YOLO model<br/>[ok.pt]"]
end

subgraph group_playback["Video delivery"]
  node_framequeue["Processed frame queue<br/>[main.py]"]
  node_livestream["Live video streamer<br/>[video.py]"]
  node_filestream["File video streamer<br/>[video.py]"]
  node_feed["MJPEG camera feed<br/>[main.py]"]
end

node_user(("Monitoring user"))

node_user -->|"uses"| node_webui
node_webui -.->|"submits requests"| node_flask
node_user -->|"configures"| node_esp32
node_flask -->|"routes uploads"| node_upload
node_upload -->|"saves video"| node_uploadedvideo
node_upload -->|"starts processing"| node_yolo
node_yolo -->|"loads model"| node_model
node_yolo -->|"enqueues frames"| node_framequeue
node_flask -->|"creates capture"| node_httpcapture
node_flask -->|"creates streamer"| node_livestream
node_livestream -->|"reads frames"| node_httpcapture
node_livestream -->|"processes frames"| node_yolo
node_flask -->|"selects file stream"| node_filestream
node_filestream -->|"dequeues frames"| node_framequeue
node_livestream -->|"yields MJPEG"| node_feed
node_filestream -->|"yields MJPEG"| node_feed
node_feed -->|"streams video"| node_user
node_esp32 -->|"streams over Wi-Fi"| node_httpcapture
node_pose -.->|"detects pose"| node_user

click node_flask "https://github.com/tonlongthuat/real-time-fall-detection/blob/main/main.py"
click node_webui "https://github.com/tonlongthuat/real-time-fall-detection/blob/main/templates/index.html"
click node_esp32 "https://github.com/tonlongthuat/real-time-fall-detection/blob/main/esp32_stream.ino"
click node_httpcapture "https://github.com/tonlongthuat/real-time-fall-detection/blob/main/esp32cam_streamer.py"
click node_upload "https://github.com/tonlongthuat/real-time-fall-detection/blob/main/main.py"
click node_uploadedvideo "https://github.com/tonlongthuat/real-time-fall-detection/tree/main/uploads"
click node_yolo "https://github.com/tonlongthuat/real-time-fall-detection/blob/main/video.py"
click node_pose "https://github.com/tonlongthuat/real-time-fall-detection/blob/main/fall_detector.py"
click node_model "https://github.com/tonlongthuat/real-time-fall-detection/blob/main/ok.pt"
click node_framequeue "https://github.com/tonlongthuat/real-time-fall-detection/blob/main/main.py"
click node_livestream "https://github.com/tonlongthuat/real-time-fall-detection/blob/main/video.py"
click node_filestream "https://github.com/tonlongthuat/real-time-fall-detection/blob/main/video.py"
click node_feed "https://github.com/tonlongthuat/real-time-fall-detection/blob/main/main.py"

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_flask,node_webui,node_user toneBlue
class node_esp32,node_httpcapture,node_upload,node_uploadedvideo toneAmber
class node_yolo,node_pose,node_model toneMint
class node_framequeue,node_livestream,node_filestream,node_feed toneRose
```

## Components

### Web monitoring

- [Flask routes](https://github.com/tonlongthuat/real-time-fall-detection/blob/main/main.py): `main.py`
- [Monitoring interface](https://github.com/tonlongthuat/real-time-fall-detection/blob/main/templates/index.html): `templates/index.html`

### Frame sources

- [ESP32-CAM](https://github.com/tonlongthuat/real-time-fall-detection/blob/main/esp32_stream.ino): `esp32_stream.ino`
- [Camera frame capture](https://github.com/tonlongthuat/real-time-fall-detection/blob/main/esp32cam_streamer.py): `esp32cam_streamer.py`
- [Video upload](https://github.com/tonlongthuat/real-time-fall-detection/blob/main/main.py): `main.py`
- [Uploaded video](https://github.com/tonlongthuat/real-time-fall-detection/tree/main/uploads): `uploads`

### Fall analysis

- [YOLO frame processing](https://github.com/tonlongthuat/real-time-fall-detection/blob/main/video.py): `video.py`
- [Keypoint fall detector](https://github.com/tonlongthuat/real-time-fall-detection/blob/main/fall_detector.py): `fall_detector.py`
- [YOLO model](https://github.com/tonlongthuat/real-time-fall-detection/blob/main/ok.pt): `ok.pt`

### Video delivery

- [Processed frame queue](https://github.com/tonlongthuat/real-time-fall-detection/blob/main/main.py): `main.py`
- [Live video streamer](https://github.com/tonlongthuat/real-time-fall-detection/blob/main/video.py): `video.py`
- [File video streamer](https://github.com/tonlongthuat/real-time-fall-detection/blob/main/video.py): `video.py`
- [MJPEG camera feed](https://github.com/tonlongthuat/real-time-fall-detection/blob/main/main.py): `main.py`

### Other components

- **Monitoring user**

## Connections

- Monitoring user → Monitoring interface: uses (evidence: `README.md`)
- Monitoring interface → Flask routes: submits requests
- Monitoring user → ESP32-CAM: configures (evidence: `README.md`)
- Flask routes → Video upload: routes uploads (evidence: `main.py`)
- Video upload → Uploaded video: saves video (evidence: `main.py`)
- Video upload → YOLO frame processing: starts processing (evidence: `main.py`)
- YOLO frame processing → YOLO model: loads model (evidence: `video.py`)
- YOLO frame processing → Processed frame queue: enqueues frames (evidence: `video.py`)
- Flask routes → Camera frame capture: creates capture (evidence: `main.py`)
- Flask routes → Live video streamer: creates streamer (evidence: `main.py`)
- Live video streamer → Camera frame capture: reads frames (evidence: `video.py`)
- Live video streamer → YOLO frame processing: processes frames (evidence: `video.py`)
- Flask routes → File video streamer: selects file stream (evidence: `main.py`)
- File video streamer → Processed frame queue: dequeues frames (evidence: `video.py`)
- Live video streamer → MJPEG camera feed: yields MJPEG (evidence: `main.py`)
- File video streamer → MJPEG camera feed: yields MJPEG (evidence: `main.py`)
- MJPEG camera feed → Monitoring user: streams video (evidence: `main.py`)
- ESP32-CAM → Camera frame capture: streams over Wi-Fi (evidence: `README.md`)
- Keypoint fall detector → Monitoring user: detects pose
