# senbenz/sentinel architecture

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

- Interactive diagram: https://gitdiagram.com/senbenz/sentinel
- Repository: https://github.com/senbenz/sentinel

## Overview

Sentinel is a real-time driver-fatigue monitor: it reads camera frames, detects facial landmarks, derives fatigue metrics, scores risk, escalates alerts, and displays an on-frame status panel. Startup calibration personalizes eye-closure detection; optional CSV recording and an LSTM scoring/training path support model-based scoring. The graph reflects sampled code and SOURCE INDEX references; unsampled wiring is omitted where the excerpts do not establish it.

Main entry points: [`Orchestration.py`](https://github.com/senbenz/sentinel/blob/main/Orchestration.py) (Runtime orchestration), [`Calibration.py`](https://github.com/senbenz/sentinel/blob/main/Calibration.py) (EAR calibration), [`lstm_scorer.py`](https://github.com/senbenz/sentinel/blob/main/lstm_scorer.py) (LSTM inference), [`lstm_train.py`](https://github.com/senbenz/sentinel/blob/main/lstm_train.py) (Model training)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_capture["Capture and calibration"]
  node_orchestrator["Runtime orchestration<br/>[Orchestration.py]"]
  node_calibration["EAR calibration<br/>[Calibration.py]"]
end

subgraph group_analysis["Fatigue analysis"]
  node_metrics["Fatigue metrics<br/>[Metrics.py]"]
  node_formula_scorer["Formula scorer<br/>[Scorer.py]"]
end

subgraph group_response["Alerts and display"]
  node_alerts["Alert escalation<br/>[Alert.py]"]
  node_sound["Sound manager<br/>[Alert.py]"]
  node_overlay["Visual overlay<br/>[Overlay.py]"]
end

subgraph group_learning["LSTM learning"]
  node_lstm_scorer["LSTM inference<br/>[lstm_scorer.py]"]
  node_feature_data["Feature normalization<br/>[lstm_data.py]"]
  node_lstm_model["LSTM model<br/>[lstm_model.py]"]
  node_training["Model training<br/>[lstm_train.py]"]
  node_recording["Session recording<br/>[Orchestration.py]"]
end

node_driver(("Driver"))
node_camera["Camera"]
node_landmarker["FaceLandmarker"]

node_driver -->|"provides video"| node_camera
node_orchestrator -->|"reads frames"| node_camera
node_orchestrator -->|"detects faces"| node_landmarker
node_orchestrator -->|"calibrates EAR"| node_calibration
node_calibration -->|"processes frames"| node_landmarker
node_calibration -->|"computes EAR"| node_metrics
node_orchestrator -->|"updates metrics"| node_metrics
node_orchestrator -->|"scores snapshots"| node_formula_scorer
node_orchestrator -->|"selects optionally"| node_lstm_scorer
node_lstm_scorer -->|"normalizes features"| node_feature_data
node_lstm_scorer -->|"falls back during warmup"| node_formula_scorer
node_orchestrator -->|"updates alert state"| node_alerts
node_alerts -->|"plays alert tones"| node_sound
node_orchestrator -->|"draws status panel"| node_overlay
node_orchestrator -->|"records snapshots"| node_recording
node_training -->|"builds sequences"| node_feature_data
node_training -->|"trains model"| node_lstm_model
node_driver -.->|"views status"| node_overlay

click node_orchestrator "https://github.com/senbenz/sentinel/blob/main/Orchestration.py"
click node_calibration "https://github.com/senbenz/sentinel/blob/main/Calibration.py"
click node_metrics "https://github.com/senbenz/sentinel/blob/main/Metrics.py"
click node_formula_scorer "https://github.com/senbenz/sentinel/blob/main/Scorer.py"
click node_lstm_scorer "https://github.com/senbenz/sentinel/blob/main/lstm_scorer.py"
click node_feature_data "https://github.com/senbenz/sentinel/blob/main/lstm_data.py"
click node_lstm_model "https://github.com/senbenz/sentinel/blob/main/lstm_model.py"
click node_training "https://github.com/senbenz/sentinel/blob/main/lstm_train.py"
click node_recording "https://github.com/senbenz/sentinel/blob/main/Orchestration.py"
click node_alerts "https://github.com/senbenz/sentinel/blob/main/Alert.py"
click node_sound "https://github.com/senbenz/sentinel/blob/main/Alert.py"
click node_overlay "https://github.com/senbenz/sentinel/blob/main/Overlay.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_orchestrator,node_calibration toneBlue
class node_metrics,node_formula_scorer toneAmber
class node_alerts,node_sound,node_overlay toneMint
class node_lstm_scorer,node_feature_data,node_lstm_model,node_training,node_recording toneRose
class node_driver,node_camera,node_landmarker toneIndigo
```

## Components

### Capture and calibration

- [Runtime orchestration](https://github.com/senbenz/sentinel/blob/main/Orchestration.py): `Orchestration.py`
- [EAR calibration](https://github.com/senbenz/sentinel/blob/main/Calibration.py): `Calibration.py`

### Fatigue analysis

- [Fatigue metrics](https://github.com/senbenz/sentinel/blob/main/Metrics.py): `Metrics.py`
- [Formula scorer](https://github.com/senbenz/sentinel/blob/main/Scorer.py): `Scorer.py`

### Alerts and display

- [Alert escalation](https://github.com/senbenz/sentinel/blob/main/Alert.py): `Alert.py`
- [Sound manager](https://github.com/senbenz/sentinel/blob/main/Alert.py): `Alert.py`
- [Visual overlay](https://github.com/senbenz/sentinel/blob/main/Overlay.py): `Overlay.py`

### LSTM learning

- [LSTM inference](https://github.com/senbenz/sentinel/blob/main/lstm_scorer.py): `lstm_scorer.py`
- [Feature normalization](https://github.com/senbenz/sentinel/blob/main/lstm_data.py): `lstm_data.py`
- [LSTM model](https://github.com/senbenz/sentinel/blob/main/lstm_model.py): `lstm_model.py`
- [Model training](https://github.com/senbenz/sentinel/blob/main/lstm_train.py): `lstm_train.py`
- [Session recording](https://github.com/senbenz/sentinel/blob/main/Orchestration.py): `Orchestration.py`

### Other components

- **Driver**
- **Camera**
- **FaceLandmarker**

## Connections

- Driver → Camera: provides video
- Runtime orchestration → Camera: reads frames (evidence: `Orchestration.py`)
- Runtime orchestration → FaceLandmarker: detects faces (evidence: `Orchestration.py`)
- Runtime orchestration → EAR calibration: calibrates EAR (evidence: `Orchestration.py`)
- EAR calibration → FaceLandmarker: processes frames (evidence: `Calibration.py`)
- EAR calibration → Fatigue metrics: computes EAR (evidence: `Calibration.py`)
- Runtime orchestration → Fatigue metrics: updates metrics (evidence: `Orchestration.py`)
- Runtime orchestration → Formula scorer: scores snapshots (evidence: `Orchestration.py`)
- Runtime orchestration → LSTM inference: selects optionally (evidence: `Orchestration.py`)
- LSTM inference → Feature normalization: normalizes features (evidence: `lstm_scorer.py`)
- LSTM inference → Formula scorer: falls back during warmup (evidence: `lstm_scorer.py`)
- Runtime orchestration → Alert escalation: updates alert state (evidence: `Orchestration.py`)
- Alert escalation → Sound manager: plays alert tones (evidence: `Alert.py`)
- Runtime orchestration → Visual overlay: draws status panel (evidence: `Orchestration.py`)
- Runtime orchestration → Session recording: records snapshots (evidence: `Orchestration.py`)
- Model training → Feature normalization: builds sequences (evidence: `lstm_train.py`)
- Model training → LSTM model: trains model (evidence: `lstm_train.py`)
- Driver → Visual overlay: views status
