A comprehensive web-based library management system built with Python (Flask), SQLite, HTML, and CSS. This system allows users to create accounts, log in, browse books, borrow and return books, and provides admin functionality for managing the library inventory.
-
User Authentication
- Register new account with validation
- Secure login with password hashing
- Logout functionality
- Session management
-
Book Management
- Browse complete library catalog
- Search books by title, author, or ISBN
- Filter books by availability status
- View detailed book information
-
Borrowing System
- Borrow available books
- 14-day borrowing period
- Track borrowed books in dashboard
- Return books with automatic availability update
- Overdue tracking with visual indicators
- Days until due calculation
-
Dashboard
- View personal profile
- See currently borrowed books
- Check due dates and overdue status
- Quick access to recently added books
- Statistics (borrowed books, available books, borrow period)
- Book Inventory Management
- Add new books to library
- Track book quantities
- Monitor availability status
- View complete inventory list
- Admin-only access panel
library-management-system/
β
βββ app.py # Main Flask application
βββ models.py # Database models (User, Book, Borrowing)
βββ requirements.txt # Python dependencies
βββ library.db # SQLite database (auto-created)
β
βββ templates/ # HTML templates
β βββ base.html # Base template with navigation
β βββ login.html # Login page
β βββ register.html # User registration page
β βββ dashboard.html # User dashboard
β βββ books.html # Book browsing page
β βββ admin_books.html # Admin panel for book management
β βββ 404.html # 404 error page
β βββ 500.html # 500 error page
β
βββ static/ # Static files
β βββ css/
β β βββ style.css # Complete styling with responsive design
β βββ js/
β βββ script.js # Frontend JavaScript utilities
β
βββ README.md # This file
id(Integer, Primary Key)username(String, Unique)email(String, Unique)password(String, Hashed)is_admin(Boolean)created_at(DateTime)updated_at(DateTime)
id(Integer, Primary Key)title(String)author(String)isbn(String, Unique)publication_year(Integer)quantity(Integer)available(Boolean)description(Text)created_at(DateTime)updated_at(DateTime)
id(Integer, Primary Key)user_id(Integer, Foreign Key)book_id(Integer, Foreign Key)borrow_date(DateTime)due_date(DateTime)return_date(DateTime, Nullable)
- Python 3.7 or higher
- pip (Python package manager)
# Navigate to the project directory
cd library-management-system# For Windows
python -m venv venv
venv\Scripts\activate
# For macOS/Linux
python3 -m venv venv
source venv/bin/activatepip install -r requirements.txt# The database will be created automatically when you run the app
# But you can initialize it manually by running:
python -c "from app import db; db.create_all()"python app.pyThe application will start on http://localhost:5000
-
Create Admin Account
- Register a new account
- Once registered, manually set
is_admin = Truein the database or modify the registration logic
-
Add Books (Admin)
- Go to Admin Panel (accessible if your account has
is_admin = True) - Add books with details: Title, Author, ISBN, Publication Year, Quantity
- Books become immediately available for borrowing
- Go to Admin Panel (accessible if your account has
-
Register Account
- Click "Create Account"
- Enter username, email, and password
- Click "Create Account"
-
Login
- Enter username and password
- Click "Login"
- You'll be directed to your dashboard
-
Browse Books
- Click "Browse Books" in navigation
- Search by title, author, or ISBN
- Filter by availability status
- Click "Borrow Book" to borrow
-
Manage Borrowed Books
- View borrowed books on Dashboard
- See due dates and days remaining
- Return books when finished
- Check for overdue indicators (red badges)
-
Logout
- Click the "Logout" button in the top right
- You'll be logged out and redirected to login page
- Password Hashing: Passwords are hashed using Werkzeug security
- Session Management: Secure session-based authentication
- CSRF Protection: (Can be added with Flask-WTF)
- Input Validation: All user inputs are validated
- SQL Injection Prevention: Uses SQLAlchemy ORM
- Mobile-friendly interface
- Adapts to tablets and desktops
- Touch-friendly buttons and forms
- Optimal layout on all screen sizes
- Clean, modern design
- Intuitive navigation
- Clear visual hierarchy
- Consistent color scheme
- Helpful icons and badges
- Success messages (green)
- Error messages (red)
- Info messages (blue)
- Warning messages (yellow)
- Auto-dismissing notifications
Edit app.py:
app.config['SECRET_KEY'] = 'your-secret-key-change-this-in-production'Edit app.py:
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///library.db'Edit app.py in the borrow_book() function:
due_date = borrow_date + timedelta(days=14) # Change 14 to desired daysEdit static/css/style.css - All colors and layouts can be customized
Solution: Make sure you're in the project directory and Flask can find the modules.
Solution: Close any other instances of the app and check for .db-journal files
Solution: Ensure the static folder structure is correct and run the app from the project root directory
Solution: Clear browser cache (Ctrl+Shift+Delete) and reload the page
To initialize the database with sample data, create a script:
from app import app, db
from models import User, Book
from werkzeug.security import generate_password_hash
with app.app_context():
# Create tables
db.create_all()
# Add sample books
sample_books = [
Book(title="The Great Gatsby", author="F. Scott Fitzgerald",
isbn="978-0-7432-7356-5", publication_year=1925, quantity=3),
Book(title="To Kill a Mockingbird", author="Harper Lee",
isbn="978-0-06-112008-4", publication_year=1960, quantity=2),
Book(title="1984", author="George Orwell",
isbn="978-0-4525-2612-0", publication_year=1949, quantity=1),
]
for book in sample_books:
db.session.add(book)
db.session.commit()
print("Database initialized with sample data!")GET /- Home (redirects to dashboard if logged in)GET/POST /register- User registrationGET/POST /login- User loginGET /logout- User logout
GET /dashboard- User dashboardGET /books- Browse booksPOST /borrow/<book_id>- Borrow a bookPOST /return/<borrowing_id>- Return a book
GET/POST /admin/books- Manage books
GET /404- Page not foundGET /500- Server error
Flask==2.3.3
Flask-SQLAlchemy==3.0.5
Werkzeug==2.3.7
SQLAlchemy==2.0.20
- Change
debug=Falseinapp.py - Use a production WSGI server like Gunicorn:
pip install gunicorn gunicorn app:app
- Use a proper database (PostgreSQL, MySQL)
- Set strong SECRET_KEY
- Enable HTTPS
- Set up proper error logging
- Email notifications for due dates
- Fine system for overdue books
- Book reservations
- Wishlist feature
- Reading history
- Book ratings and reviews
- Advanced search filters
- PDF export of borrowing history
- SMS notifications
- Two-factor authentication
- Book categories and tags
- Recommendations engine
Feel free to fork this project and submit pull requests for any improvements.
This project is open source and available under the MIT License.
Library Management System v1.0 Created: 2025
For issues or questions, please refer to the troubleshooting section or create an issue in the repository.
Happy Reading! πβ¨