# seth0x41/seizure-detection architecture

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

- Interactive diagram: https://gitdiagram.com/seth0x41/seizure-detection
- Repository: https://github.com/seth0x41/seizure-detection

## Overview

Seizure-Detection combines an ESP32 sensing device, a Flask API and a Flutter monitoring app. The documented workflow measures heart rate and motion, detects falls and possible seizures, sends readings or alerts to the API, and presents heart-rate data and notifications to the user. The API retains the latest reading in memory and dispatches alerts through SMS, email and push helpers. The Flutter implementation and ESP32 source were not excerpted, so their internal calls and detailed UI flow are not mapped; documented links are identified as such.

Main entry points: [`api/app.py`](https://github.com/seth0x41/seizure-detection/blob/main/api/app.py) (Flask API), [`device/device.ino`](https://github.com/seth0x41/seizure-detection/blob/main/device/device.ino) (ESP32 detector), [`flutter application/lib/main.dart`](https://github.com/seth0x41/seizure-detection/blob/main/flutter%20application/lib/main.dart) (Flutter app), [`api/send_sms.py`](https://github.com/seth0x41/seizure-detection/blob/main/api/send_sms.py) (SMS sender)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_sensing["Sensing and detection"]
  node_esp32["ESP32 detector<br/>[device.ino]"]
  node_sensors["Heart and motion sensors<br/>[device.ino]"]
  node_fall["Fall detection<br/>[device.ino]"]
  node_seizure["Seizure detection<br/>[device.ino]"]
end

subgraph group_backend["API and alert dispatch"]
  node_api["Flask API<br/>[app.py]"]
  node_readings[("Latest heart rate<br/>[app.py]")]
  node_alert_routes["Alert dispatch<br/>[app.py]"]
end

subgraph group_messaging["Notification channels"]
  node_sms["SMS sender<br/>[send_sms.py]"]
  node_email["Email sender<br/>[send_email.py]"]
  node_push["Push sender<br/>[firebase_send.py]"]
end

subgraph group_client["Flutter monitoring"]
  node_flutter["Flutter app<br/>[main.dart]"]
  node_notifications["Local notifications<br/>[main.dart]"]
  node_winhost["Windows app host<br/>[main.cpp]"]
  node_flutterwindow["Flutter window<br/>[flutter_window.h]"]
  node_winwindow["Win32 window<br/>[win32_window.h]"]
  node_linuxhost["Linux app host<br/>[main.cc]"]
  node_linuxapp["Linux application<br/>[my_application.h]"]
  node_pluginreg["macOS plugin registration"]
  node_ioshost["iOS app host<br/>[AppDelegate.swift]"]
  node_linuxregistrant["Linux plugin registration"]
  node_windowsregistrant["Windows plugin registration"]
end

node_wearer(("Monitored person"))
node_twilio["Twilio"]
node_mailgun["Mailgun"]
node_fcm["Firebase messaging"]
node_user(("Caregiver / app user"))

node_wearer -.->|"wears"| node_sensors
node_sensors -.->|"provide readings"| node_esp32
node_esp32 -.->|"detects falls"| node_fall
node_esp32 -.->|"detects seizures"| node_seizure
node_esp32 -.->|"sends readings and alerts"| node_api
node_api -->|"stores reading"| node_readings
node_api -->|"returns reading"| node_readings
node_api -->|"routes alert"| node_alert_routes
node_alert_routes -->|"calls"| node_sms
node_alert_routes -->|"calls"| node_email
node_alert_routes -->|"calls"| node_push
node_sms -->|"sends SMS"| node_twilio
node_email -->|"sends email"| node_mailgun
node_push -.->|"sends push"| node_fcm
node_user -.->|"monitors"| node_flutter
node_flutter -.->|"fetches readings"| node_api
node_flutter -.->|"displays alerts"| node_notifications
node_fcm -.->|"delivers push"| node_flutter
node_winhost -->|"creates"| node_flutterwindow
node_flutterwindow -->|"inherits"| node_winwindow
node_linuxhost -->|"starts"| node_linuxapp
node_ioshost -->|"registers plugins"| node_pluginreg

click node_esp32 "https://github.com/seth0x41/seizure-detection/blob/main/device/device.ino"
click node_sensors "https://github.com/seth0x41/seizure-detection/blob/main/device/device.ino"
click node_fall "https://github.com/seth0x41/seizure-detection/blob/main/device/device.ino"
click node_seizure "https://github.com/seth0x41/seizure-detection/blob/main/device/device.ino"
click node_api "https://github.com/seth0x41/seizure-detection/blob/main/api/app.py"
click node_readings "https://github.com/seth0x41/seizure-detection/blob/main/api/app.py"
click node_alert_routes "https://github.com/seth0x41/seizure-detection/blob/main/api/app.py"
click node_sms "https://github.com/seth0x41/seizure-detection/blob/main/api/send_sms.py"
click node_email "https://github.com/seth0x41/seizure-detection/blob/main/api/send_email.py"
click node_push "https://github.com/seth0x41/seizure-detection/blob/main/api/firebase_send.py"
click node_flutter "https://github.com/seth0x41/seizure-detection/blob/main/flutter%20application/lib/main.dart"
click node_notifications "https://github.com/seth0x41/seizure-detection/blob/main/flutter%20application/lib/main.dart"
click node_winhost "https://github.com/seth0x41/seizure-detection/blob/main/flutter%20application/windows/runner/main.cpp"
click node_flutterwindow "https://github.com/seth0x41/seizure-detection/blob/main/flutter%20application/windows/runner/flutter_window.h"
click node_winwindow "https://github.com/seth0x41/seizure-detection/blob/main/flutter%20application/windows/runner/win32_window.h"
click node_linuxhost "https://github.com/seth0x41/seizure-detection/blob/main/flutter%20application/linux/main.cc"
click node_linuxapp "https://github.com/seth0x41/seizure-detection/blob/main/flutter%20application/linux/my_application.h"
click node_pluginreg "https://github.com/seth0x41/seizure-detection/blob/main/flutter%20application/macos/Flutter/GeneratedPluginRegistrant.swift"
click node_ioshost "https://github.com/seth0x41/seizure-detection/blob/main/flutter%20application/ios/Runner/AppDelegate.swift"
click node_linuxregistrant "https://github.com/seth0x41/seizure-detection/blob/main/flutter%20application/linux/flutter/generated_plugin_registrant.h"
click node_windowsregistrant "https://github.com/seth0x41/seizure-detection/blob/main/flutter%20application/windows/flutter/generated_plugin_registrant.h"

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_esp32,node_sensors,node_fall,node_seizure,node_user toneBlue
class node_api,node_readings,node_alert_routes toneAmber
class node_sms,node_email,node_push toneMint
class node_flutter,node_notifications,node_winhost,node_flutterwindow,node_winwindow,node_linuxhost,node_linuxapp,node_pluginreg,node_ioshost,node_linuxregistrant,node_windowsregistrant toneRose
class node_wearer,node_twilio,node_mailgun,node_fcm toneIndigo
```

## Components

### Sensing and detection

- [ESP32 detector](https://github.com/seth0x41/seizure-detection/blob/main/device/device.ino): `device/device.ino`
- [Heart and motion sensors](https://github.com/seth0x41/seizure-detection/blob/main/device/device.ino): `device/device.ino`
- [Fall detection](https://github.com/seth0x41/seizure-detection/blob/main/device/device.ino): `device/device.ino`
- [Seizure detection](https://github.com/seth0x41/seizure-detection/blob/main/device/device.ino): `device/device.ino`

### API and alert dispatch

- [Flask API](https://github.com/seth0x41/seizure-detection/blob/main/api/app.py): `api/app.py`
- [Latest heart rate](https://github.com/seth0x41/seizure-detection/blob/main/api/app.py): `api/app.py`
- [Alert dispatch](https://github.com/seth0x41/seizure-detection/blob/main/api/app.py): `api/app.py`

### Notification channels

- [SMS sender](https://github.com/seth0x41/seizure-detection/blob/main/api/send_sms.py): `api/send_sms.py`
- [Email sender](https://github.com/seth0x41/seizure-detection/blob/main/api/send_email.py): `api/send_email.py`
- [Push sender](https://github.com/seth0x41/seizure-detection/blob/main/api/firebase_send.py): `api/firebase_send.py`

### Flutter monitoring

- [Flutter app](https://github.com/seth0x41/seizure-detection/blob/main/flutter%20application/lib/main.dart): `flutter application/lib/main.dart`
- [Local notifications](https://github.com/seth0x41/seizure-detection/blob/main/flutter%20application/lib/main.dart): `flutter application/lib/main.dart`
- [Windows app host](https://github.com/seth0x41/seizure-detection/blob/main/flutter%20application/windows/runner/main.cpp): `flutter application/windows/runner/main.cpp`
- [Flutter window](https://github.com/seth0x41/seizure-detection/blob/main/flutter%20application/windows/runner/flutter_window.h): `flutter application/windows/runner/flutter_window.h`
- [Win32 window](https://github.com/seth0x41/seizure-detection/blob/main/flutter%20application/windows/runner/win32_window.h): `flutter application/windows/runner/win32_window.h`
- [Linux app host](https://github.com/seth0x41/seizure-detection/blob/main/flutter%20application/linux/main.cc): `flutter application/linux/main.cc`
- [Linux application](https://github.com/seth0x41/seizure-detection/blob/main/flutter%20application/linux/my_application.h): `flutter application/linux/my_application.h`
- [macOS plugin registration](https://github.com/seth0x41/seizure-detection/blob/main/flutter%20application/macos/Flutter/GeneratedPluginRegistrant.swift): `flutter application/macos/Flutter/GeneratedPluginRegistrant.swift`
- [iOS app host](https://github.com/seth0x41/seizure-detection/blob/main/flutter%20application/ios/Runner/AppDelegate.swift): `flutter application/ios/Runner/AppDelegate.swift`
- [Linux plugin registration](https://github.com/seth0x41/seizure-detection/blob/main/flutter%20application/linux/flutter/generated_plugin_registrant.h): `flutter application/linux/flutter/generated_plugin_registrant.h`
- [Windows plugin registration](https://github.com/seth0x41/seizure-detection/blob/main/flutter%20application/windows/flutter/generated_plugin_registrant.h): `flutter application/windows/flutter/generated_plugin_registrant.h`

### Other components

- **Monitored person**
- **Twilio**
- **Mailgun**
- **Firebase messaging**
- **Caregiver / app user**

## Connections

- Monitored person → Heart and motion sensors: wears (evidence: `README.md`)
- Heart and motion sensors → ESP32 detector: provide readings (evidence: `README.md`)
- ESP32 detector → Fall detection: detects falls (evidence: `README.md`)
- ESP32 detector → Seizure detection: detects seizures (evidence: `README.md`)
- ESP32 detector → Flask API: sends readings and alerts (evidence: `README.md`)
- Flask API → Latest heart rate: stores reading (evidence: `api/app.py`)
- Flask API → Latest heart rate: returns reading (evidence: `api/app.py`)
- Flask API → Alert dispatch: routes alert (evidence: `api/app.py`)
- Alert dispatch → SMS sender: calls (evidence: `api/app.py`)
- Alert dispatch → Email sender: calls (evidence: `api/app.py`)
- Alert dispatch → Push sender: calls (evidence: `api/app.py`)
- SMS sender → Twilio: sends SMS (evidence: `api/send_sms.py`)
- Email sender → Mailgun: sends email (evidence: `api/send_email.py`)
- Push sender → Firebase messaging: sends push (evidence: `README.md`)
- Caregiver / app user → Flutter app: monitors (evidence: `README.md`)
- Flutter app → Flask API: fetches readings (evidence: `README.md`)
- Flutter app → Local notifications: displays alerts (evidence: `README.md`)
- Firebase messaging → Flutter app: delivers push (evidence: `README.md`)
- Windows app host → Flutter window: creates (evidence: `flutter application/windows/runner/main.cpp`)
- Flutter window → Win32 window: inherits (evidence: `flutter application/windows/runner/flutter_window.h`)
- Linux app host → Linux application: starts (evidence: `flutter application/linux/main.cc`)
- iOS app host → macOS plugin registration: registers plugins (evidence: `flutter application/ios/Runner/AppDelegate.swift`)
