A production-ready RESTful API built with Node.js, Express, and MySQL for managing a full-featured e-learning platform. The system enables instructors to create and manage courses, lessons, quizzes, and assessments, while students can enroll in courses, track progress, participate in discussions, and earn badges through gamification.
The API follows a modular, scalable architecture with robust authentication, authorization, validation, testing, and documentation.
- JWT-based authentication and authorization
- Role-based access control (Student, Instructor, Admin)
- Course and lesson management (CRUD)
- Student enrollment management
- Quiz creation, attempts, and scoring
- Lesson and course progress tracking
- Discussion forums (posts and comments)
- Gamification system (badges and leaderboards)
- Request validation using Zod
- Automated API testing with Supertest and Jest
- Swagger / OpenAPI documentation
- Runtime: Node.js
- Framework: Express.js
- Database: MySQL / MariaDB
- Authentication: JWT
- Validation: Zod
- Testing: Jest, Supertest
- Documentation: Swagger (OpenAPI)
- Caching: Redis
- Node.js v18 or higher
- MySQL or MariaDB v10 or higher
- npm (comes with Node.js)
- Redis server
git clone https://github.com/imranmalakzai/elearning-platform-api
cd elearning-platform-apinpm installCreate a .env file in the project root and configure the following variables:
PORT=5000
DB_HOST=localhost
DB_USER=root
DB_PASSWORD=your_password
DB_NAME=elearning_db
JWT_SECRET=your_jwt_secret
JWT_EXPIRES_IN=7d
REDIS_CLIENT_URL= "redis://127.0.0.1:6379"- Open your MySQL client (MySQL Workbench, phpMyAdmin, etc.).
- Locate the SQL schema file inside the
schemadirectory. - Execute the provided SQL script to create the database structure.
npm run startRun automated tests:
npm run test- Base URL:
http://localhost:5000/api - Swagger UI:
http://localhost:5000/api/docs - Swagger JSON:
http://localhost:5000/api-docs.json
POST /api/auth/register— Register a new userPOST /api/auth/login— User loginGET /api/users/me— Get current user profilePUT /api/users/me— Update current user profilePATCH /api/users/me/password— Update passwordDELETE /api/users/me— Delete user account
GET /api/admin/users— Get all usersGET /api/admin/users?role=student|instructor|admin— Filter users by roleGET /api/admin/users/:id— Get user by ID
GET /api/instructors/:id/courses— Get instructor’s courses
POST /api/courses— Create a course (Instructor)GET /api/courses— Get all coursesGET /api/courses/:courseId— Get course by IDPUT /api/courses/:courseId— Update course (Instructor | Owner)DELETE /api/courses/:courseId— Delete course (Instructor | Owner)
POST /api/courses/:courseId/enroll— Enroll in a course (Authenticated users)GET /api/courses/:courseId/enroll— Get enrolled students (Instructor)DELETE /api/courses/:courseId/enroll— Cancel enrollment (Enrolled student)
POST /api/courses/:courseId/lessons— Create lesson (Instructor | Owner)GET /api/courses/:courseId/lessons— Get all lessonsGET /api/courses/:courseId/lessons/:lessonId— Get lesson by IDPUT /api/courses/:courseId/lessons/:lessonId— Update lesson (Instructor | Owner)DELETE /api/courses/:courseId/lessons/:lessonId— Delete lesson (Instructor | Owner)
POST /api/courses/:courseId/quizzes— Create quiz (Instructor)GET /api/courses/:courseId/quizzes— Get quizzes (Enrolled students)GET /api/courses/:courseId/quizzes/:quizId— Get quiz by IDPUT /api/courses/:courseId/quizzes/:quizId— Update quiz (Instructor)DELETE /api/courses/:courseId/quizzes/:quizId— Delete quiz (Instructor)
POST /api/courses/:courseId/quizzes/:quizId/questions— Create question (Instructor)GET /api/courses/:courseId/quizzes/:quizId/questions— Get quiz questionsGET /api/courses/:courseId/quizzes/:quizId/questions/:questionId— Get question by IDPUT /api/courses/:courseId/quizzes/:quizId/questions/:questionId— Update question (Instructor)
POST /api/courses/:courseId/quizzes/:quizId/attempt— Attempt quiz (Enrolled students)
POST /api/courses/:courseId/forums— Create forum post (Enrolled users)GET /api/courses/:courseId/forums— Get forum postsGET /api/courses/:courseId/forums/:postId— Get post by IDPUT /api/courses/:courseId/forums/:postId— Update post (Author only)DELETE /api/courses/:courseId/forums/:postId— Delete post (Author only)
POST /api/courses/:courseId/forums/:postId/comments— Create commentGET /api/courses/:courseId/forums/:postId/comments— Get commentsPATCH /api/courses/:courseId/forums/:postId/comments/:commentId— Update comment (Author)DELETE /api/courses/:courseId/forums/:postId/comments/:commentId— Delete comment (Comment or Post author)
POST /api/badges— Create badge (Admin)GET /api/badges— Get all badges (Admin)PUT /api/badges/:badgeId— Update badge (Admin)DELETE /api/badges/:badgeId— Delete badge (Admin)
GET /api/courses/:courseId/progress— Get course progress (Student)POST /api/courses/:courseId/progress/:lessonId— Mark lesson as completed
GET /api/leaderboard/global— Global leaderboardGET /api/leaderboard/:courseId— Course-specific leaderboard
This project is licensed under the MIT License. See the LICENSE file for more information.
