Design a Library Management System

Difficulty: MEDIUMCategory: LLDFrequency: 1Asked On 2022-05-24

Problem Statement

Design and implement a Library Management System (LMS) that supports book cataloging, user membership, borrowing/returning books, and fine calculation.

Functional Requirements (FR)


Book Management


•Add, remove, or update books in the catalog.
•Each book has details: ISBN, title, author, category, publicationYear.
•Support multiple copies of the same book.


Search & Catalog


•Search books by title, author, subject, or ISBN.
•Show availability (available vs. borrowed copies).


User Management


•Support different roles: Librarian and Member.
•Librarian → add/remove books, manage users.
•Member → borrow/return books, view fines.


Borrowing & Returning


•Each member can borrow up to a max number of books.
•Track due dates for borrowed books.
•Prevent borrowing if limits are exceeded or fines are unpaid.


Fine Calculation


•Fine applied for overdue books.
•Configurable fine per day.


Notifications (Optional/Advanced)


•Notify users when a book is due/overdue.
•Notify when reserved books become available.


Non-Functional Requirements (NFR)


•Scalability → Should handle thousands of members and books.
•Extensibility → Easy to add eBooks or audiobooks in the future.
•Consistency → Book availability must always be accurate.
•Reliability → No double booking of the same copy.


Core Classes & Entities


Book


•Attributes: ISBN, title, author, category.


BookCopy


•Attributes: copyId, ISBN, status (available/borrowed).


User


•Subtypes: Librarian, Member.


LibraryCard


•Attributes: cardId, memberId, issueDate, expiryDate.


Transaction (Borrow/Return)


•Attributes: transactionId, member, bookCopy, issueDate, dueDate, returnDate.


Fine


•Attributes: transactionId, amount, paidStatus.


Catalog


•Handles searching books by metadata.


APIs / Methods


•Book searchBookByTitle(String title)
•Book searchBookByAuthor(String author)
•BookCopy borrowBook(Member member, String ISBN)
•void returnBook(Member member, BookCopy copy)
•double calculateFine(Transaction txn)
•void addBook(Book book, int numberOfCopies)
•void removeBook(String ISBN)


Design Decisions


•Search → Implemented using Catalog with indexing.
•Borrowing → HashMap of ISBN → AvailableCopies.
•Fine Calculation → Strategy Pattern to support different fine rules.
•Scalability → Support multiple library branches by adding LibraryBranch entity.
•Thread Safety → Required for concurrent borrowing operations.


✅ This LLD problem tests object modeling, role-based access control, transaction management, and extensibility.

Solution

Comments