# Product Requirements Document: Library Management System

## 1. Overview

The Library Management System is a comprehensive digital solution designed to streamline the operations of small to medium-sized libraries. The application enables librarians to manage book inventory, track member registrations, process book loans and returns, handle reservations, and monitor overdue items. The system provides both staff-facing administrative tools and member-facing features for browsing the catalog and managing their borrowing activity.

## 2. User Roles

### 2.1 Administrator
- Full system access and configuration capabilities
- Manage librarian accounts (create, update, deactivate)
- Configure system settings (loan periods, fine rates, library information)
- Generate comprehensive reports and analytics
- Manage all book inventory operations
- Override system rules when necessary
- View audit logs and system activity

### 2.2 Librarian
- Manage book catalog (add, edit, remove books)
- Register and manage member accounts
- Process book checkouts and returns
- Handle reservations and holds
- Collect fines and fees
- Generate operational reports
- Search and browse full catalog
- Manage book copies and physical inventory

### 2.3 Member
- Browse and search book catalog
- View own borrowing history
- Reserve available books
- View current loans and due dates
- View outstanding fines
- Update own profile information (limited fields)
- Renew eligible loans

### 2.4 Guest (Unauthenticated User)
- Browse public book catalog
- Search for books by title, author, ISBN, or genre
- View book details and availability
- View library information and policies

## 3. Core Entities

### 3.1 User
Represents all system users including administrators, librarians, and members. Contains authentication credentials, personal information, and role assignment.

### 3.2 Book
Represents a unique book title in the library's collection. Contains bibliographic information such as title, author, ISBN, publisher, genre, and description.

### 3.3 BookCopy
Represents a physical copy of a book. Multiple copies of the same book can exist. Tracks condition, location, and availability status of each individual copy.

### 3.4 Member
Extends User entity with member-specific information including membership number, join date, membership status, and membership tier.

### 3.5 Loan
Represents a book checkout transaction. Tracks which book copy was borrowed, by whom, checkout date, due date, return date, and loan status.

### 3.6 Reservation
Represents a member's request to borrow a book that is currently unavailable. Tracks reservation date, status, and expiration.

### 3.7 Fine
Represents monetary penalties for overdue books or damaged items. Tracks amount, reason, status (paid/unpaid), and payment date.

### 3.8 Transaction
Represents financial transactions including fine payments and membership fees. Tracks amount, type, date, and payment method.

### 3.9 Genre
Represents book categories/classifications used for organizing and filtering the catalog.

### 3.10 Author
Represents book authors. Allows for proper author management and searching by author.

### 3.11 Publisher
Represents publishing companies. Stores publisher information for cataloging purposes.

### 3.12 LibrarySettings
Stores system-wide configuration including loan duration, maximum loans per member, fine rates, and reservation policies.

### 3.13 AuditLog
Tracks significant system events and user actions for accountability and troubleshooting.

## 4. Entity Relationships

### 4.1 User ↔ Member
- **One-to-One**: A User can be a Member (if role is "member")

### 4.2 Book ↔ BookCopy
- **One-to-Many**: A Book can have multiple BookCopies; each BookCopy belongs to one Book

### 4.3 Book ↔ Author
- **Many-to-Many**: A Book can have multiple Authors; an Author can write multiple Books

### 4.4 Book ↔ Genre
- **Many-to-Many**: A Book can belong to multiple Genres; a Genre can contain multiple Books

### 4.5 Book ↔ Publisher
- **Many-to-One**: A Book has one Publisher; a Publisher can publish multiple Books

### 4.6 Member ↔ Loan
- **One-to-Many**: A Member can have multiple Loans; each Loan belongs to one Member

### 4.7 BookCopy ↔ Loan
- **One-to-Many**: A BookCopy can have multiple Loans (over time); each Loan is for one BookCopy

### 4.8 Member ↔ Reservation
- **One-to-Many**: A Member can have multiple Reservations; each Reservation belongs to one Member

### 4.9 Book ↔ Reservation
- **One-to-Many**: A Book can have multiple Reservations; each Reservation is for one Book

### 4.10 Member ↔ Fine
- **One-to-Many**: A Member can have multiple Fines; each Fine belongs to one Member

