# ipsita675/study-gaurdian architecture

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

- Interactive diagram: https://gitdiagram.com/ipsita675/study-gaurdian
- Repository: https://github.com/ipsita675/study-gaurdian

## Overview

Study Guardian is a real-time distraction-monitoring app: the user starts Guardian Mode, the browser captures webcam frames and streams them to a FastAPI WebSocket, and the backend detects phone use or signs of looking away. It returns a distraction level that drives the browser’s status display and looping alarm. The README also describes YOLO phone detection, MediaPipe facial landmarks, eye-aspect-ratio and head-yaw checks. Backend implementation details are from the sampled main module; the README supplies the broader capability and architecture context.

Main entry points: [`backend/main.py`](https://github.com/ipsita675/study-gaurdian/blob/main/backend/main.py) (Vision endpoint), [`frontend/app/page.tsx`](https://github.com/ipsita675/study-gaurdian/blob/main/frontend/app/page.tsx) (Frame WebSocket), [`frontend/app/layout.tsx`](https://github.com/ipsita675/study-gaurdian/blob/main/frontend/app/layout.tsx) (Application shell), [`frontend/public/FAAH.mp3`](https://github.com/ipsita675/study-gaurdian/blob/main/frontend/public/FAAH.mp3) (Alarm audio)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_browser["Browser experience"]
  node_guardian_ui["Guardian controls<br/>[page.tsx]"]
  node_webcam["Webcam capture<br/>[page.tsx]"]
  node_frame_stream["Frame WebSocket<br/>[page.tsx]"]
  node_app_shell["Application shell<br/>[layout.tsx]"]
end

subgraph group_vision["Vision backend"]
  node_vision_socket["Vision endpoint<br/>[main.py]"]
  node_frame_decode["Frame decoding<br/>[main.py]"]
  node_phone_detection["Phone detection<br/>[main.py]"]
  node_face_tracking["Face tracking<br/>[main.py]"]
  node_focus_checks["Focus checks<br/>[main.py]"]
  node_distraction_state["Distraction counter<br/>[main.py]"]
end

subgraph group_feedback["Distraction feedback"]
  node_status_display["Focus status<br/>[page.tsx]"]
  node_alarm_control["Alarm control<br/>[page.tsx]"]
  node_alarm_audio["Alarm audio<br/>[FAAH.mp3]"]
end

node_user(("Study user"))

node_user -->|"starts tracking"| node_guardian_ui
node_guardian_ui -->|"requests camera"| node_webcam
node_webcam -->|"captures frames"| node_frame_stream
node_frame_stream -->|"streams frames"| node_vision_socket
node_vision_socket -->|"decodes frames"| node_frame_decode
node_vision_socket -->|"runs inference"| node_phone_detection
node_vision_socket -->|"processes face"| node_face_tracking
node_face_tracking -->|"checks landmarks"| node_focus_checks
node_focus_checks -->|"flags distraction"| node_distraction_state
node_phone_detection -->|"flags phone"| node_distraction_state
node_vision_socket -->|"updates counter"| node_distraction_state
node_vision_socket -->|"sends status"| node_frame_stream
node_frame_stream -->|"updates level"| node_status_display
node_frame_stream -->|"triggers threshold"| node_alarm_control
node_alarm_control -->|"plays or pauses"| node_alarm_audio
node_app_shell -->|"renders page"| node_guardian_ui

click node_guardian_ui "https://github.com/ipsita675/study-gaurdian/blob/main/frontend/app/page.tsx"
click node_webcam "https://github.com/ipsita675/study-gaurdian/blob/main/frontend/app/page.tsx"
click node_frame_stream "https://github.com/ipsita675/study-gaurdian/blob/main/frontend/app/page.tsx"
click node_vision_socket "https://github.com/ipsita675/study-gaurdian/blob/main/backend/main.py"
click node_frame_decode "https://github.com/ipsita675/study-gaurdian/blob/main/backend/main.py"
click node_phone_detection "https://github.com/ipsita675/study-gaurdian/blob/main/backend/main.py"
click node_face_tracking "https://github.com/ipsita675/study-gaurdian/blob/main/backend/main.py"
click node_focus_checks "https://github.com/ipsita675/study-gaurdian/blob/main/backend/main.py"
click node_distraction_state "https://github.com/ipsita675/study-gaurdian/blob/main/backend/main.py"
click node_status_display "https://github.com/ipsita675/study-gaurdian/blob/main/frontend/app/page.tsx"
click node_alarm_control "https://github.com/ipsita675/study-gaurdian/blob/main/frontend/app/page.tsx"
click node_alarm_audio "https://github.com/ipsita675/study-gaurdian/blob/main/frontend/public/FAAH.mp3"
click node_app_shell "https://github.com/ipsita675/study-gaurdian/blob/main/frontend/app/layout.tsx"

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_guardian_ui,node_webcam,node_frame_stream,node_app_shell,node_user toneBlue
class node_vision_socket,node_frame_decode,node_phone_detection,node_face_tracking,node_focus_checks,node_distraction_state toneAmber
class node_status_display,node_alarm_control,node_alarm_audio toneMint
```

## Components

### Browser experience

- [Guardian controls](https://github.com/ipsita675/study-gaurdian/blob/main/frontend/app/page.tsx): `frontend/app/page.tsx`
- [Webcam capture](https://github.com/ipsita675/study-gaurdian/blob/main/frontend/app/page.tsx): `frontend/app/page.tsx`
- [Frame WebSocket](https://github.com/ipsita675/study-gaurdian/blob/main/frontend/app/page.tsx): `frontend/app/page.tsx`
- [Application shell](https://github.com/ipsita675/study-gaurdian/blob/main/frontend/app/layout.tsx): `frontend/app/layout.tsx`

### Vision backend

- [Vision endpoint](https://github.com/ipsita675/study-gaurdian/blob/main/backend/main.py): `backend/main.py`
- [Frame decoding](https://github.com/ipsita675/study-gaurdian/blob/main/backend/main.py): `backend/main.py`
- [Phone detection](https://github.com/ipsita675/study-gaurdian/blob/main/backend/main.py): `backend/main.py`
- [Face tracking](https://github.com/ipsita675/study-gaurdian/blob/main/backend/main.py): `backend/main.py`
- [Focus checks](https://github.com/ipsita675/study-gaurdian/blob/main/backend/main.py): `backend/main.py`
- [Distraction counter](https://github.com/ipsita675/study-gaurdian/blob/main/backend/main.py): `backend/main.py`

### Distraction feedback

- [Focus status](https://github.com/ipsita675/study-gaurdian/blob/main/frontend/app/page.tsx): `frontend/app/page.tsx`
- [Alarm control](https://github.com/ipsita675/study-gaurdian/blob/main/frontend/app/page.tsx): `frontend/app/page.tsx`
- [Alarm audio](https://github.com/ipsita675/study-gaurdian/blob/main/frontend/public/FAAH.mp3): `frontend/public/FAAH.mp3`

### Other components

- **Study user**

## Connections

- Study user → Guardian controls: starts tracking (evidence: `frontend/app/page.tsx`)
- Guardian controls → Webcam capture: requests camera (evidence: `frontend/app/page.tsx`)
- Webcam capture → Frame WebSocket: captures frames (evidence: `frontend/app/page.tsx`)
- Frame WebSocket → Vision endpoint: streams frames (evidence: `frontend/app/page.tsx`)
- Vision endpoint → Frame decoding: decodes frames (evidence: `backend/main.py`)
- Vision endpoint → Phone detection: runs inference (evidence: `backend/main.py`)
- Vision endpoint → Face tracking: processes face (evidence: `backend/main.py`)
- Face tracking → Focus checks: checks landmarks (evidence: `backend/main.py`)
- Focus checks → Distraction counter: flags distraction (evidence: `backend/main.py`)
- Phone detection → Distraction counter: flags phone (evidence: `backend/main.py`)
- Vision endpoint → Distraction counter: updates counter (evidence: `backend/main.py`)
- Vision endpoint → Frame WebSocket: sends status (evidence: `backend/main.py`)
- Frame WebSocket → Focus status: updates level (evidence: `frontend/app/page.tsx`)
- Frame WebSocket → Alarm control: triggers threshold (evidence: `frontend/app/page.tsx`)
- Alarm control → Alarm audio: plays or pauses (evidence: `frontend/app/page.tsx`)
- Application shell → Guardian controls: renders page (evidence: `frontend/app/layout.tsx`)
