Skip to main content
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

1

Clone the Repository

Get the FitAiid source code from your repository:
git clone <your-repo-url>
cd fitaiid
2

Install Backend Dependencies

Navigate to the backend directory and install packages:
cd backend
npm install
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
3

Configure Environment Variables

Create a .env file in the backend directory:
.env
# 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.
4

Start the Server

Run the development server:
npm run dev
You should see:
✅ Server running on port 5000
✅ MongoDB connected successfully

Your First API Request

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.

Complete Fitness Workflow

Here’s how to set up a complete fitness tracking workflow:
1

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: ''
  })
});
2

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
    }
  }
}
3

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
4

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.

Build docs developers (and LLMs) love