ThaerGhaderi/LibraryManagmentWithPython

Python

3

2 commits

updated Oct 5, 2026

See the code

See what people are saying

SourceMessageScoreDate

Library Management System in Python with Clean Architecture & 55 Tests (r/coolgithubprojects)

Hi everyone! As a practical step in my transition from Python fundamentals toward professional software engineering, I built a modular, terminal-based \*\*Library Management System\*\* with a strong emphasis on clean architecture and design principles. \### ๐Ÿ—๏ธ Architecture & Technicalโ€ฆ

1

Oct 5, 2026

README

Python Tests Architecture

Library Management System

A modular terminal-based Library Management System built with Python.

The project was designed to apply professional software engineering concepts including:

  • Object-Oriented Programming
  • Layered Architecture
  • Repository Pattern
  • Service Layer
  • Authentication & Authorization
  • Session Management
  • JSON Persistence
  • Logging
  • Exception Handling
  • Automated Testing
  • Clean separation of concerns

Features

Authentication

  • User registration
  • User login/logout
  • Password hashing
  • Session management
  • Role-based authorization
  • Account activation/deactivation
  • Password changing

Books

  • Add books
  • List books
  • Search by title
  • Search by author
  • Search by classification
  • Find book by ID
  • Update book information
  • Delete books
  • Track book availability

Borrowing

  • Borrow books
  • Return books
  • Borrowing limits
  • Borrowing duration
  • Active borrowing tracking
  • Borrowing history
  • Late-return fines

Members

  • List members
  • Search members
  • View member details
  • View member borrowing history
  • Activate/deactivate members

Reports

  • Library statistics
  • Active/returned/overdue borrowings
  • Fine statistics
  • Most borrowed books
  • Most active users

Technical Features

  • Generic JSON storage
  • Atomic file writes
  • Data validation
  • Custom exceptions
  • Application logging
  • Automated unit/service tests

Architecture

The application follows a layered architecture:

                UI
                 โ”‚
                 โ–ผ
             Services
                 โ”‚
                 โ–ผ
           Repositories
                 โ”‚
                 โ–ผ
              Storage
                 โ”‚
                 โ–ผ
           JSON Files

UI Layer

Responsible only for:

  • Displaying screens
  • Reading user input
  • Calling services
  • Showing results/errors UI must not contain business logic or direct JSON access.

Service Layer

Responsible for:

  • Business rules
  • Validation
  • Authorization
  • Application workflows
  • Coordination between repositories

Repository Layer

Responsible for:

  • Loading entities
  • Saving entities
  • Abstracting persistence

Storage Layer

Responsible only for:

  • Reading/writing JSON
  • File handling
  • Atomic writes
  • Storage-level errors

Project Structure

LibraryManagmentWithPython/
โ”‚
โ”œโ”€โ”€ main.py
โ”‚
โ”œโ”€โ”€ Models/
โ”‚   โ”œโ”€โ”€ book.py
โ”‚   โ”œโ”€โ”€ user.py
โ”‚   โ””โ”€โ”€ borrowing.py
โ”‚
โ”œโ”€โ”€ repositories/
โ”‚   โ”œโ”€โ”€ book_repository.py
โ”‚   โ”œโ”€โ”€ user_repository.py
โ”‚   โ””โ”€โ”€ borrowing_repository.py
โ”‚
โ”œโ”€โ”€ Services/
โ”‚   โ”œโ”€โ”€ book_service.py
โ”‚   โ”œโ”€โ”€ user_service.py
โ”‚   โ”œโ”€โ”€ auth_service.py
โ”‚   โ”œโ”€โ”€ borrowing_service.py
โ”‚   โ”œโ”€โ”€ report_service.py
โ”‚   โ””โ”€โ”€ member_service.py
โ”‚
โ”œโ”€โ”€ Storage/
โ”‚   โ””โ”€โ”€ json_storage.py
โ”‚
โ”œโ”€โ”€ auth/
โ”‚   โ”œโ”€โ”€ session.py
โ”‚   โ”œโ”€โ”€ password_hasher.py
โ”‚   โ””โ”€โ”€ exceptions.py
โ”‚
โ”œโ”€โ”€ UI/
โ”‚   โ”œโ”€โ”€ auth/
โ”‚   โ”œโ”€โ”€ books/
โ”‚   โ”œโ”€โ”€ borrowing/
โ”‚   โ”œโ”€โ”€ members/
โ”‚   โ”œโ”€โ”€ menus/
โ”‚   โ”œโ”€โ”€ profile/
โ”‚   โ””โ”€โ”€ reports/
โ”‚
โ”œโ”€โ”€ config/
โ”‚   โ””โ”€โ”€ config.py
โ”‚
โ”œโ”€โ”€ data/
โ”‚   โ”œโ”€โ”€ books.json
โ”‚   โ”œโ”€โ”€ users.json
โ”‚   โ””โ”€โ”€ borrowings.json
โ”‚
โ”œโ”€โ”€ logs/
โ”‚   โ””โ”€โ”€ library.log
โ”‚
โ”œโ”€โ”€ tests/
โ”‚
โ”œโ”€โ”€ requirements.txt
โ”œโ”€โ”€ .gitignore
โ””โ”€โ”€ README.md

