Skip to content

The Fitness Tracker API is a RESTful API designed to help users manage their fitness activities. It supports user authentication, exercise management, workout planning, scheduling, and progress tracking. Built with Node.js, TypeScript, Express, and PostgreSQL, it leverages Prisma ORM for database operations and provides comprehensive API documentat

Notifications You must be signed in to change notification settings

tukue/fitness-tracker-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Workout Tracker API

A RESTful API for a workout tracker application that allows users to sign up, log in, create workout plans, and track their progress.

Features

  • User authentication with JWT
  • Exercise management
  • Workout plan creation and management
  • Workout scheduling
  • Workout completion tracking
  • Progress reporting

Tech Stack

  • Node.js with Express
  • TypeScript
  • PostgreSQL database
  • Prisma ORM
  • JWT for authentication
  • Jest for testing

Prerequisites

  • Node.js (v20 or higher)
  • PostgreSQL database

Getting Started

  1. Clone the repository

  2. Install dependencies:

    npm install
    
  3. Configure environment variables:

    • Copy .env.example to .env (if not already done)
    • Update the DATABASE_URL with your PostgreSQL connection string
    • Set a secure JWT_SECRET
  4. Run the setup script to initialize the database and start the server:

    node setup-and-run.js
    

    This script will:

    • Create database migrations
    • Seed the database with exercise data
    • Build the TypeScript code
    • Start the server

API Endpoints

Authentication

  • POST /api/auth/register - Register a new user
  • POST /api/auth/login - Login a user

Exercises

  • GET /api/exercises - Get all exercises
  • GET /api/exercises/:id - Get exercise by ID
  • GET /api/exercises/categories - Get all exercise categories
  • GET /api/exercises/muscle-groups - Get all muscle groups

Workout Plans

  • POST /api/workouts - Create a new workout plan
  • GET /api/workouts - Get all workout plans for the authenticated user
  • GET /api/workouts/:id - Get workout plan by ID
  • PUT /api/workouts/:id - Update workout plan
  • DELETE /api/workouts/:id - Delete workout plan

Workout Scheduling

  • POST /api/schedule - Schedule a workout
  • GET /api/schedule - Get scheduled workouts
  • POST /api/schedule/complete - Mark a workout as completed
  • GET /api/schedule/completed - Get completed workouts

Reports

  • GET /api/reports - Generate workout reports

Testing

Run tests with:

npm test

Database Connection Testing

Test your database connection with:

npm run test:db

This will verify that your application can connect to the PostgreSQL database using the connection string in your .env file.

If you need to troubleshoot database connection issues:

  1. Check that your PostgreSQL server is running
  2. Verify the connection details in your .env file
  3. Ensure special characters in your password are properly URL-encoded
  4. Make sure the database exists (create it if needed)

Sample Data

To populate your database with sample data for testing:

npm run seed:sample

This will create sample users, workout plans, exercises, and workout records.

API Documentation

API documentation is available using OpenAPI Specification. After starting the server, you can access the documentation at:

http://localhost:3000/api-docs

License

This project is licensed under the MIT License.

About

The Fitness Tracker API is a RESTful API designed to help users manage their fitness activities. It supports user authentication, exercise management, workout planning, scheduling, and progress tracking. Built with Node.js, TypeScript, Express, and PostgreSQL, it leverages Prisma ORM for database operations and provides comprehensive API documentat

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published