A real-time AI-powered desktop application that monitors user posture, detects prolonged screen time, and predicts burnout risk using computer vision and machine learning — all wrapped in a modern PyQt5 graphical interface.
- Overview
- Features
- System Architecture
- Tech Stack
- Project Structure
- Installation & Setup
- Building a Standalone Executable
- Configuration
- Usage
- Core Modules
- Database Schema
- Testing
- Troubleshooting
- Contributing
DeskGuardian is a comprehensive workplace wellness application designed to:
- Monitor Posture in Real-Time — Uses MediaPipe pose detection to track body position via webcam
- Track Screen Time — Detects prolonged continuous work sessions and suggests breaks
- Detect Work Breaks — Identifies when users step away from their desk
- Predict Burnout Risk — Uses a scikit-learn ML model to assess burnout probability based on posture, screen time, and break patterns
- Send Smart Alerts — Delivers desktop notification popups for poor posture, excessive screen time, idle detection, and high burnout risk
- User Authentication — Supports multi-user accounts with secure signup/login (hashed passwords)
- Analytics Dashboard — Interactive dashboard with charts for posture distribution, screen time trends, burnout history, and session analytics
All metrics are logged to an SQLite database for historical analysis and dashboard visualization.
- Secure signup and login system with PBKDF2-HMAC SHA-256 password hashing
- Multi-user support — each user has their own sessions, metrics, and history
- Clean login/signup UI with form validation and error feedback
- Continuous webcam monitoring using MediaPipe Pose
- Classifies posture into 4 categories: Good, Slightly Bad, Bad, Very Bad
- Angle-based classification (back and neck deviation from vertical, based on ISO 11226)
- Real-time posture metrics displayed in the monitoring window
- Tracks continuous and cumulative screen time per session
- Automatically detects breaks when user is not visible for a configurable period
- Logs break duration and frequency to the database
- Configurable screen time limits
- Pre-trained scikit-learn classifier loaded from
data/burnout_model.pkl - Generates burnout probability score (0.0–1.0)
- Risk classification: Low Risk (<0.7) and High Risk (≥0.7)
- Periodic predictive evaluations at configurable intervals
- Custom PyQt5 notification popups that slide in from the bottom-right corner
- Color-coded by alert type (posture, screen time, burnout, break, user detection)
- Auto-dismiss with fade-out animation; stackable when multiple alerts arrive
- System tray icon integration for persistent background presence
- Fully implemented PyQt5 dashboard accessible from the monitoring window
- Posture distribution charts, screen time trends, burnout assessment history
- Session-level analytics with aggregated metrics
- Auto-refreshing data at configurable intervals
- Application-wide logging to console and file (
data/deskguardian.log) - All posture, break, and alert events logged to the SQLite database
- Full session history with metrics and timestamps
┌─────────────────────────────────────────────────────────────┐
│ DeskGuardianApp (main.py) │
│ Application controller: Login → Monitoring │
└──────────────────┬──────────────────────────────┬────────────┘
│ │
┌────────▼────────┐ ┌─────────▼──────────┐
│ LoginSignupPage│ │ MonitoringWindow │
│ (modules/gui/) │ │ (modules/gui/) │
└────────┬────────┘ └───┬─────────┬──────┘
│ │ │
┌────────▼────────┐ │ ┌────▼───────┐
│ AuthService │ │ │DashboardUI │
│ (modules/auth/)│ │ │(modules/ │
└─────────────────┘ │ │ dashboard/)│
│ └────────────┘
┌────────────────────────────────┘
│
┌──────▼──────────────────────────────────────────────┐
│ Core Components (per session) │
├──────────┬──────────┬───────────┬───────────────────┤
│PoseDetect│SessionMgr│BurnoutMdl │NotificationEngine │
│(MediaPipe│(Behavior │(ML Model) │(Popups + DB Log) │
│ + OpenCV)│ Tracking)│ │ │
└────┬─────┴────┬─────┴─────┬─────┴─────┬─────────────┘
│ │ │ │
└──────────┴───────────┴───────────┘
│
┌────▼────┐
│DBManager│
│(SQLite) │
└┬────────┘
│
┌─────────▼──────────┐
│ Database File │
│(data/deskguardian) │
└────────────────────┘
| Component | Technology |
|---|---|
| Language | Python 3.10+ |
| GUI Framework | PyQt5 (login, monitoring, dashboard, notifications) |
| Computer Vision | MediaPipe Pose, OpenCV |
| ML Framework | scikit-learn (burnout model) |
| Database | SQLite3 |
| Data Processing | NumPy, Pandas |
| Visualization | Matplotlib |
| Serialization | joblib (model persistence) |
| Notifications | plyer (cross-platform desktop notifications) |
| Packaging | PyInstaller (standalone Windows executable) |
| Authentication | hashlib PBKDF2-HMAC SHA-256 |
DeskGuardian/
├── main.py # Application entry point (QApplication + tray icon)
├── requirements.txt # Python dependencies
├── DeskGuardian.spec # PyInstaller spec for building .exe
├── README.md # This file
│
├── config/
│ ├── constants.py # Thresholds, limits, timings, alert types
│ └── settings.py # Feature toggles (logging, alerts)
│
├── core/
│ ├── system_controller.py # Central orchestrator (headless/CLI mode)
│ ├── state_manager.py # System state machine
│ └── background_timer.py # Screen time and burnout check timers
│
├── database/
│ ├── db_manager.py # SQLite CRUD operations
│ ├── models.py # Data models / schemas
│ └── schema.sql # Database schema definition (6 tables)
│
├── modules/
│ ├── auth/
│ │ └── auth_service.py # User registration & login (password hashing)
│ │
│ ├── gui/
│ │ ├── login_page.py # Login / Signup PyQt5 window
│ │ ├── monitoring_window.py # Live camera feed + metrics + dashboard access
│ │ └── notification_popup.py # Slide-in desktop notification popups
│ │
│ ├── behavior_tracking/
│ │ ├── session_manager.py # Session lifecycle & integration layer
│ │ ├── screen_time_tracker.py # Screen time metrics
│ │ └── break_detector.py # Break event detection
│ │
│ ├── burnout_prediction/
│ │ ├── burnout_model.py # ML model inference
│ │ └── feature_engineering.py # Feature extraction for ML
│ │
│ ├── posture_detection/
│ │ ├── pose_detector.py # Webcam & pose landmark extraction
│ │ ├── posture_classifier.py # Angle-based posture classification
│ │ └── posture_metrics.py # Angle computation (back, neck, shoulder)
│ │
│ ├── notification/
│ │ └── notification_engine.py # Alert generation, popup dispatch, DB logging
│ │
│ └── dashboard/
│ ├── dashboard_ui.py # PyQt5 analytics dashboard
│ └── analytics_engine.py # Data aggregation for dashboard
│
├── tests/
│ ├── conftest.py # Pytest configuration
│ ├── test_analytics_engine.py # Dashboard analytics tests
│ ├── test_auth_service.py # Authentication tests
│ ├── test_break_detector.py # Break detection tests
│ ├── test_helpers.py # Utility function tests
│ ├── test_login_page_gui.py # Login page GUI tests
│ ├── test_notification_engine.py # Notification engine tests
│ └── test_posture_classifier.py # Posture classification tests
│
├── utils/
│ ├── enums.py # PostureClass, AlertType, SystemState
│ ├── helpers.py # Utility functions
│ └── logger.py # Centralized logging
│
├── data/ # Runtime data directory
│ ├── deskguardian.db # SQLite database
│ ├── deskguardian.log # Application log file
│ ├── burnout_model.pkl # Pre-trained burnout classifier
│ └── burnout_scaler.pkl # Feature scaler for burnout model
│
├── dist/ # PyInstaller output (built executable)
├── build/ # PyInstaller build artifacts
└── venv/ # Python virtual environment
- Python 3.10 or higher
- Webcam (required for pose detection)
- 20MB+ disk space (for database, logs, and ML models)
- Windows (primary target; macOS/Linux compatible with minor adjustments)
git clone https://github.com/7vik2005/DeskGuardian.git
cd DeskGuardian# On Windows
python -m venv venv
venv\Scripts\activate
# On macOS/Linux
python3 -m venv venv
source venv/bin/activatepip install -r requirements.txtpython main.pyYou should see:
- The Login / Signup window appears
- After logging in, the Monitoring Window opens with live camera feed
- Real-time posture classification and metrics displayed in the bottom bar
- Desktop notification popups appear for alerts
DeskGuardian can be packaged as a standalone Windows executable using PyInstaller:
# Install PyInstaller (if not already installed)
pip install pyinstaller
# Build using the included spec file
pyinstaller DeskGuardian.specThe built application will be available in dist/DeskGuardian/. Run DeskGuardian.exe to launch without needing a Python installation.
All configuration is centralized in the config/ directory:
Contains system-wide thresholds:
# Posture angle thresholds (degrees deviation from vertical, based on ISO 11226)
GOOD_POSTURE_MAX_BACK_ANGLE = 15
GOOD_POSTURE_MAX_NECK_ANGLE = 15
SLIGHT_BAD_POSTURE_MAX_BACK_ANGLE = 25
SLIGHT_BAD_POSTURE_MAX_NECK_ANGLE = 25
BAD_POSTURE_MAX_BACK_ANGLE = 40
BAD_POSTURE_MAX_NECK_ANGLE = 40
# Screen time & break thresholds
CONTINUOUS_SCREEN_TIME_LIMIT_MINUTES = 45 # Alert after 45 min continuous
BREAK_THRESHOLD_SECONDS = 120 # 2 min absence = break
IDLE_FACE_NOT_DETECTED_SECONDS = 60 # No-user-detected timeout
POSTURE_ALERT_THRESHOLD_SECONDS = 10 # Continuous bad posture trigger
# Burnout evaluation
BURNOUT_EVALUATION_INTERVAL_MINUTES = 30 # Check burnout every 30 min
LOW_RISK_THRESHOLD = 0.4
HIGH_RISK_THRESHOLD = 0.7Contains runtime defaults and feature toggles:
# Logging
ENABLE_LOGGING = True
LOG_LEVEL = "INFO" # DEBUG, INFO, WARNING, ERROR, CRITICAL
# Alert toggles (disable to suppress specific alert categories)
ENABLE_POSTURE_ALERTS = True
ENABLE_SCREEN_TIME_ALERTS = True
ENABLE_BURNOUT_ALERTS = TrueTo customize: Edit these files and restart the application.
python main.py- Login / Signup — Create an account or log in with existing credentials
- Monitoring Window — Live camera feed with real-time posture analysis
- Dashboard — Click the "📊 Dashboard" button to view analytics
- Logout — Click "Logout" to return to the login screen
┌────────────────────────────────────────────────────────┐
│ ● Monitoring Active Posture: Good 📊 Dashboard │
├────────────────────────────────────────────────────────┤
│ │
│ [Live Webcam Feed with Pose Overlay] │
│ │
├────────────────────────────────────────────────────────┤
│ Back Angle │ Neck Angle │ Screen Time │ Session │
│ 12.3° │ 8.7° │ 23.5 min │ 45.2 min │
└────────────────────────────────────────────────────────┘
Bottom Metrics Bar:
- Back Angle — Spine deviation from vertical (lower = better)
- Neck Angle — Head deviation from upright (lower = better)
- Screen Time — Cumulative active screen time this session
- Session — Total elapsed session time
Desktop popups appear in the bottom-right corner for:
| Alert Type | Description |
|---|---|
| 🔴 Posture Alert | Sustained bad posture detected |
| 🟡 Screen Time Alert | Continuous screen time limit exceeded |
| 🔴 Burnout Alert | High burnout risk probability (≥ 0.7) |
| 🔵 No User Detected | User absent from camera for extended period |
| 🔵 User Detected | User returned after absence |
- Click Logout to return to login
- Close the monitoring window to end the session
Purpose: Application controller and entry point
- Creates the
QApplicationand system tray icon - Manages the Login → Monitoring → Logout lifecycle
- Handles transitions between windows
Purpose: User registration and authentication
signup(username, password, age, occupation)— Register a new user with hashed passwordlogin(username, password)— Authenticate against stored credentials- Uses PBKDF2-HMAC SHA-256 with random salt for password hashing
Purpose: Main monitoring interface with embedded camera feed
- Runs the pose detection loop via
QTimer(~15 FPS) - Displays real-time posture classification, angle metrics, screen time
- Triggers posture, screen time, burnout, and idle alerts
- Provides dashboard access and logout functionality
Purpose: Real-time pose detection and classification
process_frame()— Captures webcam frame, detects landmarks, classifies posture- Returns
(frame, posture_class, alert_triggered, back_angle, neck_angle)
Purpose: Tracks session lifecycle and integrates behavior metrics
start_session()/end_session()— Session lifecycle managementupdate(posture_class, alert_triggered, face_detected)— Per-frame metrics processing- Internally uses
ScreenTimeTrackerandBreakDetector
Purpose: ML-based burnout risk assessment
predict_burnout(total_screen_time_min, bad_posture_count, ...)— Returns probability (0.0–1.0)- Pre-trained model loaded from
data/burnout_model.pklwith scaler fromdata/burnout_scaler.pkl
Purpose: Generate alerts via desktop popups and log to database
send_posture_alert(session_id, duration)— Bad posture notificationsend_screen_time_alert(session_id, minutes)— Screen time notificationsend_burnout_alert(session_id, assessment_id, probability)— Burnout risk notificationsend_no_user_detected_alert(session_id, seconds)— Idle detection notificationsend_user_detected_notification(session_id)— User return notification
Purpose: Interactive analytics dashboard
- Posture distribution charts, screen time trends, burnout history
- Session-level metrics with aggregated data
- Auto-refreshing at configurable intervals
SQLite database with 6 core tables (defined in database/schema.sql):
CREATE TABLE User (
user_id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL UNIQUE,
password_hash TEXT NOT NULL,
age INTEGER NOT NULL CHECK(age > 0),
occupation TEXT,
preferences_json TEXT
);CREATE TABLE Session (
session_id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id INTEGER NOT NULL,
start_time DATETIME NOT NULL,
end_time DATETIME,
total_screen_time_minutes INTEGER DEFAULT 0,
total_break_time_minutes INTEGER DEFAULT 0,
bad_posture_count INTEGER DEFAULT 0,
FOREIGN KEY(user_id) REFERENCES User(user_id) ON DELETE CASCADE
);CREATE TABLE PostureEvent (
event_id INTEGER PRIMARY KEY AUTOINCREMENT,
session_id INTEGER NOT NULL,
timestamp DATETIME NOT NULL,
posture_class TEXT NOT NULL, -- 'Good', 'Slightly Bad', 'Bad', 'Very Bad'
back_angle REAL,
neck_angle REAL,
shoulder_alignment REAL,
is_alert_triggered BOOLEAN DEFAULT 0,
FOREIGN KEY(session_id) REFERENCES Session(session_id) ON DELETE CASCADE
);CREATE TABLE BreakEvent (
break_id INTEGER PRIMARY KEY AUTOINCREMENT,
session_id INTEGER NOT NULL,
start_time DATETIME NOT NULL,
end_time DATETIME NOT NULL,
duration_minutes REAL NOT NULL CHECK(duration_minutes > 0),
break_type TEXT DEFAULT 'Short Break',
FOREIGN KEY(session_id) REFERENCES Session(session_id) ON DELETE CASCADE
);CREATE TABLE BurnoutAssessment (
assessment_id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id INTEGER NOT NULL,
interval_start DATETIME NOT NULL,
interval_end DATETIME NOT NULL,
burnout_probability REAL NOT NULL, -- 0.0 to 1.0
avg_screen_time_per_day REAL,
avg_bad_posture_per_hour REAL,
avg_breaks_per_hour REAL,
FOREIGN KEY(user_id) REFERENCES User(user_id) ON DELETE CASCADE
);CREATE TABLE Alert (
alert_id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id INTEGER NOT NULL,
session_id INTEGER,
assessment_id INTEGER,
alert_time DATETIME NOT NULL,
alert_type TEXT NOT NULL, -- 'POSTURE_ALERT', 'SCREEN_TIME_ALERT', etc.
message TEXT NOT NULL,
resolved BOOLEAN DEFAULT 0,
FOREIGN KEY(user_id) REFERENCES User(user_id) ON DELETE CASCADE
);DeskGuardian includes a test suite located in tests/. Run all tests with:
pytest tests/ -v| Test File | Covers |
|---|---|
test_auth_service.py |
Signup, login, password hashing |
test_posture_classifier.py |
Posture classification logic |
test_break_detector.py |
Break detection events |
test_notification_engine.py |
Alert generation and logging |
test_analytics_engine.py |
Dashboard data aggregation |
test_login_page_gui.py |
Login page GUI tests |
test_helpers.py |
Utility function tests |
Cause: Camera not detected or already in use
Solution:
- Check device manager for connected camera
- Close other applications using the camera
- Restart the application
- Try USB camera if built-in doesn't work
Cause: Posture angle thresholds too strict
Solution:
- Open the monitoring window and check the angle values in the bottom bar
- Adjust thresholds in
config/constants.py:GOOD_POSTURE_MAX_BACK_ANGLE = 20 # Increase from 15 GOOD_POSTURE_MAX_NECK_ANGLE = 20
- Restart the application
Cause: Alerts may be disabled in config
Solution: Check config/settings.py:
ENABLE_POSTURE_ALERTS = True
ENABLE_SCREEN_TIME_ALERTS = True
ENABLE_BURNOUT_ALERTS = TrueCause: Multiple instances running or improper shutdown
Solution:
- Close all running instances
- Delete
data/deskguardian.dbto reset - Restart application
Cause: Missing dependencies or incomplete installation
Solution:
pip install --upgrade -r requirements.txtCause: Missing hidden imports or data files
Solution:
- Ensure all dependencies are installed in your virtual environment
- Verify
data/burnout_model.pklanddata/burnout_scaler.pklexist - Run with
--debugfor more details:pyinstaller DeskGuardian.spec --debug
- PEP 8 compliance for formatting
- Type hints where practical
- Docstrings for all classes and key methods
- Create a branch:
git checkout -b feature/my-feature - Implement changes with tests
- Update README if user-facing
- Run tests:
pytest tests/ -v - Commit:
git commit -m "feat: description" - Push:
git push origin feature/my-feature - Create Pull Request
Please include:
- Python version:
python --version - OS: Windows/macOS/Linux
- Steps to reproduce
- Error message and logs (
data/deskguardian.log)
This project is licensed under the MIT License. See LICENSE file for details.
- Satvik — Lead Developer
For questions or issues, please:
- Check the Troubleshooting section
- Review logs in
data/deskguardian.log - Open an issue on GitHub
Last Updated: March 31, 2026 Version: 2.0.0