Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FitFusion API

Spring Boot REST API for managing users, exercises, and diets with MySQL persistence, JWT authentication, and role-based access control.

Overview

This project demonstrates a compact fitness-management API built with Spring Boot, JPA, and Spring Security. It models users with trainer-assigned exercises and diet plans, and uses JWT-based authentication to secure role-specific workflows for admins, trainers, and customers.

Concepts and Features Covered

  • Spring Boot REST API setup
  • Spring Data JPA repository pattern
  • MySQL-backed persistence
  • Spring Security with JWT authentication
  • Method-level authorization with @PreAuthorize
  • Custom UserDetailsService for email-based login
  • Public user registration and token-based login flow
  • Role-based access for ADMIN, TRAINER, and CUSTOMER
  • Admin user management endpoints
  • Trainer exercise assignment and exercise CRUD
  • Trainer diet assignment and diet CRUD
  • Customer endpoints for retrieving assigned exercises and diets
  • DTO-based request handling for users, exercises, diets, and auth

Tech Stack

  • Java 17
  • Spring Boot 2.7
  • Spring Web
  • Spring Data JPA
  • Spring Security
  • MySQL
  • Maven
  • Lombok
  • JJWT

Project Structure

FitFusion Template/
├── CHANGELOG.md
├── README.md
├── pom.xml
├── mvnw
├── mvnw.cmd
└── src/
    └── main/
        ├── java/com/CN/FitFusion/
        │   ├── config/
        │   ├── controller/
        │   ├── dto/
        │   ├── exception/
        │   ├── jwt/
        │   ├── model/
        │   ├── repository/
        │   ├── security/
        │   ├── service/
        │   └── FitFusionApplication.java
        └── resources/
            └── application.yml

How to Run

  1. Open a terminal in the project root.
  2. Update the MySQL connection values in src/main/resources/application.yml if needed.
  3. Run mvn test.
  4. Run mvn spring-boot:run.
  5. Register a user with POST /user/register.
  6. Obtain a JWT with POST /auth/login.
  7. Use protected endpoints with Authorization: Bearer <token>.

Available endpoints:

  • POST /auth/login
  • GET /user/all
  • GET /user/{id}
  • PUT /user/{id}
  • DELETE /user/{id}
  • GET /user/exercise/{id}
  • GET /user/diet/{id}
  • POST /user/register
  • GET /exercise/all
  • GET /exercise/{id}
  • POST /exercise/create/{userId}
  • PUT /exercise/{id}
  • DELETE /exercise/{id}
  • GET /diet/all
  • GET /diet/{id}
  • POST /diet/create/{userId}
  • PUT /diet/{id}
  • DELETE /diet/{id}

Access notes:

  • /auth/login and /user/register are public
  • ADMIN can manage users
  • TRAINER can manage diets and exercises
  • CUSTOMER can retrieve their assigned diets and exercises

Example request body for registration:

{
  "email": "john@example.com",
  "password": "secret123",
  "age": 25,
  "gender": "Male",
  "contactNo": 9876543210,
  "userType": "CUSTOMER"
}

Example request body for login:

{
  "username": "john@example.com",
  "password": "secret123"
}

Example request body for exercise assignment:

{
  "name": "Push Day",
  "description": "Chest, shoulders, and triceps routine",
  "sets": 4,
  "reps": 12
}

Example request body for diet assignment:

{
  "name": "High Protein Plan",
  "description": "Protein-rich meals with balanced carbs and fats"
}

Learning Highlights

  • Demonstrates JWT-secured REST APIs with role-based endpoint protection
  • Shows how trainers can manage domain data for customer-specific fitness plans
  • Uses JPA relationships to connect users with diet and exercise assignments
  • Keeps the project focused and easy to follow while covering meaningful security and CRUD concepts

GitHub Metadata

  • Suggested repository description: Spring Boot REST API for managing users, diets, and exercises with MySQL persistence, JWT authentication, and role-based access control.
  • Suggested topics: java, java-17, spring-boot, spring-security, spring-data-jpa, mysql, rest-api, jwt, fitness-management, diet-plans, exercise-tracker, maven, learning-project, portfolio-project

About

Spring Boot REST API for managing users, diets, and exercises with MySQL persistence, JWT authentication, and role-based access control.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages