# wonjae1230/smart_study_monitor architecture

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

- Interactive diagram: https://gitdiagram.com/wonjae1230/smart_study_monitor
- Repository: https://github.com/wonjae1230/smart_study_monitor

## Overview

This is a study-focus monitoring system: a session is started through the server, which launches camera and environmental monitoring; sensor events update session records and can trigger push alerts. The server also exposes session, environment, camera-live, and session-history data, while a standalone ultrasonic script reports phone events. The UI source is present in the tree but was not sampled, so its interactions are not mapped. Relationships shown below are supported by the sampled server and sensor code; the ultrasonic script is not shown as server-managed.

Main entry points: [`server/app.js`](https://github.com/wonjae1230/smart_study_monitor/blob/main/server/app.js) (HTTP server and API), [`camera_detect.py`](https://github.com/wonjae1230/smart_study_monitor/blob/main/camera_detect.py) (Camera detection), [`server/public/service-worker.js`](https://github.com/wonjae1230/smart_study_monitor/blob/main/server/public/service-worker.js) (Push service worker), [`environment.py`](https://github.com/wonjae1230/smart_study_monitor/blob/main/environment.py) (Temperature sensor)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web application"]
  node_web_ui["Web interface<br/>[index.html]"]
  node_service_worker["Push service worker<br/>[service-worker.js]"]
end

subgraph group_session["Session and records"]
  node_server["HTTP server and API<br/>[app.js]"]
  node_session_api["Session lifecycle<br/>[app.js]"]
  node_sensor_api["Sensor event API<br/>[app.js]"]
  node_environment_api["Environment API<br/>[app.js]"]
  node_camera_api["Camera status API<br/>[app.js]"]
  node_history_api["Session history API<br/>[app.js]"]
  node_database[("SQLite records<br/>[app.js]")]
end

subgraph group_sensing["Sensor monitoring"]
  node_camera_detector["Camera detection<br/>[camera_detect.py]"]
  node_camera_stream["MJPEG stream<br/>[camera_detect.py]"]
  node_environment_sensor["Temperature sensor<br/>[environment.py]"]
  node_phone_sensor["Phone proximity sensor<br/>[ultrasonic.py]"]
end

subgraph group_alerts["Push notifications"]
  node_push_sender["Push delivery<br/>[app.js]"]
  node_push_service["Push service"]
end

node_user(("Study user"))

node_user -.->|"uses"| node_web_ui
node_server -->|"serves"| node_web_ui
node_server -->|"routes"| node_session_api
node_server -->|"routes"| node_sensor_api
node_server -->|"routes"| node_environment_api
node_server -->|"routes"| node_camera_api
node_server -->|"routes"| node_history_api
node_session_api -->|"reads and writes"| node_database
node_sensor_api -->|"updates"| node_database
node_environment_api -->|"stores readings"| node_database
node_history_api -->|"reads sessions"| node_database
node_session_api -->|"starts and stops"| node_camera_detector
node_session_api -->|"starts and stops"| node_environment_sensor
node_camera_detector -->|"checks session"| node_server
node_camera_detector -->|"reports events"| node_sensor_api
node_camera_detector -->|"posts live status"| node_camera_api
node_camera_detector -->|"updates frames"| node_camera_stream
node_environment_sensor -->|"posts readings"| node_environment_api
node_phone_sensor -->|"reports phone events"| node_sensor_api
node_sensor_api -->|"triggers alerts"| node_push_sender
node_session_api -->|"triggers alerts"| node_push_sender
node_push_sender -->|"loads subscriptions"| node_database
node_push_sender -->|"sends notifications"| node_push_service
node_push_service -.->|"delivers push"| node_service_worker
node_service_worker -->|"shows notification"| node_user

click node_web_ui "https://github.com/wonjae1230/smart_study_monitor/blob/main/server/public/index.html"
click node_service_worker "https://github.com/wonjae1230/smart_study_monitor/blob/main/server/public/service-worker.js"
click node_server "https://github.com/wonjae1230/smart_study_monitor/blob/main/server/app.js"
click node_session_api "https://github.com/wonjae1230/smart_study_monitor/blob/main/server/app.js"
click node_sensor_api "https://github.com/wonjae1230/smart_study_monitor/blob/main/server/app.js"
click node_environment_api "https://github.com/wonjae1230/smart_study_monitor/blob/main/server/app.js"
click node_camera_api "https://github.com/wonjae1230/smart_study_monitor/blob/main/server/app.js"
click node_history_api "https://github.com/wonjae1230/smart_study_monitor/blob/main/server/app.js"
click node_database "https://github.com/wonjae1230/smart_study_monitor/blob/main/server/app.js"
click node_camera_detector "https://github.com/wonjae1230/smart_study_monitor/blob/main/camera_detect.py"
click node_camera_stream "https://github.com/wonjae1230/smart_study_monitor/blob/main/camera_detect.py"
click node_environment_sensor "https://github.com/wonjae1230/smart_study_monitor/blob/main/environment.py"
click node_phone_sensor "https://github.com/wonjae1230/smart_study_monitor/blob/main/ultrasonic.py"
click node_push_sender "https://github.com/wonjae1230/smart_study_monitor/blob/main/server/app.js"

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_web_ui,node_service_worker,node_user toneBlue
class node_server,node_session_api,node_sensor_api,node_environment_api,node_camera_api,node_history_api,node_database toneAmber
class node_camera_detector,node_camera_stream,node_environment_sensor,node_phone_sensor toneMint
class node_push_sender,node_push_service toneRose
```

## Components

### Web application

- [Web interface](https://github.com/wonjae1230/smart_study_monitor/blob/main/server/public/index.html): `server/public/index.html`
- [Push service worker](https://github.com/wonjae1230/smart_study_monitor/blob/main/server/public/service-worker.js): `server/public/service-worker.js`

### Session and records

- [HTTP server and API](https://github.com/wonjae1230/smart_study_monitor/blob/main/server/app.js): `server/app.js`
- [Session lifecycle](https://github.com/wonjae1230/smart_study_monitor/blob/main/server/app.js): `server/app.js`
- [Sensor event API](https://github.com/wonjae1230/smart_study_monitor/blob/main/server/app.js): `server/app.js`
- [Environment API](https://github.com/wonjae1230/smart_study_monitor/blob/main/server/app.js): `server/app.js`
- [Camera status API](https://github.com/wonjae1230/smart_study_monitor/blob/main/server/app.js): `server/app.js`
- [Session history API](https://github.com/wonjae1230/smart_study_monitor/blob/main/server/app.js): `server/app.js`
- [SQLite records](https://github.com/wonjae1230/smart_study_monitor/blob/main/server/app.js): `server/app.js`

### Sensor monitoring

- [Camera detection](https://github.com/wonjae1230/smart_study_monitor/blob/main/camera_detect.py): `camera_detect.py`
- [MJPEG stream](https://github.com/wonjae1230/smart_study_monitor/blob/main/camera_detect.py): `camera_detect.py`
- [Temperature sensor](https://github.com/wonjae1230/smart_study_monitor/blob/main/environment.py): `environment.py`
- [Phone proximity sensor](https://github.com/wonjae1230/smart_study_monitor/blob/main/ultrasonic.py): `ultrasonic.py`

### Push notifications

- [Push delivery](https://github.com/wonjae1230/smart_study_monitor/blob/main/server/app.js): `server/app.js`
- **Push service**

### Other components

- **Study user**

## Connections

- Study user → Web interface: uses
- HTTP server and API → Web interface: serves (evidence: `server/app.js`)
- HTTP server and API → Session lifecycle: routes (evidence: `server/app.js`)
- HTTP server and API → Sensor event API: routes (evidence: `server/app.js`)
- HTTP server and API → Environment API: routes (evidence: `server/app.js`)
- HTTP server and API → Camera status API: routes (evidence: `server/app.js`)
- HTTP server and API → Session history API: routes (evidence: `server/app.js`)
- Session lifecycle → SQLite records: reads and writes (evidence: `server/app.js`)
- Sensor event API → SQLite records: updates (evidence: `server/app.js`)
- Environment API → SQLite records: stores readings (evidence: `server/app.js`)
- Session history API → SQLite records: reads sessions (evidence: `server/app.js`)
- Session lifecycle → Camera detection: starts and stops (evidence: `server/app.js`)
- Session lifecycle → Temperature sensor: starts and stops (evidence: `server/app.js`)
- Camera detection → HTTP server and API: checks session (evidence: `camera_detect.py`)
- Camera detection → Sensor event API: reports events (evidence: `camera_detect.py`)
- Camera detection → Camera status API: posts live status (evidence: `camera_detect.py`)
- Camera detection → MJPEG stream: updates frames (evidence: `camera_detect.py`)
- Temperature sensor → Environment API: posts readings (evidence: `environment.py`)
- Phone proximity sensor → Sensor event API: reports phone events (evidence: `ultrasonic.py`)
- Sensor event API → Push delivery: triggers alerts (evidence: `server/app.js`)
- Session lifecycle → Push delivery: triggers alerts (evidence: `server/app.js`)
- Push delivery → SQLite records: loads subscriptions (evidence: `server/app.js`)
- Push delivery → Push service: sends notifications (evidence: `server/app.js`)
- Push service → Push service worker: delivers push
- Push service worker → Study user: shows notification (evidence: `server/public/service-worker.js`)
