You are required to design and implement a modular, secure Quiz Management REST API using:
- Node.js & Express
- MongoDB (Mongoose)
- JWT Authentication
- Best-practice project structure
- Full CRUD and permission controls
The API will allow authenticated users to create quizzes, add questions & answers, manage them, and track quiz performance.
Your API will be used by a potential frontend (not part of the assignment), so the routes, responses, and error handling must be clean and predictable.
-
Implement JWT-based user authentication.
-
Users must be able to:
- Register
- Login
- Access protected routes using tokens
Users should be able to:
- Title (required)
- Optional description
- Status: active, archived
- Update quiz details
- Delete a quiz
- Archive/unarchive quizzes
- Fetch all quizzes created by the authenticated user
- Fetch a single quiz with all its nested questions & answers
Within a quiz, the owner can:
- Add questions
- Add optional help/description text (e.g., βOnly one answer is correctβ or βMultiple answers allowedβ)
- Edit questions
- Delete questions
For each question, the quiz owner can:
- Add answers
- Mark one or more answers as correct
- Edit answers
- Delete answers
Validation required:
- If the question type only allows one correct answer, enforce it
- Handle bad or contradictory submissions with proper error responses
Users participating in a quiz should be able to:
- Submit answers for a quiz
- Have their submission evaluated
The API must return:
correct_answerstotal_questionstotal_questions_answeredscore_percentagegrade(A/B/C/D/F β your own scale)
- Must follow a modular folder structure (routers, controllers, services, models, middlewares, utils)
- Use Mongoose schema relationships (Quiz β Questions β Answers)
- Code must be well documented
- Use environment variables for secrets and DB config
- Use async/await and proper error handling
-
Protect routes with JWT authentication middleware
-
Users may only manage:
- Their own quizzes
- The questions/answers within their quizzes
-
Validate object IDs & request bodies
-
Prevent unauthorized access by returning correct HTTP errors
Return structured JSON errors such as:
{
"error": true,
"message": "Quiz not found",
"status": 404
}Handle:
- Missing fields
- Invalid IDs
- Unauthorized access
- Forbidden operations
- Unknown routes
- Server errors
Students must submit:
-
Source code repository (GitHub or similar)
-
README.md including:
- Project setup instructions
- Route documentation
- Authentication instructions
-
Postman Collection (exported JSON)
-
Short explanation of key decisions:
- Folder structure
- Middleware usage
- Permission checks
- Error handling strategy
- Rate limiting
- Swagger API docs
- Quiz categories
- Pagination on large quiz lists
- Soft deletes
- Role-based access control
By completing this assignment, you will learn to:
β Build secure REST APIs using Express β Implement JWT authentication β Model relational data using MongoDB β Design clean, modular backend architecture β Implement access control and validation β Return meaningful API responses and errors