FitAiid is an AI-powered fitness platform that provides personalized workout routines, real-time tracking, and gamified achievements.
Prerequisites
Before you begin, ensure you have:
Node.js 16+
Required for running the backend server
MongoDB
Database for storing user data and workouts
Firebase Account
For Google OAuth authentication
OpenAI API Key
For AI-powered workout generation
Installation
Clone the Repository
Get the FitAiid source code from your repository:git clone <your-repo-url>
cd fitaiid
Install Backend Dependencies
Navigate to the backend directory and install packages:
The project includes these key dependencies:
express - Web framework
mongoose - MongoDB ODM
bcryptjs - Password hashing
jsonwebtoken - JWT authentication
openai - AI workout generation
firebase-admin - Google authentication
web-push - Push notifications
nodemailer - Email verification
Configure Environment Variables
Create a .env file in the backend directory:# Server
PORT=5000
NODE_ENV=development
# Database
MONGO_URI=mongodb://localhost:27017/fitaiid
# JWT
JWT_SECRET=your_super_secret_jwt_key_here
JWT_EXPIRE=30d
# OpenAI
OPENAI_API_KEY=sk-your-openai-api-key
# Firebase Admin SDK
FIREBASE_PROJECT_ID=your-project-id
FIREBASE_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\n..."
FIREBASE_CLIENT_EMAIL=[email protected]
# Email (Nodemailer)
EMAIL_HOST=smtp.gmail.com
EMAIL_USER=[email protected]
EMAIL_PASS=your-app-password
# Web Push (VAPID Keys)
VAPID_PUBLIC_KEY=your-vapid-public-key
VAPID_PRIVATE_KEY=your-vapid-private-key
VAPID_SUBJECT=mailto:[email protected]
Never commit your .env file to version control. Keep your API keys secure.
Start the Server
Run the development server:You should see:✅ Server running on port 5000
✅ MongoDB connected successfully
Your First API Request
Register a User
Login
Google OAuth
Create a new user account with email verification:const response = await fetch('http://localhost:5000/api/auth/register-with-code', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
firstName: 'John',
lastName: 'Doe',
email: '[email protected]',
password: 'SecurePass123',
phone: '1234567890'
})
});
const data = await response.json();
console.log(data);
// { success: true, message: 'Código de verificación enviado a tu correo', email: '[email protected]' }
The user receives a 6-digit verification code via email. Use the /api/auth/verify-registration endpoint to complete registration.
Authenticate and receive a JWT token:const response = await fetch('http://localhost:5000/api/auth/login', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
email: '[email protected]',
password: 'SecurePass123'
})
});
const data = await response.json();
console.log(data);
Response:{
"success": true,
"message": "Login exitoso",
"data": {
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"user": {
"id": "507f1f77bcf86cd799439011",
"firstName": "John",
"lastName": "Doe",
"email": "[email protected]",
"role": "customer",
"fitnessProfile": {
"questionnaireCompleted": false
}
}
}
}
Save the JWT token for subsequent API requests. Include it in the Authorization header as Bearer <token>.
Register or login using Google authentication:// For new users - Registration
const registerResponse = await fetch('http://localhost:5000/api/auth/google-register', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
firstName: 'John',
lastName: 'Doe',
email: '[email protected]',
uid: 'firebase-uid-from-google'
})
});
// For existing users - Login
const loginResponse = await fetch('http://localhost:5000/api/auth/google', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
email: '[email protected]',
uid: 'firebase-uid-from-google'
})
});
Complete Fitness Workflow
Here’s how to set up a complete fitness tracking workflow:
Complete Fitness Profile
After registration, users should complete their fitness profile:const token = 'your-jwt-token';
const response = await fetch('http://localhost:5000/api/questionnaire/submit', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${token}`
},
body: JSON.stringify({
userId: '507f1f77bcf86cd799439011',
gender: 'hombre',
age: 28,
height: 175,
weight: 75,
fitnessLevel: 'intermedio',
mainGoal: 'tonificar',
trainingLocation: 'gym',
trainingDaysPerWeek: 4,
sessionDuration: '1 hr',
medicalConditions: ''
})
});
Get Daily Workout
Retrieve the current day’s workout from the AI-generated routine:const response = await fetch(`http://localhost:5000/api/rutina/${userId}/dia-actual`, {
method: 'GET',
headers: {
'Authorization': `Bearer ${token}`
}
});
const workout = await response.json();
Response:{
"success": true,
"data": {
"diaActual": {
"indice": 0,
"nombre": "lunes",
"enfoque": "Pecho y Tríceps",
"duracionTotal": 60,
"caloriasEstimadas": 450,
"ejercicios": [
{
"nombre": "Press de banca",
"series": 4,
"repeticiones": "8-10",
"descanso": "90 segundos",
"musculoObjetivo": "Pecho",
"completado": false
}
]
},
"progreso": {
"cicloActual": 1,
"diaActualIndex": 0,
"diasCompletadosEsteCiclo": 0
}
}
}
Complete Workout
Mark the workout as complete and advance to the next day:const response = await fetch(`http://localhost:5000/api/rutina/${userId}/completar-dia`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${token}`
},
body: JSON.stringify({
duracion: 60,
calorias: 450,
ejerciciosCompletados: 6
})
});
This automatically:
- Records the workout in your history
- Updates your statistics (total workouts, calories, minutes)
- Calculates your current streak
- Checks and unlocks achievements
- Advances to the next workout day
View Statistics
Get comprehensive fitness statistics:const response = await fetch(`http://localhost:5000/api/estadisticas/${userId}`, {
method: 'GET',
headers: {
'Authorization': `Bearer ${token}`
}
});
Response includes:
- Total workouts completed
- Total exercises and minutes
- Calories burned
- Current and max streak
- Unlocked achievements
- Recent workout history
Authentication Flow
// Step 1: Register with email
const registerResponse = await fetch('/api/auth/register-with-code', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
firstName: 'John',
lastName: 'Doe',
email: '[email protected]',
password: 'SecurePass123'
})
});
// Step 2: Verify with code from email
const verifyResponse = await fetch('/api/auth/verify-registration', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
email: '[email protected]',
code: '123456' // Code received via email
})
});
const { token, user } = await verifyResponse.json();
Next Steps
Explore Features
Learn about all 8 core features of FitAiid
API Reference
Browse complete API documentation
AI Workouts
Understand the AI workout generation
Push Notifications
Set up real-time push notifications
For production deployment, see the DEPLOYMENT_MANUAL.md file in your source repository for detailed instructions on hosting, security, and scaling.