The Library

A modern library management system built with Next.js, allowing users to browse, borrow, and return books with an intuitive interface.

Browse Books
Borrow & Return
Secure & Fast

Digital Catalog

User Management

Track Borrowings

The Library

A modern library management system built with Next.js, allowing users to browse, borrow, and return books with an intuitive interface.

šŸš€ Quick Access

Preview Link:

Test Credentials:

Admin Account

  • Email: admin@test.com
  • Password: Admin@123

User Account

  • Email: user@test.com
  • Password: User@123

Table of Contents

Overview

The Library is a full-stack web application that provides a digital library experience.

For Regular Users

  • Browse and search through a catalog of books
  • Borrow books (with a limit of 2 active borrowings per user)
  • View their borrowed books
  • Return books when finished
  • View borrowing history
  • Manage their profile

For Administrators

  • Manage books (create, update, delete)
  • View and manage inventory with detailed statistics
  • Monitor all borrowings across the library
  • Access comprehensive analytics and reports

Architecture

The application follows a modern full-stack architecture with clear separation of concerns:

Architecture Layers

  1. Client Layer: React components with Redux for global state and React Query for server state management
  2. Next.js Layer: App Router with pages, API routes, and authentication middleware
  3. Service Layer: Business logic and data models using Mongoose
  4. Data Layer: MongoDB for persistent storage

Tech Stack

Frontend

  • Next.js 16 - React framework with App Router
  • React 19 - UI library
  • TypeScript - Type safety
  • HeroUI - Component library
  • Tailwind CSS - Styling
  • Redux Toolkit - Global state management
  • TanStack Query (React Query) - Server state management
  • NextAuth - Authentication
  • React Hook Form - Form management
  • Framer Motion - Animations
  • next-themes - Theme management (dark mode)
  • Sonner - Toast notifications
  • Iconify - Icon library

Backend

  • Next.js API Routes - Serverless API endpoints
  • Mongoose - MongoDB ODM
  • MongoDB - NoSQL database
  • NextAuth - Authentication & session management

Development Tools

  • pnpm - Package manager
  • ESLint - Code linting
  • TypeScript - Type checking
  • tsx - TypeScript execution for scripts

Book Borrowing System

Database Schema

Borrowing Flow

The book borrowing system enforces business rules and manages inventory:

Return Flow

Business Rules

  1. Borrowing Limit: Users can have a maximum of 2 active borrowings at any time
  2. Stock Management: Each book has a stock count that is decremented on borrow and incremented on return
  3. Status Tracking: Borrowings have two states:
    • ACTIVE: Book is currently borrowed
    • RETURNED: Book has been returned
  4. Availability Check: Books with stock <= 0 cannot be borrowed

API Endpoints

Books

  • GET /api/v1/books - Get paginated list of books with search
  • GET /api/v1/books/categories - Get book categories

Borrowing

  • POST /api/v1/books/[id]/borrow - Borrow a book
  • POST /api/v1/books/[id]/return - Return a book
  • GET /api/v1/borrowings - Get user's active borrowings
  • GET /api/v1/borrowings/history - Get user's borrowing history

Admin Endpoints (Admin Only)

  • POST /api/v1/admin/books - Create a new book
  • PUT /api/v1/admin/books/[id] - Update a book
  • DELETE /api/v1/admin/books/[id] - Delete a book
  • GET /api/v1/admin/inventory - Get inventory statistics and analytics
  • GET /api/v1/admin/borrowings - Get all borrowings across the library

Authentication

  • POST /api/v1/auth/register - Register a new user
  • POST /api/auth/[...nextauth] - NextAuth authentication endpoints

Project Structure

Getting Started

Prerequisites

  • Node.js (version specified in .nvmrc)
  • pnpm (package manager)
  • MongoDB database (local or cloud)

Installation

  1. Clone the repository:
  1. Install dependencies:
  1. Set up environment variables (see )

  2. Run the development server:

  1. Open in your browser

MongoDB Setup

After setting up your MongoDB database (local or cloud), you need to import the existing data to get started with sample books and test user accounts.

Import Data

The project includes sample data in the tmp/ directory. Import the data using mongoimport:

For local MongoDB:

For MongoDB Atlas (cloud):

Note: Replace username, password, and cluster.mongodb.net with your actual MongoDB Atlas connection details.

After importing the data, you can use the test credentials mentioned in the section to log in.

Build for Production

Environment Variables

Create a .env.local file in the root directory with the following variables:

Features

Authentication

  • Email/password authentication
  • Google OAuth integration
  • Protected routes with NextAuth
  • Session management

Book Management

  • Browse books with pagination
  • Search books by title, author, or description
  • View book details
  • Filter by categories

Borrowing System

  • Borrow books (max 2 active at a time)
  • View borrowed books
  • Return books
  • Real-time stock management
  • Borrowing history tracking

Admin Features

  • Book Management: Create, update, and delete books with full CRUD operations
  • Inventory Management: View comprehensive inventory statistics including:
    • Total books count
    • Stock levels (in stock, low stock, out of stock)
    • Active and returned borrowings
    • Top categories analytics
  • Borrowing Management: View and monitor all borrowings across the library
  • Role-based Access Control: Admin-only routes and API endpoints

User Experience

  • Responsive design
  • Loading states
  • Error handling
  • Toast notifications
  • Smooth navigation with loading skeletons
  • Dark mode support (via next-themes)

License

This project is private.