Skip to content

nuriadevs/backend-api-fitflow

Repository files navigation

Backend - FitFlow App

πŸ“˜ Disponible tambiΓ©n en EspaΓ±ol

Overview

FitFlow App is an AI-powered agent that helps users discover and get personalized workout recommendations. It uses a RAG (Retrieval-Augmented Generation) architecture with Upstash to optimize storage and semantic retrieval of workout.

The backend is built with TypeScript and Node.js, and interfaces with a MongoDB database to manage user profiles and workout data. Integrates OpenAI’s API to enable a conversational AI assistant for user interactions.

Technologies

  • Node.js: JavaScript runtime environment.

  • TypeScript: Language that builds on JavaScript

  • MongoDB: NoSQL database for storing users and exercises.

  • Upstash: RAG-based vector DB for fast semantic search.

  • OpenAI API: API KEY para poder utilizar el chat y consultar datos.

  • Jest: Testing framework for backend and route logic

Key Features

  • Authentication: User management with JWT.

  • Exercise Recommendation: Personalized search and suggestions.

  • AI Chat Assistant: Natural language interaction for workout guidance, saved directly to the user profile.

  • RAG Integration: Uses Upstash to optimize speed and accuracy in exercise-related queries.

Project Structure


backend/

  

β”œβ”€β”€ docs/ # API documentation (Swagger)

  

β”œβ”€β”€ src/ # Main source code

  

β”‚ β”œβ”€β”€ api/ # Controllers, routes, middlewares

  

β”‚ β”œβ”€β”€ config/ # App configuration

  

β”‚ β”œβ”€β”€ constants/ # Global constants

  

β”‚ β”œβ”€β”€ interfaces/ # TypeScript interfaces

  

β”‚ β”œβ”€β”€ models/ # Data models

  

β”‚ β”œβ”€β”€ responses/ # Standardized API responses

  

β”‚ β”œβ”€β”€ schemas/ # Validation schemas

  

β”‚ β”œβ”€β”€ services/ # Business logic

  

β”‚ β”œβ”€β”€ tests/ # Unit and integration tests

  

β”‚ β”œβ”€β”€ utils/ # Utility functions

  

β”œβ”€β”€ package.json # Dependencies and scripts

  

β”œβ”€β”€ tsconfig.json # TypeScript config

  

Prerequisites

  • Node.js (v16 o +)

  • npm

πŸ‹οΈβ€β™€οΈ Gym Exercises Dataset

The megaGymDataset.csv dataset located in the src/services/rag folder. This dataset contains detailed information about exercises targeting different parts of the body.

The analysis was essential for preparing the data for the RAG system (Retrieval-Augmented Generation).

πŸ“ You can view the full data analysis here:
πŸ”— Data Analysis Repository

Setup

  1. Clone the repository:
git clone https://github.com/nuriadevs/backend-api-fitflow

cd backend-api-fitflow
  1. Install dependencies:
npm install

Scripts

  • npm start: Starts the server in development mode with nodemon.

  • npm test: Runs tests using Jest.

Environment Variables

  1. Create a .env file in the root directory and define the following variables:
  

DATABASE_URL=<DATABASE_URL>

  

JWT_SECRET=<JWT_SECRET>

  

OPENAI_API_KEY=<YOUR_OPENAI_API_KEY>

  

MONGODB_URI=<MONGODB_CONNECTION_URI>

  

PORT=<SERVER_PORT>

  

CORS_ORIGIN=<ALLOWED_ORIGIN>

  

NODE_ENV=<ENVIRONMENT>

  

UPSTASH_VECTOR_REST_URL=<VECTOR_REST_URL>

  

UPSTASH_VECTOR_REST_TOKEN=<UPSTASH_TOKEN>

  
  1. You can customize additional settings in src/config/env.ts as needed.

API Documentation

API docs are available in docs/swagger.yaml. You can preview them using Swagger UI or import into Postman, Bruno,etc... .

Testing

Run tests with:

npm  test

Chat requests

You can send chat requests using the following examples:

  • Recommend exercises for biceps.

  • Recommend exercises for triceps.

  • Recommend a routine for training glutes.

Demo

backend api

Watch video demo backend

Links

Summary

  • Don't forget to create your own .env file for the variables.

  • This project is under construction...can be improved.

About

AI agent that helps users discover and get personalized workout recommendations.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published