Skip to content

About

BodyAsync is a complete Fitness & Gym Management Platform backend designed to manage fitness classes, trainer applications, bookings, community discussions, and administrative operations.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

36 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ‹οΈ BodyAsync Backend API

A robust and scalable backend service for the BodyAsync Fitness & Gym Management Platform, built with Node.js, Express.js, and MongoDB. This backend powers a complete fitness management ecosystem where users can explore classes, book fitness programs, participate in community forums, apply as trainers, manage favorites, and interact with role-based dashboards.

The system supports three different user roles:

  • πŸ‘€ User
  • πŸ§‘β€πŸ« Trainer
  • πŸ‘‘ Admin

Each role has dedicated permissions and access control implemented through middleware-based authorization.


πŸ“– Table of Contents

  • Project Overview
  • Features
  • Technology Stack
  • Architecture Overview
  • User Roles
  • Database Collections
  • Authentication & Authorization
  • API Endpoints
  • Classes Module
  • Bookings Module
  • Favorites Module
  • Forum Module
  • Comments & Replies Module
  • Reactions Module
  • Trainer Application Module
  • User Management Module
  • Dashboard Statistics Module
  • Environment Variables
  • Installation Guide
  • Running the Project
  • Error Handling
  • Security Features
  • Future Improvements
  • License

πŸš€ Project Overview

BodyAsync is a complete Fitness & Gym Management Platform backend designed to manage fitness classes, trainer applications, bookings, community discussions, and administrative operations.

The platform enables:

  • Trainers to create and manage fitness classes.
  • Users to discover and book classes.
  • Users to save favorite classes.
  • Community interaction through forums.
  • Admins to control users, trainers, classes, and platform-wide activities.
  • Real-time statistics and analytics for dashboards.

✨ Features

Authentication & Authorization

  • Session-based token verification
  • Protected routes
  • Role-based authorization
  • Admin-only access control
  • Trainer-only access control
  • Shared Admin/Trainer permissions
  • Blocked user restrictions

User Features

  • Browse approved classes
  • Search classes
  • Filter classes by category
  • Book classes
  • Save favorite classes
  • Join community discussions
  • Comment on forum posts
  • Reply to comments
  • Like or dislike forum posts
  • Apply as a trainer

Trainer Features

  • Create classes
  • Update classes
  • Delete classes
  • View enrolled students
  • Create forum posts
  • Manage forum content
  • Access trainer dashboard analytics

Admin Features

  • Approve classes
  • Reject classes
  • Remove classes
  • Promote users to admin
  • Block users
  • Unblock users
  • Review trainer applications
  • Approve trainer applications
  • Reject trainer applications
  • Remove trainer roles
  • Access platform statistics

πŸ›  Technology Stack

Backend

  • Node.js
  • Express.js

Database

  • MongoDB
  • MongoDB Native Driver

Middleware

  • CORS
  • Express JSON Parser

Authentication

  • Session Collection
  • Token Verification Middleware

Environment Configuration

  • dotenv

πŸ— Architecture Overview

The backend follows a modular API-driven architecture.

Client
   β”‚
   β–Ό
Express Server
   β”‚
   β”œβ”€β”€ Authentication Middleware
   β”œβ”€β”€ Authorization Middleware
   β”œβ”€β”€ Route Handlers
   └── MongoDB Collections
           β”‚
           β–Ό
       MongoDB Database

πŸ‘₯ User Roles

User

Permissions:

  • View classes
  • Book classes
  • Add favorites
  • Create comments
  • Reply to comments
  • Apply as trainer

Trainer

Permissions:

  • All User permissions
  • Create classes
  • Update classes
  • Delete own classes
  • Create forum posts
  • View enrolled students

Admin

Permissions:

  • Full system access
  • Manage users
  • Manage trainers
  • Approve classes
  • Reject classes
  • View analytics
  • Manage applications

πŸ—„ Database Collections

The application uses the following collections:

users

Stores:

  • Name
  • Email
  • Profile Image
  • Role
  • Status
  • Login Information

classes

Stores:

  • Class Name
  • Category
  • Trainer Information
  • Booking Count
  • Difficulty Level
  • Price
  • Status

bookings

Stores:

  • User Information
  • Class Information
  • Booking Date
  • Transaction Information

forum

Stores:

  • Forum Posts
  • Author Information
  • Reactions
  • Comment Counts

comments

Stores:

  • Forum Comments

commentreplay

Stores:

  • Replies to comments

favorites

Stores:

  • User favorite classes

applyastrainer

Stores:

  • Trainer applications

session

Stores:

  • Login session tokens

πŸ” Authentication & Authorization

verifyToken

Validates:

  • Authorization header
  • Session token existence
  • User existence

Used for:

  • Protected routes

verifyTrainer

Allows access only to trainers.


verifyAdmin

Allows access only to admins.


verifyAdminOrTrainer

Allows access to:

  • Admin
  • Trainer

πŸ“š API Documentation


πŸ‹οΈ Classes APIs

Create Class

POST /class

Access:

Trainer Only

