Skip to content

Repository files navigation

LibraCore Enterprise

Build Status License: MIT Java Version Database

An enterprise-grade, portfolio-quality Library Management System built from the ground up using Core Java 25, JDBC, MySQL 8.0, HikariCP, and Log4j2.

LibraCore exhibits clean software engineering patterns, custom thread-bound database transactions context management, salted BCrypt user authentication, fine-grained role authorization, automatic late-return penalty calculations, and an interactive Console User Interface.


Features

  • Interactive Command-Line Interface: Dynamic console menus tailored to active user roles with color-coded ANSI formatting and clean tabular alignment.
  • Role-Based Access Control (RBAC): Fine-grained authorizations distinct for ADMIN, LIBRARIAN, and STUDENT profiles.
  • Double-Booking & Reservation Control: Concurrency controls, waitlists, and reservation holds to prevent book allocation conflicts.
  • Automatic Fine Invoicing: Automatic scan and calculation of late-return penalties ($0.50/day overdue).
  • Enterprise Reporting: Built-in CSV report exporter mapping book catalog inventories.
  • Audit Footprinting: Custom system-wide auditing triggers recording database updates and user security footprint logs.

Security Features

LibraCore is designed with a defense-in-depth approach to application security:

  • BCrypt Password Hashing: Utilizes the industry-standard jBCrypt library to hash passwords with a secure salt, protecting credentials from disclosure.
  • Environment-Based Secrets: Connection parameters and secrets are loaded dynamically from a .env configuration file at runtime, ensuring no raw passwords are committed to source control.
  • Secure JDBC PreparedStatements: All SQL execution is handled via parameterized queries, strictly eliminating SQL injection (SQLi) vulnerabilities.
  • Transaction Management & Rollbacks: Uses a thread-local transaction helper that guarantees database mutations commit only on successful execution, auto-rolling back if exceptions are encountered.
  • Input Validation: Centralized validation helper (com.libracore.validation) checking for structural validity of parameters (such as Email format checks and ISBN-10/13 length matching) before processing data.
  • Thread-Safe Configurations: Implements thread-safe singleton connection pools via HikariCP and Initialization-on-demand holder configurations for system variables.

Software Architecture & Design Patterns

LibraCore implements a strict Clean Layered Architecture with unidirectional dependency flows:

graph TD
    UI[Presentation Layer: Console CLI] --> AppService[Authentication & Session Cache Managers]
    AppService --> BizService[Business Service Layer: Rules & Transaction Boundaries]
    BizService --> DAO[Data Access Object Layer: PreparedStatements]
    DAO --> DB[(MySQL 8 Database / HikariCP Pool)]
    
    style UI fill:#f9f,stroke:#333,stroke-width:2px
    style BizService fill:#bbf,stroke:#333,stroke-width:2px
    style DAO fill:#dfd,stroke:#333,stroke-width:2px
    style DB fill:#fdb,stroke:#333,stroke-width:2px
Loading

Layer Responsibilities

  1. Presentation Layer (com.libracore.ui): Manages console inputs via Scanner helpers, renders ANSI-styled displays, prints tables, and forwards navigation based on active roles.
  2. Security & Session Layer (com.libracore.security): Intercepts unauthorized commands, hashes credentials, monitors active sessions, and handles session caching.
  3. Business Service Layer (com.libracore.service): Manages business rules (limits, status checks, waitlist queuing), sets transaction boundaries, and processes system actions.
  4. DAO Persistence Layer (com.libracore.dao): Decouples Java domain models from MySQL execution blocks by extending JDBC query execution templates.
  5. Database Layer: Enforces referential integrity constraints, primary/foreign key mappings, performance indexes, and audit log triggers.

Design Patterns Used

  • DAO (Data Access Object) Pattern: Decouples domain services from raw database execution.
  • Template Method: Standardizes SQL execution and query mapping inside AbstractJdbcDAO.java.
  • Builder Pattern: Enforces validation on domain models (e.g. Book.Builder, User.Builder).
  • Strategy Pattern: Decouples role-based permission checks into polymorphic strategy classes (PermissionStrategy, AdminPermissionStrategy, etc.).
  • Singleton Pattern: Guarantees single thread-safe instances for connection pools and configurations.
  • Command Pattern: Encapsulates menu navigation routes as executable command commands (Command, CommandInvoker).

Project Structure

LibraCore/
├── .github/                       # GitHub Actions CI workflow & pull request templates
│   └── workflows/
│       └── maven.yml              # CI build testing (JDK 25 + MySQL service container)
├── docs/                          # Architecture guides, database designs, and dev references
├── src/
│   ├── main/
│   │   ├── java/com/libracore/
│   │   │   ├── dao/               # Data Access Object contracts & execution templates
│   │   │   │   └── impl/          # Entity implementations (User, Book, Reservation, etc.)
│   │   │   ├── database/          # HikariCP pool configurations & transaction utilities
│   │   │   ├── exception/         # Domain exception hierarchy
│   │   │   ├── model/             # Builders and rich relational models
│   │   │   ├── security/          # BCrypt cryptography, session cache, RBAC strategies
│   │   │   ├── service/           # Service contracts & transaction management limits
│   │   │   │   └── impl/          # Business implementations & CSV report exporters
│   │   │   ├── ui/                # Interactive Console CLI navigation layers & MainApp
│   │   │   │   ├── command/       # UI routing encapsulating Command Pattern
│   │   │   │   └── menu/          # Action options for Admin, Student, and Librarian
│   │   │   └── validation/        # Central input validation checking
│   │   └── resources/             # database.properties, log4j2 configs & schemas
│   └── test/java/com/libracore/   # JUnit 5, Mockito, AssertJ integration/unit tests
├── pom.xml                        # Maven dependencies & build plugins
├── .env.example                   # Template file detailing configuration credentials
└── LICENSE                        # MIT License

Database ER Diagram

erDiagram
    CATEGORIES ||--o{ BOOKS : classifies
    BOOKS ||--o{ BORROW_TRANSACTIONS : "borrowed in"
    BOOKS ||--o{ RESERVATIONS : "reserved in"
    BOOKS ||--o{ WAITLIST : "waitlisted in"
    USERS ||--o{ BORROW_TRANSACTIONS : performs
    USERS ||--o{ RESERVATIONS : holds
    USERS ||--o{ WAITLIST : joins
    USERS ||--o{ AUDIT_LOGS : triggers
    BORROW_TRANSACTIONS ||--o{ FINE_PAYMENTS : accrues
Loading

Technology Stack

The application leverages pinned versions of production-ready enterprise libraries:


Installation & Local Setup

1. Prerequisites

  • JDK 25 installed and configured in your path variables.
  • Maven 3.8+ installed.
  • MySQL Server 8.0+ running locally or remotely.

2. Database Schema Initialization

Connect to your local MySQL instance and load the database structure:

CREATE DATABASE IF NOT EXISTS libracore_db;
USE libracore_db;

-- Execute SQL script (creates tables, indexes, audit triggers, and default seeds)
SOURCE src/main/resources/schema.sql;

3. Connection & Secrets Configuration

To configure database connection credentials securely, copy the example template to a local environment file:

cp .env.example .env

Open your newly created .env file and set your MySQL username and password:

DB_USERNAME=your_mysql_username
DB_PASSWORD=your_mysql_secure_password

The application configures connection pooling properties in src/main/resources/database.properties by reading these environment values at startup, maintaining credential safety:

database.url=jdbc:mysql://localhost:3306/libracore_db?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC
database.username=${DB_USERNAME:root}
database.password=${DB_PASSWORD:}
...

Compiling, Running, and Testing

1. Compiling the Application

Compile the source code using Maven:

mvn clean compile

2. Running the Application

Launch the Console CLI directly:

mvn exec:java -Dexec.mainClass="com.libracore.ui.MainApp"

3. Executing Tests & Coverage

Run the full JUnit 5 test suite:

mvn clean test

Generates HTML JaCoCo code coverage reports:

mvn jacoco:report

The test coverage reports will be located inside the project workspace directory at: target/site/jacoco/index.html.


Testing

LibraCore prioritizes high test coverage and structural correctness. The project maintains a complete integration and unit test suite targeting:

  • Authentication, tokens, and authorization security strategies.
  • Service transaction rollbacks and limits.
  • Validation checks and data integrity.

Status: All 46 test cases execute and pass successfully with JaCoCo test coverage validation.


License

This project is licensed under the MIT License - see the LICENSE file for details.

About

Enterprise Library Management System built with Java, JDBC, MySQL, Maven, HikariCP, JUnit 5, Mockito, BCrypt, and Layered Architecture.

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages