fitaiProto/docs/FITNESS_PROFILE.md
echo b9f33fdcc6 fitness profile
functionality added, need polishing
2025-11-11 02:16:29 +01:00

217 lines
4.9 KiB
Markdown

# Fitness Profile Feature
## Overview
The Fitness Profile feature allows mobile app users to create and manage their personal fitness information, including physical metrics, fitness goals, activity levels, and health-related information.
## Features
- **Basic Information**: Height, weight, age, and gender
- **Fitness Goals**: Primary fitness goal and activity level
- **Health Information**: Medical conditions, allergies, and injuries
- **Auto-save**: Automatically updates existing profile or creates new one
- **Persistent Storage**: Data saved to SQLite database
## Database Schema
The fitness profile is stored in the `fitness_profiles` table with the following structure:
```sql
CREATE TABLE fitness_profiles (
id TEXT PRIMARY KEY,
user_id TEXT NOT NULL UNIQUE,
height REAL, -- in cm
weight REAL, -- in kg
age INTEGER,
gender TEXT, -- male, female, other, prefer_not_to_say
fitness_goal TEXT, -- weight_loss, muscle_gain, endurance, flexibility, general_fitness
activity_level TEXT, -- sedentary, lightly_active, moderately_active, very_active, extremely_active
medical_conditions TEXT,
allergies TEXT,
injuries TEXT,
created_at INTEGER NOT NULL,
updated_at INTEGER NOT NULL,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
);
```
## Mobile App Implementation
### Location
- Screen: `apps/mobile/src/app/fitness-profile.tsx`
- Components:
- `apps/mobile/src/components/Input.tsx`
- `apps/mobile/src/components/Picker.tsx`
### Navigation
Accessible from the home screen's "Quick Actions" section with a "Fitness Profile" button.
### User Flow
1. User taps "Fitness Profile" from Quick Actions
2. App fetches existing profile (if any) from API
3. User fills in or updates fitness information
4. User taps "Save Profile"
5. Data is saved to database via API
6. User receives success confirmation and returns to home screen
## API Endpoints
### GET `/api/fitness-profile`
Fetches the authenticated user's fitness profile.
**Authentication**: Required (Clerk Bearer token)
**Response**:
```json
{
"profile": {
"id": "fp_...",
"userId": "user_...",
"height": 175,
"weight": 70,
"age": 25,
"gender": "male",
"fitnessGoal": "muscle_gain",
"activityLevel": "moderately_active",
"medicalConditions": "None",
"allergies": "Peanuts",
"injuries": "Previous knee injury",
"createdAt": 1234567890000,
"updatedAt": 1234567890000
}
}
```
### POST `/api/fitness-profile`
Creates or updates the authenticated user's fitness profile.
**Authentication**: Required (Clerk Bearer token)
**Request Body**:
```json
{
"height": 175,
"weight": 70,
"age": 25,
"gender": "male",
"fitnessGoal": "muscle_gain",
"activityLevel": "moderately_active",
"medicalConditions": "None",
"allergies": "Peanuts",
"injuries": "Previous knee injury"
}
```
**Response** (Create):
```json
{
"message": "Fitness profile created successfully",
"profileId": "fp_..."
}
```
**Response** (Update):
```json
{
"message": "Fitness profile updated successfully",
"profileId": "fp_..."
}
```
## Field Options
### Gender
- Male
- Female
- Other
- Prefer not to say
### Fitness Goals
- Weight Loss
- Muscle Gain
- Endurance
- Flexibility
- General Fitness
### Activity Levels
- Sedentary
- Lightly Active
- Moderately Active
- Very Active
- Extremely Active
## Environment Variables
For mobile app to connect to the admin API:
```env
EXPO_PUBLIC_API_URL=http://localhost:3000 # Development
EXPO_PUBLIC_API_URL=https://your-domain.com # Production
```
## Testing
### Manual Testing
1. **Create Profile**:
- Open mobile app and sign in
- Navigate to home screen
- Tap "Fitness Profile" in Quick Actions
- Fill in fitness information
- Tap "Save Profile"
- Verify success message
2. **Update Profile**:
- Return to Fitness Profile screen
- Verify existing data is loaded
- Modify some fields
- Tap "Save Profile"
- Verify success message
3. **Persistence**:
- Close and reopen app
- Navigate to Fitness Profile
- Verify data persists
### Database Verification
```bash
# View fitness profiles in database
cd apps/admin
npm run db:studio
# Navigate to fitness_profiles table
```
## Future Enhancements
- [ ] BMI calculation and display
- [ ] Progress tracking over time
- [ ] Integration with workout plans based on fitness goals
- [ ] Trainer access to client fitness profiles
- [ ] Health metrics charts and trends
- [ ] Photo upload for progress tracking
- [ ] Export fitness data
## Dependencies
### Mobile App
- `@react-native-picker/picker`: For dropdown selectors
- `@clerk/clerk-expo`: For authentication
- `expo-router`: For navigation
### Admin API
- `better-sqlite3`: For database operations
- `@clerk/nextjs/server`: For authentication verification
## Migration
To apply the database schema changes:
```bash
cd packages/database
npm run db:push
```
This will create the `fitness_profiles` table in the SQLite database.