r/learnpython • • 14h ago

Library Management System in Python with Clean Architecture & 55 Tests

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 Highlights

- **Layered Architecture:** Strict separation between UI, Services, Repositories, and Storage layers. UI has zero business logic or direct storage access.

- **Repository Pattern & Persistence:** Generic JSON persistence utilizing **atomic file replacement** to eliminate data corruption.

- **Authentication & Security:** Custom session management, password hashing, and role-based authorization (Librarians vs. Members).

- **Domain Business Rules:** Borrowing limits, availability tracking, overdue fine calculation, and account activation logic enforced strictly in the Service layer.

- **Automated Testing:** 55 passed unit and service tests using `pytest`.

### 📂 Project Structure

LibraryManagmentWithPython/

├── Models/

├── Repositories/

├── Services/

├── Storage/

├── UI/

└── tests/

### 🎯 Objective My goal was to practice enterprise-level engineering principles (Separation of Concerns, Dependency Direction, Single Source of Truth) before stepping into Machine Learning and AI. ### 🔗 Source Code GitHub Repository: https://github.com/ThaerGhaderi/LibraryManagmentWithPython I'd love to get your feedback on the architecture, repository patterns, or any code review suggestions!

1 Upvotes

2 comments sorted by

•

u/riklaunim 32m ago
  • Repo with one big commit is bit sus if it was actually made by a human learning to code.
  • There is bit to much JAVA-isms in the code of foo -> return self._foo
  • You could likely use longer code lines as it's starting to be hard to read. 120 is often used nowadays.
  • it's better to import the module instead thing out of the module so you know what is what and where it's from.
  • For logging, usually the message is not parametrized, while parameters are passed to the extra dict.

Not sure what you want from ML and AI, but you could look at existing (web/api) frameworks, databases and do something similar using them (and a nice frontend). That's what your typical commercial code will use/look like.