RESTful API backend for the Blue Feathers Gym membership management system.
- Node.js & Express.js
- MongoDB with Mongoose
- TypeScript
- JWT Authentication
- Passport.js for OAuth
- Nodemailer with Brevo SMTP
-
Authentication & Authorization
- User authentication (JWT & Google OAuth)
- Password reset with OTP via email
- Role-based access control (Admin/User)
-
User Management
- User management with CRUD operations
- User profile with membership details
- Payment history tracking per user
-
Membership Management
- Membership package creation and management
- Package categories (Basic, Premium, VIP)
- Active/Inactive package status
- Member limits per package
- Discount management
-
Payment Processing
- PayHere payment gateway integration
- Secure payment initiation and verification
- Payment status tracking (Success, Failed, Pending, Cancelled)
- Payment refund and chargeback handling
- Automatic membership activation on successful payment
-
Revenue & Reporting
- Weekly revenue reports with aggregated data
- Monthly revenue reports with package distribution
- Real-time payment statistics dashboard
- User payment history with detailed breakdown
-
Notifications
- Email notifications (welcome, password reset, membership activation)
- In-app notification system
- Notification preferences management
- Bulk notification sending (Admin)
- Node.js v16+
- MongoDB Atlas account
- Brevo account for email service
- Google OAuth credentials (optional)
- Clone the repository:
git clone https://github.com/Blue-Feathers-001/Back.git
cd Back- Install dependencies:
npm install- Create
.envfile from.env.example:
cp .env.example .env- Configure environment variables in
.env:
PORT=5000
MONGODB_URI=your-mongodb-connection-string
JWT_SECRET=your-secure-jwt-secret
JWT_EXPIRE=7d
NODE_ENV=development
# Google OAuth (optional)
GOOGLE_CLIENT_ID=your-google-client-id
GOOGLE_CLIENT_SECRET=your-google-client-secret
GOOGLE_CALLBACK_URL=http://localhost:5000/api/auth/google/callback
FRONTEND_URL=http://localhost:3000
# Email Configuration (Brevo SMTP)
SMTP_HOST=smtp-relay.brevo.com
SMTP_PORT=587
SMTP_USER=your-brevo-smtp-user
SMTP_PASSWORD=your-brevo-smtp-password
EMAIL_FROM=Your Gym Name <your-email@example.com>- Start the development server:
npm run devThe API will run on http://localhost:5000
POST /api/auth/register- Register new userPOST /api/auth/login- Login userGET /api/auth/me- Get current user (Protected)PUT /api/auth/update-profile- Update user profile (Protected)PUT /api/auth/change-password- Change password (Protected)POST /api/auth/forgot-password- Request password reset OTPPOST /api/auth/reset-password- Reset password with OTPGET /api/auth/google- Google OAuth loginGET /api/auth/google/callback- Google OAuth callback
GET /api/users- Get all users (Admin only)GET /api/users/:id- Get single userPOST /api/users- Create user (Admin only)PUT /api/users/:id- Update userDELETE /api/users/:id- Delete user (Admin only)
GET /api/packages- Get all packages (with optional filters)GET /api/packages/:id- Get single packagePOST /api/packages- Create package (Admin only)PUT /api/packages/:id- Update package (Admin only)DELETE /api/packages/:id- Delete package (Admin only)PATCH /api/packages/:id/toggle-active- Toggle package active status (Admin only)GET /api/packages/:id/stats- Get package statistics (Admin only)
POST /api/payments/initiate- Initiate payment for a packagePOST /api/payments/notify- PayHere webhook (Public)GET /api/payments/my-payments- Get user's payment historyGET /api/payments/order/:orderId- Get payment by order IDGET /api/payments- Get all payments (Admin only)GET /api/payments/stats- Get payment statistics (Admin only)GET /api/payments/reports/weekly- Get weekly revenue report (Admin only)GET /api/payments/reports/monthly- Get monthly revenue report (Admin only)GET /api/payments/user/:userId- Get user payment history (Admin only)
GET /api/notifications- Get user notificationsGET /api/notifications/unread-count- Get unread notification countPATCH /api/notifications/:id/read- Mark notification as readPATCH /api/notifications/mark-all-read- Mark all notifications as readDELETE /api/notifications/:id- Delete notificationPOST /api/notifications- Create notification (Admin only)POST /api/notifications/bulk- Send bulk notifications (Admin only)GET /api/notifications/stats- Get notification statistics (Admin only)
npm run dev # Development with hot reload
npm run build # Compile TypeScript
npm start # Run production buildsrc/
├── config/
│ ├── database.ts # MongoDB connection
│ └── passport.ts # OAuth configuration
├── controllers/
│ ├── authController.ts
│ ├── oauthController.ts
│ └── userController.ts
├── middleware/
│ └── auth.ts # JWT verification
├── models/
│ └── User.ts # User schema
├── routes/
│ ├── authRoutes.ts
│ └── userRoutes.ts
├── utils/
│ └── emailService.ts # Email templates and sending
└── server.ts # Express app setup
| Variable | Description | Required |
|---|---|---|
| PORT | Server port | No (default: 5000) |
| NODE_ENV | Environment (development/production) | Yes |
| MONGODB_URI | MongoDB connection string | Yes |
| JWT_SECRET | Secret for JWT signing | Yes |
| JWT_EXPIRE | JWT expiration time | No (default: 7d) |
| GOOGLE_CLIENT_ID | Google OAuth client ID | No |
| GOOGLE_CLIENT_SECRET | Google OAuth secret | No |
| GOOGLE_CALLBACK_URL | Google OAuth callback URL | No |
| SMTP_HOST | SMTP server host | Yes (for emails) |
| SMTP_PORT | SMTP server port | Yes (for emails) |
| SMTP_USER | Brevo SMTP username | Yes (for emails) |
| SMTP_PASSWORD | Brevo SMTP password | Yes (for emails) |
| EMAIL_FROM | Sender email address | Yes (for emails) |
| FRONTEND_URL | Frontend application URL | Yes |
| BACKEND_URL | Backend application URL | Yes |
| PAYHERE_MERCHANT_ID | PayHere merchant ID | Yes (for payments) |
| PAYHERE_MERCHANT_SECRET | PayHere merchant secret | Yes (for payments) |
- Password hashing with bcryptjs
- JWT token authentication
- SHA-256 hashing for OTP storage
- Protected routes with middleware
- Role-based access control
- CORS enabled
- Environment variable protection
This project uses Brevo (formerly Sendinblue) for email delivery:
- Create account at https://www.brevo.com/
- Navigate to SMTP & API settings
- Create SMTP credentials
- Add to
.envfile
- Railway
- Render
- Heroku
- DigitalOcean
Update these for production:
NODE_ENV=production- Strong
JWT_SECRET - Production
MONGODB_URI - Production
FRONTEND_URL - Production
GOOGLE_CALLBACK_URL
Frontend: https://github.com/Blue-Feathers-001/Front.git
MIT