## Major Features - Apple Watch companion app (6 phases complete) - WatchConnectivity iPhone ↔ Watch - HealthKit integration (HR, calories) - SwiftUI premium UI - 9 complication types - Always-On Display support - Paywall screen with RevenueCat integration - Privacy Policy screen - App rebranding: tabatago → TabataFit - Bundle ID: com.millianlmx.tabatafit ## Changes - New: ios/TabataFit Watch App/ (complete Watch app) - New: app/paywall.tsx (subscription UI) - New: app/privacy.tsx (privacy policy) - New: src/features/watch/ (Watch sync hooks) - New: admin-web/ (admin dashboard) - Updated: app.json, package.json (branding) - Updated: profile.tsx (paywall + privacy links) - Updated: i18n translations (EN/FR/DE/ES) - New: app icon 1024x1024 ## Watch App Files - TabataFitWatchApp.swift (entry point) - ContentView.swift (premium UI) - HealthKitManager.swift (HR + calories) - WatchSessionManager.swift (communication) - Complications/ (WidgetKit) - UserDefaults+Shared.swift (data sharing)
6.5 KiB
6.5 KiB
TabataFit Supabase Integration
This document explains how to set up and use the Supabase backend for TabataFit.
Overview
TabataFit now uses Supabase as its backend for:
- Database: Storing workouts, trainers, collections, programs, and achievements
- Storage: Managing video files, thumbnails, and trainer avatars
- Authentication: Admin dashboard access control
- Real-time: Future support for live features
Setup Instructions
1. Create Supabase Project
- Go to Supabase Dashboard
- Create a new project
- Note your project URL and anon key
2. Configure Environment Variables
Create a .env file in the project root:
EXPO_PUBLIC_SUPABASE_URL=your_supabase_project_url
EXPO_PUBLIC_SUPABASE_ANON_KEY=your_supabase_anon_key
3. Run Database Migrations
- Go to your Supabase project's SQL Editor
- Open
supabase/migrations/001_initial_schema.sql - Run the entire script
This creates:
- All necessary tables (workouts, trainers, collections, programs, achievements)
- Storage buckets (videos, thumbnails, avatars)
- Row Level Security policies
- Triggers for auto-updating timestamps
4. Seed the Database
Run the seed script to populate your database with initial data:
npx ts-node supabase/seed.ts
This will import all 50 workouts, 5 trainers, 6 collections, 3 programs, and 8 achievements.
5. Set Up Admin User
- Go to Supabase Dashboard → Authentication → Users
- Create a new user with email/password
- Go to SQL Editor and run:
INSERT INTO admin_users (id, email, role)
VALUES ('USER_UUID_HERE', 'admin@example.com', 'admin');
Replace USER_UUID_HERE with the actual user UUID from step 2.
6. Configure Storage
In Supabase Dashboard → Storage:
- Verify buckets exist:
videos,thumbnails,avatars - Set bucket privacy to public for all three
- Configure CORS if needed for your domain
Architecture
Data Flow
┌─────────────────┐ ┌──────────────┐ ┌─────────────────┐
│ React Native │────▶│ Supabase │────▶│ PostgreSQL │
│ Client │ │ Client │ │ Database │
└─────────────────┘ └──────────────┘ └─────────────────┘
│
│ ┌──────────────┐
└──────────────▶│ Admin │
│ Dashboard │
└──────────────┘
Key Components
-
Supabase Client (
src/shared/supabase/)client.ts: Configured Supabase clientdatabase.types.ts: TypeScript definitions for tables
-
Data Service (
src/shared/data/dataService.ts)SupabaseDataService: Handles all database operations- Falls back to mock data if Supabase is not configured
-
React Hooks (
src/shared/hooks/useSupabaseData.ts)useWorkouts,useTrainers,useCollections, etc.- Automatic loading states and error handling
-
Admin Service (
src/admin/services/adminService.ts)- CRUD operations for content management
- File upload/delete for storage
- Admin authentication
-
Admin Dashboard (
app/admin/)/admin/login: Authentication screen/admin: Main dashboard with stats/admin/workouts: Manage workouts/admin/trainers: Manage trainers/admin/collections: Manage collections/admin/media: Storage management
Database Schema
Tables
| Table | Description |
|---|---|
trainers |
Trainer profiles with colors and avatars |
workouts |
Workout definitions with exercises and metadata |
collections |
Curated workout collections |
collection_workouts |
Many-to-many link between collections and workouts |
programs |
Multi-week workout programs |
program_workouts |
Link between programs and workouts with week/day |
achievements |
User achievement definitions |
admin_users |
Admin dashboard access control |
Storage Buckets
| Bucket | Purpose | Access |
|---|---|---|
videos |
Workout videos | Public read, Admin write |
thumbnails |
Workout thumbnails | Public read, Admin write |
avatars |
Trainer avatars | Public read, Admin write |
Using the App
As a User
The app works seamlessly:
- If Supabase is configured: Loads data from the cloud
- If not configured: Falls back to local mock data
As an Admin
- Navigate to
/adminin the app - Sign in with your admin credentials
- Manage content through the dashboard:
- View all workouts, trainers, collections
- Delete items (create/edit coming soon)
- Upload media files
Development
Adding New Workouts
import { adminService } from '@/src/admin/services/adminService'
await adminService.createWorkout({
title: 'New Workout',
trainer_id: 'emma',
category: 'full-body',
level: 'Beginner',
duration: 4,
calories: 45,
rounds: 8,
prep_time: 10,
work_time: 20,
rest_time: 10,
equipment: ['No equipment'],
music_vibe: 'electronic',
exercises: [
{ name: 'Jumping Jacks', duration: 20 },
// ...
],
})
Uploading Media
const videoUrl = await adminService.uploadVideo(file, 'workout-1.mp4')
const thumbnailUrl = await adminService.uploadThumbnail(file, 'workout-1.jpg')
Troubleshooting
"Supabase is not configured" Warning
This is expected if environment variables are not set. The app will use mock data.
Authentication Errors
- Verify admin user exists in
admin_userstable - Check that email/password match
- Ensure user is confirmed in Supabase Auth
Storage Upload Failures
- Verify storage buckets exist
- Check RLS policies allow admin uploads
- Ensure file size is within limits
Data Not Syncing
- Check network connection
- Verify Supabase URL and key are correct
- Check browser console for errors
Security Considerations
- Row Level Security (RLS) is enabled on all tables
- Public can only read content
- Only admin users can write content
- Storage buckets have public read access
- Storage uploads restricted to admin users
Future Enhancements
- Real-time workout tracking
- User progress sync across devices
- Offline support with local caching
- Push notifications
- Analytics and user insights