# VitFit V2 — Requirements ## Context VitFit is a gym coaching tool. The primary runtime environment is: - A dedicated iPad running Safari full-screen - That iPad's screen is AirPlay-mirrored to a VIZIO TV via AirPlay 24/7 - The browser is only refreshed once every ~24 hours - iPads are never restarted; the app runs continuously The server is a Linux machine (Ubuntu 24.04.1 LTS, 2 CPU, 4 GB RAM). Server is accessed remotely only — via **PuTTY** (SSH) and **WinSCP** (SFTP). There is no local terminal or file manager access. **Server paths:** - App root: `/home/ubuntu/site/` - Frontend pages: `/home/ubuntu/site/public/` - Video uploads: `/home/ubuntu/site/uploads/` ← **outside public, must stay here** --- ## Functional Requirements ### Must Carry Over from V1 | Feature | Notes | |---------|-------| | Video workouts | Up to N videos with rep counts and a scheduled date | | Interval timers | Configurable work/rest/move phases, multiple sets/exercises/laps | | CrossFit workouts | Free-text workout items, ordered list | | Video library | Upload, categorize, browse, delete exercise videos | | User accounts | Admin and Coach roles | | Admin panel | User management, role changes, password reset, logo upload | | JWT authentication | Must survive a 24-hour session without expiry forcing re-login | ### New Requirements - **Workout display mode** — A full-screen, high-contrast view designed to be read from across a gym on a TV. Separate from the management/control UI. - **Stable long-running timer** — Timer execution must not drift, stop, or glitch during a multi-hour session. Must survive the iPad going to sleep/wake if AirPlay connection is maintained. - **Session persistence** — If the page can't be refreshed for 24h, the app must not lose state. No forced logouts mid-session. - **Modular feature system** — New features can be added as self-contained modules without touching existing code. Deployed live. - **Secure by default** — No open registration endpoint. All user creation is admin-gated. - **Future iOS app compatibility** — API must be clean REST so a native iOS client can consume it without changes. - **Storage monitoring in admin panel** — Admin panel must display total disk space, used space, available space, and uploads folder size. Must prevent admins from filling the drive by showing a clear warning when storage is low. Upload endpoint must refuse new files when available space falls below a configurable threshold. --- ## Non-Functional Requirements ### Stability - The app must run continuously without memory leaks degrading performance over 24h+ - All JavaScript intervals and event listeners must be properly cleaned up - WebSocket connections must auto-reconnect on drop (no user interaction needed) - Server process must be managed by PM2 with auto-restart on crash - Server must recover from reboot automatically (PM2 startup config) ### Performance - Page load (initial, after the 24h refresh) must be under 3 seconds on wifi - Timer UI must update at exactly 1-second intervals without drift - Server resource usage must stay well under the 4 GB RAM / 2 CPU ceiling - No memory bloat from video elements left in DOM — properly destroy players when not in view ### Security - JWT secret must come from an environment variable, never hardcoded - All user creation is admin-only (no open `/register`) - Passwords hashed with bcrypt (already in V1, maintain) - HTTPS required — use nginx + Let's Encrypt on the server - Input validation on all API routes (backend, not just frontend) - Rate limiting on login endpoint to prevent brute force - Security headers via helmet.js - Video uploads: validate MIME type server-side, not just file extension ### Reliability - Database writes must be transactional where multiple tables are affected - Soft deletes or confirmation guards for destructive actions (videos, workouts) - Health check endpoint (`/health`) for monitoring ### Browser/Platform Compatibility - Must work correctly in Safari on iPadOS (primary target) - Must work in Safari on macOS (admin use) - Chrome desktop support is a nice-to-have, not required - No features that require browser permissions Safari doesn't support (e.g., no background JS execution assumptions) --- ## Constraints ### Hardware - Server: Ubuntu 24.04.1 LTS, 2 vCPU, 4 GB RAM - SQLite is acceptable at this scale (single gym, small team) - No Redis, no Postgres required — keep the stack lean - Disk space is limited — storage monitoring is a first-class feature, not an afterthought ### Server Access - SSH only (PuTTY), SFTP only (WinSCP) — no control panel, no local access - All deployments are manual file transfers via WinSCP + SSH commands - No CI/CD pipeline; no automated deployment assumed ### Data - V1 database must be migrated, not abandoned - All existing workouts, videos, categories, timers, and users must survive the migration - Schema changes must go through migration scripts (not `sync({ force: true })`) - **Video files at `/home/ubuntu/site/uploads/` must not move** — re-uploading is not an option - V2 must serve video files from this path via an authenticated route (not static middleware) ### Development - Code must be modular: each feature is a self-contained unit (routes + frontend + migrations) - Adding a new feature = dropping in a new module folder + registering it; no other files changed - Removing a feature = removing the module folder; no orphaned code left behind --- ## Out of Scope for V2 - Native iOS app (future phase — but API compatibility must be maintained) - Push notifications - Multi-gym / multi-tenant support - Billing or subscriptions - Video streaming from external providers (YouTube, Vimeo)