Skip to content

tchan102/Posturemon

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

3 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Posturemon ๐Ÿฆดโœจ

A real-time posture monitoring application with gamification elements. Uses AI-powered pose detection to help you maintain good posture while working, with a virtual pet companion that grows as you improve your habits!

Why?

In today's digital age, many people spend hours sitting in front of computers for work and entertainment. This often leads to poor posture, neck pain, and long-term health issues.

Posturemon solves this problem by:

  • ๐ŸŽฏ Monitoring your posture in real-time using your webcam
  • ๐ŸŽฎ Gamifying good posture habits with quests and achievements
  • ๐Ÿพ Providing a virtual pet companion that evolves based on your performance
  • ๐Ÿ“Š Tracking your posture statistics over time
  • โฐ Reminding you to maintain proper posture and take breaks

Features

  • Real-time Posture Detection: Uses MediaPipe and OpenCV for accurate pose estimation
  • Personalized Calibration: Set your ideal posture for customized monitoring
  • Gamification System:
    • Daily and weekly quests
    • Achievement system with unlockable rewards
    • Virtual pet that grows with your progress
    • Experience points and leveling
  • Statistics Dashboard: Track your posture performance over time
  • Session Management: Start/stop monitoring sessions with detailed logs
  • SQLite Database: Persistent storage of user data and posture logs

Tech Stack

Frontend (/posturemon)

  • Framework: Next.js 16.0.0 (React 19.2.0)
  • Language: TypeScript
  • Styling: Tailwind CSS 4.0
  • UI Components: Radix UI (tabs, progress, slots)
  • State Management: Zustand
  • API Client: Custom REST client for Flask backend

Backend (/backend)

  • Framework: Flask 3.1.2
  • Language: Python 3
  • Computer Vision:
    • OpenCV 4.12.0.88
    • MediaPipe 0.10.14 (pose detection)
  • Database: SQLite with custom ORM
  • Data Processing: NumPy, SciPy
  • Concurrency: Threading for camera management

Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                    Next.js Frontend (Port 3000)              โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”      โ”‚
โ”‚  โ”‚ Landing Page โ”‚  โ”‚  Main App    โ”‚  โ”‚   UI Store   โ”‚      โ”‚
โ”‚  โ”‚              โ”‚  โ”‚ (Tabs: Home, โ”‚  โ”‚   (Zustand)  โ”‚      โ”‚
โ”‚  โ”‚              โ”‚  โ”‚  Quest, Pet) โ”‚  โ”‚              โ”‚      โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜      โ”‚
โ”‚         โ”‚                   โ”‚                  โ”‚             โ”‚
โ”‚         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜             โ”‚
โ”‚                             โ–ผ                                โ”‚
โ”‚                   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                       โ”‚
โ”‚                   โ”‚  backend-api.ts  โ”‚                       โ”‚
โ”‚                   โ”‚  (API Client)    โ”‚                       โ”‚
โ”‚                   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                       โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”‚โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                             โ”‚ HTTP REST API
                             โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                Flask Backend (Port 5050)                     โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”      โ”‚
โ”‚  โ”‚   main.py    โ”‚  โ”‚  posture.py  โ”‚  โ”‚ database.py  โ”‚      โ”‚
โ”‚  โ”‚ (API Routes) โ”‚  โ”‚ (Pose Logic) โ”‚  โ”‚(SQLite ORM)  โ”‚      โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜      โ”‚
โ”‚         โ”‚                   โ”‚                  โ”‚             โ”‚
โ”‚         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜             โ”‚
โ”‚                             โ–ผ                                โ”‚
โ”‚                   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                       โ”‚
โ”‚                   โ”‚ Camera Thread    โ”‚                       โ”‚
โ”‚                   โ”‚ (MediaPipe +     โ”‚                       โ”‚
โ”‚                   โ”‚  OpenCV)         โ”‚                       โ”‚
โ”‚                   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                       โ”‚
โ”‚                             โ”‚                                โ”‚
โ”‚                             โ–ผ                                โ”‚
โ”‚                   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                       โ”‚
โ”‚                   โ”‚ posture_logs.db  โ”‚                       โ”‚
โ”‚                   โ”‚ (SQLite)         โ”‚                       โ”‚
โ”‚                   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                       โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                             โ–ฒ
                             โ”‚ Webcam Access
                        (Hardware)

API Endpoints

Method Endpoint Description
POST /api/camera/start Start webcam monitoring
POST /api/camera/stop Stop webcam
POST /api/camera/calibrate Calibrate ideal posture
GET /api/posture/current Get real-time posture status
GET /api/stats/today Get today's statistics
GET /api/stats/week Get 7-day statistics
POST /api/user/set Set username
GET /api/user/get Get user information
GET /api/health Health check
GET /api/status Get camera & calibration status

