# VitFit V2 — Product Vision & Resale Strategy ## What This Product Is VitFit V2 is a gym management and coaching platform targeting two use cases simultaneously: 1. **Group gym display** — workouts, timers, and CrossFit content displayed on a TV via iPad + AirPlay (the current use case) 2. **1-on-1 coaching** — a coach manages individual client programming, scheduling, and progress through a personal portal The product is designed to be **white-labeled and resold** to gym owners, personal trainers, and fitness studios. --- ## Deployment Model Decision: Multi-Instance vs True SaaS This is the most important architectural decision before writing code. The two options: ### Option A — Multi-Instance (Recommended for V2) Each customer (gym/trainer) gets their own **separate deployment** of VitFit on their own server or a VPS provided as part of the sale. ``` Customer A: vitfit.gymA.com → Server A (their own database, files, branding) Customer B: vitfit.gymB.com → Server B (completely separate) You (seller): deploy + maintain each instance ``` **Pros:** - Complete data isolation — no cross-tenant risk - Each instance is self-contained; one customer's problem can't affect another - Simple: no multi-tenancy code, no subdomain routing - Customer owns their data/server — easier for compliance, white-labeling - Matches current architecture exactly — V1 already does this - SQLite scales fine for a single gym **Cons:** - Manual work to deploy each new customer - Updates must be pushed to each instance separately - You maintain N servers instead of 1 ### Option B — True SaaS Multi-Tenant One platform, many gyms. Each gym signs up and gets a subdomain. ``` gymA.vitfit.com ─┐ gymB.vitfit.com ─┤─ One server, shared database (with tenant_id isolation) gymC.vitfit.com ─┘ ``` **Pros:** - One codebase to update - Automatic provisioning (self-serve signup) - Scales to many customers without proportional infrastructure work **Cons:** - Requires Postgres (SQLite is not suitable for true multi-tenant SaaS) - Requires wildcard DNS, SSL, and subdomain routing - Data leakage risk if tenant isolation is imperfect - Billing/subscription integration required - Much higher development and operational complexity - Over-engineered for the current customer base ### Decision: Start with Multi-Instance, Design for SaaS **V2 will be multi-instance.** One codebase, deployed separately per customer. **However:** The data model will be designed as if it will be multi-tenant later: - Every table that belongs to an organization will have an `organizationId` column from day one - All queries will filter by `organizationId` even with only one org in the DB - When/if SaaS is needed, adding tenant routing is a surface-level change — the data model is already correct This means V2 is "SaaS-ready without being SaaS." --- ## The Organization Model Each deployed instance is owned by one **Organization** (a gym, a studio, a personal trainer's business). Within that organization: - One or more **Owners** (the person who bought the license) - One or more **Coaches** (staff, trainers) - Zero or more **Clients** (members, athletes) - One **System Admin** (the platform operator — you) See `ROLES_AND_PERMISSIONS.md` for the full role breakdown. --- ## Branding & White-Labeling Each organization can customize the look and feel through the admin panel: | Setting | Where Used | |---------|-----------| | Organization name | Page titles, login screen, emails | | Logo | Nav header, login screen, TV display | | Primary color | Buttons, active states, highlights | | Secondary color | Accents, secondary actions | | Timer display colors | Work/rest/move phase colors on TV | Branding is stored per-organization in the database. The frontend reads branding settings on load and applies them via CSS custom properties: ```js // On page load, after auth const brand = await fetch('/api/branding').then(r => r.json()); document.documentElement.style.setProperty('--color-primary', brand.primaryColor); document.documentElement.style.setProperty('--color-secondary', brand.secondaryColor); ``` This means the entire app re-themes without a page rebuild. New organizations get default VitFit branding until they customize it. **For resale:** The default branding can be set in `.env` at deploy time: ``` DEFAULT_BRAND_NAME=VitFit DEFAULT_BRAND_COLOR=#00FF88 ``` When deployed for a specific gym, these are set to their brand before first launch. The gym owner then manages their own branding through the Owner panel. --- ## Feature Tiers (Future) VitFit is structured so features can be enabled/disabled per organization via a `features` JSON column on the Organization model. This allows selling different tiers: | Feature | Tier | |---------|------| | Group display (TV workouts, timers) | Base | | Video library + upload | Base | | CrossFit workouts | Base | | 1-on-1 client management | Plus | | Client calendar + scheduling | Plus | | Audit logs | Plus | | Custom branding | All tiers | Feature flags are checked server-side (not just frontend): ```js // middleware if (!req.organization.features.includes('client-management')) { return res.sendStatus(403); } ``` This is implemented but not actively gated in V2 (all features on for all customers). The structure exists for future tiering. --- ## Current Customer Migration (V1 → V2) The existing gym has: - Multiple user accounts (Admin + Coach roles) that are shared among staff — they log in as the same accounts - No individual client accounts - No branding customization applied (uses default) **V2 migration path for current customer:** 1. One Organization is created (seeded) representing their gym 2. All existing V1 users are assigned to that Organization with their existing roles mapped (Admin → Owner/Coach, Coach → Coach) 3. The existing single shared Admin account can continue to be used as-is 4. Individual accounts are set up as staff start using their own logins 5. Clients are added when the 1-on-1 features are ready to use The gym does not need to change their workflow on day one. V2 is additive. --- ## Credential Saving (iPad Kiosk Use Case) The iPad in the gym needs to: - Auto-login on page refresh (24h cycle) without anyone touching it - Not prompt for credentials unless explicitly logged out ### Device Token Approach Standard JWT (7-day TTL) is used for session auth as today. Additionally, a **Device Token** mechanism is added for trusted devices: 1. On login, if "Remember this device" is checked (or always for the iPad), the server issues a `deviceToken` (a long-lived token, 90 days, stored in a `DeviceTokens` table) 2. The `deviceToken` is stored in localStorage separately from the session JWT 3. On page load, if the JWT is expired or missing, the app silently calls `POST /auth/device-login` with the `deviceToken` 4. Server validates the device token and issues a fresh JWT — no username/password re-entry 5. Device tokens can be revoked by an Owner/Admin (e.g., if an iPad is lost) This means the iPad essentially never needs manual re-login as long as the device token is valid and not revoked. For coach personal devices (phones, laptops) where they want to remember their credentials without a device token, a standard 30-day "remember me" JWT is offered on login. --- ## Roadmap Phases ### Phase 1 — V2 Core (current scope) - Multi-instance architecture with `organizationId` on all models - SystemAdmin, Owner, Coach roles - All V1 features rebuilt cleanly - Storage monitoring - Audit logs - Branding per org - Credential saving / device tokens ### Phase 2 — Client Features - Client role and portal - 1-on-1 workout assignment (coach → client) - Calendar and scheduling - Client-facing workout view ### Phase 3 — SaaS (if needed) - Multi-tenant routing (subdomain per org) - Postgres migration - Self-serve signup and billing - Automated provisioning