A comprehensive RESTful API for an online learning platform similar to Udemy. This backend powers course creation, user management, enrollment, and content delivery.
- User registration (students and instructors)
- JWT-based authentication
- Role-based authorization
- Password encryption with bcrypt
- Profile management
- Course CRUD operations
- Category and level filtering
- Pricing options
- Course status management (draft, published, unpublished)
- Rating system
- Section creation and organization
- Module management (videos, articles, quizzes, assignments)
- Content ordering within courses
- Resource attachments
- Enrollment tracking
- Payment processing
- Reviews and ratings
- Question & Answer system
- Notifications
- Node.js - JavaScript runtime
- Express - Web framework
- TypeScript - Type safety and developer experience
- MongoDB - Database (with Mongoose ODM)
- JWT - Authentication
- Zod - Input validation
- Winston - Logging
- Swagger/OpenAPI - API documentation
- Jest/Vitest - Testing framework
API documentation is available at /docs when the server is running. The documentation is automatically generated from the JSDoc comments in the codebase using swagger-jsdoc.
uLearnApi/
├── src/ # Source code
│ ├── config/ # Configuration files
│ ├── controllers/ # Request handlers
│ ├── interfaces/ # TypeScript interfaces
│ ├── middlewares/ # Express middlewares
│ ├── models/ # Mongoose models
│ ├── routes/ # Route definitions
│ ├── utils/ # Utility functions
│ ├── app.ts # Express app setup
│ └── server.ts # Server entry point
├── __tests__/ # Test files
├── .env # Environment variables (create from .env.example)
├── .env.example # Example environment variables
├── package.json # Project dependencies and scripts
├── tsconfig.json # TypeScript configuration
└── README.md # Project documentation
- Node.js (v16+)
- MongoDB (local or Atlas)
- npm or yarn
-
Clone the repository
git clone https://your-repository-url.git cd uLearnApi -
Install dependencies
npm install
-
Create a
.envfile based on.env.examplecp .env.example .env
-
Update the
.envfile with your configuration values
Development mode with hot reload:
npm run devProduction build:
npm run build
npm startPOST /api/auth/register/student- Register a new studentPOST /api/auth/register/instructor- Register a new instructorPOST /api/auth/login- Login userGET /api/auth/profile- Get current user profilePUT /api/auth/profile- Update user profilePUT /api/auth/password- Change passwordPOST /api/auth/logout- Logout user
POST /api/courses- Create a new courseGET /api/courses- Get all coursesGET /api/courses/:id- Get course by IDPUT /api/courses/:id- Update courseDELETE /api/courses/:id- Delete courseGET /api/courses/instructor- Get instructor's courses
-
POST /api/content/:courseId/sections- Create a section -
GET /api/content/:courseId/sections- Get all sections for a course -
GET /api/content/:courseId/sections/:sectionId- Get section by ID -
PUT /api/content/:courseId/sections/:sectionId- Update section -
DELETE /api/content/:courseId/sections/:sectionId- Delete section -
POST /api/content/:courseId/sections/reorder- Reorder sections -
POST /api/content/sections/:sectionId/modules- Create a module -
GET /api/content/sections/:sectionId/modules- Get all modules for a section -
GET /api/content/sections/:sectionId/modules/:moduleId- Get module by ID -
PUT /api/content/sections/:sectionId/modules/:moduleId- Update module -
DELETE /api/content/sections/:sectionId/modules/:moduleId- Delete module -
POST /api/content/sections/:sectionId/modules/reorder- Reorder modules
PORT=5000
NODE_ENV=development
MONGODB_URI=mongodb://localhost:27017/ulearn
JWT_SECRET=your-jwt-secret
JWT_EXPIRES_IN=24h
JWT_REFRESH_SECRET=your-refresh-token-secret
JWT_REFRESH_EXPIRES_IN=7d
BCRYPT_SALT_ROUNDS=12
This project uses import aliases to avoid lengthy relative paths. The aliases are configured in package.json under the "imports" field:
"imports": {
"#config/*": "./dist/config/*",
"#controllers/*": "./dist/controllers/*",
"#interfaces/*": "./dist/interfaces/*",
"#middlewares/*": "./dist/middlewares/*",
"#models/*": "./dist/models/*",
"#routes/*": "./dist/routes/*",
"#utils/*": "./dist/utils/*"
}Example usage:
import { config } from "#config/config.js";
import { authenticate } from "#middlewares/auth.js";Run tests:
npm testContributions, issues and feature requests are welcome!