This project is a Flask-based web application for managing books, users, and loans in a library. The project includes detailed setup instructions, an explanation of the file structure, and guidance on how to run the application.
-
Python 3.11
- Ensure Python 3.11.x is installed. Check by running:
python3 --version
- If not installed, download from python.org.
- Ensure Python 3.11.x is installed. Check by running:
-
pip (comes with Python)
- Check by running:
pip --version
- Check by running:
-
Virtual Environment (venv)
- Make sure you can create virtual environments using
venv.
- Make sure you can create virtual environments using
-
SQLite (comes pre-installed with Python).
scriptorium-library-management-system/
│
├── app/
│ ├── __init__.py # Initializes the Flask app and database
│ ├── models.py # Contains database models: Book, User, Loan
│ ├── routes.py # Defines app routes and business logic
│ ├── forms.py # Contains WTForms classes for user input validation
│ ├── static/ # Static assets (CSS, JS, images)
│ │ ├── css/
│ │ │ └── styles.css # Main stylesheet for the application
│ │ ├── js/
│ │ │ └── scripts.js # Custom JavaScript functionality
│ │ └── img/ # Images used in the application
│ │ ├── book1.jpg
│ │ ├── book2.jpg
│ │ ├── book3.jpg
│ │ ├── book4.jpg
│ │ └── library-welcome-horizontal.jpg
│ ├── templates/ # HTML templates for rendering views
│ ├── base.html # Base template for consistent layout
│ ├── index.html # Homepage template
│ ├── books.html # Displays book list
│ ├── all_users.html # Displays all users
│ ├── user_loans.html # Displays loans for a specific user
│ └── statistics.html # Displays library statistics
│
├── instance/ # Holds instance-specific data
├── .gitignore # Specifies files to ignore in version control
├── populate_data.py # Populates the database with mock data
├── requirements.txt # Python dependencies with pinned versions
├── run.py # Main script to run the Flask app
├── test.py # Script for descriptive statistics and visualizations
└── README.md # Project documentation (this file)
-
app/__init__.py- Initializes the Flask app.
- Configures the SQLite database with URI:
sqlite:///library.db. - Registers the app’s routes from
routes.py.
-
app/models.py- Defines the database models:
- Book: Represents books with attributes like title, author, pages, etc.
- User: Represents library users.
- Loan: Tracks loans of books by users.
- Defines the database models:
-
app/routes.py- Contains route handlers and logic for the web app.
- Manages user interactions like viewing books, loans, and users.
-
app/forms.py- Defines forms using Flask-WTF for handling and validating user inputs.
-
populate_data.py- Populates the database with mock data for testing purposes.
- Adds sample books, users, and loans to the database.
-
run.py- Launches the Flask app and starts the development server.
- Provides an online navigation interface (menu) to access the following sections:
- View Book List: Displays all books, separating available and borrowed books.
- Loan History by User: Allows users to view their loan history (both returned and unreturned books).
- Descriptive Statistics: Shows average loans per user in 2024 and average loan duration, along with a dynamic graph that toggles between users with the most books borrowed or longest average loan duration.
- Access the app in the browser at: http://127.0.0.1:5001/.
-
test.py- Python script to calculate descriptive statistics from the loan data.
- This script runs in the terminal and displays the results of the following descriptive statistics:
- The author with the most books in the library catalog.
- The most borrowed author by all users.
- For each user, the list of authors they have exclusively borrowed.
- The most borrowed book since the library’s opening.
- The user with the most simultaneous unreturned loans, showing the dates during which this user had this maximum number of loans.
- It also produces two visualizations:
- The estimated probability density of the Goodreads ratings for all the books in the library.
- A scatter plot representing the linear relationship between the number of pages and the borrowing time of books that have already been borrowed and returned.
-
static/- Contains all static files:
- CSS: For styling the web pages.
- JS: For custom JavaScript.
- Images: Used across the web pages.
- Contains all static files:
-
templates/- Contains HTML templates for rendering pages dynamically.
git clone https://github.com/amanisakif/scriptorium-library-management-system.git
cd scriptorium-library-management-systempython3.11 -m venv venv
source venv/bin/activateInstall all necessary Python packages with version constraints:
pip install -r requirements.txt- Flask:
2.2.2 - Werkzeug:
2.2.3 - Flask-SQLAlchemy:
2.5.1 - Flask-WTF:
1.0.1 - Flask-Migrate:
3.1.0 - pandas:
1.5.3 - matplotlib:
3.6.3 - numpy:
1.23.5 - SQLAlchemy:
1.4.47
Run the following script to populate the database with sample data:
python populate_data.pyThis step creates mock data for books, users, and loans in the SQLite database (library.db).
Start the Flask development server:
python run.pyThe app will be accessible at:
Run the following command to execute the test.py script:
python test.pyThe script will display the descriptive statistics in the terminal and generate two visualizations saved as image files.
To verify the installed versions of all dependencies, use:
pip show Flask Werkzeug Flask-SQLAlchemyYou should see the following versions:
- Flask:
2.2.2 - Werkzeug:
2.2.3 - Flask-SQLAlchemy:
2.5.1
-
Flask Import Errors:
- Ensure the virtual environment is activated.
- Check that all dependencies are installed correctly.
- Verify the Python version is 3.11.
-
Dependency Issues:
- If
pip install -r requirements.txtfails, install the packages manually with pinned versions:pip install Flask==2.2.2 Werkzeug==2.2.3 Flask-SQLAlchemy==2.5.1 Flask-WTF==1.0.1 Flask-Migrate==3.1.0 pandas==1.5.3 matplotlib==3.6.3 numpy==1.23.5 SQLAlchemy==1.4.47
- If
-
Database Not Found:
- Ensure
populate_data.pyhas been run before starting the app.
- Ensure