# anantkumarc/drivesentinel architecture

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

- Interactive diagram: https://gitdiagram.com/anantkumarc/drivesentinel
- Repository: https://github.com/anantkumarc/drivesentinel

## Overview

DriveSentinel is a local driver-monitoring prototype: it captures camera frames, derives visual cues, tracks them over time, fuses available evidence into warning states, and presents a preview or alert. The README documents laptop audio and optional ESP32 BLE buzzer outputs, plus hand-tracking diagnostics and calibration. The graph preserves those product branches; edges follow the documented workflow and sampled source references. Some app orchestration details and unsampled subsystem internals are not shown, so unverified connections are omitted.

Main entry points: [`src/dms/app.py`](https://github.com/anantkumarc/drivesentinel/blob/main/src/dms/app.py) (Monitoring App), [`src/dms/detectors/face_landmarks.py`](https://github.com/anantkumarc/drivesentinel/blob/main/src/dms/detectors/face_landmarks.py) (Face Landmarks), [`src/dms/fusion/engine.py`](https://github.com/anantkumarc/drivesentinel/blob/main/src/dms/fusion/engine.py) (Alert Fusion), [`src/dms/detectors/eyes.py`](https://github.com/anantkumarc/drivesentinel/blob/main/src/dms/detectors/eyes.py) (Eye Cues)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_capture["Frame Capture"]
  node_capture_backend["Capture Backend<br/>[backend.py]"]
  node_frame_packets["Frame Packets<br/>[packets.py]"]
end

subgraph group_vision["Visual Cues"]
  node_face_landmarks["Face Landmarks<br/>[face_landmarks.py]"]
  node_eye_detector["Eye Cues<br/>[eyes.py]"]
  node_head_pose["Head Pose<br/>[head_pose.py]"]
  node_mouth_detector["Mouth Cues<br/>[mouth.py]"]
  node_phone_detector["Phone Presence<br/>[phone_boxes.py]"]
  node_phone_interaction["Phone Interaction"]
  node_hand_tracking["Hand Diagnostics<br/>[hands.py]"]
end

subgraph group_analysis["Temporal Analysis"]
  node_eye_tracking["Eye Closure / PERCLOS<br/>[eye_closure.py]"]
  node_temporal_windows["Evidence Windows<br/>[windows.py]"]
  node_head_tracking["Head Distraction"]
  node_fusion_engine["Alert Fusion<br/>[engine.py]"]
  node_fusion_strategies["Fusion Strategies<br/>[rules.py]"]
  node_risk_model["Risk Evidence<br/>[base.py]"]
end

subgraph group_alerts["Alerts and Outputs"]
  node_alert_states["Alert States<br/>[states.py]"]
  node_app["Monitoring App<br/>[app.py]"]
  node_audio["Laptop Audio<br/>[audio.py]"]
  node_ble_output["BLE Buzzer Client<br/>[ble_buzzer.py]"]
  node_esp_firmware["ESP32 Alert Service<br/>[alert_service.cpp]"]
end

subgraph group_support["Calibration and Health"]
  node_model_assets["Model Assets<br/>[model_assets.py]"]
  node_watchdog["Capture Watchdog<br/>[watchdog.py]"]
  node_calibration["Camera / Head Calibration"]
end

node_driver(("Driver / Operator"))
node_camera(("Camera Source"))
node_preview(("Monitoring Preview"))
node_buzzer(("Active Buzzer"))

node_camera -->|"provides frames"| node_capture_backend
node_capture_backend -->|"emits packets"| node_frame_packets
node_frame_packets -->|"supplies frames"| node_app
node_app -->|"runs inference"| node_face_landmarks
node_face_landmarks -->|"provides landmarks"| node_eye_detector
node_face_landmarks -->|"provides landmarks"| node_head_pose
node_face_landmarks -->|"provides landmarks"| node_mouth_detector
node_app -->|"runs detection"| node_phone_detector
node_app -->|"runs diagnostics"| node_hand_tracking
node_app -->|"evaluates interaction"| node_phone_interaction
node_eye_detector -->|"tracks closure"| node_eye_tracking
node_eye_detector -->|"records observations"| node_temporal_windows
node_head_pose -->|"tracks direction"| node_head_tracking
node_app -->|"updates over time"| node_eye_tracking
node_app -->|"updates over time"| node_head_tracking
node_app -->|"combines cues"| node_fusion_engine
node_fusion_engine -->|"dispatches strategy"| node_fusion_strategies
node_fusion_engine -->|"evaluates evidence"| node_risk_model
node_fusion_engine -->|"produces decisions"| node_alert_states
node_app -->|"shows monitoring"| node_preview
node_app -->|"drives warnings"| node_audio
node_app -.->|"sends alert levels"| node_ble_output
node_ble_output -.->|"writes BLE level"| node_esp_firmware
node_esp_firmware -->|"switches output"| node_buzzer
node_app -->|"verifies models"| node_model_assets
node_app -.->|"monitors capture"| node_watchdog
node_driver -->|"calibrates setup"| node_calibration
node_calibration -->|"sets neutral pose"| node_head_pose

click node_capture_backend "https://github.com/anantkumarc/drivesentinel/blob/main/src/dms/capture/backend.py"
click node_frame_packets "https://github.com/anantkumarc/drivesentinel/blob/main/src/dms/capture/packets.py"
click node_face_landmarks "https://github.com/anantkumarc/drivesentinel/blob/main/src/dms/detectors/face_landmarks.py"
click node_eye_detector "https://github.com/anantkumarc/drivesentinel/blob/main/src/dms/detectors/eyes.py"
click node_head_pose "https://github.com/anantkumarc/drivesentinel/blob/main/src/dms/detectors/head_pose.py"
click node_mouth_detector "https://github.com/anantkumarc/drivesentinel/blob/main/src/dms/detectors/mouth.py"
click node_phone_detector "https://github.com/anantkumarc/drivesentinel/blob/main/src/dms/detectors/phone_boxes.py"
click node_phone_interaction "https://github.com/anantkumarc/drivesentinel/blob/main/src/dms/detectors/phone_interaction.py"
click node_hand_tracking "https://github.com/anantkumarc/drivesentinel/blob/main/src/dms/detectors/hands.py"
click node_eye_tracking "https://github.com/anantkumarc/drivesentinel/blob/main/src/dms/temporal/eye_closure.py"
click node_temporal_windows "https://github.com/anantkumarc/drivesentinel/blob/main/src/dms/temporal/windows.py"
click node_head_tracking "https://github.com/anantkumarc/drivesentinel/blob/main/src/dms/temporal/head_distraction.py"
click node_fusion_engine "https://github.com/anantkumarc/drivesentinel/blob/main/src/dms/fusion/engine.py"
click node_fusion_strategies "https://github.com/anantkumarc/drivesentinel/blob/main/src/dms/fusion/rules.py"
click node_risk_model "https://github.com/anantkumarc/drivesentinel/blob/main/src/dms/fusion/base.py"
click node_alert_states "https://github.com/anantkumarc/drivesentinel/blob/main/src/dms/alerts/states.py"
click node_app "https://github.com/anantkumarc/drivesentinel/blob/main/src/dms/app.py"
click node_audio "https://github.com/anantkumarc/drivesentinel/blob/main/src/dms/alerts/audio.py"
click node_ble_output "https://github.com/anantkumarc/drivesentinel/blob/main/src/dms/hardware/ble_buzzer.py"
click node_esp_firmware "https://github.com/anantkumarc/drivesentinel/blob/main/firmware/DriveSentinel_BLE/alert_service.cpp"
click node_model_assets "https://github.com/anantkumarc/drivesentinel/blob/main/src/dms/model_assets.py"
click node_watchdog "https://github.com/anantkumarc/drivesentinel/blob/main/src/dms/health/watchdog.py"
click node_calibration "https://github.com/anantkumarc/drivesentinel/blob/main/src/dms/tools/calibrate_head_neutral.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_capture_backend,node_frame_packets,node_preview toneBlue
class node_face_landmarks,node_eye_detector,node_head_pose,node_mouth_detector,node_phone_detector,node_phone_interaction,node_hand_tracking toneAmber
class node_eye_tracking,node_temporal_windows,node_head_tracking,node_fusion_engine,node_fusion_strategies,node_risk_model toneMint
class node_alert_states,node_app,node_audio,node_ble_output,node_esp_firmware toneRose
class node_model_assets,node_watchdog,node_calibration,node_driver,node_camera,node_buzzer toneIndigo
```

## Components

### Frame Capture

- [Capture Backend](https://github.com/anantkumarc/drivesentinel/blob/main/src/dms/capture/backend.py): `src/dms/capture/backend.py`
- [Frame Packets](https://github.com/anantkumarc/drivesentinel/blob/main/src/dms/capture/packets.py): `src/dms/capture/packets.py`

### Visual Cues

- [Face Landmarks](https://github.com/anantkumarc/drivesentinel/blob/main/src/dms/detectors/face_landmarks.py): `src/dms/detectors/face_landmarks.py`
- [Eye Cues](https://github.com/anantkumarc/drivesentinel/blob/main/src/dms/detectors/eyes.py): `src/dms/detectors/eyes.py`
- [Head Pose](https://github.com/anantkumarc/drivesentinel/blob/main/src/dms/detectors/head_pose.py): `src/dms/detectors/head_pose.py`
- [Mouth Cues](https://github.com/anantkumarc/drivesentinel/blob/main/src/dms/detectors/mouth.py): `src/dms/detectors/mouth.py`
- [Phone Presence](https://github.com/anantkumarc/drivesentinel/blob/main/src/dms/detectors/phone_boxes.py): `src/dms/detectors/phone_boxes.py`
- [Phone Interaction](https://github.com/anantkumarc/drivesentinel/blob/main/src/dms/detectors/phone_interaction.py): `src/dms/detectors/phone_interaction.py`
- [Hand Diagnostics](https://github.com/anantkumarc/drivesentinel/blob/main/src/dms/detectors/hands.py): `src/dms/detectors/hands.py`

### Temporal Analysis

- [Eye Closure / PERCLOS](https://github.com/anantkumarc/drivesentinel/blob/main/src/dms/temporal/eye_closure.py): `src/dms/temporal/eye_closure.py`
- [Evidence Windows](https://github.com/anantkumarc/drivesentinel/blob/main/src/dms/temporal/windows.py): `src/dms/temporal/windows.py`
- [Head Distraction](https://github.com/anantkumarc/drivesentinel/blob/main/src/dms/temporal/head_distraction.py): `src/dms/temporal/head_distraction.py`
- [Alert Fusion](https://github.com/anantkumarc/drivesentinel/blob/main/src/dms/fusion/engine.py): `src/dms/fusion/engine.py`
- [Fusion Strategies](https://github.com/anantkumarc/drivesentinel/blob/main/src/dms/fusion/rules.py): `src/dms/fusion/rules.py`
- [Risk Evidence](https://github.com/anantkumarc/drivesentinel/blob/main/src/dms/fusion/base.py): `src/dms/fusion/base.py`

### Alerts and Outputs

- [Alert States](https://github.com/anantkumarc/drivesentinel/blob/main/src/dms/alerts/states.py): `src/dms/alerts/states.py`
- [Monitoring App](https://github.com/anantkumarc/drivesentinel/blob/main/src/dms/app.py): `src/dms/app.py`
- [Laptop Audio](https://github.com/anantkumarc/drivesentinel/blob/main/src/dms/alerts/audio.py): `src/dms/alerts/audio.py`
- [BLE Buzzer Client](https://github.com/anantkumarc/drivesentinel/blob/main/src/dms/hardware/ble_buzzer.py): `src/dms/hardware/ble_buzzer.py`
- [ESP32 Alert Service](https://github.com/anantkumarc/drivesentinel/blob/main/firmware/DriveSentinel_BLE/alert_service.cpp): `firmware/DriveSentinel_BLE/alert_service.cpp`

### Calibration and Health

- [Model Assets](https://github.com/anantkumarc/drivesentinel/blob/main/src/dms/model_assets.py): `src/dms/model_assets.py`
- [Capture Watchdog](https://github.com/anantkumarc/drivesentinel/blob/main/src/dms/health/watchdog.py): `src/dms/health/watchdog.py`
- [Camera / Head Calibration](https://github.com/anantkumarc/drivesentinel/blob/main/src/dms/tools/calibrate_head_neutral.py): `src/dms/tools/calibrate_head_neutral.py`

### Other components

- **Driver / Operator**
- **Camera Source**
- **Monitoring Preview**
- **Active Buzzer**

## Connections

- Camera Source → Capture Backend: provides frames (evidence: `README.md`)
- Capture Backend → Frame Packets: emits packets (evidence: `src/dms/capture/backend.py`)
- Frame Packets → Monitoring App: supplies frames (evidence: `README.md`)
- Monitoring App → Face Landmarks: runs inference (evidence: `src/dms/app.py`)
- Face Landmarks → Eye Cues: provides landmarks (evidence: `README.md`)
- Face Landmarks → Head Pose: provides landmarks (evidence: `README.md`)
- Face Landmarks → Mouth Cues: provides landmarks (evidence: `README.md`)
- Monitoring App → Phone Presence: runs detection (evidence: `src/dms/app.py`)
- Monitoring App → Hand Diagnostics: runs diagnostics (evidence: `README.md`)
- Monitoring App → Phone Interaction: evaluates interaction (evidence: `src/dms/app.py`)
- Eye Cues → Eye Closure / PERCLOS: tracks closure (evidence: `README.md`)
- Eye Cues → Evidence Windows: records observations (evidence: `src/dms/temporal/windows.py`)
- Head Pose → Head Distraction: tracks direction (evidence: `README.md`)
- Monitoring App → Eye Closure / PERCLOS: updates over time (evidence: `README.md`)
- Monitoring App → Head Distraction: updates over time (evidence: `README.md`)
- Monitoring App → Alert Fusion: combines cues (evidence: `README.md`)
- Alert Fusion → Fusion Strategies: dispatches strategy (evidence: `src/dms/fusion/engine.py`)
- Alert Fusion → Risk Evidence: evaluates evidence (evidence: `src/dms/fusion/engine.py`)
- Alert Fusion → Alert States: produces decisions (evidence: `README.md`)
- Monitoring App → Monitoring Preview: shows monitoring (evidence: `README.md`)
- Monitoring App → Laptop Audio: drives warnings (evidence: `README.md`)
- Monitoring App → BLE Buzzer Client: sends alert levels (evidence: `README.md`)
- BLE Buzzer Client → ESP32 Alert Service: writes BLE level (evidence: `README.md`)
- ESP32 Alert Service → Active Buzzer: switches output (evidence: `firmware/DriveSentinel_BLE/alert_service.cpp`)
- Monitoring App → Model Assets: verifies models (evidence: `src/dms/app.py`)
- Monitoring App → Capture Watchdog: monitors capture (evidence: `src/dms/app.py`)
- Driver / Operator → Camera / Head Calibration: calibrates setup (evidence: `README.md`)
- Camera / Head Calibration → Head Pose: sets neutral pose (evidence: `README.md`)
