# johnnykozman2007/studymonitor architecture

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

- Interactive diagram: https://gitdiagram.com/johnnykozman2007/studymonitor
- Repository: https://github.com/johnnykozman2007/studymonitor

## Overview

1. **Repository shape**
   - This is a small, mostly monolithic C++ Windows application.
   - The core logic appears to live in a single source file, `StudyMonitor.cpp`.
   - The rest of the tracked files are runtime assets or build artifacts: `sound.wav`, `sound2.wav`, `sound3.wav`, `study_helper.exe`, and `OpenCVConfig-version.cmake`.

2. **Primary runtime model**
   - The app runs locally on a user’s machine and processes live webcam video in real time.
   - There is no sign of a network service, database, or multi-process architecture.
   - The executable is a study-session monitoring tool that continuously evaluates posture/focus signals and emits alerts.

3. **External dependencies that define the architecture**
   - **OpenCV** provides camera capture, image processing, face detection, and UI/windowing support.
   - **dlib** provides facial landmark detection through the 68-point landmark model.
   - **Windows APIs** are used for message boxes and audio playback, which makes this specifically a Windows desktop application rather than a cross-platform one.

4. **Startup and configuration flow**
   - On launch, the app shows a welcome message and asks the user to choose a session length: 30, 60, or 90 minutes.
   - It expects local runtime assets to be present near the executable, including:
     - `shape_predictor_68_face_landmarks.dat`
     - `haarcascade_frontalface_default.xml`
     - optional sound files
   - The README also points to configurable thresholds in an `AppConfig` structure, implying the behavior is controlled by runtime parameters rather than multiple services.

5. **Video acquisition and detection pipeline**
   - The webcam feed is the primary data source.
   - Each frame likely goes through a sequence like:
     - detect face presence,
     - locate facial landmarks,
     - infer eye openness,
     - estimate pupil movement,
     - estimate screen distance.
   - That pipeline is the heart of the system and is where all “focus” signals are derived.

6. **Focus-signal subsystems**
   - **Distance tracking:** determines whether the user is too close to the screen, with a warning threshold around 0.5 m.
   - **Eye state detection:** classifies eyes as open or closed and tracks how long they remain closed.
   - **Pupil movement / zoning-out detection:** watches whether the pupil appears stationary for too long, used as a proxy for reduced attention.
   - These are not separate services; they are distinct analyses over the same video stream.

7. **State accumulation and timers**
   - The app keeps running counters for:
     - time spent too close,
     - time with eyes closed,
     - time zoning out.
   - It also tracks session time remaining.
   - The alert thresholds are temporal, not just visual: for example, eyes closed for more than 6 seconds or pupil stagnation for around 2 seconds.

8. **Alerting and feedback loop**
   - When the app detects a focus issue, it warns the user with audio alerts using the bundled sound files.
   - The README mentions Windows sound APIs, so the alerts are likely triggered directly from the app without any middleware.
   - The user-facing output includes real-time status for face presence, eye state, focus level, and session countdown.

9. **User interaction controls**
   - The app is interactive but minimal:
     - **ESC** exits early.
     - **SPACE three times within 3 seconds** triggers a study report.
   - This suggests the main loop is event-driven around keyboard input while continuously processing camera frames.

10. **Session summary/reporting**
   - The report feature aggregates the tracked durations into a session summary.
   - This is the main “end-of-session” artifact of the application: it turns raw detection history into a human-readable assessment of study quality.
   - It reinforces that the app is a single-session monitor rather than a long-running analytics system.

11. **Packaging and deployment boundary**
   - The repo is designed to ship as a local Windows executable with companion files in the same folder.
   - `study_helper.exe` indicates a built binary, while the XML model and WAV files are external runtime dependencies.
   - The project boundary is therefore “desktop executable plus local assets,” not a layered client/server stack.

12. **Architecture summary for diagramming**
   - The main diagram should show one local application process in the center.
   - Inputs: webcam, keyboard, local model files, cascade XML, optional sound assets.
   - Core processing: OpenCV frame loop + dlib landmarks + heuristics/timers.
   - Outputs: on-screen status, Windows message boxes, audio reminders, final session report.
   - The architecture is fundamentally a real-time computer-vision monitoring loop with lightweight local persistence only in the form of bundled files and session state in memory.

Main entry points: [`StudyMonitor.cpp`](https://github.com/johnnykozman2007/studymonitor/blob/main/StudyMonitor.cpp) (Frame loop), [`study_helper.exe`](https://github.com/johnnykozman2007/studymonitor/blob/main/study_helper.exe) (study_helper.exe), [`OpenCVConfig-version.cmake`](https://github.com/johnnykozman2007/studymonitor/blob/main/OpenCVConfig-version.cmake) (OpenCV), [`sound.wav`](https://github.com/johnnykozman2007/studymonitor/blob/main/sound.wav) (sound.wav)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Application"]
  node_main["Study Monitor<br/>win-app<br/>[StudyMonitor.cpp]"]
  node_config["Session setup<br/>session-config<br/>[StudyMonitor.cpp]"]
  node_keys(("Keyboard input<br/>control<br/>[StudyMonitor.cpp]"))
end

subgraph group_pipeline["Processing"]
  node_loop(("Frame loop<br/>capture-loop<br/>[StudyMonitor.cpp]"))
  node_face{{"Face detect<br/>vision-stage<br/>[StudyMonitor.cpp]"}}
  node_landmarks{{"Landmarks<br/>dlib-stage<br/>[StudyMonitor.cpp]"}}
  node_eyes{{"Eye state<br/>signal-stage<br/>[StudyMonitor.cpp]"}}
  node_pupil{{"Pupil focus<br/>signal-stage<br/>[StudyMonitor.cpp]"}}
  node_distance{{"Distance check<br/>signal-stage<br/>[StudyMonitor.cpp]"}}
  node_state[("Session state<br/>timers<br/>[StudyMonitor.cpp]")]
  node_alerts["Alerts<br/>feedback<br/>[StudyMonitor.cpp]"]
  node_report["Study report<br/>summary<br/>[StudyMonitor.cpp]"]
  node_ui["Status display<br/>overlay-ui<br/>[StudyMonitor.cpp]"]
end

subgraph group_deps["Dependencies"]
  node_opencv["OpenCV<br/>cv-lib"]
  node_dlib["dlib<br/>ml-lib"]
  node_winapi["Windows APIs<br/>platform-api"]
end

subgraph group_assets["Runtime files"]
  node_exe["study_helper.exe<br/>binary<br/>[study_helper.exe]"]
  node_wav1["sound.wav<br/>audio-asset<br/>[sound.wav]"]
  node_wav2["sound2.wav<br/>audio-asset<br/>[sound2.wav]"]
  node_wav3["sound3.wav<br/>audio-asset<br/>[sound3.wav]"]
end

node_exe -->|"runs"| node_main
node_config -->|"starts"| node_loop
node_keys -->|"selects"| node_config
node_loop -->|"captures"| node_opencv
node_loop -->|"analyzes"| node_face
node_face -->|"refines"| node_landmarks
node_landmarks -->|"derives"| node_eyes
node_landmarks -->|"derives"| node_pupil
node_landmarks -->|"derives"| node_distance
node_eyes -->|"updates"| node_state
node_pupil -->|"updates"| node_state
node_distance -->|"updates"| node_state
node_state -->|"renders"| node_ui
node_state -->|"triggers"| node_alerts
node_alerts -->|"plays"| node_winapi
node_alerts -->|"uses"| node_wav1
node_alerts -->|"uses"| node_wav2
node_alerts -->|"uses"| node_wav3
node_loop -->|"uses"| node_dlib
node_loop -->|"summarizes"| node_report
node_keys -->|"invokes"| node_report

click node_main "https://github.com/johnnykozman2007/studymonitor/blob/main/StudyMonitor.cpp"
click node_config "https://github.com/johnnykozman2007/studymonitor/blob/main/StudyMonitor.cpp"
click node_loop "https://github.com/johnnykozman2007/studymonitor/blob/main/StudyMonitor.cpp"
click node_face "https://github.com/johnnykozman2007/studymonitor/blob/main/StudyMonitor.cpp"
click node_landmarks "https://github.com/johnnykozman2007/studymonitor/blob/main/StudyMonitor.cpp"
click node_eyes "https://github.com/johnnykozman2007/studymonitor/blob/main/StudyMonitor.cpp"
click node_pupil "https://github.com/johnnykozman2007/studymonitor/blob/main/StudyMonitor.cpp"
click node_distance "https://github.com/johnnykozman2007/studymonitor/blob/main/StudyMonitor.cpp"
click node_state "https://github.com/johnnykozman2007/studymonitor/blob/main/StudyMonitor.cpp"
click node_alerts "https://github.com/johnnykozman2007/studymonitor/blob/main/StudyMonitor.cpp"
click node_report "https://github.com/johnnykozman2007/studymonitor/blob/main/StudyMonitor.cpp"
click node_ui "https://github.com/johnnykozman2007/studymonitor/blob/main/StudyMonitor.cpp"
click node_keys "https://github.com/johnnykozman2007/studymonitor/blob/main/StudyMonitor.cpp"
click node_opencv "https://github.com/johnnykozman2007/studymonitor/blob/main/OpenCVConfig-version.cmake"
click node_exe "https://github.com/johnnykozman2007/studymonitor/blob/main/study_helper.exe"
click node_wav1 "https://github.com/johnnykozman2007/studymonitor/blob/main/sound.wav"
click node_wav2 "https://github.com/johnnykozman2007/studymonitor/blob/main/sound2.wav"
click node_wav3 "https://github.com/johnnykozman2007/studymonitor/blob/main/sound3.wav"

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_main,node_config,node_keys toneBlue
class node_loop,node_face,node_landmarks,node_eyes,node_pupil,node_distance,node_state,node_alerts,node_report,node_ui toneAmber
class node_opencv,node_dlib,node_winapi toneMint
class node_exe,node_wav1,node_wav2,node_wav3 toneRose
```

## Components

### Application

Local Windows study-session monitor

- [Study Monitor](https://github.com/johnnykozman2007/studymonitor/blob/main/StudyMonitor.cpp): win-app · Single-process desktop app that monitors study focus in real time · `StudyMonitor.cpp`
- [Session setup](https://github.com/johnnykozman2007/studymonitor/blob/main/StudyMonitor.cpp): session-config · Starts with welcome prompt and session-length choice · `StudyMonitor.cpp`
- [Keyboard input](https://github.com/johnnykozman2007/studymonitor/blob/main/StudyMonitor.cpp): control · ESC exits; triple-space triggers report · `StudyMonitor.cpp`

### Processing

Real-time webcam analysis and session state

- [Frame loop](https://github.com/johnnykozman2007/studymonitor/blob/main/StudyMonitor.cpp): capture-loop · Continuously reads webcam frames and drives analysis · `StudyMonitor.cpp`
- [Face detect](https://github.com/johnnykozman2007/studymonitor/blob/main/StudyMonitor.cpp): vision-stage · Finds face presence in the live video stream · `StudyMonitor.cpp`
- [Landmarks](https://github.com/johnnykozman2007/studymonitor/blob/main/StudyMonitor.cpp): dlib-stage · Extracts facial landmarks from detected faces · `StudyMonitor.cpp`
- [Eye state](https://github.com/johnnykozman2007/studymonitor/blob/main/StudyMonitor.cpp): signal-stage · Classifies open vs closed eyes and tracks closure time · `StudyMonitor.cpp`
- [Pupil focus](https://github.com/johnnykozman2007/studymonitor/blob/main/StudyMonitor.cpp): signal-stage · Tracks pupil movement to detect zoning out · `StudyMonitor.cpp`
- [Distance check](https://github.com/johnnykozman2007/studymonitor/blob/main/StudyMonitor.cpp): signal-stage · Estimates whether the user is too close to the screen · `StudyMonitor.cpp`
- [Session state](https://github.com/johnnykozman2007/studymonitor/blob/main/StudyMonitor.cpp): timers · Accumulates close-eye, distance, and zoning-out durations · `StudyMonitor.cpp`
- [Alerts](https://github.com/johnnykozman2007/studymonitor/blob/main/StudyMonitor.cpp): feedback · Triggers audio and message-box warnings on focus issues · `StudyMonitor.cpp`
- [Study report](https://github.com/johnnykozman2007/studymonitor/blob/main/StudyMonitor.cpp): summary · Builds the end-of-session summary from tracked history · `StudyMonitor.cpp`
- [Status display](https://github.com/johnnykozman2007/studymonitor/blob/main/StudyMonitor.cpp): overlay-ui · Shows live face, eye, focus, and countdown status · `StudyMonitor.cpp`

### Dependencies

External libraries and platform APIs

- [OpenCV](https://github.com/johnnykozman2007/studymonitor/blob/main/OpenCVConfig-version.cmake): cv-lib · Provides camera capture, image processing, and windowing · `OpenCVConfig-version.cmake`
- **dlib**: ml-lib · Provides facial landmark detection
- **Windows APIs**: platform-api · Provides message boxes and sound playback

### Runtime files

Bundled executable and companion assets

- [study_helper.exe](https://github.com/johnnykozman2007/studymonitor/blob/main/study_helper.exe): binary · Built local executable shipped with the repo · `study_helper.exe`
- [sound.wav](https://github.com/johnnykozman2007/studymonitor/blob/main/sound.wav): audio-asset · Bundled alert sound · `sound.wav`
- [sound2.wav](https://github.com/johnnykozman2007/studymonitor/blob/main/sound2.wav): audio-asset · Bundled alert sound · `sound2.wav`
- [sound3.wav](https://github.com/johnnykozman2007/studymonitor/blob/main/sound3.wav): audio-asset · Bundled alert sound · `sound3.wav`

## Connections

- study_helper.exe → Study Monitor: runs · The packaged executable launches the application
- Session setup → Frame loop: starts · Session setup feeds the monitoring loop
- Keyboard input → Session setup: selects · Keyboard interaction chooses session length and can end early
- Frame loop → OpenCV: captures · OpenCV drives webcam acquisition and UI display
- Frame loop → Face detect: analyzes · Each frame begins with face presence detection
- Face detect → Landmarks: refines · Detected face regions are passed to landmark extraction
- Landmarks → Eye state: derives · Landmarks are used to classify eye openness
- Landmarks → Pupil focus: derives · Landmarks support pupil-motion heuristics
- Landmarks → Distance check: derives · Facial geometry supports screen-distance estimation
- Eye state → Session state: updates · Eye-closure duration is accumulated in session state
- Pupil focus → Session state: updates · Zoning-out duration is accumulated in session state
- Distance check → Session state: updates · Too-close duration is accumulated in session state
- Session state → Status display: renders · Current status and countdown are shown to the user
- Session state → Alerts: triggers · Threshold breaches emit warnings
- Alerts → Windows APIs: plays · Windows APIs handle message boxes and sound playback
- Alerts → sound.wav: uses · One of the bundled audio cues
- Alerts → sound2.wav: uses · One of the bundled audio cues
- Alerts → sound3.wav: uses · One of the bundled audio cues
- Frame loop → dlib: uses · Landmark detection depends on dlib
- Frame loop → Study report: summarizes · Session history is condensed into a study report
- Keyboard input → Study report: invokes · Triple-space gesture triggers report generation