### 4.11 Loan ↔ Fine
- **One-to-One (optional)**: A Loan may generate one Fine; a Fine may be associated with one Loan

### 4.12 Member ↔ Transaction
- **One-to-Many**: A Member can have multiple Transactions; each Transaction belongs to one Member

### 4.13 Fine ↔ Transaction
- **One-to-One (optional)**: A Fine may be paid through one Transaction; a Transaction may settle one Fine

### 4.14 User ↔ AuditLog
- **One-to-Many**: A User can generate multiple AuditLog entries; each AuditLog entry is created by one User

## 5. Key Workflows

### 5.1 Member Registration Workflow
1. Librarian/Admin initiates new member registration
2. System generates unique membership number
3. Librarian enters member personal information (name, email, phone, address)
4. System creates User account with "member" role
5. System creates associated Member record with "active" status
6. System sends welcome email with login credentials
7. Member record is saved and available for transactions

### 5.2 Book Checkout Workflow
1. Member presents membership ID and requests book
2. Librarian searches for book in system
3. System displays available copies
4. Librarian selects specific BookCopy
5. System validates:
   - Member has no outstanding fines above threshold
   - Member hasn't exceeded maximum loan limit
   - BookCopy status is "available"
6. System creates Loan record with checkout date and calculated due date
7. System updates BookCopy status to "checked_out"
8. System sends confirmation email to member with due date
9. Librarian hands book to member

### 5.3 Book Return Workflow
1. Member returns book to librarian
2. Librarian scans/searches for the BookCopy
3. System retrieves active Loan record
4. Librarian inspects book condition
5. If damaged:
   - Librarian notes damage in system
   - System creates Fine for damage
6. System updates Loan with return date
7. System calculates if return is late
8. If late:
   - System calculates overdue fine based on days late
   - System creates Fine record
9. System updates BookCopy status to "available"
10. If book has active Reservations:
    - System notifies next member in queue
    - System updates Reservation status to "ready"
11. System updates member's borrowing history

### 5.4 Book Reservation Workflow
1. Member searches for book in catalog
2. Member clicks "Reserve" on unavailable book
3. System validates:
   - Member has active membership
   - Member doesn't already have reservation for this book
   - Member hasn't exceeded maximum reservations
4. System creates Reservation record with "pending" status
5. System adds member to reservation queue
6. System sends confirmation email
7. When book becomes available:
   - System updates Reservation status to "ready"
   - System sends notification to member
   - Member has configured time period (e.g., 3 days) to pick up
8. If member picks up:
   - Proceed with checkout workflow
   - System updates Reservation status to "fulfilled"
9. If member doesn't pick up within time period:
   - System updates Reservation status to "expired"
   - System notifies next member in queue

### 5.5 Fine Payment Workflow
1. Member/Librarian views outstanding fines
2. Member provides payment
3. Librarian selects fine(s) to pay
4. Librarian enters payment amount and method
5. System validates payment amount covers selected fines
6. System creates Transaction record
7. System updates Fine status to "paid"
8. System updates Fine with payment date
9. System generates receipt
10. System sends payment confirmation email to member

### 5.6 Book Catalog Management Workflow
1. Librarian navigates to catalog management
2. Librarian clicks "Add New Book"
3. Librarian enters book details:
   - Title, ISBN, publication date, description
   - Selects/creates authors
   - Selects/creates publisher
   - Assigns genres
4. System validates ISBN uniqueness
5. System creates Book record
6. Librarian specifies number of physical copies
7. For each copy:
   - System generates unique copy identifier
   - Librarian enters location and condition
   - System creates BookCopy record with "available" status
8. System saves all records
9. Book appears in searchable catalog

### 5.7 Loan Renewal Workflow
1. Member requests to renew loan (via system or librarian)
2. System retrieves Loan record
3. System validates:
   - Loan is not already overdue
   - Book has no pending reservations
   - Member hasn't exceeded maximum renewals for this loan
   - Member has no outstanding fines above threshold
4. If valid:
   - System extends due date by standard loan period
   - System increments renewal count
   - System sends confirmation with new due date
5. If invalid:
   - System displays reason for denial
   - Member must return book or resolve issues

## 6. Features & Requirements

### 6.1 Authentication & Authorization Module

#### 6.1.1 User Authentication
- Users must log in with email and password
- Support password reset via email link
- Implement session management with configurable timeout
- Lock account after configurable number of failed login attempts
- Support "Remember Me" functionality

#### 6.1.2 Role-Based Access Control
- Enforce role-based permissions on all endpoints
- Restrict administrative functions to Admin role
- Restrict catalog management to Librarian and Admin roles
- Allow Members to access only their own data
- Implement permission checks at both API and UI levels

#### 6.1.3 User Management
- Admins can create, update, and deactivate user accounts
- Admins can assign and change user roles
- Users can update their own profile information (limited fields)
- Support user search and filtering by role, status, name

### 6.2 Book Catalog Module

#### 6.2.1 Book Management
- Create new book entries with complete bibliographic information
- Edit existing book details
- Soft delete books (mark as inactive rather than permanent deletion)
- Upload and display book cover images
- Support multiple authors per book
- Assign multiple genres per book
- Track publisher information

#### 6.2.2 Book Copy Management
- Add multiple physical copies for each book
- Assign unique identifiers to each copy
- Track copy-specific information (condition, location, acquisition date)
- Update copy status (available, checked_out, reserved, maintenance, lost)
- Remove copies from circulation

#### 6.2.3 Catalog Search & Browse
- Full-text search across title, author, ISBN, description
- Filter by genre, author, publisher, availability
- Sort results by title, author, publication date, popularity
- Display book details including all copies and their status
- Show availability count for each book
- Public catalog view for guests (limited information)

#### 6.2.4 Author & Publisher Management
- Create and edit author profiles
- Create and edit publisher information
- View all books by specific author or publisher
- Merge duplicate author/publisher entries

#### 6.2.5 Genre Management
- Create, edit, and delete genre categories
- Assign genre hierarchy (parent/child relationships)
- View all books in a genre

### 6.3 Member Management Module

#### 6.3.1 Member Registration
- Register new members with personal information
- Auto-generate unique membership numbers
- Set membership start date and tier
- Create associated user account
- Send welcome email with credentials

#### 6.3.2 Member Profile Management
- View complete member profile
- Edit member information (address, phone, email)
- Update membership status (active, suspended, expired)
- View membership history and statistics
- Track membership tier and benefits

#### 6.3.3 Member Search & Listing
- Search members by name, email, membership number
- Filter by membership status and tier
- View member borrowing statistics
- Export member lists

### 6.4 Circulation Module

#### 6.4.1 Checkout Processing
- Search and select book copies for checkout
- Validate member eligibility
- Create loan records with automatic due date calculation
- Update book copy status
- Print/email checkout receipt
- Support batch checkout for multiple books

#### 6.4.2 Return Processing
- Search for active loans by book copy or member
- Record return date
- Inspect and record book condition
- Calculate and create overdue fines automatically
- Update book copy status
- Trigger reservation notifications if applicable

#### 6.4.3 Loan Management
- View all active loans system-wide
- View loans by specific member
- View loan history for a book copy
- Filter loans by status (active, returned, overdue)
- Display overdue loans prominently
- Support loan renewal with validation

#### 6.4.4 Overdue Management
- Automatically identify overdue loans
- Display overdue loans dashboard
- Send automated overdue reminder emails
- Calculate overdue fines based on configured rates
- Generate overdue reports

### 6.5 Reservation Module

#### 6.5.1 Reservation Creation
- Members can reserve unavailable books
- Validate reservation eligibility
- Add member to reservation queue
- Send confirmation notification

#### 6.5.2 Reservation Management
- View all reservations by status
- View member's active reservations
- Cancel reservations
- Process reservation fulfillment when book available
- Handle reservation expiration automatically
- Notify next member in queue when reservation expires

#### 6.5.3 Reservation Queue
- Display reservation queue for each book
- Show member's position in queue
- Allow librarians to adjust queue order (if needed)
- Track reservation wait times

### 6.6 Fines & Payments Module

#### 6.6.1 Fine Management
- Automatically generate overdue fines
- Manually create fines (damage, lost books, etc.)
- View all fines by member
- View unpaid fines system-wide
- Waive or adjust fine amounts (with proper permissions)
- Track fine history

#### 6.6.2 Payment Processing
- Record fine payments
- Support multiple payment methods (cash, card, online)
- Apply payments to specific fines
- Generate payment receipts
- Track payment history
- Send payment confirmation emails

#### 6.6.3 Financial Reporting
- Generate revenue reports by date range
- Track outstanding fines total
- Report on payment methods used
- Export financial data

### 6.7 Reporting & Analytics Module

#### 6.7.1 Circulation Reports
- Most borrowed books
- Borrowing trends over time
- Average loan duration
- Return rate statistics
- Overdue rate analysis

#### 6.7.2 Inventory Reports
- Total books and copies count
- Books by genre distribution
- Book condition reports
- Lost and damaged books report
- Acquisition reports

#### 6.7.3 Member Reports
- Active members count
- New member registrations over time
- Most active borrowers
- Member demographics

#### 6.7.4 Financial Reports
- Fines collected by period
- Outstanding fines report
- Revenue by fine type
- Payment method breakdown

### 6.8 System Administration Module

#### 6.8.1 Library Settings Configuration
- Configure default loan period
- Set maximum loans per member
- Configure overdue fine rates (per day)
- Set maximum renewals allowed
- Configure reservation hold period
- Set fine threshold for blocking checkouts
- Configure email notification templates

#### 6.8.2 System Monitoring
- View audit logs
- Monitor system activity
- Track user actions
- View error logs

#### 6.8.3 Data Management
- Backup and restore functionality
- Data export capabilities
- Bulk import books from CSV/Excel
- Archive old records

### 6.9 Notification Module

#### 6.9.1 Email Notifications
- Welcome email on member registration
- Checkout confirmation with due date
- Due date reminders (configurable days before)
- Overdue notices
- Reservation ready notifications
- Reservation expiration warnings
- Fine payment confirmations

#### 6.9.2 Notification Management
- Configure notification triggers
- Customize email templates
- View notification history
- Enable/disable specific notification types

### 6.10 Dashboard Module

#### 6.10.1 Admin/Librarian Dashboard
- Overview statistics (total books, members, active loans)
- Overdue loans summary
- Recent activity feed
- Pending reservations count
- Outstanding fines total
- Quick action buttons

#### 6.10.2 Member Dashboard
- Current loans with due dates
- Reservation status
- Outstanding fines
- Borrowing history summary
- Quick search and browse

## 7. Business Rules

### 7.1 Membership Rules
- Each member must have a unique email address
- Membership numbers must be unique and auto-generated
- Members must be at least 13 years old (configurable)
- Suspended members cannot borrow books or make reservations
- Expired memberships must be renewed before borrowing

### 7.2 Loan Rules
- A member can have a maximum of 5 active loans simultaneously (configurable)
- Default loan period is 14 days (configurable)
- A loan can be renewed maximum 2 times (configurable)
- Loans cannot be renewed if the book has pending reservations
- Loans cannot be renewed if already overdue
- Members with outstanding fines above $10 (configurable) cannot checkout books
- A book copy can only have one active loan at a time

### 7.3 Reservation Rules
- Members can only reserve books that are currently unavailable
- A member can have maximum 3 active reservations (configurable)
- A member cannot reserve the same book multiple times
- Reservations expire if not picked up within 3 days of notification (configurable)
- Reservations are queued in first-come, first-served order
- Members with suspended accounts cannot make reservations

### 7.4 Fine Rules
- Overdue fines are calculated at $0.50 per day (configurable)
- Maximum fine per book is $25 (configurable)
- Fines for damaged books are assessed by librarian (manual entry)
- Fines for lost books equal replacement cost plus $10 processing fee
- Partial fine payments are allowed
- Fines must be paid before membership can be renewed
- Fines older than 2 years can be written off by administrators

### 7.5 Book Copy Rules
- Each book copy must have a unique identifier
- Book copies marked as "lost" or "maintenance" are not available for checkout
- Book copies cannot be deleted if they have active loans
- At least one copy must remain in the system for a book (cannot delete all copies)

### 7.6 Catalog Rules
- ISBN must be unique per book (if provided)
- Book title and at least one author are required
- Books cannot be permanently deleted, only marked inactive
- Inactive books do not appear in public catalog searches
- A book must have at least one genre assigned

