Architecture: Clean layered design ConsoleUI (presentation) → LibraryService (business logic) → StorageManager (data access) → JSON files
Key technical decisions:
- HashMap and HashMap for O(1) lookups
- Enums (BorrowResult, ReturnResult) for type-safe operation outcomes instead of exceptions
- Gson with custom LocalDateAdapter for clean JSON serialization
- Streams API for search filtering and statistics aggregation
- Switch expressions (Java 17) for menu dispatch
- Try-with-resources for all file I/O
Validation strategy: Defensive checks at service layer — member must be active, under borrow limit, book must have available copies. Returns verify the member actually borrowed that ISBN.
Challenges
- Bidirectional relationships — Books track available copies, Members track borrowed ISBNs. Both must stay in sync. Solved by centralizing borrow/return logic in LibraryService.
- Copy count integrity — Updating total copies can't go below currently borrowed. Added validation in updateBook().
- JSON LocalDate — Gson doesn't handle java.time.LocalDate natively. Wrote a custom TypeAdapter.
- Menu UX in console — Built reusable input helpers (readIntChoice, readInt) with validation loops.
What I learned
- Layered architecture pays off: UI stays thin, business logic is testable, storage is swappable
- Enums for operation results are cleaner than exceptions for expected failures
- Streams API makes search/stats code declarative and concise
- JSON persistence with Gson is surprisingly painless with a proper adapter
- Console apps benefit from the same architectural rigor as web apps
Future improvements
- Due dates and overdue tracking
- Fine calculation
- Multi-library support
- Export/import (CSV, Excel)
- Simple GUI (JavaFX/Swing)
- Unit tests with JUnit 5