A full-stack library management system built with Next.js, Prisma, SQLite, and TypeScript. The application provides comprehensive book borrowing, return, and fine management functionality with a complete backend API and database.
- Complete book catalog with title, author, category, and pricing
- Multiple copy management for each book
- Real-time availability tracking
- Category-based organization and filtering
- Individual user accounts with borrowing limits
- Group accounts for organizations/classrooms
- User type differentiation (INDIVIDUAL, GROUP_LEADER)
- Borrowing history tracking
- Automated book borrowing with validation
- Intelligent due date calculation:
- 14 days for individual users
- 21 days for group users
- One-active-borrow-per-user enforcement
- Real-time inventory updates
- Comprehensive return processing
- Damage assessment at return (NONE, SMALL, LARGE)
- Automatic fine calculation based on:
- Late returns
- Book damage
- Missing books
- Book status updates (AVAILABLE, DAMAGED, MISSING)
- Automated fine generation
- Multiple fine categories:
- LATE_RETURN: 2% of book price per day (max 50%)
- DAMAGE_SMALL: 10% of book price
- DAMAGE_LARGE: 50% of book price
- MISSING_BOOK: 100% of book price
- Fine status tracking (PENDING, PAID, WAIVED)
Books & Copies
- Books table for catalog information
- Book copies table for individual copy tracking
- Copy status: AVAILABLE, BORROWED, DAMAGED, MAINTENANCE
Users & Groups
- Users table for individual borrowers
- Groups table for organizational borrowing
- Relationship management between users and groups
Borrowing System
- Borrow records tracking all lending transactions
- Status management: ACTIVE, RETURNED, OVERDUE, MISSING
- Due date and return date tracking
Fine System
- Fine records linked to borrow transactions
- Multiple fine reasons and status tracking
- Payment date recording
GET /api/books- Retrieve all books with availability- Query parameters: category, search for filtering
GET /api/users- Get all system users
POST /api/borrow- Borrow a book- Required: bookId, borrowerId, borrowerType
- Automatic due date calculation
- Inventory validation
POST /api/return- Return a borrowed book- Required: borrowRecordId, damageType
- Automatic fine calculation
- Book status updates
GET /api/fines- Retrieve all fine records- Fine status and amount tracking
POST /api/test/late-return- Simulate late returns for testing
- Users limited to one active borrow at a time
- Book availability validation before borrowing
- Automatic due date assignment based on user type
- Real-time inventory updates
- Damage type assessment required at return
- Automatic fine calculation based on:
- Days overdue
- Damage severity
- Book replacement costs
- Book copy status updates
Late Returns
- Daily charge: 2% of book price
- Maximum charge: 50% of book price
- Automatic calculation based on return date
Damage Fines
- Small damage: 10% of book price
- Large damage: 50% of book price
- Missing books: 100% of book price
- Request body validation for all endpoints
- Data type and format checking
- Required field enforcement
- Borrowing limit validation
- Book availability checking
- User existence verification
- Active borrow status validation
- 400: Bad Request - Invalid input data
- 404: Not Found - Resource not found
- 500: Internal Server Error - Server issues
- Descriptive error messages for debugging
- React-based user interface
- TypeScript for type safety
- Responsive design for all devices
- Real-time state management
- Next.js API routes
- Prisma ORM for database operations
- SQLite database for data persistence
- Transaction support for data integrity
- Relational database design
- Foreign key constraints
- Unique constraints for data integrity
- Cascade delete for related records
- Node.js 18 or higher
- npm or yarn package manager
- Clone repository and install dependencies
- Configure environment variables
- Generate Prisma client
- Initialize database schema
- Start development server
- SQLite database file creation
- Schema initialization via Prisma
- Table creation with relationships
- Initial data seeding (if applicable)
Comprehensive testing of all endpoints:
- Book borrowing and returning
- Fine calculation accuracy
- Error condition handling
- Data validation
- Borrowing limit enforcement
- Fine calculation correctness
- Inventory management accuracy
- User type differentiation
- Frontend-backend communication
- Database transaction integrity
- Error handling across layers
- Data consistency validation
- Input sanitization and validation
- SQL injection prevention via Prisma
- Type safety with TypeScript
- Graceful error recovery
- Informative error messages
- No sensitive data exposure
- Efficient query design
- Proper indexing
- Relationship management
- Optimized response structures
- Minimal data transfer
- Efficient error handling
- Next.js production optimization
- Database configuration for production
- Environment variable management
- Schema migration support
- Data backup procedures
- Production data seeding
- Regular backup procedures
- Performance monitoring
- Data integrity checks
- API endpoint health checks
- Error logging and tracking
- Performance metrics collection
- User authentication and authorization
- Email notifications for due dates
- Online fine payment integration
- Book reservation system
- Advanced reporting and analytics
- Barcode/QR code integration
- Multi-library support
- Mobile application
- Database migration to PostgreSQL/MySQL
- API rate limiting
- Caching implementation
- Load balancing support
This complete library management system provides robust functionality for book lending operations with automated fine calculation, comprehensive user management, and reliable inventory tracking. The system is production-ready with proper error handling, data validation, and scalable architecture.