Develop a Library Management System using Express, TypeScript, and MongoDB (via Mongoose).
Your project must include:
- Proper schema validation
- Business logic enforcement (e.g., availability control on borrow)
- Use of aggregation pipeline
- At least one Mongoose static or instance method
- Use of Mongoose middleware (
pre
,post
) - Filtering features
- Use Express and TypeScript
- Connect to MongoDB using Mongoose
- Follow the exact API endpoints and response structures described below
- title (string) — Mandatory. The book’s title.
- author (string) — Mandatory. The book’s author.
- genre (string) — Mandatory. Must be one of:
FICTION
,NON_FICTION
,SCIENCE
,HISTORY
,BIOGRAPHY
,FANTASY
. - isbn (string) — Mandatory and unique. The book’s International Standard Book Number.
- description (string) — Optional. A brief summary or description of the book.
- copies (number) — Mandatory. Non-negative integer representing total copies available.
- available (boolean) — Defaults to
true
. Indicates if the book is currently available for borrowing.
- book (objectId) — Mandatory. References the borrowed book’s ID.
- quantity (number) — Mandatory. Positive integer representing the number of copies borrowed.
- dueDate (date) — Mandatory. The date by which the book must be returned.
message
: A brief error message explaining what went wrong.success
: Set tofalse
for error responses.error
: The error message or error object returned by the application
{
"message": "Validation failed",
"success": false,
"error": {
"name": "ValidationError",
"errors": {
"copies": {
"message": "Copies must be a positive number",
"name": "ValidatorError",
"properties": {
"message": "Copies must be a positive number",
"type": "min",
"min": 0
},
"kind": "min",
"path": "copies",
"value": -5
}
}
}
}
POST /api/books
{
"title": "The Theory of Everything",
"author": "Stephen Hawking",
"genre": "SCIENCE",
"isbn": "9780553380163",
"description": "An overview of cosmology and black holes.",
"copies": 5,
"available": true
}
{
"success": true,
"message": "Book created successfully",
"data": {
"_id": "64f123abc4567890def12345",
"title": "The Theory of Everything",
"author": "Stephen Hawking",
"genre": "SCIENCE",
"isbn": "9780553380163",
"description": "An overview of cosmology and black holes.",
"copies": 5,
"available": true,
"createdAt": "2024-11-19T10:23:45.123Z",
"updatedAt": "2024-11-19T10:23:45.123Z"
}
}
GET /api/books
Supports filtering, and sorting.
/api/books?filter=FANTASY&sortBy=createdAt&sort=desc&limit=5
filter
: Filter by genresort
:asc
ordesc
limit
: Number of results (default: 10)
{
"success": true,
"message": "Books retrieved successfully",
"data": [
{
"_id": "64f123abc4567890def12345",
"title": "The Theory of Everything",
"author": "Stephen Hawking",
"genre": "SCIENCE",
"isbn": "9780553380163",
"description": "An overview of cosmology and black holes.",
"copies": 5,
"available": true,
"createdAt": "2024-11-19T10:23:45.123Z",
"updatedAt": "2024-11-19T10:23:45.123Z"
}
{...}
]
}
GET /api/books/:bookId
{
"success": true,
"message": "Book retrieved successfully",
"data": {
"_id": "64f123abc4567890def12345",
"title": "The Theory of Everything",
"author": "Stephen Hawking",
"genre": "SCIENCE",
"isbn": "9780553380163",
"description": "An overview of cosmology and black holes.",
"copies": 5,
"available": true,
"createdAt": "2024-11-19T10:23:45.123Z",
"updatedAt": "2024-11-19T10:23:45.123Z"
}
}
PUT /api/books/:bookId
{
"copies": 50
}
{
"success": true,
"message": "Book updated successfully",
"data": {
"_id": "64f123abc4567890def12345",
"title": "The Theory of Everything",
"author": "Stephen Hawking",
"genre": "SCIENCE",
"isbn": "9780553380163",
"description": "An overview of cosmology and black holes.",
"copies": 50,
"available": true,
"createdAt": "2024-11-19T10:23:45.123Z",
"updatedAt": "2024-11-20T08:30:00.000Z"
}
}
DELETE /api/books/:bookId
{
"success": true,
"message": "Book deleted successfully",
"data": null
}
POST /api/borrow
- Verify the book has enough available copies.
- Deduct the requested quantity from the book’s copies.
- If copies become 0, update
available
tofalse
(implement this using a static method or instance method). - Save the borrow record with all relevant details.
{
"book": "64ab3f9e2a4b5c6d7e8f9012",
"quantity": 2,
"dueDate": "2025-07-18T00:00:00.000Z"
}
{
"success": true,
"message": "Book borrowed successfully",
"data": {
"_id": "64bc4a0f9e1c2d3f4b5a6789",
"book": "64ab3f9e2a4b5c6d7e8f9012",
"quantity": 2,
"dueDate": "2025-07-18T00:00:00.000Z",
"createdAt": "2025-06-18T07:12:15.123Z",
"updatedAt": "2025-06-18T07:12:15.123Z"
}
}
GET /api/borrow
Purpose:
Return a summary of borrowed books, including:
- Total borrowed quantity per book (
totalQuantity
) - Book details:
title
andisbn
Details:
Use MongoDB aggregation pipeline to:
- Group borrow records by book
- Sum total quantity borrowed per book
- Return book info and total borrowed quantity
Response:
{
"success": true,
"message": "Borrowed books summary retrieved successfully",
"data": [
{
"book": {
"title": "The Theory of Everything",
"isbn": "9780553380163"
},
"totalQuantity": 5
},
{
"book": {
"title": "1984",
"isbn": "9780451524935"
},
"totalQuantity": 3
}
]
}
💡 Pro Tip: Strictly follow the exact API endpoints and response formats provided in this document — any deviation may result in mark deduction.
- Code Quality: Clean, readable code with meaningful names.
- API Structure: Follow provided endpoints and response formats exactly.
- Error Handling: Handle invalid input, 404s, and validation errors clearly.
- Video Explanation: Short recorded video explaining key features and logic.
- Documentation: Well-written README.md with setup and API details.
- GitHub Repository Link
- Live Deployment Link
- Video Explanation (Public Link)
- Professional README file with features of your application and instructions on setting up the project locally.
- 60 Marks: Jun 21, 2025 - 11:59 PM
- 50 Marks: Jun 22, 2025 - 11:59 PM
- 30 Marks: After Jun 22, 2025
Plagiarism will not be tolerated. Ensure that the code you submit is your work. Any instances of plagiarism will result in 0 Marks.
By following these instructions, you'll be well-equipped to complete Assignment 3 successfully. Good luck! 🍀