The LMS Backend is a Node.js/Express REST API organized around a layered folder structure where each layer has a single responsibility. Every HTTP request enters through a shared middleware stack — security, rate limiting, body parsing — before reaching a route handler, which delegates logic to a controller, which in turn reads and writes data through a Mongoose model. Understanding this flow helps you predict error shapes, know where auth is enforced, and debug failed requests effectively.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Pragyat-Nikunj/Learning-Management-System-backend/llms.txt
Use this file to discover all available pages before exploring further.
Folder structure
Request lifecycle
Every request passes through the following stages in order:Security middleware
Helmet sets HTTP security headers. HPP blocks HTTP parameter pollution.
mongo-sanitize strips MongoDB operators from req.body and req.params. The global rate limiter (/api/*) enforces 100 requests per 15 minutes per IP.Body parsing
The Stripe webhook path (
/api/v1/payments/webhook) receives a raw Buffer so Stripe’s signature verification works. All other routes receive JSON and URL-encoded bodies parsed up to 10 kb. cookie-parser makes req.cookies available.Route matching
Express matches the method and path to the correct router file mounted in
index.js. Unmatched requests fall through to a 404 handler that returns { status: "error", message: "Route not found." }.Route-level middleware
Individual routes may apply
isAuthenticated (JWT check), validateSignUp (input validation), or upload.single(...) (file upload) before reaching the controller function.Controller
The controller function contains the business logic. It queries or mutates one or more Mongoose models, calls utility helpers (e.g.
uploadMedia, generateToken), and builds the response object.Model
Mongoose models enforce schema validation, run
pre('save') hooks (e.g. bcrypt password hashing), and execute the database query against MongoDB.API route groups
All routes are mounted under the base URL/api/v1.
/api/v1/user
Account creation, sign-in, sign-out, profile management, avatar upload, password change, forgot/reset password, and account deletion.
/api/v1/courses
Browse published courses, search by keyword, fetch course details and lectures, create courses (instructors), add lectures with video upload, and update course details.
/api/v1/progress
Track lecture-level completion for an enrolled student, mark a course as fully completed, and reset progress back to zero.
/api/v1/payments
Initiate a Stripe Checkout session to purchase a course, receive Stripe webhook events, check purchase status for a specific course, and list all purchased courses.
/api/v1/healthcheck
Lightweight liveness probe. Returns a 200 response with no authentication required — useful for load balancer health checks.
Error response shape
All errors — whether operational (wrong password, missing field) or unexpected (unhandled exception) — are returned in a consistent envelope:status is "fail" for 4xx errors and "error" for 5xx errors. In development mode the response also includes a stack field.
The
password field is excluded from all User query results by default (select: false in the schema). It is only fetched explicitly when comparing passwords during sign-in.