# adilaslam581/driver-safety architecture

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

- Interactive diagram: https://gitdiagram.com/adilaslam581/driver-safety
- Repository: https://github.com/adilaslam581/driver-safety

## Overview

Driver Drowsiness Detector has three runtime forms: a browser-based webcam monitor, a separate FastAPI inference service, and a standalone Python/OpenCV desktop monitor. The documented primary workflow is browser-local: load the ONNX model, capture webcam frames, classify eye images, accumulate closed-eye detections, and sound an alarm while updating the monitoring display. The backend exposes independent image-prediction endpoints; the sampled frontend does not show calls to it. Relationships below are limited to the README and sampled source, so unsampled UI and deployment details are omitted.

Main entry points: [`frontend/app.js`](https://github.com/adilaslam581/driver-safety/blob/main/frontend/app.js) (Browser controller), [`drowsiness_app.py`](https://github.com/adilaslam581/driver-safety/blob/main/drowsiness_app.py) (Desktop monitor), [`backend/app/main.py`](https://github.com/adilaslam581/driver-safety/blob/main/backend/app/main.py) (Image preprocessing), [`frontend/index.html`](https://github.com/adilaslam581/driver-safety/blob/main/frontend/index.html) (Monitoring interface)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_browser["Browser monitor"]
  node_browser_app["Browser controller<br/>[app.js]"]
  node_browser_ui["Monitoring interface<br/>[index.html]"]
end

subgraph group_api["Inference API"]
  node_api_service["Prediction API<br/>[main.py]"]
  node_api_preprocess["Image preprocessing<br/>[main.py]"]
  node_api_inference["ONNX inference<br/>[main.py]"]
end

subgraph group_desktop["Desktop monitor"]
  node_desktop_app["Desktop monitor<br/>[drowsiness_app.py]"]
end

subgraph group_assets["Model assets"]
  node_browser_model[("Browser ONNX model<br/>[model.onnx]")]
  node_api_model[("Backend ONNX model<br/>[model.onnx]")]
  node_root_model[("Standalone ONNX model<br/>[model.onnx]")]
end

node_driver(("Driver"))
node_webcam["Webcam"]
node_audio["Browser audio output"]

node_driver -->|"starts monitoring"| node_browser_app
node_browser_app -->|"requests video"| node_webcam
node_browser_app -->|"fetches model"| node_browser_model
node_browser_app -->|"crops and classifies"| node_browser_app
node_browser_app -->|"tracks closed eyes"| node_browser_app
node_browser_app -->|"sounds alarm"| node_audio
node_browser_app -->|"updates display"| node_browser_ui
node_api_service -->|"decodes and resizes"| node_api_preprocess
node_api_preprocess -->|"passes image tensor"| node_api_inference
node_api_inference -->|"runs model"| node_api_model
node_driver -->|"runs monitor"| node_desktop_app
node_desktop_app -->|"loads model"| node_root_model
node_desktop_app -->|"captures frames"| node_webcam
node_desktop_app -->|"classifies and scores"| node_desktop_app

click node_browser_app "https://github.com/adilaslam581/driver-safety/blob/main/frontend/app.js"
click node_browser_ui "https://github.com/adilaslam581/driver-safety/blob/main/frontend/index.html"
click node_browser_model "https://github.com/adilaslam581/driver-safety/blob/main/frontend/model.onnx"
click node_api_service "https://github.com/adilaslam581/driver-safety/blob/main/backend/app/main.py"
click node_api_preprocess "https://github.com/adilaslam581/driver-safety/blob/main/backend/app/main.py"
click node_api_inference "https://github.com/adilaslam581/driver-safety/blob/main/backend/app/main.py"
click node_api_model "https://github.com/adilaslam581/driver-safety/blob/main/backend/model.onnx"
click node_desktop_app "https://github.com/adilaslam581/driver-safety/blob/main/drowsiness_app.py"
click node_root_model "https://github.com/adilaslam581/driver-safety/blob/main/model.onnx"

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_browser_app,node_browser_ui,node_audio toneBlue
class node_api_service,node_api_preprocess,node_api_inference toneAmber
class node_desktop_app toneMint
class node_browser_model,node_api_model,node_root_model toneRose
class node_driver,node_webcam toneIndigo
```

## Components

### Browser monitor

- [Browser controller](https://github.com/adilaslam581/driver-safety/blob/main/frontend/app.js): `frontend/app.js`
- [Monitoring interface](https://github.com/adilaslam581/driver-safety/blob/main/frontend/index.html): `frontend/index.html`

### Inference API

- [Prediction API](https://github.com/adilaslam581/driver-safety/blob/main/backend/app/main.py): `backend/app/main.py`
- [Image preprocessing](https://github.com/adilaslam581/driver-safety/blob/main/backend/app/main.py): `backend/app/main.py`
- [ONNX inference](https://github.com/adilaslam581/driver-safety/blob/main/backend/app/main.py): `backend/app/main.py`

### Desktop monitor

- [Desktop monitor](https://github.com/adilaslam581/driver-safety/blob/main/drowsiness_app.py): `drowsiness_app.py`

### Model assets

- [Browser ONNX model](https://github.com/adilaslam581/driver-safety/blob/main/frontend/model.onnx): `frontend/model.onnx`
- [Backend ONNX model](https://github.com/adilaslam581/driver-safety/blob/main/backend/model.onnx): `backend/model.onnx`
- [Standalone ONNX model](https://github.com/adilaslam581/driver-safety/blob/main/model.onnx): `model.onnx`

### Other components

- **Driver**
- **Webcam**
- **Browser audio output**

## Connections

- Driver → Browser controller: starts monitoring (evidence: `frontend/app.js`)
- Browser controller → Webcam: requests video (evidence: `frontend/app.js`)
- Browser controller → Browser ONNX model: fetches model (evidence: `frontend/app.js`)
- Browser controller → Browser controller: crops and classifies (evidence: `frontend/app.js`)
- Browser controller → Browser controller: tracks closed eyes (evidence: `frontend/app.js`)
- Browser controller → Browser audio output: sounds alarm (evidence: `frontend/app.js`)
- Browser controller → Monitoring interface: updates display (evidence: `frontend/app.js`)
- Prediction API → Image preprocessing: decodes and resizes (evidence: `backend/app/main.py`)
- Image preprocessing → ONNX inference: passes image tensor (evidence: `backend/app/main.py`)
- ONNX inference → Backend ONNX model: runs model (evidence: `backend/app/main.py`)
- Driver → Desktop monitor: runs monitor (evidence: `drowsiness_app.py`)
- Desktop monitor → Standalone ONNX model: loads model (evidence: `drowsiness_app.py`)
- Desktop monitor → Webcam: captures frames (evidence: `drowsiness_app.py`)
- Desktop monitor → Desktop monitor: classifies and scores (evidence: `drowsiness_app.py`)
