A RESTful API for a workout tracker application that allows users to sign up, log in, create workout plans, and track their progress.
- User authentication with JWT
- Exercise management
- Workout plan creation and management
- Workout scheduling
- Workout completion tracking
- Progress reporting
- Node.js with Express
- TypeScript
- PostgreSQL database
- Prisma ORM
- JWT for authentication
- Jest for testing
- Node.js (v20 or higher)
- PostgreSQL database
-
Clone the repository
-
Install dependencies:
npm install -
Configure environment variables:
- Copy
.env.exampleto.env(if not already done) - Update the
DATABASE_URLwith your PostgreSQL connection string - Set a secure
JWT_SECRET
- Copy
-
Run the setup script to initialize the database and start the server:
node setup-and-run.jsThis script will:
- Create database migrations
- Seed the database with exercise data
- Build the TypeScript code
- Start the server
POST /api/auth/register- Register a new userPOST /api/auth/login- Login a user
GET /api/exercises- Get all exercisesGET /api/exercises/:id- Get exercise by IDGET /api/exercises/categories- Get all exercise categoriesGET /api/exercises/muscle-groups- Get all muscle groups
POST /api/workouts- Create a new workout planGET /api/workouts- Get all workout plans for the authenticated userGET /api/workouts/:id- Get workout plan by IDPUT /api/workouts/:id- Update workout planDELETE /api/workouts/:id- Delete workout plan
POST /api/schedule- Schedule a workoutGET /api/schedule- Get scheduled workoutsPOST /api/schedule/complete- Mark a workout as completedGET /api/schedule/completed- Get completed workouts
GET /api/reports- Generate workout reports
Run tests with:
npm test
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:
- Check that your PostgreSQL server is running
- Verify the connection details in your
.envfile - Ensure special characters in your password are properly URL-encoded
- Make sure the database exists (create it if needed)
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 is available using OpenAPI Specification. After starting the server, you can access the documentation at:
http://localhost:3000/api-docs
This project is licensed under the MIT License.