PHP Project

# Maddington Library Management System

Table of Contents

๐Ÿ—๏ธ Architecture Overview

The system follows a layered architecture with clear separation of concerns:

layered architecture
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Presentation Layer (CLI) โ”‚
โ”‚ Menu โ†’ MenuHandlers โ†’ ConsoleUI โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ†“
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Business Logic Layer โ”‚
โ”‚ Controllers โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ†“
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Data Access Layer โ”‚
โ”‚ Repositories โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ†“
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Data Storage Layer โ”‚
โ”‚ DataStore โ†’ JSON Files โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Design Principles

  • Single Responsibility: Each class has one clear purpose
  • Separation of Concerns: UI, business logic, and data access are isolated
  • DRY (Donโ€™t Repeat Yourself): Shared functionality is extracted to helpers
  • MVC Pattern: Models, Controllers, and Views (CLI) are separated

๐Ÿ“ Folder Structure

maddington_library/
โ”‚
โ”œโ”€โ”€ app.php # Application entry point
โ”œโ”€โ”€ composer.json # Dependencies configuration
โ”œโ”€โ”€ composer.lock # Locked dependency versions
โ”œโ”€โ”€ phpunit.xml # PHPUnit configuration
โ”œโ”€โ”€ README.md # Project documentation
โ”‚
โ”œโ”€โ”€ architecture/ # Architecture diagrams
โ”‚ โ”œโ”€โ”€ cover.gif
โ”‚ โ””โ”€โ”€ POP_Diagram.png
โ”‚
โ”œโ”€โ”€ Core/ # Application core
โ”‚ โ”‚
โ”‚ โ”œโ”€โ”€ CLI/ # Presentation Layer
โ”‚ โ”‚ โ”œโ”€โ”€ Menu.php # Main menu navigation
โ”‚ โ”‚ โ”œโ”€โ”€ ConsoleUI.php # UI helper utilities
โ”‚ โ”‚ โ”‚
โ”‚ โ”‚ โ””โ”€โ”€ Handlers/ # Menu action handlers
โ”‚ โ”‚ โ”œโ”€โ”€ BookMenuHandler.php
โ”‚ โ”‚ โ”œโ”€โ”€ MemberMenuHandler.php
โ”‚ โ”‚ โ”œโ”€โ”€ OtherResourceMenuHandler.php
โ”‚ โ”‚ โ””โ”€โ”€ BorrowTransactionMenuHandler.php
โ”‚ โ”‚
โ”‚ โ”œโ”€โ”€ Controllers/ # Business Logic Layer
โ”‚ โ”‚ โ”œโ”€โ”€ BookController.php
โ”‚ โ”‚ โ”œโ”€โ”€ MemberController.php
โ”‚ โ”‚ โ”œโ”€โ”€ OtherResourceController.php
โ”‚ โ”‚ โ””โ”€โ”€ BorrowTransactionController.php
โ”‚ โ”‚
โ”‚ โ”œโ”€โ”€ Models/ # Domain Models
โ”‚ โ”‚ โ”œโ”€โ”€ LibraryResource.php # Base class for resources
โ”‚ โ”‚ โ”œโ”€โ”€ Book.php # Book entity
โ”‚ โ”‚ โ”œโ”€โ”€ Author.php # Author entity
โ”‚ โ”‚ โ”œโ”€โ”€ OtherResource.php # Other resource entity
โ”‚ โ”‚ โ”œโ”€โ”€ Member.php # Member entity
โ”‚ โ”‚ โ””โ”€โ”€ BorrowTransaction.php # Transaction entity
โ”‚ โ”‚
โ”‚ โ”œโ”€โ”€ Repositories/ # Data Access Layer
โ”‚ โ”‚ โ”œโ”€โ”€ DataStore.php # Generic JSON file handler
โ”‚ โ”‚ โ”œโ”€โ”€ BookRepository.php
โ”‚ โ”‚ โ”œโ”€โ”€ MemberRepository.php
โ”‚ โ”‚ โ”œโ”€โ”€ OtherResourceRepository.php
โ”‚ โ”‚ โ””โ”€โ”€ BorrowTransactionRepository.php
โ”‚ โ”‚
โ”‚ โ””โ”€โ”€ data/ # Data Storage (JSON files)
โ”‚ โ”œโ”€โ”€ books.json
โ”‚ โ”œโ”€โ”€ members.json
โ”‚ โ”œโ”€โ”€ otherResources.json
โ”‚ โ””โ”€โ”€ transactions.json
โ”‚
โ”œโ”€โ”€ tests/ # Test Suite
โ”‚ โ”œโ”€โ”€ Unit/ # Unit Tests (isolated)
โ”‚ โ”‚ โ”œโ”€โ”€ Models/
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ BookTest.php
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ MemberTest.php
โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ BorrowTransactionTest.php
โ”‚ โ”‚ โ””โ”€โ”€ Repositories/
โ”‚ โ”‚ โ””โ”€โ”€ DataStoreTest.php
โ”‚ โ”‚
โ”‚ โ””โ”€โ”€ Integration/ # Integration Tests (full workflow)
โ”‚ โ””โ”€โ”€ Controllers/
โ”‚ โ””โ”€โ”€ BookControllerTest.php
โ”‚
โ””โ”€โ”€ vendor/ # Composer dependencies (auto-generated)
โ”œโ”€โ”€ autoload.php # Composer autoloader
โ”œโ”€โ”€ phpunit/phpunit/ # PHPUnit testing framework
โ”œโ”€โ”€ php-school/cli-menu/ # Interactive CLI menus
โ””โ”€โ”€ symfony/console/ # Console output styling

Install Project Dependencies

Terminal window
cd /path/to/maddington_library
composer install

๐Ÿงช Running Tests

Install PHPUnit

PHPUnit is included in the composer.json as a dev dependency. Install it with:

Terminal window
composer install --dev

Or if you already installed dependencies:

Terminal window
composer update

Run All Tests

Or using Composer:

Terminal window
composer test

Then open coverage/index.html in your browser.

Test Structure

tests/
โ”œโ”€โ”€ Unit/ # Unit tests (isolated tests)
โ”‚ โ”œโ”€โ”€ Models/
โ”‚ โ”‚ โ”œโ”€โ”€ BookTest.php
โ”‚ โ”‚ โ”œโ”€โ”€ MemberTest.php
โ”‚ โ”‚ โ””โ”€โ”€ BorrowTransactionTest.php
โ”‚ โ””โ”€โ”€ Repositories/
โ”‚ โ””โ”€โ”€ DataStoreTest.php
โ”‚
โ””โ”€โ”€ Integration/ # Integration tests (full workflow)
โ””โ”€โ”€ Controllers/
โ””โ”€โ”€ BookControllerTest.php

Starting the Application

Terminal window
php app.php

Dependencies

  • php-school/cli-menu: Interactive CLI menus
  • symfony/console: Console output styling and formatting
Next: PBS Library Network
My avatar

Appreciate you reading. If you want more hacking write-ups, network labs, and code deep-dives, check out my other posts or connect via the social links in the footer.


Projects Series