A comprehensive library management system built with Django and Django REST Framework, featuring both RESTful API endpoints and user-friendly HTML interfaces.
- ✅ User registration and login with HTML pages (
/account/login,/account/register) - ✅ JWT-based authentication for API access
- ✅ Role-based access control (Admin, Librarian, Member)
- ✅ Member self-registration with automatic account creation
- ✅ User-friendly HTML book browsing interface (
/library/books/) - ✅ Search books by title, ISBN, author, or subject
- ✅ Filter books by author and subject
- ✅ Book detail pages with availability information
- ✅ Adding new Authors and Books by librarians and admins
- ✅ Book availability tracking (Available, Borrowed, Reserved, Lost)
- ✅ Multiple copies support with barcode tracking
- ✅ Members can borrow books directly from the web interface
- ✅ Automatic due date calculation (14 days default)
- ✅ Borrowing history tracking
- ✅ Duplicate borrow prevention
- ✅ Automatic book status updates
- ✅ RESTful API endpoints for all features
- ✅ OpenAPI/Swagger documentation (
/api/docs)
- ✅ Docker and Docker Compose support
- ✅ PostgreSQL database support
- ✅ Static files configuration
- ✅ Gunicorn WSGI server configuration
- ✅ Celery for background tasks
- ✅ Redis for task queue
- ✅ Modular design
- ✅ Cloud-native 12-factor methodology
The project consists of 4 Django apps:
- 🔋
core: Core models and abstract features used throughout the project - 🔋
accounts: User authentication, member and librarian management - 🔋
library: Book and author management, HTML views for browsing - 🔋
borrowing: Book borrowing functionality and records
- ✨ Python - Programming Language
- ✨ Django - Web Framework
- ✨ Django REST Framework - RESTful API Framework
- ✨ Docker - Container Platform
- ✨ PostgreSQL - Database
- ✨ Redis - Task Queue & Caching
- ✨ Celery - Distributed Task Queue
- ✨ Celery Beat - Task Scheduler
- ✨ Gunicorn - WSGI HTTP Server
- ✨ drf-spectacular - OpenAPI 3 schema generation
- Python 3.7+
- PostgreSQL (or use Docker)
- Docker & Docker Compose (optional, for containerized setup)
-
Clone the repository
git clone <your-repository-url> cd library-management-main
-
Create virtual environment
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies
pip install -r requirements.txt
-
Set up environment variables
Create
.envs/.envfile:DEBUG=True SECRET_KEY=your-secret-key-here ALLOWED_HOSTS=localhost,127.0.0.1 DB_NAME=library_db DB_USER=your_db_user DB_PASSWORD=your_db_password DB_HOST=localhost DB_PORT=5432
-
Set up PostgreSQL database
Create database and user:
CREATE USER library_user WITH PASSWORD 'your_password'; ALTER USER library_user CREATEDB; CREATE DATABASE library_db OWNER library_user;
-
Run migrations
python manage.py migrate
-
Create superuser (optional)
python manage.py createsuperuser
-
Run development server
python manage.py runserver
Access the application at
http://localhost:8000
For detailed Docker setup instructions, refer to:
DOCKER_SETUP.md- Complete step-by-step Docker setup guideDOCKER_QUICK_START.md- Quick reference for Docker setupDOCKER_POSTGRESQL_ACCESS.md- PostgreSQL database access guide
-
Prerequisites
- Docker Desktop installed and running
- Docker Compose (included with Docker Desktop)
-
Configuration Files
The following files are used for Docker setup:
docker-compose.yml- Docker Compose configuration (defines all services)Dockerfile- Docker image build instructions.envs/.env.dev- Environment variables for Docker developmentconfig/settings/docker.py- Django settings for Docker environmentdocker-run.ps1- PowerShell script for automated Docker setup (Windows)
-
Set up environment file
Create or edit
.envs/.env.devwith your configuration:DEBUG=True SECRET_KEY=your-secret-key-here-change-in-production ALLOWED_HOSTS=localhost,127.0.0.1,0.0.0.0,web DB_NAME=library_db DB_USER=library_user DB_PASSWORD=library_password DB_HOST=db DB_PORT=5432
-
Run with Docker Compose
Option A: Using PowerShell script (Windows)
.\docker-run.ps1Option B: Manual Docker Compose command
docker-compose up -d --build
This will start 7 containers:
web- Django application serverdb- PostgreSQL databasepgadmin- PostgreSQL admin interface (port 5050)redis- Redis server for Celerycelery- Celery worker for background taskscelery-beat- Celery scheduler for periodic tasks
-
Run migrations
docker-compose exec web python manage.py migrate --settings=config.settings.docker -
Create superuser (optional)
docker-compose exec web python manage.py createsuperuser --settings=config.settings.docker -
Access the application
- Main Application:
http://localhost:8000 - pgAdmin:
http://localhost:5050 - API Docs:
http://localhost:8000/api/docs
- Main Application:
| Service | Port | Description |
|---|---|---|
| web | 8000 | Django application |
| db | 5432 | PostgreSQL database |
| pgadmin | 5050 | PostgreSQL admin interface |
| redis | 6379 | Redis server (internal) |
# View running containers
docker-compose ps
# View logs
docker-compose logs -f web
# Stop all containers
docker-compose down
# Stop and remove volumes
docker-compose down -v
# Rebuild containers
docker-compose up -d --build
# Execute commands in web container
docker-compose exec web python manage.py <command>
# Access database shell
docker-compose exec db psql -U library_user -d library_dbdocker-compose.yml: Defines all services (web, db, redis, celery, etc.)Dockerfile: Builds the Python/Django application image.envs/.env.dev: Environment variables for Docker developmentconfig/settings/docker.py: Django settings module for Dockerdocker-run.ps1: Automated setup script for Windows PowerShell
- Main Application:
http://localhost:8000(orhttp://0.0.0.0:8000in Docker) - Login Page:
http://localhost:8000/account/login - Registration Page:
http://localhost:8000/accounts/register/ - Books List:
http://localhost:8000/library/books/ - Django Admin:
http://localhost:8000/admin/
- Swagger UI:
http://localhost:8000/api/docs - Redoc:
http://localhost:8000/api/redoc - OpenAPI Schema:
http://localhost:8000/api/schema/
- pgAdmin:
http://localhost:5050(when using Docker)
- Full system access
- Manage all books, authors, and users
- View all borrowing records
- Add/edit books and authors
- View all borrowing records
- Process book returns
- Browse books (HTML interface)
- Borrow books directly
- View personal borrowing history
- Register new account
library-management-main/
├── accounts/ # User authentication and management
├── borrowing/ # Book borrowing functionality
├── config/ # Django settings and configuration
├── core/ # Core models and utilities
├── fines/ # Fine calculation and management
├── library/ # Book and author management
├── reservation/ # Book reservation system
├── static/ # Static files (CSS, JS)
├── templates/ # HTML templates
├── .envs/ # Environment configuration files
├── docker-compose.yml # Docker Compose configuration
├── Dockerfile # Docker image definition
├── manage.py # Django management script
├── pyproject.toml # Poetry dependencies
└── requirements.txt # Python dependencies
python manage.py testblack .# Create migrations
python manage.py makemigrations
# Apply migrations
python manage.py migrateMIT License
Copyright (c) 2025