Get Featured Classes

Returns top 4 approved classes sorted by booking count.

GET /classes/featured

Get All Classes

Supports:

  • Pagination
  • Search
  • Category Filter
GET /classes?page=1&limit=6

Example:

GET /classes?page=1&limit=6&search=yoga&category=Yoga

Get Trainer Classes

GET /classes/:userId

Get Class Details

GET /classes/:id/details

Update Class

PATCH /classes/:id

Delete Class

DELETE /classes/:id

Approve Class

PATCH /classes/:id/approve

Admin Only


Reject Class

PATCH /classes/:id/reject

Admin Only


Increment Booking Count

PATCH /classes/:id/increment-booking

Get Class Students

GET /classes/:id/students

πŸ“… Booking APIs

Create Booking

POST /bookings

Check Existing Booking

GET /bookings/user/:userId/class/:classId

Get User Bookings

GET /bookings/user/:userId

❀️ Favorite APIs

Toggle Favorite

POST /favorites/toggle

Automatically:

  • Adds favorite
  • Removes favorite

Check Favorite Status

GET /favorites/check

Query:

userId
classId

Get Favorites

GET /favorites/:userId

Delete Favorite

DELETE /favorites/:id

πŸ’¬ Forum APIs

Create Forum Post

POST /forum

Trainer/Admin Only


Get Latest Posts

GET /forum/latest

Get All Posts

GET /forum-posts

Supports:

Search

Get Single Post

GET /forum-posts/:id

Delete Post

DELETE /forum/:id

πŸ’­ Comment APIs

Add Comment

POST /forum/:id/comment

Get Comments

GET /forum/:id/comments

Update Comment

PATCH /comments/:id

Delete Comment

DELETE /comments/:id

πŸ’¬ Reply APIs

Add Reply

POST /comment/:commentId/reply

Get Replies

GET /comment/:commentId/replies

πŸ‘ Reaction APIs

Like / Dislike Post

POST /post/reaction

Supported Types:

{
  "type": "like"
}
{
  "type": "dislike"
}

Features:

  • Toggle reaction
  • Remove previous reaction
  • Update counts

πŸ§‘β€πŸ« Trainer Application APIs

Apply as Trainer

POST /apply-trainer

Get Application Status

GET /apply-trainer/:userId

Get All Applications

GET /apply-trainer

Admin Only


Approve Application

PATCH /apply-trainer/:id/approve

Automatically:

  • Updates application status
  • Updates user role to trainer

Reject Application

PATCH /apply-trainer/:id/reject

Automatically:

  • Updates application status
  • Resets user role

πŸ‘€ User APIs

Sync User

POST /users/sync

Creates user automatically on first login.


Get All Users

GET /users

Supports:

Email Search

Admin Only


Get Single User

GET /users/:id

Block / Unblock User

PATCH /users/:id/status

Promote User To Admin

PATCH /users/:id/make-admin

Remove Trainer Role

PATCH /users/:id/remove-trainer

πŸ“Š Dashboard Statistics APIs

User Statistics

GET /users/:userId/stats

Returns:

  • Booking Count
  • Favorite Count

Trainer Statistics

GET /users/:userId/total-stats

Returns:

  • Total Classes
  • Total Bookings
  • Total Forum Posts

Admin Overview Statistics

GET /admin/overview-stats

Returns:

  • Total Users
  • Total Classes
  • Total Bookings
  • Total Forum Posts
  • Total Comments
  • Total Trainer Applications

Transactions

GET /transactions

Returns:

  • Payment History
  • Transaction Records

Trainers List

GET /trainers

Returns:

  • All Active Trainers

βš™οΈ Environment Variables

Create a .env file in the root directory.

PORT=5000
MONGODB_URI=your_mongodb_connection_string

πŸ“₯ Installation

Clone the repository:

git clone <repository-url>

Install dependencies:

npm install

▢️ Running The Application

Development:

npm run dev

or

nodemon index.js

Production:

node index.js

πŸ›‘ Security Features

  • Route Protection
  • Role-Based Access Control
  • Session Verification
  • Duplicate Trainer Application Prevention
  • Favorite Duplication Prevention
  • ObjectId Validation
  • Blocked User Restriction
  • Protected Dashboard Routes

πŸ“ˆ Future Improvements

  • Stripe Payment Integration
  • SSLCommerz Integration
  • JWT Verification Upgrade
  • Refresh Token System
  • Real-Time Notifications
  • Email Verification
  • Password Authentication
  • Socket.IO Chat System
  • Admin Activity Logs
  • Analytics Dashboard Enhancements
  • Report System
  • Content Moderation

πŸ“„ License

This project was developed for educational purposes and portfolio demonstration.


πŸ‘¨β€πŸ’» Developer

Backend developed using:

  • Node.js
  • Express.js
  • MongoDB

as part of the BodyAsync Fitness & Gym Management Platform.

About

BodyAsync is a complete Fitness & Gym Management Platform backend designed to manage fitness classes, trainer applications, bookings, community discussions, and administrative operations.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages