(Revised based on feedback)
- Introduction
- Architecture
- Design
- Implementation
- Testing
- Documentation
- Development Workflow
- Dependencies
- Build and Deployment
- Troubleshooting
This guide provides comprehensive information for developers working on the Library Management System. It covers the system's architecture, design decisions, implementation details, and development guidelines.
The Library Management System follows a layered architecture:
- Presentation Layer: JavaFX-based UI components (
uipackage). Handles user interaction and displays information. - Business Logic Layer: Core application logic and services (
servicepackage). Orchestrates operations and enforces rules. - Data Access Layer: Data persistence and retrieval (
storagepackage). Manages reading from and writing to files. - Domain Layer: Core business entities and models (
modelspackage). Represents the data structures like Books, Loans, Users.
The following diagrams provide visual representations of the system architecture:
-
System Architecture Overview
- Shows the layered architecture and component interactions.
- Illustrates data flow between layers.
- Highlights external dependencies.
-
Class Structure
- Displays the main classes and their relationships within key packages (
ui,service,models,storage). - Shows inheritance and composition.
- Highlights key interfaces (if any).
- Displays the main classes and their relationships within key packages (
-
Book Management Flow
- Shows the sequence of operations for book management (e.g., adding, loaning).
- Illustrates component interactions (e.g.,
AddBookController->LibraryService->BookList->GeneralStorage). - Highlights error handling.
-
Component Interaction Diagram
- Details the interaction between components during key operations (e.g., User Login, Loan Book).
- Shows the flow of data and control.
- Highlights service dependencies.
-
Deployment Architecture
- Shows the runtime environment (JRE + Application JAR).
- Illustrates configuration requirements (e.g., data file locations).
- Highlights deployment dependencies (Java version, JavaFX).
-
Security Architecture
- Shows authentication (Login screen) and authorization (Admin checks) flows.
- Illustrates security boundaries (Admin-only features in UI and Service layer).
- Highlights data protection mechanisms (if any beyond basic file storage).
-
Error Handling Flow
- Shows error detection (e.g., validation in
LibraryService, file I/O exceptions inGeneralStorage) and handling (e.g., displaying messages in UI Controllers). - Illustrates user feedback paths (e.g.,
messageLabelupdates in controllers). - Highlights logging and monitoring points (Standard output or dedicated logging framework if added).
- Shows error detection (e.g., validation in
- User Interface (
uipackage)- JavaFX-based GUI.
- Scene Builder recommended for UI design.
- FXML (
src/main/resources/fxml) for layout definition. - CSS (
src/main/resources/css) for styling.
- Core Services (
service.LibraryService)- Central hub for application logic.
- Manages interactions between UI, models, and storage.
- Handles Book Management, Loan Management, User Session, Search/Sort logic.
- Data Management (
storage.GeneralStorage)- File-based storage system.
- Uses a custom CSV-like format for
bookDatabase.txt(ISBN,Title,Author,Status). - Uses Java Serialization (.dat file) for storing
UserPreferencesobjects. (Note: Jackson/JSON is mentioned in dependencies but does not appear to be used for primary data storage based onGeneralStorage.java). - Includes basic data validation logic within services before storage calls.
The system implements several design patterns:
- MVC (Model-View-Controller): Applied loosely with JavaFX. FXML files define the View, Controller classes (
uipackage) handle user input and update the View, and Model classes (modelspackage) represent the data.LibraryServiceoften acts as an intermediary or part of the Controller/Model logic. - Singleton:
LibraryServiceis likely intended to be managed as a single instance throughout the application lifecycle, often provided via a static method in the mainLibraryAppclass, ensuring consistent state management. - Factory: Might be used implicitly or explicitly for creating domain objects (e.g.,
Loanobjects withinLoanListorLibraryService). - Observer: JavaFX properties and bindings inherently use the Observer pattern for updating the UI when underlying data changes.
- Strategy: The use of
SortCriteriaandLoanSortCriteriaenums, passed to sorting methods inLibraryService, allows changing the sorting algorithm/behavior based on user selection.
The project source code follows this general package structure:
src/main/java/
├── models/ # Data models (Book, Loan, User, UserPreferences, Enums)
├── service/ # Business logic (LibraryService)
├── storage/ # Data persistence (GeneralStorage)
├── ui/ # UI controllers and JavaFX Application classes
│ # (LoginController, DashboardController, LibraryApp, etc.)
└── utils/ # Utility classes (InputUtil - potentially for text UI)
src/main/resources/
├── fxml/ # FXML layout files for UI screens
├── css/ # CSS stylesheets for UI styling
├── images/ # Application icons or other image assets
└── bookDatabase.txt # Default book data file
- Application Entry Point: The primary entry point for the JavaFX application is
ui.Launcher.
- Book Management
- Logic primarily in
service.LibraryService,models.BookList,models.Book. - ISBN validation occurs within service methods (e.g., checking for non-empty strings).
- Book status (
BookStatusenum) is tracked within theBookobject and updated byLibraryServicemethods. - UI handled by
ui.AddBookController,ui.RemoveBookController,ui.ViewBooksController,ui.SearchBooksController.
- Logic primarily in
- Loan System
- Logic primarily in
service.LibraryService,models.LoanList,models.Loan. - Loan period tracking and due date calculation happen during loan creation in
LibraryServiceorLoanList. Overdue status checked inLoanorLibraryService. - Return processing handled in
LibraryService, updating bothLoanandBookstatus. - UI handled by
ui.LoanBookController,ui.ReturnBookController,ui.MyLoansController,ui.ViewLoansController,ui.LoanHistoryController.
- Logic primarily in
- User Management
- Authentication handled by
ui.LoginController, which creates amodels.Userobject. - Authorization (Admin checks) performed in
service.LibraryServiceand UI controllers (e.g.,ui.DashboardController,ui.SearchBooksController) to enable/disable features. - User state managed by
LibraryAppandLibraryService.
- Authentication handled by
- Search and Sorting
- Logic implemented in
service.LibraryService,models.BookList,models.LoanListusingSearchCriteria,SortCriteria,LoanSortCriteriaenums. - Uses Java Streams and Comparators for filtering and sorting collections.
- UI handled by
ui.SearchBooksController,ui.ViewBooksController,ui.ViewLoansController,ui.MyLoansController,ui.LoanHistoryController.
- Logic implemented in
- Naming Conventions
- Classes: PascalCase
- Methods: camelCase
- Variables: camelCase
- Constants: UPPER_SNAKE_CASE
- Code Organization
- Maximum file length: 500 lines (Guideline)
- Maximum method length: 50 lines (Guideline)
- Maximum line length: 100 characters (Guideline)
- Documentation
- Javadoc for public methods and classes.
- Inline comments for complex or non-obvious logic.
- Clear, descriptive method and variable names.
- Unit Tests
- JUnit 5 framework
- Test coverage > 80%
- Mock objects (Mockito) for dependencies
- Integration Tests
- Component interaction testing
- Data flow verification
- Error handling validation
- UI Tests
- JavaFX Test Framework (TestFX)
- User interaction simulation
- Layout verification
- Write tests ideally before or alongside implementing features.
- Maintain and review test coverage reports.
- Run tests (
./gradlew test) before committing code. - Document test cases clearly.
- Javadoc Requirements
- Class descriptions
- Method documentation (@param, @return, @throws)
- Parameter descriptions
- Return value documentation
- Exception documentation
- Inline Comments
- Complex logic explanation
- Algorithm descriptions
- Important assumptions or non-obvious decisions
- Generation: API documentation (Javadoc) can be generated using the Gradle
javadoctask (./gradlew javadoc). - Location: The generated HTML documentation will typically be found in the
build/docs/javadocdirectory after running the task. - Public API: Key public APIs include methods in
service.LibraryService, public getters/setters inmodelsclasses, and potentiallystorage.GeneralStoragemethods. - Internal API: Implementation details within service methods, private methods, and UI controller logic are considered internal.
- Branch Strategy
- main: Production code
- develop: Development branch
- feature/*: Feature branches
- hotfix/*: Emergency fixes
- Commit Guidelines
- Atomic commits (one logical change per commit).
- Descriptive messages (e.g., using conventional commits).
- Related changes grouped together.
- Create pull request from feature branch to develop.
- Request review from team members.
- Address feedback and update the pull request.
- Merge after approval.
- Java 21
- JavaFX 17.0.7 (or compatible)
- JUnit 5 (for testing)
- TestFX (for UI testing)
- IntelliJ IDEA (or other Java IDE)
- Scene Builder (for FXML editing)
- Git
- Gradle
- Local Build (Compile & Assemble)
./gradlew build
- Test Execution
./gradlew test - Executable JAR Creation (includes dependencies)
(The executable JAR will likely be in
./gradlew shadowJar
build/libs/)
- Requirements
- Java 21 Runtime Environment (JRE) installed on the target machine.
- JavaFX runtime components (may need to be installed separately or bundled depending on the JRE distribution and build configuration).
- Minimum 2GB RAM recommended.
- ~500MB disk space for application and data files.
- Installation Steps
- Copy the executable JAR file (e.g.,
cs2103de-tp-all.jarfrombuild/libs/) to the target system. - Ensure the data files (
bookDatabase.txt,user_preferences.dat) are placed where the application expects them. By default, this is often the same directory the JAR is run from, or potentially a fixed path likesrc/main/resources/if loaded as resources (though saving back to resources is usually problematic). Clarify data file location strategy if different. The currentLibraryServiceuses relative paths which might assume the files are relative to the execution directory. - (Optional) Create a launch script if needed.
- Copy the executable JAR file (e.g.,
- Configuration
- Data File Paths: The locations for
bookDatabase.txtanduser_preferences.datare currently hardcoded inLibraryService.javaandGeneralStorage.javaas relative paths. For robust deployment, consider making these paths configurable (e.g., via command-line arguments, environment variables, or a separate configuration file). - Initial Data: Ensure
bookDatabase.txtexists with the initial book catalog if required for the first run. - Admin Credentials: Currently, login seems based only on username and the 'admin' checkbox state. There are no configured passwords or admin user lists mentioned. This might need enhancement for a real deployment.
- Data File Paths: The locations for
- Build Problems
- Dependency Conflicts: Run
./gradlew dependenciesto check the dependency tree. Resolve version clashes. - Version Mismatches: Ensure correct Java (21) and JavaFX versions are used. Check
JAVA_HOMEand IDE settings. - Resource Access Issues: Verify paths in code (
src/main/resources/...) match file locations and build configuration.
- Dependency Conflicts: Run
- Runtime Errors
ClassNotFoundException/NoClassDefFoundError: Often related to JavaFX modules not being included correctly in the runtime classpath, especially when running outside an IDE. Ensure theshadowJarincludes JavaFX or that modules are specified correctly when runningjava -jar ... --module-path ... --add-modules ....- File Access Problems (
IOExceptionduring Load/Save): Check file permissions in the execution directory. EnsurebookDatabase.txtanduser_preferences.datare readable/writable. Verify the relative paths resolve correctly based on where the JAR is being run. - JavaFX UI Rendering Issues/Freezes: Look for long-running tasks blocking the JavaFX Application Thread. Use
Platform.runLater()for UI updates from background threads if necessary. Check console for JavaFX-specific errors. NullPointerException: Often occur ifLibraryServiceorcurrentUserisn't initialized correctly or if data models are missing expected values (e.g., trying to accessloan.getBook().getTitle()whengetBook()returns null).
- Logging: Add more robust logging (e.g., using SLF4j and Logback) instead of just
System.out.println. Log key events, service method entries/exits, exceptions, and data states. - Check Data Files: Manually inspect
bookDatabase.txtfor correct formatting (comma-separated, valid status). Check ifuser_preferences.datexists and is readable (though its binary format isn't human-readable, its presence/absence/permissions can be checked). Corrupted.datfiles might causeClassNotFoundExceptionorIOExceptionon load; deleting it might reset preferences. - Verify JavaFX Setup: Ensure the correct JavaFX SDK is configured in the IDE and included in the runtime environment. Check for missing
--module-pathor--add-modulesarguments if running modularly. - Test Edge Cases: Explicitly test scenarios like empty files, files with invalid formats, loaning/returning non-existent books, administrator actions by regular users, etc..
- Use Debugger: Step through the code execution in the IDE, especially around UI event handling (
uicontrollers), service logic (LibraryService), and file I/O (GeneralStorage).
For development support:
- Check documentation (User Guide, Developer Guide, Javadoc).
- Review code examples within the project.
- Contact senior developers or team leads.
- Create issue tickets in the project's issue tracker.


