Skip to content

Repository files navigation

πŸ’ͺ Trainify API

A REST API for the Trainify app to manage workouts, exercises, sessions, metrics and user progress.

last-commit repo-top-language repo-language-count

πŸ“ƒ AboutΒ Β β€’Β Β  πŸ› οΈ Tech StackΒ Β β€’Β Β  ✨ FeaturesΒ Β β€’Β Β  πŸš€ Getting StartedΒ Β β€’Β Β  πŸ“– API DocumentationΒ Β β€’Β Β  πŸ§ͺ Tests


πŸ“ƒ About

Trainify API is the backend of the Trainify app, responsible for providing a REST layer to register and track workouts. The application allows managing exercises, creating and finishing workout sessions, logging weight, tracking metrics, and consuming progress data through a well-organized modular structure.

The project was built with Fastify, TypeScript, Prisma ORM and PostgreSQL, with a focus on performance, strong typing, hardened security and interactive documentation via Scalar.


πŸ› οΈ Tech Stack

  • 🟒 Node.js β€” Server-side JavaScript runtime.
  • ⚑ Fastify β€” Fast and efficient web framework.
  • πŸ”· TypeScript β€” Static typing and safer development.
  • πŸ—ƒοΈ Prisma ORM β€” Modern, type-safe ORM for relational databases.
  • 🐘 PostgreSQL β€” Robust relational database.
  • 🐳 Docker β€” Containerization of the local database.
  • πŸ” @fastify/jwt β€” JWT authentication.
  • πŸͺ @fastify/cookie β€” Cookie parsing and management.
  • 🌐 @fastify/cors β€” CORS handling.
  • πŸ›‘οΈ @fastify/helmet β€” Security headers for HTTP responses.
  • 🚦 @fastify/rate-limit β€” Request rate limiting.
  • πŸ“– @fastify/swagger + @scalar/fastify-api-reference β€” Interactive API documentation.
  • πŸ”‘ bcrypt β€” Password hashing.
  • πŸ“… dayjs β€” Lightweight date manipulation.
  • 🧩 Zod β€” Runtime schema validation with full type inference.
  • πŸ“¦ tsup β€” Bundler for building the production output.
  • πŸ§ͺ Vitest β€” Automated testing.
  • πŸ” Biome β€” Fast, opinionated linter and formatter.

✨ Features

  • πŸ‹οΈ Exercise management (catalog and custom exercises)
  • πŸ—“οΈ Workout creation, plans and weekly scheduling
  • ⏱️ Starting, pausing and finishing workout sessions
  • πŸ“ Exercise log tracking and session history
  • πŸ“Š Performance comparisons (weekly, monthly and per exercise)
  • βš–οΈ Weight logging, weight goals and analytics
  • πŸ“ˆ Overall user metrics and progress
  • πŸ† Gamification module: streaks, badges and achievements
  • πŸ” JWT authentication and Google sign-in
  • πŸ›‘οΈ Security hardening with Helmet and rate limiting
  • 🧩 Data validation with Zod
  • πŸ“– Interactive API documentation with Scalar
  • πŸ§ͺ Automated testing with Vitest

πŸš€ Getting Started

πŸ“‹ Prerequisites

πŸ”§ Installation

  1. Clone the repository:

    git clone https://github.com/joschonarth/trainify-api.git
  2. Navigate into the project:

    cd trainify-api
  3. Install dependencies:

    npm install

πŸ”‘ Environment Variables

Copy the example env file and fill in your values:

cp .env.example .env

Example content:

NODE_ENV=dev
PORT=3333
JWT_SECRET=your_jwt_secret
DATABASE_URL="postgresql://docker:docker@localhost:5432/trainify?schema=public"

🐳 Database

Start the PostgreSQL container:

docker compose up -d

Run the Prisma migrations:

npm run migrate

Optionally, seed the database with sample data:

npm run seed

▢️ Running

Start the server in development mode:

npm run dev

API running at http://localhost:3333


πŸ“– API Documentation

With the server running, access the interactive documentation at:

There is also a health check endpoint available at:


πŸ§ͺ Tests

Tests are run with Vitest and cover the main application flows.

# Run all tests
npm run test

# Run tests in watch mode
npm run test:watch

# Generate coverage report
npm run test:coverage

πŸ“ Project Structure

src/
  modules/
    exercise/
    gamification/
    metric/
    session/
    user/
    weight/
    workout/
  lib/
  env/

⭐ Contributing

Contributions are welcome. If you'd like to help, open an issue or submit a pull request with your proposed improvements.

If you liked this project, consider leaving a ⭐ on GitHub β€” it really helps!


Made with β™₯ by JoΓ£o OtΓ‘vio Schonarth

GitHub LinkedIn Gmail

About

πŸ’ͺ RESTful API built with Node.js and Fastify to manage user data, workouts, and gamification for the Trainify app.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages