How nikhil-gna/activity-booking-api works
Project type and purpose
• This is a stateless, RESTful API backend for an Activity Booking App, built with Node.js and Express, using MongoDB (Mongoose) as its datastore and JWT for authentication. There is no separate frontend in this repo—clients (web/mobile apps, Postman, etc.) consume the API endpoints.
File structure
• Top-level: package.json, README, deployment and env config.
• src/index.js: server bootstrap and Express app entry.
• src/app.js: Express app configuration (middleware, error handlers, CORS).
• src/routes/*: HTTP route definitions by resource (auth, activities, booking, healthcheck).
• src/controllers/*: business-logic for each route.
• src/middlewares/auth.middleware.js: JWT token validation/guard.
• src/models/*: Mongoose schema definitions (User, Activity, Booking).
• src/db/index.js: MongoDB connection logic.
• src/utils/*: generic helpers (ApiError, ApiResponse, asyncHandler).
Extract architectural details from README
• Node + Express for HTTP.
• MongoDB with Mongoose for persistence.
• bcrypt for password hashing, JWT for stateless auth.
• Hosted on Render (implies a load-balanced, containerized or auto-scaled deployment).
Main components
a. External Clients
‑ Mobile/Web App or API Consumer (e.g., Postman).
b. (Optional) Load Balancer or API Gateway
‑ Represents Render’s routing layer.
c. Express API Server
‑ Routes Layer (activity.routes, auth.routes, booking.routes, healthcheck.routes).
‑ Middleware Layer (CORS, JSON parsing, auth.middleware).
‑ Controller Layer (auth.controller, activity.controller, booking.controller, healthcheck.controller).
‑ Utility Layer (ApiError, ApiResponse, asyncHandler).
d. Database Layer
‑ Mongoose models and MongoDB cluster.
e. Authentication Subsystem
‑ JWT issuer/validator, bcrypt for hashing.
Relationships and data flow
• Client → HTTP Request → Load Balancer → Express Routes → Auth Middleware (for protected routes) → Controller → Mongoose Model → MongoDB → Controller → HTTP Response → Client.
• Both successful flows (200 OK) and error flows (ApiError → error handler → client).
Architectural patterns and principles
• Layered (Route → Middleware → Controller → Model → DB).
• MVC-style separation of concerns.
• Stateless, token-based authentication.
• Single-responsibility per file/module.
• Asynchronous error handling via asyncHandler and centralized error middleware.
Technologies and frameworks to annotate
• Node.js (runtime)
• Express.js (web framework)
• Mongoose (ORM)
• MongoDB (NoSQL DB)
• JWT (jsonwebtoken library)
• bcrypt (password hashing)
• Render.com (deployment)