This document provides comprehensive information about all API endpoints available in the Coalight Frontend application. All endpoints are proxied through Next.js API routes to the backend Express server.
- Overview
- Authentication
- Base URL & Headers
- Error Handling
- Authentication Endpoints
- Course Management
- Asset Management
- Event Management
- User Management
The Coalight Frontend acts as a proxy to the backend Express API. All API calls go through Next.js API routes for better security, cookie management, and error handling.
Frontend (Next.js) → API Routes → Backend (Express) → Database
The application uses JWT tokens stored in HTTP-only cookies for authentication. All protected endpoints require valid authentication tokens.
- User logs in with credentials
- Backend validates and returns JWT tokens
- Tokens are stored in HTTP-only cookies
- Subsequent requests include cookies automatically
- Middleware validates tokens on protected routes
Development: http://localhost:3000/api
Production: https://your-domain.com/api
Content-Type: application/json
Cookie: accessToken=<jwt_token>; refreshToken=<refresh_token>interface ErrorResponse {
error: string;
message?: string;
code?: string;
details?: any;
}200- Success201- Created400- Bad Request401- Unauthorized403- Forbidden404- Not Found500- Internal Server Error
{
"error": "Invalid credentials",
"message": "Email or password is incorrect",
"code": "AUTH_INVALID_CREDENTIALS"
}Register a new user account.
Request Body:
interface SignUpRequest {
name: string;
email: string;
password: string;
confirmPassword: string;
}Example Request:
{
"name": "John Doe",
"email": "john.doe@example.com",
"password": "securePassword123",
"confirmPassword": "securePassword123"
}Success Response (201):
{
"message": "User registered successfully",
"user": {
"id": "user_123",
"email": "john.doe@example.com",
"name": "John Doe",
"role": "STUDENT"
},
"isEmailVerified": false
}Error Responses:
// 400 - Validation Error
{
"error": "Passwords do not match"
}
// 400 - Invalid Email
{
"error": "Invalid email format"
}
// 409 - User Exists
{
"error": "User already exists with this email"
}Authenticate user with email and password.
Request Body:
interface LoginRequest {
email: string;
password: string;
}Example Request:
{
"email": "john.doe@example.com",
"password": "securePassword123"
}Success Response (200):
{
"message": "Login successful",
"user": {
"id": "user_123",
"email": "john.doe@example.com",
"name": "John Doe",
"role": "STUDENT"
},
"isEmailVerified": true
}Error Responses:
// 400 - Missing Fields
{
"error": "Email and password are required"
}
// 401 - Invalid Credentials
{
"error": "Invalid email or password"
}
// 403 - Email Not Verified
{
"error": "Please verify your email before logging in"
}Logout user and clear authentication tokens.
Request: No body required
Success Response (200):
{
"message": "Logout successful"
}Refresh authentication tokens using refresh token.
Request: No body required (uses refresh token from cookies)
Success Response (200):
{
"message": "Token refreshed successfully",
"user": {
"id": "user_123",
"email": "john.doe@example.com",
"name": "John Doe",
"role": "STUDENT"
}
}Error Response (401):
{
"error": "Invalid or expired refresh token"
}Get current authenticated user information.
Request: No body required
Success Response (200):
{
"user": {
"id": "user_123",
"email": "john.doe@example.com",
"name": "John Doe",
"role": "STUDENT",
"isEmailVerified": true,
"createdAt": "2024-01-15T08:30:00Z"
}
}Error Response (401):
{
"error": "Unauthorized"
}Send email verification code to user's email.
Request Body:
interface SendCodeRequest {
email: string;
}Example Request:
{
"email": "john.doe@example.com"
}Success Response (200):
{
"message": "Verification code sent successfully"
}Verify email using verification code.
Request Body:
interface VerifyCodeRequest {
email: string;
code: string;
}Example Request:
{
"email": "john.doe@example.com",
"code": "123456"
}Success Response (200):
{
"message": "Email verified successfully",
"user": {
"id": "user_123",
"email": "john.doe@example.com",
"name": "John Doe",
"role": "STUDENT",
"isEmailVerified": true
}
}Error Responses:
// 400 - Invalid Code
{
"error": "Invalid verification code"
}
// 410 - Expired Code
{
"error": "Verification code has expired"
}Get all courses enrolled by the current user.
Request: No body required
Success Response (200):
{
"courses": [
{
"id": "course_123",
"title": "Introduction to Computer Science",
"code": "CS101",
"joining_code": "ABC123",
"description": "Basic computer science concepts",
"credits": "3",
"start_date": "2024-01-15T00:00:00Z",
"class_days": ["mon", "wed", "fri"],
"total_students": 25,
"created_at": "2024-01-01T00:00:00Z",
"instructor": {
"id": "instructor_456",
"name": "Dr. Jane Smith",
"email": "jane.smith@university.edu"
},
"currentUserRole": "STUDENT"
}
]
}Course Object Interface:
interface Course {
id: string;
title: string;
code: string;
joining_code: string;
created_by: string;
created_at: string;
description: string;
credits: string;
start_date: string;
class_days: DayOfWeek[];
total_students: number;
instructor?: {
id: string;
name: string;
email: string;
};
currentUserRole?: "STUDENT" | "INSTRUCTOR" | "ADMIN" | "MODERATOR";
Peoples?: EnrolledPeople[];
Events?: CourseEvent[];
}
type DayOfWeek = "mon" | "tue" | "wed" | "thu" | "fri" | "sat" | "sun";Create a new course (Instructors/Admins only).
Request Body:
interface CreateCourseRequest {
title: string;
code: string;
description: string;
credits: string;
start_date: string; // ISO date string
class_days: DayOfWeek[];
}Example Request:
{
"title": "Advanced Data Structures",
"code": "CS201",
"description": "Advanced concepts in data structures and algorithms",
"credits": "4",
"start_date": "2024-02-01T00:00:00Z",
"class_days": ["tue", "thu"]
}Success Response (201):
{
"message": "Course created successfully",
"course": {
"id": "course_456",
"title": "Advanced Data Structures",
"code": "CS201",
"joining_code": "XYZ789",
"description": "Advanced concepts in data structures and algorithms",
"credits": "4",
"start_date": "2024-02-01T00:00:00Z",
"class_days": ["tue", "thu"],
"total_students": 0,
"created_at": "2024-01-20T08:30:00Z",
"created_by": "instructor_456"
}
}Error Responses:
// 400 - Missing Fields
{
"error": "All required fields must be provided"
}
// 403 - Insufficient Permissions
{
"error": "Only instructors and admins can create courses"
}
// 409 - Course Code Exists
{
"error": "Course with this code already exists"
}Join a course using course ID or joining code.
URL Parameters:
courseID: Course ID or joining code
Request Body:
interface JoinCourseRequest {
joiningCode?: string; // Alternative to URL parameter
}Example Request:
{
"joiningCode": "ABC123"
}Success Response (200):
{
"message": "Successfully joined the course",
"enrollment": {
"id": "enrollment_789",
"user_id": "user_123",
"course_id": "course_123",
"role": "STUDENT",
"enrolled_at": "2024-01-20T10:15:00Z"
}
}Error Responses:
// 404 - Course Not Found
{
"error": "Course not found"
}
// 409 - Already Enrolled
{
"error": "You are already enrolled in this course"
}
// 403 - Course Full
{
"error": "Course has reached maximum capacity"
}Get all people enrolled in user's courses.
Success Response (200):
{
"people": [
{
"id": "enrollment_123",
"user_id": "user_456",
"course_id": "course_123",
"role": "STUDENT",
"enrolled_at": "2024-01-15T08:30:00Z",
"user_name": "Alice Johnson",
"user_email": "alice.johnson@example.com"
}
]
}EnrolledPeople Interface:
interface EnrolledPeople {
id: string;
user_id: string;
course_id: string;
role: "STUDENT" | "INSTRUCTOR" | "ADMIN" | "MODERATOR";
enrolled_at: string;
user_name: string;
user_email: string;
}Get all events for user's enrolled courses.
Success Response (200):
{
"events": [
{
"id": "event_123",
"title": "Midterm Exam",
"description": "Midterm examination for CS101",
"event_date": "2024-03-15T14:00:00Z",
"event_type": "EXAM",
"course_id": "course_123",
"created_by": "instructor_456",
"created_at": "2024-01-20T08:30:00Z"
}
]
}CourseEvent Interface:
interface CourseEvent {
id: string;
title: string;
description: string;
event_date: string;
event_type: "ASSIGNMENT" | "EXAM" | "LECTURE" | "LAB" | "OTHER";
course_id: string;
created_by: string;
created_at: string;
}Get all assets for user's enrolled courses.
Success Response (200):
{
"assets": [
{
"id": "asset_123",
"title": "Lecture Notes - Chapter 1",
"description": "Introduction to programming concepts",
"file_url": "https://storage.example.com/files/lecture1.pdf",
"file_type": "application/pdf",
"file_size": 2048576,
"course_id": "course_123",
"uploaded_by": "instructor_456",
"uploaded_at": "2024-01-20T08:30:00Z"
}
]
}Asset Interface:
interface Asset {
id: string;
title: string;
description: string;
file_url: string;
file_type: string;
file_size: number;
course_id: string;
uploaded_by: string;
uploaded_at: string;
}Get specific asset by ID.
URL Parameters:
id: Asset ID
Success Response (200):
{
"asset": {
"id": "asset_123",
"title": "Lecture Notes - Chapter 1",
"description": "Introduction to programming concepts",
"file_url": "https://storage.example.com/files/lecture1.pdf",
"file_type": "application/pdf",
"file_size": 2048576,
"course_id": "course_123",
"uploaded_by": "instructor_456",
"uploaded_at": "2024-01-20T08:30:00Z",
"download_count": 45
}
}Error Response (404):
{
"error": "Asset not found"
}Delete an asset (Instructors/Admins only).
URL Parameters:
id: Asset ID
Success Response (200):
{
"message": "Asset deleted successfully"
}Error Responses:
// 404 - Asset Not Found
{
"error": "Asset not found"
}
// 403 - Insufficient Permissions
{
"error": "You don't have permission to delete this asset"
}Get all events for the authenticated user.
Query Parameters:
course_id(optional): Filter by specific courseevent_type(optional): Filter by event typestart_date(optional): Filter events from date (ISO string)end_date(optional): Filter events until date (ISO string)
Example Request:
GET /api/events?course_id=course_123&event_type=EXAM&start_date=2024-01-01T00:00:00Z
Success Response (200):
{
"events": [
{
"id": "event_123",
"title": "Final Exam",
"description": "Comprehensive final examination",
"event_date": "2024-05-15T14:00:00Z",
"event_type": "EXAM",
"course_id": "course_123",
"created_by": "instructor_456",
"created_at": "2024-01-20T08:30:00Z",
"course": {
"title": "Introduction to Computer Science",
"code": "CS101"
}
}
]
}Create a new event (Instructors/Admins only).
Request Body:
interface CreateEventRequest {
title: string;
description: string;
event_date: string; // ISO date string
event_type: "ASSIGNMENT" | "EXAM" | "LECTURE" | "LAB" | "OTHER";
course_id: string;
}Example Request:
{
"title": "Assignment 1",
"description": "First programming assignment",
"event_date": "2024-02-15T23:59:00Z",
"event_type": "ASSIGNMENT",
"course_id": "course_123"
}Success Response (201):
{
"message": "Event created successfully",
"event": {
"id": "event_456",
"title": "Assignment 1",
"description": "First programming assignment",
"event_date": "2024-02-15T23:59:00Z",
"event_type": "ASSIGNMENT",
"course_id": "course_123",
"created_by": "instructor_456",
"created_at": "2024-01-20T08:30:00Z"
}
}Get current user's detailed profile.
Success Response (200):
{
"profile": {
"id": "user_123",
"email": "john.doe@example.com",
"name": "John Doe",
"role": "STUDENT",
"isEmailVerified": true,
"createdAt": "2024-01-01T00:00:00Z",
"lastLoginAt": "2024-01-20T08:30:00Z",
"preferences": {
"theme": "dark",
"notifications": true,
"language": "en"
},
"stats": {
"coursesEnrolled": 3,
"assignmentsCompleted": 12,
"totalScore": 85.5
}
}
}Update user profile information.
Request Body:
interface UpdateProfileRequest {
name?: string;
preferences?: {
theme?: "light" | "dark";
notifications?: boolean;
language?: string;
};
}Example Request:
{
"name": "John Smith",
"preferences": {
"theme": "dark",
"notifications": false
}
}Success Response (200):
{
"message": "Profile updated successfully",
"user": {
"id": "user_123",
"email": "john.doe@example.com",
"name": "John Smith",
"role": "STUDENT",
"preferences": {
"theme": "dark",
"notifications": false,
"language": "en"
}
}
}Health check endpoint.
Success Response (200):
{
"status": "healthy",
"timestamp": "2024-01-20T08:30:00Z",
"version": "1.0.0"
}Get application version information.
Success Response (200):
{
"version": "1.0.0",
"buildDate": "2024-01-20T08:30:00Z",
"environment": "production"
}All API endpoints are subject to rate limiting:
- Authentication endpoints: 5 requests per minute per IP
- Data endpoints: 100 requests per minute per user
- Upload endpoints: 10 requests per minute per user
Rate limit headers:
X-RateLimit-Limit: 100
X-RateLimit-Remaining: 95
X-RateLimit-Reset: 1642665600In development mode, all API requests and responses are logged. Use the browser's Developer Tools Network tab to inspect API calls.
- CORS Errors: Ensure proper origin configuration
- Cookie Issues: Check SameSite and Secure flags
- Authentication Errors: Verify token expiration
- Timeout Errors: Check backend server status
For API-related issues:
- Check the Developer Tools Network tab
- Review server logs
- Contact the backend development team
- Create an issue in the project repository
Last Updated: August 17, 2025