### 7.7 Return Rules
- Books can be returned even if overdue
- Late returns automatically generate overdue fines
- Damaged books must have condition noted and fine assessed
- Returned books with pending reservations are held for pickup, not marked available

### 7.8 Payment Rules
- Payments must be positive amounts
- Payments cannot exceed total outstanding fines
- Payment transactions are immutable once recorded
- Receipts must be generated for all payments

### 7.9 User Account Rules
- Email addresses must be unique across all users
- Passwords must meet minimum complexity requirements (8+ characters, mix of letters and numbers)
- Accounts are locked after 5 failed login attempts (configurable)
- Locked accounts can only be unlocked by administrators
- User accounts cannot be deleted, only deactivated

### 7.10 Data Retention Rules
- Loan history is retained indefinitely
- Audit logs are retained for minimum 1 year
- Returned loans older than 5 years can be archived
- Member accounts inactive for 3+ years can be marked for review

## 8. Non-Functional Requirements

### 8.1 Performance Requirements
- Page load time must not exceed 2 seconds under normal load
- Search queries must return results within 1 second
- System must support at least 100 concurrent users
- Database queries must be optimized with appropriate indexing
- API response time must be under 500ms for 95% of requests
- Batch operations (imports, reports) should run asynchronously

### 8.2 Security Requirements
- All passwords must be hashed using bcrypt or similar strong algorithm
- Implement HTTPS for all communications
- Protect against SQL injection through parameterized queries
- Implement CSRF protection for all state-changing operations
- Sanitize all user inputs to prevent XSS attacks
- Implement rate limiting on authentication endpoints
- Session tokens must expire after 24 hours of inactivity
- Sensitive data (passwords, payment info) must never be logged
- Implement proper CORS policies
- Regular security audits and dependency updates

### 8.3 Scalability Requirements
- Database design must support growth to 100,000+ books
- System must handle 10,000+ member accounts
- Architecture should support horizontal scaling if needed
- File storage (book covers) should be scalable (cloud storage ready)
- Database connection pooling must be implemented

### 8.4 Reliability & Availability
- System uptime target of 99.5%
- Implement automated database backups daily
- Backup retention period of 30 days
- Implement error logging and monitoring
- Graceful error handling with user-friendly messages
- Transaction rollback on failures to maintain data integrity

### 8.5 Usability Requirements
- Interface must be intuitive and require minimal training
- Responsive design supporting desktop, tablet, and mobile devices
- Consistent UI/UX patterns throughout application
- Accessibility compliance with WCAG 2.1 Level AA standards
- Support for keyboard navigation
- Clear error messages with actionable guidance
- Confirmation dialogs for destructive actions

### 8.6 Maintainability Requirements
- Code must follow consistent style guidelines
- Comprehensive inline documentation
- Modular architecture with clear separation of concerns
- RESTful API design principles
- Comprehensive API documentation
- Database migrations for schema changes
- Logging of all significant system events

### 8.7 Compatibility Requirements
- Support latest two versions of major browsers (Chrome, Firefox, Safari, Edge)
- Mobile responsive design for iOS and Android devices
- API should be version-controlled for backward compatibility
- Support for modern database systems (PostgreSQL, MySQL)

### 8.8 Data Integrity Requirements
- Implement database constraints (foreign keys, unique constraints)
- Use database transactions for multi-step operations
- Validate all data at both client and server side
- Implement soft deletes for critical entities
- Maintain audit trail for sensitive operations
- Regular data integrity checks and reports

### 8.9 Compliance Requirements
- GDPR compliance for personal data handling
- Provide data export functionality for members
- Implement right to be forgotten (data anonymization)
- Privacy policy and terms of service acceptance
- Secure handling of minor's data (if applicable)

### 8.10 Monitoring & Logging Requirements
- Application performance monitoring (APM)
- Error tracking and alerting
- User activity logging for audit purposes
- System health monitoring (CPU, memory, disk usage)
- Automated alerts for critical errors
- Log retention policy (minimum 90 days for application logs)

---

**Document Version:** 1.0  
**Last Updated:** 2025  
**Document Owner:** Product Management Team