A comprehensive Library Management System built with Django REST Framework featuring user authentication, book borrowing/returning, inventory management, and penalty tracking system.
-
๐ 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
- Django, Django REST Framework
- SimpleJWT for JWT authentication
- drf_yasg for Swagger API Documentation
- django_extensions for ER Diagram generation
Access the interactive API documentation:
http://localhost:8000/api/docs/ # Swagger UI
http://localhost:8000/api/redoc/ # ReDoc UI Click "Authorize" in Swagger UI and paste your JWT token:
Bearer <your_access_token>
- User: Extended with
penalty_pointsfield - 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)
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 configurationapps/borrow/: Borrowing and returning logicapps/catalog/: Book, author, and category managementapps/users/: Authentication, user registration, and penalty tracking
POST /api/register/
{
"username": "johndoe",
"email": "[email protected]",
"password": "securepass123"
}POST /api/login/
{
"username": "johndoe",
"password": "securepass123"
}GET /api/books/
- Query params:
?author=<author_name>&category=<category_name>
GET /api/books/{id}/
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
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
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
GET /api/borrow/
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)
GET /api/users/{id}/penalties/
- Accessible by admin and the user themselves
- Limit Enforcement: Users cannot borrow more than 3 books simultaneously
- Inventory Validation: Only books with
available_copies > 0can be borrowed - Atomic Updates: All inventory changes use database transactions to prevent race conditions
- Due Date Calculation: Automatically set to 14 days from borrow date
- 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
- Real-time Tracking:
available_copiesupdated instantly on borrow/return - Data Integrity: Uses Django's
select_for_update()for atomic operations - Validation: Prevents borrowing when no copies available
git clone https://github.com/shemanto27/Django-Library-Management-Borrowing-System.git
cd Django-Library-Management-Borrowing-Systemcd backenduv syncsource .venv/bin/activate python manage.py migratepython manage.py createsuperuserpython manage.py runserverhttp://localhost:8000/api/docs/- Create User โ
POST /api/register/ - Login โ
POST /api/login/(get JWT token) - Authorize โ Use token in Swagger UI
- Browse Books โ
GET /api/books/ - Borrow Book โ
POST /api/borrow/ - Check Borrows โ
GET /api/borrow/ - Return Book โ
POST /api/return/
- Create Superuser โ
python manage.py createsuperuser(in terminal) - Login with Admin โ
POST /api/login/(use superuser credentials) - Authorize โ Use admin JWT token in Swagger UI
- Admin Operations โ Create/Update/Delete books, authors, categories
- This project uses uv for modern Python package management, NO NEED FOR requirements.txt FILE, USE
uv syncCOMMAND - 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