Backend API for the Smart Bachelor Life project. The service is built with Node.js, Express, MongoDB, Redis, Firebase Admin, and Swagger, with production hardening for logging, rate limiting, CORS, and security headers.
This server provides the core APIs for group-based bachelor life management, including authentication, group membership, expenses, payments, meals, menus, bazar records, and group chat.
Production-focused features currently included in the codebase:
- Structured JSON logging with request context
- Swagger UI and raw OpenAPI JSON
- Redis-backed caching and invalidation
- Helmet security headers
- Global and route-level rate limiting
- Environment validation at startup
- CORS allow-list for frontend origins
- Stripe checkout support
- File upload support for expenses and bazar documents
- Node.js 20+
- Express 5
- MongoDB with Mongoose
- Redis
- Firebase Admin SDK
- Swagger UI / swagger-jsdoc
- Winston logging
- Multer for file uploads
- Stripe
- SendGrid email delivery
- ImageKit storage
Smart-Bachelor-Life-Server/
|-- server.js
|-- package.json
|-- README.md
|-- src/
| |-- app.js
| |-- config/
| | |-- env.config.js
| | |-- firebase.config.js
| | |-- mongoDB.config.js
| | |-- redis.config.js
| | |-- swagger.config.js
| |-- controllers/
| |-- middlewares/
| |-- models/
| |-- routes/
| |-- services/
| |-- utils/
|-- __tests__/
- Node.js 20 or newer
- MongoDB connection string
- Redis connection string
- Firebase service account credentials
- ImageKit credentials
- SendGrid API key and sender email
- Stripe secret key and currency
npm installCreate a .env file in the project root.
NODE_ENV=development
PORT=3000
CLIENT_URL=http://localhost:5173
MONGO_URI=mongodb+srv://...
REDIS_URL=redis://...
FIREBASE_PROJECT_ID=your_firebase_project_id
FIREBASE_CLIENT_EMAIL=your_firebase_client_email
FIREBASE_PRIVATE_KEY="your_firebase_private_key"
IMAGEKIT_PRIVATE_KEY=your_imagekit_private_key
IMAGEKIT_PUBLIC_KEY=your_imagekit_public_key
IMAGEKIT_URL_ENDPOINT=https://ik.imagekit.io/your_id
SENDGRID_API_KEY=your_sendgrid_api_key
EMAIL_USER=your_verified_sender_email
STRIPE_SECRET_KEY=your_stripe_secret_key
STRIPE_CURRENCY=bdt
SWAGGER_SERVER_URL=https://your-api-domain.comPORTis optional. The server defaults to3000.NODE_ENVdefaults todevelopmentif omitted.CLIENT_URLis optional in development, but required in production.FIREBASE_PRIVATE_KEYshould keep escaped newlines as\nin the.envfile.SWAGGER_SERVER_URLis optional and lets Swagger point at your deployed API URL.
Development mode:
npm run devProduction mode:
npm startnpm run dev- Start the server with nodemon.npm start- Start the server with Node.js.npm test- Run the smoke test suite.
- Swagger UI:
/api/docs - Raw OpenAPI JSON:
/api/docs.json
GET /health
Example response:
{
"success": true,
"message": "OK"
}POST /api/auth/registerPOST /api/auth/manager-registerPOST /api/auth/loginPOST /api/auth/logout
POST /api/groupPOST /api/group/send-join-codePOST /api/group/joinPOST /api/group/remove-userPOST /api/group/revoke-inviteGET /api/group/detailsGET /api/group/details/:groupIdPATCH /api/group/titlePATCH /api/group/noticePOST /api/group/leavePOST /api/group/change-role
POST /api/expensesGET /api/expenses
POST /api/paymentPOST /api/payment/stripe/checkout-sessionPOST /api/payment/stripe/confirm-sessionPOST /api/payment/confirm/:paymentIDPOST /api/payment/reject/:paymentIDGET /api/paymentGET /api/payment/user
POST /api/mealsGET /api/mealsPATCH /api/meals/:idDELETE /api/meals/:id
POST /api/menusGET /api/menusPATCH /api/menus/:idDELETE /api/menus/:id
POST /api/bazarGET /api/bazarPATCH /api/bazar/:idDELETE /api/bazar/:id
POST /api/chat/messagesGET /api/chat/messagesPATCH /api/chat/messages/readPATCH /api/chat/typingGET /api/chat/typing
GET /api/testPOST /api/test/test-loginPOST /api/test/test-emailPOST /api/test/test-uploadGET /api/test/get-code
- The app uses Helmet and rate limiting globally, with additional limits on sensitive routes.
- CORS is allow-listed using
CLIENT_URLplus local development origins. - MongoDB and Redis must be available before the server starts.
- The server mounts Swagger and logs requests before the route handlers, so operational issues are easier to trace.
- Development-only test routes are only mounted when
NODE_ENV=development.
- Set all required environment variables.
- Point
CLIENT_URLto the real frontend origin. - Ensure MongoDB, Redis, and external services are reachable from the deployment platform.
- Verify
/healthreturns 200. - Open
/api/docsand confirm the OpenAPI spec loads.
ISC