# thelost-beep/focous-gouard architecture

> Architecture diagram of the GitHub repository thelost-beep/focous-gouard, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-02-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/thelost-beep/focous-gouard
- Repository: https://github.com/thelost-beep/focous-gouard

## Overview

##### Project type & purpose (from README + tree)
**FocusGuard** is a **single-user, local-only distraction detection app** with **two delivery modes**:

##### Web version (static site + browser AI/WebGL)
- Files: `index.html`, `style.css`, `app.js`, `*.mp3`
- Hosted via **Vercel** (`vercel.json`) and also on **GitHub Pages** (per README).
- Uses the **webcam** in-browser and runs detection locally.

##### Python desktop version (native runtime)
- Files: `focusguard.py`, `requirements.txt`
- Likely uses OpenCV / ML libs for face/eye/pose detection, triggers alarms locally.

##### Web runtime
- `index.html`: UI shell (start/stop, status text, video canvas elements)
- `style.css`: UI styling
- `app.js`: core logic (camera access, ML inference loop, distraction rules, audio playback, UI updates)
- `abey-uth-jaa-saale.mp3`, `uth-jaa-no-censor.mp3`: alert audio assets (local)
- `vercel.json`: hosting/deployment config for static delivery

##### Python runtime
- `focusguard.py`: camera capture loop, inference, rules, alerting, window display, key handling

##### What the README adds (architecturally important)
- **All processing is local** (privacy): no backend, no database, no telemetry.
- **Triggers**: “looking down too long” (phone trap) and “eyes closing” (sleep alert), threshold “> 2 seconds”
- **Controls**: Web STOP button; Python `q` key.
- **Reliability differences**: web depends on Browser/WebGL; Python is more “locked-in”.

These statements guide what you emphasize: **edge inference loop + device APIs**, and differences between the two deployments.

##### UI Layer (DOM/Canvas)
- status display (“FOCUSED” / distracted)
- Start/Stop controls
##### Camera Capture Module
- `getUserMedia` video stream
- frame extraction (canvas/video frame)
##### Distraction Logic / State Machine
- timers (e.g., >2 seconds)
- rules: “head down” / “eyes closed”
- debounce / “only alerts when really lost focus”
##### Alerting Module
- audio playback (mp3 assets)
- possibly looping / cooldown
##### Static Assets
- mp3 files
- css/html/js
##### Hosting/CDN (Vercel / GitHub Pages)
- serves static files only

Hosting → Browser (HTML/CSS/JS/MP3)
Webcam → Camera Capture → Inference Engine → Distraction Logic → Alerting → Speakers
Distraction Logic → UI Layer (status updates)

##### CLI/App Runner
- starts loop, handles exit (`q`)
##### Distraction Logic / State Machine
- same two rules + 2s thresholds
##### Alerting Module
- play sound (could be OS audio lib)
##### Display/Preview Window (optional)
- if it renders camera feed/status
##### Dependencies

Webcam → Video Capture → Inference Engine → Distraction Logic → Alerting → Speakers
Distraction Logic → Display/CLI (status)
Keyboard (`q`) → App Runner (stop)

##### Level 2 “Algorithm pipeline” inset (shared conceptual pipeline)
- Frame acquisition
- Landmark/feature extraction (eyes/head pose)
- Temporal smoothing / rolling window
- Rule evaluation (down gaze duration, eye closure duration)
- Alert trigger + cooldown

This clarifies “smart tracking” and the 2-second logic.

##### Architectural patterns/principles to call out (specific to this repo)
- **Edge AI / on-device inference** (privacy-preserving, no backend)
- **Event loop + state machine** (real-time stream processing)
- **Separation of concerns** even in small code:
- Vs inference vs decision vs presentation vs alerting
- **Two deployment targets** with analogous pipelines:
- Browser (WebGL/Web APIs) vs Python (native CV stack)

##### What
To be maximally clear:

##### Labels
- Use concrete labels tied to the repo:
- “`app.js` (camera + inference loop + rules)”
- “`focusguard.py` (capture + inference + rules)”
- “mp3 alert assets”
- “Vercel static hosting (`vercel.json`)”
- “Python deps (`requirements.txt`)”

##### Python container: internal module flow
(+ small shared pipeline inset)

That will be the most accurate representation of FocusGuard’s actual architecture and its two execution modes.

## Diagram (Mermaid)