Setup Instructions

Prerequisites

  • Python 3.8+
  • Node.js 18+ and npm/pnpm
  • Webcam access

Backend Setup

  1. Navigate to backend directory:

    cd backend
  2. Create and activate a virtual environment:

    # Create the environment
    python3 -m venv .venv
    
    # Activate on macOS/Linux
    source .venv/bin/activate
    
    # Activate on Windows
    # .venv\Scripts\activate
  3. Install Python dependencies:

    pip install -r requirements.txt
  4. Run the Flask backend:

    python main.py

    Backend will run on http://localhost:5050

    Optional demo mode (shows OpenCV window):

    python main.py --demo

Frontend Setup

  1. Navigate to frontend directory:

    cd posturemon
  2. Install dependencies:

    npm install
    # or
    pnpm install
  3. Run the development server:

    npm run dev
    # or
    pnpm dev

    Frontend will run on http://localhost:3000

  4. Build for production:

    npm run build
    npm start

Environment Variables

Create a .env.local file in /posturemon (optional):

NEXT_PUBLIC_API_URL=http://localhost:5050

How to Use

  1. Start both backend and frontend (in separate terminals)
  2. Open browser to http://localhost:3000
  3. Click "Start Monitoring" on the home screen
  4. Calibrate your posture: Click calibrate when sitting in your ideal posture
  5. Start working! The app will monitor your posture and alert you when slouching
  6. Complete quests to earn XP and level up your virtual pet
  7. View statistics to track your progress over time

Project Structure

Posturemon/
โ”œโ”€โ”€ backend/                    # Flask API server
โ”‚   โ”œโ”€โ”€ main.py                # API routes and Flask app
โ”‚   โ”œโ”€โ”€ posture.py             # PostureChecker class (MediaPipe logic)
โ”‚   โ”œโ”€โ”€ database.py            # SQLite database wrapper
โ”‚   โ”œโ”€โ”€ requirements.txt       # Python dependencies
โ”‚   โ””โ”€โ”€ .venv/                 # Python virtual environment
โ”‚
โ”œโ”€โ”€ posturemon/                # Next.js frontend
โ”‚   โ”œโ”€โ”€ app/                   # Next.js app router
โ”‚   โ”‚   โ”œโ”€โ”€ page.tsx          # Landing page
โ”‚   โ”‚   โ””โ”€โ”€ app/page.tsx      # Main application
โ”‚   โ”œโ”€โ”€ components/            # React components
โ”‚   โ”‚   โ”œโ”€โ”€ screens/          # Tab screen components
โ”‚   โ”‚   โ”œโ”€โ”€ ui/               # Radix UI components
โ”‚   โ”‚   โ””โ”€โ”€ pet/              # Virtual pet components
โ”‚   โ”œโ”€โ”€ services/             # Business logic
โ”‚   โ”‚   โ”œโ”€โ”€ backend-api.ts    # API client
โ”‚   โ”‚   โ”œโ”€โ”€ quest-system.ts   # Quest management
โ”‚   โ”‚   โ””โ”€โ”€ achievement-system.ts
โ”‚   โ”œโ”€โ”€ store/                # Zustand state management
โ”‚   โ”œโ”€โ”€ package.json
โ”‚   โ””โ”€โ”€ next.config.ts
โ”‚
โ””โ”€โ”€ README.md

Database Schema

Users Table:

  • id (INTEGER PRIMARY KEY)
  • name (TEXT)
  • created_at (TIMESTAMP)

Posture Logs Table:

  • id (INTEGER PRIMARY KEY)
  • user_id (INTEGER)
  • timestamp (TIMESTAMP)
  • posture_quality (TEXT): "good" or "bad"
  • session_id (TEXT)

How It Works

  1. Pose Detection: MediaPipe detects 33 body landmarks from webcam feed
  2. Calibration: Users calibrate their ideal posture, storing reference angles
  3. Real-time Monitoring: Backend compares current angles to calibrated angles
  4. Threshold Detection: Alerts when slouch duration exceeds threshold
  5. Data Logging: Stores posture events in SQLite database
  6. Gamification: Frontend processes logs into quests, achievements, and pet progression

Contributing

Contributions are welcome! Feel free to open issues or submit pull requests.

License

MIT License - feel free to use this project for personal or commercial purposes.


Made with โค๏ธ to help you maintain better posture!

About

Life Changing Virtual Pet Raising Experience

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •