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.
- 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
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.
- Session-based token verification
- Protected routes
- Role-based authorization
- Admin-only access control
- Trainer-only access control
- Shared Admin/Trainer permissions
- Blocked user restrictions
- 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
- Create classes
- Update classes
- Delete classes
- View enrolled students
- Create forum posts
- Manage forum content
- Access trainer dashboard analytics
- 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
- Node.js
- Express.js
- MongoDB
- MongoDB Native Driver
- CORS
- Express JSON Parser
- Session Collection
- Token Verification Middleware
- dotenv
The backend follows a modular API-driven architecture.
Client
β
βΌ
Express Server
β
βββ Authentication Middleware
βββ Authorization Middleware
βββ Route Handlers
βββ MongoDB Collections
β
βΌ
MongoDB Database
Permissions:
- View classes
- Book classes
- Add favorites
- Create comments
- Reply to comments
- Apply as trainer
Permissions:
- All User permissions
- Create classes
- Update classes
- Delete own classes
- Create forum posts
- View enrolled students
Permissions:
- Full system access
- Manage users
- Manage trainers
- Approve classes
- Reject classes
- View analytics
- Manage applications
The application uses the following collections:
Stores:
- Name
- Profile Image
- Role
- Status
- Login Information
Stores:
- Class Name
- Category
- Trainer Information
- Booking Count
- Difficulty Level
- Price
- Status
Stores:
- User Information
- Class Information
- Booking Date
- Transaction Information
Stores:
- Forum Posts
- Author Information
- Reactions
- Comment Counts
Stores:
- Forum Comments
Stores:
- Replies to comments
Stores:
- User favorite classes
Stores:
- Trainer applications
Stores:
- Login session tokens
Validates:
- Authorization header
- Session token existence
- User existence
Used for:
- Protected routes
Allows access only to trainers.
Allows access only to admins.
Allows access to:
- Admin
- Trainer
POST /classAccess:
Trainer Only
Returns top 4 approved classes sorted by booking count.
GET /classes/featuredSupports:
- Pagination
- Search
- Category Filter
GET /classes?page=1&limit=6Example:
GET /classes?page=1&limit=6&search=yoga&category=YogaGET /classes/:userIdGET /classes/:id/detailsPATCH /classes/:idDELETE /classes/:idPATCH /classes/:id/approveAdmin Only
PATCH /classes/:id/rejectAdmin Only
PATCH /classes/:id/increment-bookingGET /classes/:id/studentsPOST /bookingsGET /bookings/user/:userId/class/:classIdGET /bookings/user/:userIdPOST /favorites/toggleAutomatically:
- Adds favorite
- Removes favorite
GET /favorites/checkQuery:
userId
classId
GET /favorites/:userIdDELETE /favorites/:idPOST /forumTrainer/Admin Only
GET /forum/latestGET /forum-postsSupports:
Search
GET /forum-posts/:idDELETE /forum/:idPOST /forum/:id/commentGET /forum/:id/commentsPATCH /comments/:idDELETE /comments/:idPOST /comment/:commentId/replyGET /comment/:commentId/repliesPOST /post/reactionSupported Types:
{
"type": "like"
}{
"type": "dislike"
}Features:
- Toggle reaction
- Remove previous reaction
- Update counts
POST /apply-trainerGET /apply-trainer/:userIdGET /apply-trainerAdmin Only
PATCH /apply-trainer/:id/approveAutomatically:
- Updates application status
- Updates user role to trainer
PATCH /apply-trainer/:id/rejectAutomatically:
- Updates application status
- Resets user role
POST /users/syncCreates user automatically on first login.
GET /usersSupports:
Email Search
Admin Only
GET /users/:idPATCH /users/:id/statusPATCH /users/:id/make-adminPATCH /users/:id/remove-trainerGET /users/:userId/statsReturns:
- Booking Count
- Favorite Count
GET /users/:userId/total-statsReturns:
- Total Classes
- Total Bookings
- Total Forum Posts
GET /admin/overview-statsReturns:
- Total Users
- Total Classes
- Total Bookings
- Total Forum Posts
- Total Comments
- Total Trainer Applications
GET /transactionsReturns:
- Payment History
- Transaction Records
GET /trainersReturns:
- All Active Trainers
Create a .env file in the root directory.
PORT=5000
MONGODB_URI=your_mongodb_connection_stringClone the repository:
git clone <repository-url>Install dependencies:
npm installDevelopment:
npm run devor
nodemon index.jsProduction:
node index.js- Route Protection
- Role-Based Access Control
- Session Verification
- Duplicate Trainer Application Prevention
- Favorite Duplication Prevention
- ObjectId Validation
- Blocked User Restriction
- Protected Dashboard Routes
- 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
This project was developed for educational purposes and portfolio demonstration.
Backend developed using:
- Node.js
- Express.js
- MongoDB
as part of the BodyAsync Fitness & Gym Management Platform.