Library Management
Last updated August 2, 2026
Classgrid's Library Module provides a complete book catalog, issue/return workflow, reservation system, AI-powered book categorization, overdue fine tracking, and analytics dashboard. All data is stored in Supabase/Postgres tables (library_books, library_copies, library_transactions, library_reservations), with student identity resolved from MongoDB (User model).
Book Catalog
View Catalog
API: GET /api/library/catalog
Roles: Any authenticated user in the organization
Query params:
search— filters bybook_name,book_id, orsubjectusingilike(case-insensitive)
Returns all books with their copy-level status:
Add/Edit Book
API: POST /api/library/books
Roles: org_admin, library_manager
Body:
- If
idis provided → updates existing book - If no
id→ inserts new book - Duplicate
book_idwithin same org returns HTTP 409 (Postgres unique constraint23505)
Delete Book
API: DELETE /api/library/books/:id
Roles: org_admin, library_manager
Bulk Import with AI Categorization
API: POST /api/library/import
Roles: org_admin, library_manager
Body:
Workflow:
- Separates books with missing
subjectfield - Sends uncategorized book titles to Classgrid AI (model:
classgrid-v3) - AI categorizes them into academic subjects (e.g., "Physics", "Computer Science", "Literature")
- Books with AI-assigned subjects are flagged with
is_auto_categorized: true - All books are upserted into
library_books(conflict onorg_id, book_id— updates existing) - Returns count of AI-filled subjects
Issue/Return Workflow
Issue a Book
API: POST /api/library/issue
Roles: org_admin, library_manager
Body:
Workflow:
- Checks book availability (
available_copies > 0) - Decrements
available_copiesonlibrary_books - Updates specific copy status to
Issued(ifcopy_db_idprovided) - Creates
library_transactionsrecord with statusIssued - Sends checkout email to student via AWS SES:
- Subject: "📚 Library Book Issued"
- Body: book name, due date, return reminder
- Creates in-app
Notification(type:library) - If any step fails after decrementing copies, rolls back the availability count
Return a Book
API: POST /api/library/return
Roles: org_admin, library_manager
Body:
Workflow:
- Validates transaction exists and status is
Issued - Updates transaction:
status→Returned, setsreturn_date,fine_amount,fine_status - Increments
available_copiesonlibrary_books - Updates copy status to
Available(if copy tracking is enabled)
Student Views
My Books (Active + History)
API: GET /api/library/student/books
Roles: Any authenticated student
Returns all transactions for the logged-in student with:
- Book details (name, ID, subject) via Supabase join
- Dynamically calculated
active_finefor overdue books:- ₹5 per day past due date
- Calculated as:
Math.ceil(daysDiff) * 5
AI Book Summary
API: POST /api/library/student/book-info
Roles: Any authenticated student
Body: { "book_name": "Data Structures in C", "subject": "Computer Science" }
Uses Classgrid AI (model: classgrid-v3, temperature: 0.5) to generate a 2-3 sentence overview of what the student will learn from the book.
Book Reservation System
Reserve a Book
API: POST /api/library/reserve
Roles: Any authenticated student
Body: { "book_db_id": 1 }
- Checks for existing pending reservation (prevents duplicates, returns HTTP 409)
- Calculates queue position based on existing pending reservations
- Creates
library_reservationsrecord withstatus: pendingandqueue_position - Returns: "Book reserved! You are #3 in queue."
View My Reservations (Student)
API: GET /api/library/student/reservations
Roles: Any authenticated student
Cancel Reservation
API: POST /api/library/cancel-reservation
Roles: Any authenticated user (student or admin)
Body: { "reservation_id": 15 }
Updates status to cancelled.
Admin: View All Reservations
API: GET /api/library/reservations
Roles: org_admin, library_manager
Returns all pending reservations with student info (name, PRN, roll number) from MongoDB.
Fulfill Reservation
API: POST /api/library/fulfill-reservation
Roles: org_admin, library_manager
Body: { "reservation_id": 15 }
Workflow:
- Updates reservation status to
fulfilled - Sends email to student: "📚 Your Reserved Book is Ready!"
- Creates in-app notification: "Please visit the library to collect it within 48 hours."
Overdue Reminder System
API: GET /api/library/overdue-check
Roles: org_admin, library_manager
Workflow:
- Queries all transactions with
status: Issuedanddue_date < now - For each overdue transaction:
- Calculates
daysOverdueandfine(₹5/day) - Sends email via AWS SES: "⚠️ Library Book Overdue Reminder" with book name, due date, days overdue, and current fine
- Creates in-app
Notification
- Calculates
- Returns
{ sent: 12, totalOverdue: 15 }
Analytics Dashboard
API: GET /api/library/analytics
Roles: org_admin, library_manager
Returns:
Summary
totalBooks— sum of alltotal_copiesavailableBooks— sum of allavailable_copiestotalIssued— count of active issuestotalReturned— count of returnstotalOverdue— count of overdue bookstotalFines— sum of all calculated fines (₹5/day for each overdue)
Most Issued Books (Top 10)
Aggregated from all transactions, sorted by issue count.
Top Defaulters (Top 10)
Students with the most overdue books, with name and PRN from MongoDB.
Monthly Trends (Last 6 Months)
Per-month breakdown of issued vs returned books.
Admin View: All Transactions
API: GET /api/library/transactions
Roles: org_admin, library_manager
Query params: status — filter by Issued or Returned
Returns all transactions with:
- Book info (name, book_id) via Supabase join
- Copy info (copy_id) via Supabase join
- Student info (name, PRN, roll_no) from MongoDB