# aya31aidi/drowsiness-detection-system architecture

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

- Interactive diagram: https://gitdiagram.com/aya31aidi/drowsiness-detection-system
- Repository: https://github.com/aya31aidi/drowsiness-detection-system

## Overview

This is a real-time driver-drowsiness monitor: camera frames become calibrated, smoothed fatigue indicators and timed alert episodes; alerts are persisted and surfaced in a React dashboard. The README documents detector behavior, API/database fallback, and dashboard capabilities. Some implementation details—especially detector internals and several dashboard pages—are unsampled, so those links are based on README statements or explicit import references rather than inferred call chains.

Main entry points: [`frontend/src/App.jsx`](https://github.com/aya31aidi/drowsiness-detection-system/blob/main/frontend/src/App.jsx) (Routed dashboard), [`facial_detection.py`](https://github.com/aya31aidi/drowsiness-detection-system/blob/main/facial_detection.py) (Alert episodes), [`frontend/src/data/api.js`](https://github.com/aya31aidi/drowsiness-detection-system/blob/main/frontend/src/data/api.js) (API client), [`frontend/src/pages/OverviewPage.jsx`](https://github.com/aya31aidi/drowsiness-detection-system/blob/main/frontend/src/pages/OverviewPage.jsx) (Overview analytics)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_detection["Detection runtime"]
  node_detector["Face monitoring"]
  node_indicators["Fatigue indicators"]
  node_episode["Alert episodes"]
  node_alarm["Audio alarm"]
  node_livefeed["Live camera feed<br/>[live_feed.py]"]
end

subgraph group_services["Alert services"]
  node_flask["Flask API<br/>[app.py]"]
  node_supabase_utils["Alert persistence<br/>[supabase_utils.py]"]
  node_database[("Supabase alerts")]
end

subgraph group_frontend["Dashboard application"]
  node_app["Routed dashboard<br/>[App.jsx]"]
  node_provider["Alert state and refresh<br/>[AlertsProvider.jsx]"]
  node_api_client["API client<br/>[api.js]"]
  node_live_state["Live state client<br/>[useLiveState.js]"]
end

subgraph group_analytics["Dashboard features"]
  node_overview["Overview analytics<br/>[OverviewPage.jsx]"]
  node_alerts_page["Alert history<br/>[AlertsPage.jsx]"]
  node_live_page["Live monitor<br/>[LivePage.jsx]"]
  node_system_page["System status<br/>[SystemPage.jsx]"]
  node_settings_page["User settings<br/>[SettingsPage.jsx]"]
  node_stats["Alert statistics<br/>[stats.js]"]
  node_alert_kinds["Alert categories<br/>[alertKinds.js]"]
  node_csv["CSV export<br/>[csv.js]"]
end

node_driver(("Driver"))
node_camera["Webcam"]
node_browser(("Dashboard user"))

node_driver -->|"faces"| node_camera
node_camera -->|"frames"| node_detector
node_detector -->|"extracts landmarks"| node_indicators
node_indicators -->|"thresholds over time"| node_episode
node_episode -->|"plays alarm"| node_alarm
node_episode -->|"posts alerts"| node_flask
node_episode -.->|"fallback writes"| node_supabase_utils
node_detector -->|"publishes camera feed"| node_livefeed
node_flask -->|"delegates storage"| node_supabase_utils
node_supabase_utils -->|"reads and writes alerts"| node_database
node_browser -->|"uses dashboard"| node_app
node_app -->|"wraps routes"| node_provider
node_provider -->|"loads and deletes alerts"| node_api_client
node_api_client -->|"requests alerts"| node_flask
node_app -->|"routes to"| node_overview
node_app -->|"routes to"| node_alerts_page
node_app -->|"routes to"| node_live_page
node_app -->|"routes to"| node_system_page
node_app -->|"routes to"| node_settings_page
node_overview -->|"computes summaries"| node_stats
node_overview -->|"groups alert types"| node_alert_kinds
node_alerts_page -->|"exports filtered alerts"| node_csv
node_alerts_page -->|"filters and labels"| node_alert_kinds
node_live_page -->|"loads live metrics"| node_live_state
node_live_state -->|"uses API helpers"| node_api_client
node_live_page -->|"views detector stream"| node_livefeed
node_system_page -->|"checks API"| node_api_client
node_settings_page -->|"exports alerts"| node_csv

click node_detector "https://github.com/aya31aidi/drowsiness-detection-system/blob/main/facial_detection.py"
click node_indicators "https://github.com/aya31aidi/drowsiness-detection-system/blob/main/facial_detection.py"
click node_episode "https://github.com/aya31aidi/drowsiness-detection-system/blob/main/facial_detection.py"
click node_alarm "https://github.com/aya31aidi/drowsiness-detection-system/blob/main/facial_detection.py"
click node_livefeed "https://github.com/aya31aidi/drowsiness-detection-system/blob/main/live_feed.py"
click node_flask "https://github.com/aya31aidi/drowsiness-detection-system/blob/main/backend/app.py"
click node_supabase_utils "https://github.com/aya31aidi/drowsiness-detection-system/blob/main/backend/supabase_utils.py"
click node_app "https://github.com/aya31aidi/drowsiness-detection-system/blob/main/frontend/src/App.jsx"
click node_provider "https://github.com/aya31aidi/drowsiness-detection-system/blob/main/frontend/src/data/AlertsProvider.jsx"
click node_api_client "https://github.com/aya31aidi/drowsiness-detection-system/blob/main/frontend/src/data/api.js"
click node_live_state "https://github.com/aya31aidi/drowsiness-detection-system/blob/main/frontend/src/data/useLiveState.js"
click node_overview "https://github.com/aya31aidi/drowsiness-detection-system/blob/main/frontend/src/pages/OverviewPage.jsx"
click node_alerts_page "https://github.com/aya31aidi/drowsiness-detection-system/blob/main/frontend/src/pages/AlertsPage.jsx"
click node_live_page "https://github.com/aya31aidi/drowsiness-detection-system/blob/main/frontend/src/pages/LivePage.jsx"
click node_system_page "https://github.com/aya31aidi/drowsiness-detection-system/blob/main/frontend/src/pages/SystemPage.jsx"
click node_settings_page "https://github.com/aya31aidi/drowsiness-detection-system/blob/main/frontend/src/pages/SettingsPage.jsx"
click node_stats "https://github.com/aya31aidi/drowsiness-detection-system/blob/main/frontend/src/lib/stats.js"
click node_alert_kinds "https://github.com/aya31aidi/drowsiness-detection-system/blob/main/frontend/src/lib/alertKinds.js"
click node_csv "https://github.com/aya31aidi/drowsiness-detection-system/blob/main/frontend/src/lib/csv.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_detector,node_indicators,node_episode,node_alarm,node_livefeed,node_browser toneBlue
class node_flask,node_supabase_utils,node_database toneAmber
class node_app,node_provider,node_api_client,node_live_state toneMint
class node_overview,node_alerts_page,node_live_page,node_system_page,node_settings_page,node_stats,node_alert_kinds,node_csv toneRose
class node_driver,node_camera toneIndigo
```

## Components

### Detection runtime

- [Face monitoring](https://github.com/aya31aidi/drowsiness-detection-system/blob/main/facial_detection.py): `facial_detection.py`
- [Fatigue indicators](https://github.com/aya31aidi/drowsiness-detection-system/blob/main/facial_detection.py): `facial_detection.py`
- [Alert episodes](https://github.com/aya31aidi/drowsiness-detection-system/blob/main/facial_detection.py): `facial_detection.py`
- [Audio alarm](https://github.com/aya31aidi/drowsiness-detection-system/blob/main/facial_detection.py): `facial_detection.py`
- [Live camera feed](https://github.com/aya31aidi/drowsiness-detection-system/blob/main/live_feed.py): `live_feed.py`

### Alert services

- [Flask API](https://github.com/aya31aidi/drowsiness-detection-system/blob/main/backend/app.py): `backend/app.py`
- [Alert persistence](https://github.com/aya31aidi/drowsiness-detection-system/blob/main/backend/supabase_utils.py): `backend/supabase_utils.py`
- **Supabase alerts**

### Dashboard application

- [Routed dashboard](https://github.com/aya31aidi/drowsiness-detection-system/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`
- [Alert state and refresh](https://github.com/aya31aidi/drowsiness-detection-system/blob/main/frontend/src/data/AlertsProvider.jsx): `frontend/src/data/AlertsProvider.jsx`
- [API client](https://github.com/aya31aidi/drowsiness-detection-system/blob/main/frontend/src/data/api.js): `frontend/src/data/api.js`
- [Live state client](https://github.com/aya31aidi/drowsiness-detection-system/blob/main/frontend/src/data/useLiveState.js): `frontend/src/data/useLiveState.js`

### Dashboard features

- [Overview analytics](https://github.com/aya31aidi/drowsiness-detection-system/blob/main/frontend/src/pages/OverviewPage.jsx): `frontend/src/pages/OverviewPage.jsx`
- [Alert history](https://github.com/aya31aidi/drowsiness-detection-system/blob/main/frontend/src/pages/AlertsPage.jsx): `frontend/src/pages/AlertsPage.jsx`
- [Live monitor](https://github.com/aya31aidi/drowsiness-detection-system/blob/main/frontend/src/pages/LivePage.jsx): `frontend/src/pages/LivePage.jsx`
- [System status](https://github.com/aya31aidi/drowsiness-detection-system/blob/main/frontend/src/pages/SystemPage.jsx): `frontend/src/pages/SystemPage.jsx`
- [User settings](https://github.com/aya31aidi/drowsiness-detection-system/blob/main/frontend/src/pages/SettingsPage.jsx): `frontend/src/pages/SettingsPage.jsx`
- [Alert statistics](https://github.com/aya31aidi/drowsiness-detection-system/blob/main/frontend/src/lib/stats.js): `frontend/src/lib/stats.js`
- [Alert categories](https://github.com/aya31aidi/drowsiness-detection-system/blob/main/frontend/src/lib/alertKinds.js): `frontend/src/lib/alertKinds.js`
- [CSV export](https://github.com/aya31aidi/drowsiness-detection-system/blob/main/frontend/src/lib/csv.js): `frontend/src/lib/csv.js`

### Other components

- **Driver**
- **Webcam**
- **Dashboard user**

## Connections

- Driver → Webcam: faces
- Webcam → Face monitoring: frames
- Face monitoring → Fatigue indicators: extracts landmarks (evidence: `facial_detection.py`)
- Fatigue indicators → Alert episodes: thresholds over time (evidence: `facial_detection.py`)
- Alert episodes → Audio alarm: plays alarm (evidence: `facial_detection.py`)
- Alert episodes → Flask API: posts alerts
- Alert episodes → Alert persistence: fallback writes (evidence: `facial_detection.py`)
- Face monitoring → Live camera feed: publishes camera feed (evidence: `facial_detection.py`)
- Flask API → Alert persistence: delegates storage (evidence: `backend/app.py`)
- Alert persistence → Supabase alerts: reads and writes alerts
- Dashboard user → Routed dashboard: uses dashboard
- Routed dashboard → Alert state and refresh: wraps routes (evidence: `frontend/src/App.jsx`)
- Alert state and refresh → API client: loads and deletes alerts (evidence: `frontend/src/data/AlertsProvider.jsx`)
- API client → Flask API: requests alerts (evidence: `frontend/src/data/api.js`)
- Routed dashboard → Overview analytics: routes to (evidence: `frontend/src/App.jsx`)
- Routed dashboard → Alert history: routes to (evidence: `frontend/src/App.jsx`)
- Routed dashboard → Live monitor: routes to (evidence: `frontend/src/App.jsx`)
- Routed dashboard → System status: routes to (evidence: `frontend/src/App.jsx`)
- Routed dashboard → User settings: routes to (evidence: `frontend/src/App.jsx`)
- Overview analytics → Alert statistics: computes summaries (evidence: `frontend/src/pages/OverviewPage.jsx`)
- Overview analytics → Alert categories: groups alert types (evidence: `frontend/src/pages/OverviewPage.jsx`)
- Alert history → CSV export: exports filtered alerts (evidence: `frontend/src/pages/AlertsPage.jsx`)
- Alert history → Alert categories: filters and labels (evidence: `frontend/src/pages/AlertsPage.jsx`)
- Live monitor → Live state client: loads live metrics (evidence: `frontend/src/pages/LivePage.jsx`)
- Live state client → API client: uses API helpers (evidence: `frontend/src/data/useLiveState.js`)
- Live monitor → Live camera feed: views detector stream
- System status → API client: checks API (evidence: `frontend/src/pages/SystemPage.jsx`)
- User settings → CSV export: exports alerts (evidence: `frontend/src/pages/SettingsPage.jsx`)
