Lesson 7 of 8
Final Project: Complete Library System - Production-Ready
Assemble the complete Library Management System - all 12 modules integrated. Maven multi-module project, SOLID + design patterns, JDBC persistence, JSON API, HTTP client, comprehensive logging, JUnit 5 tests, Properties config with dev/prod profiles, and CLI front-end.
Complete System Architecture
- library-parent/ (Maven multi-module root pom.xml)
- ├── library-model/ (com.priygop.library.model) - Book, Genre, BookStatus, BorrowRecord, DTOs
- ├── library-repository/ (com.priygop.library.repo) - BookRepository interface + JdbcBookRepository
- ├── library-service/ (com.priygop.library.service) - LibraryService, CheckoutService, SearchService
- ├── library-notifications/ (com.priygop.library.notify) - EmailService, SmsService, Observer bus
- └── library-app/ (com.priygop.library.app) - LibraryCli main, AppConfig, DI wiring
Wiring It All Together - Main
import com.priygop.library.app.AppConfig;
import com.priygop.library.repo.*;
import com.priygop.library.service.*;
import com.priygop.library.notify.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Main {
private static final Logger log = LoggerFactory.getLogger(Main.class);
public static void main(String[] args) throws Exception {
log.info("=== Library Management System starting ===");
// 1. Load configuration (profile from APP_PROFILE env var)
AppConfig config = AppConfig.getInstance();
log.info("Active profile: {}", config.getProfile());
// 2. Build repository stack with decorators
BookRepository base = new JdbcBookRepository(config.getDbUrl(),
config.getDbUser(),
config.getDbPassword());
BookRepository logged = new LoggingBookRepository(base);
BookRepository cached = new CachingBookRepository(logged);
// 3. Notification bus (Observer)
LibrarySubject eventBus = new LibrarySubject();
eventBus.subscribe(LibraryEvent.BOOK_BORROWED, new AuditLogger());
eventBus.subscribe(LibraryEvent.BOOK_BORROWED, new EmailNotificationService(config));
eventBus.subscribe(LibraryEvent.BOOK_RETURNED, new AuditLogger());
// 4. Services (Dependency Injection via constructors - DIP)
SearchService searchService = new SearchService();
LibraryService libraryService = new LibraryService(cached, eventBus, searchService);
// 5. Bootstrap data (for dev profile)
if ("dev".equals(config.getProfile())) {
libraryService.addBook(new Book("001", "Clean Code", "R.Martin", 39.99));
libraryService.addBook(new Book("002", "Effective Java", "J.Bloch", 44.99));
libraryService.addBook(new Book("003", "DDIA", "M.Kleppmann", 49.99));
log.info("Dev bootstrap: {} books added", 3);
}
// 6. Start CLI
log.info("Starting CLI interface...");
new LibraryCli(libraryService).run();
log.info("=== Library Management System stopped ===");
}
}
// ── Run commands ──────────────────────────────────────────────────
// mvn clean package Build fat JAR
// java -jar target/library-system.jar Run (prod profile)
// APP_PROFILE=dev java -jar ... Run with dev profile
// mvn test Run all tests
// mvn test -pl library-service Run tests for one module only
// ── Database setup ── (run once in PostgreSQL) ────────────────────
// CREATE TABLE books (
// isbn VARCHAR(20) PRIMARY KEY,
// title VARCHAR(200) NOT NULL,
// author VARCHAR(100) NOT NULL,
// price DECIMAL(10,2) NOT NULL,
// available BOOLEAN NOT NULL DEFAULT TRUE
// );
// CREATE TABLE borrow_records (
// id SERIAL PRIMARY KEY,
// isbn VARCHAR(20) REFERENCES books(isbn),
// member_id VARCHAR(50) NOT NULL,
// borrowed_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
// returned_at TIMESTAMP
// );
// pg_dump library_db > backup.sql Backup (PostgreSQL)
// psql library_db < backup.sql RestoreWhat You've Built - 12 Modules in One System
- Module 1: JVM setup, data types, String, methods - the Book model and CLI arg parsing.
- Module 2: OOP - classes, constructors, encapsulation - the Book class lifecycle.
- Module 3: Inheritance, interfaces, polymorphism - LibraryItem hierarchy and Borrowable/Viewable.
- Module 4: String API, java.time, Enums, Optional - BorrowRecord, BookStatus, due-date calculation.
- Module 5: Collections - HashMap/TreeMap/PriorityQueue catalog, genre grouping.
- Module 6: Exception handling - custom hierarchy, guard clauses, try-with-resources in JDBC.
- Module 7: File I/O - CSV catalog, Properties config, WatchService for auto-import.
- Module 8: Streams - analytics reports, composable BookQuery, parallel catalog stats.
- Module 9: Concurrency - BlockingQueue checkout, CompletableFuture notifications.
- Module 10: JVM/JPMS - multi-module structure, SoftReference cache, health monitoring.
- Module 11: Design Patterns - Singleton, Builder, Decorator, Observer, Strategy, Command, CLI facade.
- Module 12: Maven, JUnit 5, JDBC with transactions, Jackson JSON, HttpClient, SLF4J logging.
Quick Quiz
Module 12 Quiz
What does Maven's pom.xml define?
Tip
Tip
Practice Final Project Complete Library System ProductionReady in small, isolated examples before integrating into larger projects. Breaking concepts into small experiments builds genuine understanding faster than reading alone.
Visual architecture and concepts for Final Project: Complete Library System - Production-Ready
Practice Task
Note
Practice Task - (1) Write a working example of Final Project Complete Library System ProductionReady from scratch without looking at notes. (2) Modify it to handle an edge case (empty input, null value, or error state). (3) Share your solution in the Priygop community for feedback.
Common Mistake
Warning
A common mistake with Final Project Complete Library System ProductionReady is skipping edge case testing - empty inputs, null values, and unexpected data types. Always validate boundary conditions to write robust, production-ready java code.
Key Takeaways
- Assemble the complete Library Management System - all 12 modules integrated.
- library-parent/ (Maven multi-module root pom.xml)
- ├── library-model/ (com.priygop.library.model) - Book, Genre, BookStatus, BorrowRecord, DTOs
- ├── library-repository/ (com.priygop.library.repo) - BookRepository interface + JdbcBookRepository
Finished this lesson?