Running the Project

Create and activate a virtual environment:

python -m venv .venv

Windows:

.venv\Scripts\activate

Install dependencies:

pip install -r requirements.txt

Run the application:

python main.py

Running Tests

Run the complete test suite:

python -m pytest -q

Current test status:

55 passed

Design Principles

The project follows several important principles:

Separation of Concerns

Each layer has one clear responsibility.

Single Source of Truth

Borrowing information is stored in the borrowing system rather than duplicating borrowing state inside the user model.

Dependency Direction

Higher-level application logic depends on abstractions such as repositories instead of directly manipulating JSON files.

Explicit Business Rules

Rules such as:

  • maximum active borrowings
  • book availability
  • duplicate books
  • overdue fines
  • librarian permissions are enforced in the service layer.

Persistence Safety

JSON writes use atomic replacement to reduce the risk of corrupted data.

Future Improvements

Possible future versions include:

  • SQLite database
  • Database migrations
  • REST API
  • Web interface
  • Advanced analytics
  • Recommendation system
  • Machine learning integration

Learning Goal

This project was built as a practical transition from Python fundamentals toward professional software engineering and Artificial Intelligence.

The next major learning phase is focused on:

NumPy
   โ†“
Pandas
   โ†“
Matplotlib
   โ†“
Mathematics for ML
   โ†“
Scikit-learn
   โ†“
Machine Learning
   โ†“
Deep Learning
   โ†“
Artificial Intelligence

ThaerGhaderi/LibraryManagmentWithPython

Python

3

2 commits

updated Oct 5, 2026

See the code

See what people are saying

SourceMessageScoreDate

Library Management System in Python with Clean Architecture & 55 Tests (r/coolgithubprojects)

Hi everyone! As a practical step in my transition from Python fundamentals toward professional software engineering, I built a modular, terminal-based \*\*Library Management System\*\* with a strong emphasis on clean architecture and design principles. \### ๐Ÿ—๏ธ Architecture & Technicalโ€ฆ

1

Oct 5, 2026

README

Python Tests Architecture

Library Management System

A modular terminal-based Library Management System built with Python.

The project was designed to apply professional software engineering concepts including:

  • Object-Oriented Programming
  • Layered Architecture
  • Repository Pattern
  • Service Layer
  • Authentication & Authorization
  • Session Management
  • JSON Persistence
  • Logging
  • Exception Handling
  • Automated Testing
  • Clean separation of concerns

Features

Authentication

  • User registration
  • User login/logout
  • Password hashing
  • Session management
  • Role-based authorization
  • Account activation/deactivation
  • Password changing

Books

  • Add books
  • List books
  • Search by title
  • Search by author
  • Search by classification
  • Find book by ID
  • Update book information
  • Delete books
  • Track book availability

Borrowing

  • Borrow books
  • Return books
  • Borrowing limits
  • Borrowing duration
  • Active borrowing tracking
  • Borrowing history
  • Late-return fines

Members

  • List members
  • Search members
  • View member details
  • View member borrowing history
  • Activate/deactivate members

Reports

  • Library statistics
  • Active/returned/overdue borrowings
  • Fine statistics
  • Most borrowed books
  • Most active users

Technical Features

  • Generic JSON storage
  • Atomic file writes
  • Data validation
  • Custom exceptions
  • Application logging
  • Automated unit/service tests

Architecture

The application follows a layered architecture:

                UI
                 โ”‚
                 โ–ผ
             Services
                 โ”‚
                 โ–ผ
           Repositories
                 โ”‚
                 โ–ผ
              Storage
                 โ”‚
                 โ–ผ
           JSON Files

UI Layer

Responsible only for:

  • Displaying screens
  • Reading user input
  • Calling services
  • Showing results/errors UI must not contain business logic or direct JSON access.

Service Layer

Responsible for:

  • Business rules
  • Validation
  • Authorization
  • Application workflows
  • Coordination between repositories

Repository Layer

Responsible for:

  • Loading entities
  • Saving entities
  • Abstracting persistence

Storage Layer

Responsible only for:

  • Reading/writing JSON
  • File handling
  • Atomic writes
  • Storage-level errors

Project Structure

LibraryManagmentWithPython/
โ”‚
โ”œโ”€โ”€ main.py
โ”‚
โ”œโ”€โ”€ Models/
โ”‚   โ”œโ”€โ”€ book.py
โ”‚   โ”œโ”€โ”€ user.py
โ”‚   โ””โ”€โ”€ borrowing.py
โ”‚
โ”œโ”€โ”€ repositories/
โ”‚   โ”œโ”€โ”€ book_repository.py
โ”‚   โ”œโ”€โ”€ user_repository.py
โ”‚   โ””โ”€โ”€ borrowing_repository.py
โ”‚
โ”œโ”€โ”€ Services/
โ”‚   โ”œโ”€โ”€ book_service.py
โ”‚   โ”œโ”€โ”€ user_service.py
โ”‚   โ”œโ”€โ”€ auth_service.py
โ”‚   โ”œโ”€โ”€ borrowing_service.py
โ”‚   โ”œโ”€โ”€ report_service.py
โ”‚   โ””โ”€โ”€ member_service.py
โ”‚
โ”œโ”€โ”€ Storage/
โ”‚   โ””โ”€โ”€ json_storage.py
โ”‚
โ”œโ”€โ”€ auth/
โ”‚   โ”œโ”€โ”€ session.py
โ”‚   โ”œโ”€โ”€ password_hasher.py
โ”‚   โ””โ”€โ”€ exceptions.py
โ”‚
โ”œโ”€โ”€ UI/
โ”‚   โ”œโ”€โ”€ auth/
โ”‚   โ”œโ”€โ”€ books/
โ”‚   โ”œโ”€โ”€ borrowing/
โ”‚   โ”œโ”€โ”€ members/
โ”‚   โ”œโ”€โ”€ menus/
โ”‚   โ”œโ”€โ”€ profile/
โ”‚   โ””โ”€โ”€ reports/
โ”‚
โ”œโ”€โ”€ config/
โ”‚   โ””โ”€โ”€ config.py
โ”‚
โ”œโ”€โ”€ data/
โ”‚   โ”œโ”€โ”€ books.json
โ”‚   โ”œโ”€โ”€ users.json
โ”‚   โ””โ”€โ”€ borrowings.json
โ”‚
โ”œโ”€โ”€ logs/
โ”‚   โ””โ”€โ”€ library.log
โ”‚
โ”œโ”€โ”€ tests/
โ”‚
โ”œโ”€โ”€ requirements.txt
โ”œโ”€โ”€ .gitignore
โ””โ”€โ”€ README.md

Running the Project

Create and activate a virtual environment:

python -m venv .venv

Windows:

.venv\Scripts\activate

Install dependencies:

pip install -r requirements.txt

Run the application:

python main.py

Running Tests

Run the complete test suite:

python -m pytest -q

Current test status:

55 passed

Design Principles

The project follows several important principles:

Separation of Concerns

Each layer has one clear responsibility.

Single Source of Truth

Borrowing information is stored in the borrowing system rather than duplicating borrowing state inside the user model.

Dependency Direction

Higher-level application logic depends on abstractions such as repositories instead of directly manipulating JSON files.

Explicit Business Rules

Rules such as:

  • maximum active borrowings
  • book availability
  • duplicate books
  • overdue fines
  • librarian permissions are enforced in the service layer.

Persistence Safety

JSON writes use atomic replacement to reduce the risk of corrupted data.

Future Improvements

Possible future versions include:

  • SQLite database
  • Database migrations
  • REST API
  • Web interface
  • Advanced analytics
  • Recommendation system
  • Machine learning integration

Learning Goal

This project was built as a practical transition from Python fundamentals toward professional software engineering and Artificial Intelligence.

The next major learning phase is focused on:

NumPy
   โ†“
Pandas
   โ†“
Matplotlib
   โ†“
Mathematics for ML
   โ†“
Scikit-learn
   โ†“
Machine Learning
   โ†“
Deep Learning
   โ†“
Artificial Intelligence