Skip to content

shemanto27/Django-Library-Management-Borrowing-System

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

9 Commits
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ“š Library Management & Borrowing System

A comprehensive Library Management System built with Django REST Framework featuring user authentication, book borrowing/returning, inventory management, and penalty tracking system.

Features

  • ๐Ÿ” User Authentication

    • JWT-based login/register using Simple-JWT
    • Custom user model with penalty points tracking
  • ๐Ÿ“– Book Management

    • Admins โž Full CRUD operations for books, authors, and categories
    • Users โž Browse books with advanced filtering (author, category)
    • Real-time inventory tracking with atomic updates
  • ๐Ÿ“‹ Borrowing System

    • Smart borrowing limits (max 3 books per user)
    • Automated due date calculation (14 days)
    • Early return support
    • Late return penalty system (1 point per day late)
  • ๐Ÿ“Š Inventory Management

    • Multiple copies per book tracking
    • Atomic inventory updates during borrow/return
    • Real-time availability checking
  • ๐Ÿ“˜ API Documentation

    • Swagger & ReDoc support for live testing via drf_yasg

Tech Stack

  • Django, Django REST Framework
  • SimpleJWT for JWT authentication
  • drf_yasg for Swagger API Documentation
  • django_extensions for ER Diagram generation

๐Ÿ“„ API Documentation (Swagger)

Access the interactive API documentation:

http://localhost:8000/api/docs/   # Swagger UI
http://localhost:8000/api/redoc/  # ReDoc UI 

๐Ÿชช Authorization

Click "Authorize" in Swagger UI and paste your JWT token:

Bearer <your_access_token>

๐Ÿ—„๏ธ Database Models

Core Models

  • User: Extended with penalty_points field
  • Author: name, bio
  • Category: name
  • Book: title, description, author (FK), category (FK), total_copies, available_copies
  • Borrow: user (FK), book (FK), borrow_date, due_date, return_date (nullable)

๐Ÿ“ Project Structure

The project follows a modular and scalable architecture:

backend/
โ”œโ”€โ”€ core/               # Project-level configuration
โ”‚   โ”œโ”€โ”€ settings.py     # Django settings
โ”‚   โ”œโ”€โ”€ urls.py         # Main URL routing
โ”‚   โ””โ”€โ”€ wsgi.py         # WSGI configuration
โ”œโ”€โ”€ apps/               # Modular app structure
โ”‚   โ”œโ”€โ”€ borrow/         # Borrowing and returning related APIs
โ”‚   โ”œโ”€โ”€ catalog/        # Books, authors, categories related APIs  
โ”‚   โ””โ”€โ”€ users/          # Authentication, registration, and penalty APIs
โ””โ”€โ”€ manage.py

App Responsibilities:

  • core/: Project-level settings, URL routing, and configuration
  • apps/borrow/: Borrowing and returning logic
  • apps/catalog/: Book, author, and category management
  • apps/users/: Authentication, user registration, and penalty tracking

๐Ÿ” API Endpoints & Usage

๐Ÿ‘ค Authentication

Register

POST /api/register/

{
  "username": "johndoe",
  "email": "[email protected]", 
  "password": "securepass123"
}

Login (JWT)

POST /api/login/

{
  "username": "johndoe",
  "password": "securepass123"
}

๐Ÿ“š Books & Metadata

Browse Books

GET /api/books/

  • Query params: ?author=<author_name>&category=<category_name>

Book Details

GET /api/books/{id}/

Admin-Only Book Management

POST /api/books/          # Create book (admin only)
PUT /api/books/{id}/      # Update book (admin only)
DELETE /api/books/{id}/   # Delete book (admin only)

Note: Admin permissions required. Create superuser via python manage.py createsuperuser

Authors & Categories

GET /api/authors/         # List authors
POST /api/authors/        # Create author (admin only)
GET /api/categories/      # List categories  
POST /api/categories/     # Create category (admin only)

Note: Admin permissions required for POST operations

๐Ÿ“‹ Borrowing Operations

Borrow a Book

POST /api/borrow/

{
  "book_id": 1
}

Validation Logic:

  • โœ… User has < 3 active borrows
  • โœ… Book has available copies (available_copies > 0)
  • โœ… Atomically decrements available_copies
  • โœ… Sets due_date = borrow_date + 14 days

View Active Borrows

GET /api/borrow/

Return a Book

POST /api/return/

{
  "borrow_id": 1
}

Return Logic:

  • โœ… Updates return_date to current timestamp
  • โœ… Atomically increments available_copies
  • โœ… Calculates late days if past due_date
  • โœ… Adds penalty points (1 point per day late)

Check Penalty Points

GET /api/users/{id}/penalties/

  • Accessible by admin and the user themselves

๐Ÿงฎ Business Logic

Borrowing System

  1. Limit Enforcement: Users cannot borrow more than 3 books simultaneously
  2. Inventory Validation: Only books with available_copies > 0 can be borrowed
  3. Atomic Updates: All inventory changes use database transactions to prevent race conditions
  4. Due Date Calculation: Automatically set to 14 days from borrow date

Penalty System

  • Late Return Detection: Compares return_date with due_date
  • Penalty Calculation: 1 penalty point per day late
  • Accumulative: Penalty points accumulate across multiple late returns
  • Admin Oversight: Admins can view all user penalties

Inventory Management

  • Real-time Tracking: available_copies updated instantly on borrow/return
  • Data Integrity: Uses Django's select_for_update() for atomic operations
  • Validation: Prevents borrowing when no copies available

๐Ÿš€ Setup & Installation

โœ… Clone the repository

git clone https://github.com/shemanto27/Django-Library-Management-Borrowing-System.git
cd Django-Library-Management-Borrowing-System

โœ… Navigate to backend directory

cd backend

โœ… Install dependencies using uv || NO NEED FOR requirements.txt FILE, USE uv sync COMMAND

uv sync

โœ… Activate Virtual Environment

source .venv/bin/activate  

โœ… Apply migrations

python manage.py migrate

โœ… Create superuser for admin operations

python manage.py createsuperuser

โœ… Run the development server

python manage.py runserver

โœ… Access API Documentation

http://localhost:8000/api/docs/

๐Ÿ”„ Testing Workflow

For Regular Users:

  1. Create User โž POST /api/register/
  2. Login โž POST /api/login/ (get JWT token)
  3. Authorize โž Use token in Swagger UI
  4. Browse Books โž GET /api/books/
  5. Borrow Book โž POST /api/borrow/
  6. Check Borrows โž GET /api/borrow/
  7. Return Book โž POST /api/return/

For Admin Operations:

  1. Create Superuser โž python manage.py createsuperuser (in terminal)
  2. Login with Admin โž POST /api/login/ (use superuser credentials)
  3. Authorize โž Use admin JWT token in Swagger UI
  4. Admin Operations โž Create/Update/Delete books, authors, categories

โ„น๏ธ Notes

  • This project uses uv for modern Python package management, NO NEED FOR requirements.txt FILE, USE uv sync COMMAND
  • Authentication uses Simple-JWT for stateless JWT tokens
  • API documentation generated with drf_yasg
  • Database operations use atomic transactions for data integrity
  • Admin interface available at /admin/ for manual data management
  • Project follows Django best practices with modular app structure

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages