To run the project, you need to navigate to the main.py file and execute the main function.
From there, a GUI will be displayed to the user. The first page will present three options:
- Login with an existing user.
- Register a user.
- Exit the application.
After logging in, the user (librarian) will be notified of their existing notifications. The system manages a notification system unique to each librarian.
At the backend, the librarian who logs in will have an online flag activated, indicating that they are currently logged in.
The main screen displays a welcome message that includes the librarian's username. The menu screen is populated with buttons arranged in a "chocolate cube" pattern. These buttons include:
- Add Book: Allows the librarian to add a new book to the system.
- Remove Book: Enables the librarian to remove a book from the collection.
- Search Books: Facilitates searching for books by title, author, or genre.
- View Books: Displays the list of all books available in the library.
- Lend Book: Allows the librarian to lend a book to a user.
- Return Book: Enables the librarian to process the return of a book.
- Popular Books: Displays a list of the most popular books based on lending data. (Popular book is determined by the number of times it has been lent out plus the size of his user waiting list.)
- Logout: Logs the librarian out of the system.
- Exit: Closes the application.
Each button is linked to its specific functionality, enabling seamless navigation and task execution.
The project uses CSV files to store essential data:
books.csv: Stores book information, including the number of available copies, which updates dynamically.librarians_users.csv: Stores usernames and hashed passwords for users. Passwords are encrypted usinghashlibwith SHA-256.waiting_list.csv: Manages the waiting list for unavailable books. Each entry includes:- Full Name
- Phone Number
- Book Title
- Queue Number (updates automatically)
The application has a custom exception system. Each exception clearly specifies potential issues that may arise during runtime.
Purpose:
This exception is raised when an operation results in a value below zero, which violates business logic constraints (e.g., reducing the count of available books below zero).
Purpose:
This exception is raised when a required field is left blank, ensuring mandatory information is provided before proceeding.
Purpose:
Raised when a book requested by the user cannot be found in the library's catalog or database.
Purpose:
Raised when a user attempts to borrow more books than their account allows.
Purpose:
This exception is triggered when an operation requires at least one observer, but none are registered.
Purpose:
Raised when a requested record (e.g., user profile, transaction history) is not found in the database.
Purpose:
Raised when a user attempts to return more books than they have borrowed.
Purpose:
This exception is raised when a user is added to a list (e.g., waitlist) but is already present in the list.
Purpose:
Raised when a user-related operation is attempted, but the user cannot be found in the system.
Purpose:
Raised when an attempt is made to remove a book that is being watched by users (e.g., reserved or requested).
The system logs all major actions and events performed by librarians. This includes actions such as adding books, lending books, updating the waiting list, and logging in or out. The logging system is implemented using Python's logging module and follows these principles:
- Log Levels: The system uses different log levels (
INFO,ERROR) to categorize log messages based on their importance. - Log Storage:
- General application logs are stored in
logs/app.log. - Notifications are logged in
notification_temp.txtand later merged into the main log system.
- General application logs are stored in
- Log Format: Each log entry includes a timestamp, the log level, the module or function name, and a descriptive message.
- Decorator Pattern: Key functions use decorators from
log_decorator.pyto ensure consistent and efficient logging.
This centralized logging approach simplifies debugging and provides an audit trail of all actions performed within the system.
- When a user is added to the waiting list and a book becomes available, all observers (librarians) are notified.
- The system automatically assigns the book to the first user in the queue and updates all related files accordingly.
- Notifications are logged one file:
notification_temp.txt: Stores all the notifications.
If a librarian logs out and another logs in, the new librarian is presented with the last five notifications sent to them.
- Book Management:
- Add, remove, search, lend, and return books.
- Maintain a list of popular books.
- User Management:
- Register and authenticate librarians securely.
- Manage librarian-specific notifications.
- Waiting List Management:
- Track users in the waiting list and notify them when books become available.
- Encryption:
- Securely store sensitive data using SHA-256 encryption.
- Logging:
- Detailed logs for all operations and errors.
- Used in
book_factory.pyandlibrarian_factory.pyto create book and librarian instances dynamically.
- Implemented in
observer.pyfor real-time notifications of waiting list updates.
- Used in
search_strategy.pyto provide flexible search mechanisms for books (e.g., by title, author, or genre).
- Ensures a single instance of the
Loggerclass for consistent logging across the system (logger_config.py).
- Facilitates traversing available books and lent books efficiently in
avl_books_iter.pyandlend_book_iter.py.
- Used in
log_decorator.pyto add logging capabilities to key functions.
- Each class in the system has a single, well-defined responsibility. For instance,
book_manager.pyhandles book-related logic, whilelibrarian_manager.pyfocuses on managing librarians.
- The system is designed to be easily extendable. For example, adding new search strategies only requires extending the
search_strategy.pywithout modifying existing code.
- Subtypes can replace their parent types without altering the functionality. This is evident in the observer system, where different observer types (e.g., librarians) can subscribe to updates seamlessly.
- Interfaces are designed to be client-specific. Each component, such as the
book_factory.pyandsearch_strategy.py, has minimal and focused methods.
- High-level modules do not depend on low-level modules but rather on abstractions. For instance, the
LoggerandObserverfunctionalities rely on abstract interfaces, allowing flexibility in implementation.