A comprehensive REST API for a Learning Management System built with Node.js, Express, and modern best practices.
- 🔐 Authentication & Authorization - JWT-based auth with role-based access control
- 👥 User Management - Students, instructors, and administrators
- 📚 Course Management - Create, manage, and publish courses
- 📖 Lesson System - Video lessons with progress tracking
- 📊 Progress Tracking - Student progress and completion rates
- 📈 Analytics - Course and user analytics
- 🔒 Security - Rate limiting, input validation, and sanitization
- 📧 Email Integration - Email verification and notifications
- 🧪 Testing - Comprehensive test suite
- 📖 Documentation - API documentation and examples
- Runtime: Node.js 16+
- Framework: Express.js
- Authentication: JWT (JSON Web Tokens)
- Password Security: bcryptjs
- Email: Nodemailer
- Testing: Jest & Supertest
- Linting: ESLint with Airbnb config
- Code Formatting: Prettier
lms-api/
├── controllers/ # Request handlers
├── middleware/ # Custom middleware
├── models/ # Data models
├── routes/ # API routes
├── services/ # Business services
├── utils/ # Utility functions
├── config/ # Configuration files
├── database/ # Database setup and migrations
├── tests/ # Test files
├── uploads/ # File uploads
├── logs/ # Application logs
└── docs/ # Documentation
- Node.js 16 or higher
- npm or yarn
-
Clone the repository
git clone https://github.com/DahamSathmina/ODS-LMS-API.git cd ODS-LMS-API -
Install dependencies
npm install
-
Set up environment variables
cp .env.example .env
Edit
.envwith your configuration:NODE_ENV=development PORT=3000 JWT_SECRET=your-super-secret-jwt-key JWT_EXPIRE=24h # Email Configuration SMTP_HOST=smtp.gmail.com SMTP_PORT=587 SMTP_USER=your-email@gmail.com SMTP_PASS=your-app-password
-
Start the development server
npm run dev
The API will be available at http://localhost:3000
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/auth/register |
Register new user |
| POST | /api/auth/login |
User login |
| POST | /api/auth/logout |
User logout |
| POST | /api/auth/forgot-password |
Request password reset |
| POST | /api/auth/reset-password/:token |
Reset password |
| POST | /api/auth/change-password |
Change password (authenticated) |
| GET | /api/auth/verify-email/:token |
Verify email address |
| POST | /api/auth/resend-verification |
Resend verification email |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/users/profile |
Get current user profile |
| PUT | /api/users/profile |
Update current user profile |
| GET | /api/users |
Get all users (admin only) |
| POST | /api/users/check-email |
Check if email exists |
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/courses |
Create new course |
| GET | /api/courses |
Get all published courses |
| GET | /api/courses/:id |
Get course by ID |
| PUT | /api/courses/:id |
Update course |
| DELETE | /api/courses/:id |
Delete course |
| GET | /api/courses/featured |
Get featured courses |
| GET | /api/courses/popular |
Get popular courses |
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/courses/:courseId/lessons |
Create lesson |
| GET | /api/courses/:courseId/lessons |
Get course lessons |
| PUT | /api/lessons/:id |
Update lesson |
| DELETE | /api/lessons/:id |
Delete lesson |
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/courses/:courseId/enroll |
Enroll in course |
| GET | /api/users/enrollments |
Get user enrollments |
| DELETE | /api/enrollments/:id |
Unenroll from course |
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/lessons/:lessonId/complete |
Mark lesson complete |
| GET | /api/courses/:courseId/progress |
Get course progress |
| GET | /api/users/progress |
Get user progress |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/courses/:courseId/analytics |
Get course analytics |
| GET | /api/analytics/overview |
Get system overview |
The API uses JWT (JSON Web Tokens) for authentication. Include the token in the Authorization header:
Authorization: Bearer <your-jwt-token>
- Student: Can enroll in courses, track progress, submit assignments
- Instructor: Can create and manage courses, view analytics
- Admin: Full system access, user management, system analytics
POST /api/auth/register
Content-Type: application/json
{
"email": "student@example.com",
"password": "SecurePass123",
"firstName": "John",
"lastName": "Doe",
"role": "student"
}{
"status": "success",
"message": "User registered successfully",
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"data": {
"user": {
"id": "abc123",
"email": "student@example.com",
"firstName": "John",
"lastName": "Doe",
"role": "student"
}
}
}POST /api/courses
Authorization: Bearer <token>
Content-Type: application/json
{
"title": "Introduction to Web Development",
"description": "Learn the basics of HTML, CSS, and JavaScript",
"category": "Programming",
"difficulty": "beginner",
"duration": 40,
"price": 99.99
}The API returns consistent error responses:
{
"status": "error",
"message": "Error description",
"timestamp": "2023-08-03T10:30:00.000Z"
}200- Success201- Created400- Bad Request401- Unauthorized403- Forbidden404- Not Found429- Too Many Requests500- Internal Server Error
# Development
npm run dev # Start development server with hot reload
# Testing
npm test # Run all tests
npm run test:watch # Run tests in watch mode
npm run test:coverage # Run tests with coverage report
# Code Quality
npm run lint # Check code style
npm run lint:fix # Fix code style issues
npm run format # Format code with Prettier
# Database
npm run migrate # Run database migrations
npm run seed # Seed database with sample data| Variable | Description | Default |
|---|---|---|
NODE_ENV |
Environment (development/production) | development |
PORT |
Server port | 3000 |
JWT_SECRET |
JWT signing secret | - |
JWT_EXPIRE |
JWT expiration time | 24h |
SMTP_HOST |
Email SMTP host | - |
SMTP_PORT |
Email SMTP port | 587 |
SMTP_USER |
Email username | - |
SMTP_PASS |
Email password | - |
Run the test suite:
# Run all tests
npm test
# Run with coverage
npm run test:coverage
# Run specific test file
npm test auth.test.js- Unit Tests: Test individual functions and methods
- Integration Tests: Test API endpoints and workflows
- Fixtures: Sample data for testing
-
Set environment variables
NODE_ENV=production JWT_SECRET=your-production-secret # ... other production configs -
Install production dependencies
npm ci --only=production
-
Start the server
npm start
FROM node:16-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
EXPOSE 3000
CMD ["npm", "start"]- Rate Limiting: Prevents abuse and DoS attacks
- Helmet: Sets security headers
- Input Validation: Validates and sanitizes user input
- Password Hashing: Uses bcrypt for secure password storage
- JWT Authentication: Secure token-based authentication
- CORS: Configurable cross-origin resource sharing
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Follow the existing code style
- Write tests for new features
- Update documentation as needed
- Ensure all tests pass before submitting PR
This project is licensed under the Apache 2.0 License - see the LICENSE file for details.
- 🐛 Issues: GitHub Issues
- 📖 Docs: API Documentation
- Real-time notifications
- Video streaming integration
- Mobile app API endpoints
- Advanced analytics dashboard
- Multi-language support
- Payment gateway integration
- Discussion forums
- Assignment submissions
- Quiz/exam system
- Certificate generation