```mermaid
flowchart TD
  %% =========================
  %% Level 0: Context
  %% =========================
  subgraph "Context (Local-only, single-user)"
    U["User"]:::user
    CAM["Webcam (Device)"]:::device
    SPK["Speakers / Audio Output"]:::device
    KB["Keyboard Input ('q' to quit)"]:::device

    HOST["Static Hosting (Vercel / GitHub Pages)"]:::cloud
    NODB["No Backend / No Database\n(Local processing only)"]:::nodb

    BROWSER["Web App Runtime (Browser)"]:::web
    PYAPP["Python Desktop Runtime (Local Machine)"]:::py
  end

  HOST -.->|"serves_static_files"| BROWSER
  U -->|"opens"| BROWSER
  U -->|"runs"| PYAPP

  CAM -->|"video_stream"| BROWSER
  CAM -->|"video_frames"| PYAPP
  KB -->|"quit_signal"| PYAPP

  BROWSER -->|"plays_alert_audio"| SPK
  PYAPP -->|"plays_alert_audio"| SPK

  BROWSER -.->|"no_network_processing"| NODB
  PYAPP -.->|"no_network_processing"| NODB

  %% =========================
  %% Level 1: Web Runtime
  %% =========================
  subgraph "Web Runtime (Static site + on-device inference)"
    direction TB

    subgraph "Static Assets (downloaded to browser)"
      direction TB
      W_HTML["UI Shell (DOM/Canvas)\nindex.html"]:::webAsset
      W_CSS["UI Styling\nstyle.css"]:::webAsset
      W_JS["Core Logic (Loop + Modules)\napp.js"]:::webCore
      W_MP3A["Alert Audio Asset\nabey-uth-jaa-saale.mp3"]:::asset
      W_MP3B["Alert Audio Asset\nuth-jaa-no-censor.mp3"]:::asset
      VERCEL["Deployment Config\nvercel.json"]:::config
      DOCS["Project Docs / Notes\nREADME"]:::doc
    end

    subgraph "Browser Modules (conceptual responsibilities inside app.js)"
      direction TB
      W_UI["UI Layer\nStart/Stop + Status Updates"]:::web
      W_CAM["Camera Capture Module\ngetUserMedia + frame extraction"]:::web
      W_INF["Inference Engine\nClient-side ML (WebGL/WASM)"]:::web
      W_LOGIC["Distraction Logic / State Machine\n2s_thresholds: head_down, eyes_closed"]:::web
      W_ALERT["Alerting Module\nAudio playback + cooldown"]:::web
    end

    W_HTML -->|"renders_controls"| W_UI
    W_CSS -->|"styles"| W_UI
    W_JS -->|"implements"| W_CAM
    W_JS -->|"implements"| W_INF
    W_JS -->|"implements"| W_LOGIC
    W_JS -->|"implements"| W_ALERT
    W_MP3A -->|"audio_source"| W_ALERT
    W_MP3B -->|"audio_source"| W_ALERT

    CAM -->|"browser_permission_stream"| W_CAM
    W_CAM -->|"frames"| W_INF
    W_INF -->|"signals: gaze/eyes_state"| W_LOGIC
    W_LOGIC -->|"status_text"| W_UI
    W_LOGIC -->|"trigger_alert"| W_ALERT
    W_ALERT -->|"audio_out"| SPK
  end

  %% Delivery linkage (context to internals)
  HOST -.->|"downloads"| W_HTML
  HOST -.->|"downloads"| W_CSS
  HOST -.->|"downloads"| W_JS
  HOST -.->|"downloads"| W_MP3A
  HOST -.->|"downloads"| W_MP3B
  HOST -.->|"uses"| VERCEL

  BROWSER -->|"runs"| W_UI
  BROWSER -->|"runs"| W_CAM
  BROWSER -->|"runs"| W_INF
  BROWSER -->|"runs"| W_LOGIC
  BROWSER -->|"runs"| W_ALERT

  %% =========================
  %% Level 1: Python Runtime
  %% =========================
  subgraph "Python Runtime (Native app + local ML/CV stack)"
    direction TB

    P_MAIN["Python App\nfocusguard.py"]:::pyCore
    P_REQ["Python Dependencies\nOpenCV + ML/CV libs (requirements.txt)"]:::config

    subgraph "Python Modules (conceptual responsibilities inside focusguard.py)"
      direction TB
      P_RUN["CLI/App Runner\nstartup + loop + exit handling ('q')"]:::py
      P_VCAP["Video Capture\nOpenCV / OS camera access"]:::py
      P_INF["Inference Engine\nPython ML/CV stack"]:::py
      P_LOGIC["Distraction Logic / State Machine\n2s_thresholds: head_down, eyes_closed"]:::py
      P_ALERT["Alerting Module\nsound playback"]:::py
      P_VIEW["Display / Preview Window\n(optional camera/status)"]:::py
    end

    P_REQ -->|"provides_libs"| P_MAIN
    P_MAIN -->|"orchestrates"| P_RUN
    P_MAIN -->|"uses"| P_VCAP
    P_MAIN -->|"uses"| P_INF
    P_MAIN -->|"uses"| P_LOGIC
    P_MAIN -->|"uses"| P_ALERT
    P_MAIN -->|"updates"| P_VIEW

    KB -->|"q_key"| P_RUN
    CAM -->|"frames"| P_VCAP
    P_VCAP -->|"frames"| P_INF
    P_INF -->|"signals: gaze/eyes_state"| P_LOGIC
    P_LOGIC -->|"trigger_alert"| P_ALERT
    P_LOGIC -->|"status_overlay"| P_VIEW
    P_ALERT -->|"audio_out"| SPK
  end

  PYAPP -->|"executes"| P_MAIN

  %% =========================
  %% Level 2: Shared Algorithm Pipeline (Conceptual inset)
  %% =========================
  subgraph "Shared Real-time Detection Pipeline (Conceptual)"
    direction TB
    S1["Frame Acquisition"]:::shared
    S2["Feature Extraction\n(eyes/head pose cues)"]:::shared
    S3["Temporal Smoothing\n(rolling window)"]:::shared
    S4["Rule Evaluation\n>2s head_down OR >2s eyes_closed"]:::shared
    S5["Alert Trigger + Cooldown"]:::shared
  end

  W_CAM -->|"maps_to"| S1
  P_VCAP -->|"maps_to"| S1
  W_INF -->|"maps_to"| S2
  P_INF -->|"maps_to"| S2
  W_LOGIC -->|"maps_to"| S3
  P_LOGIC -->|"maps_to"| S3
  W_LOGIC -->|"maps_to"| S4
  P_LOGIC -->|"maps_to"| S4
  W_ALERT -->|"maps_to"| S5
  P_ALERT -->|"maps_to"| S5

  %% =========================
  %% Click Events (from component_mapping)
  %% =========================
  click W_HTML "https://github.com/thelost-beep/focous-gouard/blob/main/index.html"
  click W_CSS "https://github.com/thelost-beep/focous-gouard/blob/main/style.css"
  click W_JS "https://github.com/thelost-beep/focous-gouard/blob/main/app.js"
  click W_CAM "https://github.com/thelost-beep/focous-gouard/blob/main/app.js"
  click W_INF "https://github.com/thelost-beep/focous-gouard/blob/main/app.js"
  click W_LOGIC "https://github.com/thelost-beep/focous-gouard/blob/main/app.js"
  click W_ALERT "https://github.com/thelost-beep/focous-gouard/blob/main/app.js"
  click W_MP3A "https://github.com/thelost-beep/focous-gouard/blob/main/abey-uth-jaa-saale.mp3"
  click W_MP3B "https://github.com/thelost-beep/focous-gouard/blob/main/uth-jaa-no-censor.mp3"
  click VERCEL "https://github.com/thelost-beep/focous-gouard/blob/main/vercel.json"
  click P_MAIN "https://github.com/thelost-beep/focous-gouard/blob/main/focusguard.py"
  click P_RUN "https://github.com/thelost-beep/focous-gouard/blob/main/focusguard.py"
  click P_VCAP "https://github.com/thelost-beep/focous-gouard/blob/main/focusguard.py"
  click P_INF "https://github.com/thelost-beep/focous-gouard/blob/main/focusguard.py"
  click P_LOGIC "https://github.com/thelost-beep/focous-gouard/blob/main/focusguard.py"
  click P_ALERT "https://github.com/thelost-beep/focous-gouard/blob/main/focusguard.py"
  click P_REQ "https://github.com/thelost-beep/focous-gouard/blob/main/requirements.txt"
  click DOCS "https://github.com/thelost-beep/focous-gouard/blob/main/README.md"

  %% =========================
  %% Styles
  %% =========================
  classDef user fill:#FFE6A7,stroke:#7A5C00,stroke-width:1.5,color:#1F1400
  classDef device fill:#E6E6E6,stroke:#6B6B6B,stroke-width:1.2,color:#111
  classDef cloud fill:#E8F1FF,stroke:#2B6CB0,stroke-width:1.5,color:#0B2A4A
  classDef nodb fill:#F2F2F2,stroke:#8A8A8A,stroke-dasharray: 5 3,color:#222

  classDef web fill:#D7ECFF,stroke:#1E5AA8,stroke-width:1.5,color:#0A2540
  classDef webCore fill:#BFE0FF,stroke:#144A8B,stroke-width:1.8,color:#0A2540
  classDef webAsset fill:#EAF5FF,stroke:#3B82F6,stroke-width:1.2,color:#0A2540

  classDef py fill:#DCFCE7,stroke:#166534,stroke-width:1.5,color:#052E16
  classDef pyCore fill:#BBF7D0,stroke:#14532D,stroke-width:1.8,color:#052E16

  classDef asset fill:#FFF1F2,stroke:#BE123C,stroke-width:1.3,color:#4A0B1A
  classDef config fill:#FFF7ED,stroke:#C2410C,stroke-width:1.3,color:#3B1205
  classDef doc fill:#F5F3FF,stroke:#6D28D9,stroke-width:1.2,color:#1F1238

  classDef shared fill:#F1F5F9,stroke:#334155,stroke-width:1.2,color:#0F172A
```
