Skip to content

Nexvyn/Library-manager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 

Repository files navigation

Library Management System - Complete Application Documentation

System Overview

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.

Core Features

Book Management

  • Complete book catalog with title, author, category, and pricing
  • Multiple copy management for each book
  • Real-time availability tracking
  • Category-based organization and filtering

User Management

  • Individual user accounts with borrowing limits
  • Group accounts for organizations/classrooms
  • User type differentiation (INDIVIDUAL, GROUP_LEADER)
  • Borrowing history tracking

Borrowing System

  • 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

Return System

  • 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)

Fine Management

  • 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)

Database Architecture

Core Entities

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

API Endpoints

Book Management

  • GET /api/books - Retrieve all books with availability
  • Query parameters: category, search for filtering

User Management

  • GET /api/users - Get all system users

Borrow Operations

  • POST /api/borrow - Borrow a book
  • Required: bookId, borrowerId, borrowerType
  • Automatic due date calculation
  • Inventory validation

Return Operations

  • POST /api/return - Return a borrowed book
  • Required: borrowRecordId, damageType
  • Automatic fine calculation
  • Book status updates

Fine Management

  • GET /api/fines - Retrieve all fine records
  • Fine status and amount tracking

Testing Endpoints

  • POST /api/test/late-return - Simulate late returns for testing

Business Logic

Borrowing Rules

  • 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

Return Processing

  • Damage type assessment required at return
  • Automatic fine calculation based on:
    • Days overdue
    • Damage severity
    • Book replacement costs
  • Book copy status updates

Fine Calculation

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

Validation & Error Handling

Input Validation

  • Request body validation for all endpoints
  • Data type and format checking
  • Required field enforcement

Business Rule Enforcement

  • Borrowing limit validation
  • Book availability checking
  • User existence verification
  • Active borrow status validation

Error Responses

  • 400: Bad Request - Invalid input data
  • 404: Not Found - Resource not found
  • 500: Internal Server Error - Server issues
  • Descriptive error messages for debugging

System Architecture

Frontend Components

  • React-based user interface
  • TypeScript for type safety
  • Responsive design for all devices
  • Real-time state management

Backend Services

  • Next.js API routes
  • Prisma ORM for database operations
  • SQLite database for data persistence
  • Transaction support for data integrity

Database Schema

  • Relational database design
  • Foreign key constraints
  • Unique constraints for data integrity
  • Cascade delete for related records

Installation & Setup

Prerequisites

  • Node.js 18 or higher
  • npm or yarn package manager

Installation Steps

  1. Clone repository and install dependencies
  2. Configure environment variables
  3. Generate Prisma client
  4. Initialize database schema
  5. Start development server

Database Setup

  • SQLite database file creation
  • Schema initialization via Prisma
  • Table creation with relationships
  • Initial data seeding (if applicable)

Testing & Validation

API Testing

Comprehensive testing of all endpoints:

  • Book borrowing and returning
  • Fine calculation accuracy
  • Error condition handling
  • Data validation

Business Logic Testing

  • Borrowing limit enforcement
  • Fine calculation correctness
  • Inventory management accuracy
  • User type differentiation

Integration Testing

  • Frontend-backend communication
  • Database transaction integrity
  • Error handling across layers
  • Data consistency validation

Security Features

Data Validation

  • Input sanitization and validation
  • SQL injection prevention via Prisma
  • Type safety with TypeScript

Error Handling

  • Graceful error recovery
  • Informative error messages
  • No sensitive data exposure

Performance Considerations

Database Optimization

  • Efficient query design
  • Proper indexing
  • Relationship management

API Performance

  • Optimized response structures
  • Minimal data transfer
  • Efficient error handling

Deployment

Production Build

  • Next.js production optimization
  • Database configuration for production
  • Environment variable management

Database Migration

  • Schema migration support
  • Data backup procedures
  • Production data seeding

Maintenance & Monitoring

Database Maintenance

  • Regular backup procedures
  • Performance monitoring
  • Data integrity checks

System Monitoring

  • API endpoint health checks
  • Error logging and tracking
  • Performance metrics collection

Future Enhancements

Planned Features

  • 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

Scalability Improvements

  • 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.

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •