# meheralimeer/librarymanagementsystem architecture

> Architecture diagram of the GitHub repository meheralimeer/librarymanagementsystem, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/meheralimeer/librarymanagementsystem
- Repository: https://github.com/meheralimeer/librarymanagementsystem

## Overview

##### Project Type and Purpose
- This is a **desktop full-stack** Library Management System built in **Java (Swing)** with a **MySQL** backend.
- It provides a **GUI** (Swing) and also a **CLI** for staff/user operations, a layered **Service** and **DAO** architecture, and uses **JDBC** plus **SQL triggers** for fines and metadata updates.

##### File Structure
- **Presentation Layer**
- `src/main/java/com/assignment/gui` → Swing forms (`LoginForm`, `MainWindow`) and panels (`BookPanel`, `BorrowPanel`, etc.)
- `src/main/java/com/assignment/cli` → Command‐line interface entry point and handlers.
- **Service Layer**
- `src/main/java/com/assignment/service` → service interfaces and `ServiceFactory`
- `src/main/java/com/assignment/service/impl` → implementations (`BookServiceImpl`, `BorrowServiceImpl`, etc.)
- **Data Access Layer**
- `src/main/java/com/assignment/dao` → DAO interfaces (`BookDao`, `UserDao`, etc.)
- `src/main/java/com/assignment/dao/mysql` → MySQL‐specific DAO implementations (`MySqlBookDao`, etc.)
- **Domain/Data Models**
- `src/main/java/com/assignment/data` → entity classes (`Book`, `User`, `Magazine`, `UserActivityLog`, etc.)
- **Resources**
- `src/main/resources/database/mysql/schema.sql`, `test_data.sql` → schema & seed data

##### README for Additional Insights
- Confirms **Swing GUI**, **MySQL**, **JDBC**, and **SQL triggers** for automated fines and counts.
- Lists core tables and triggers used for real‐time updates.

##### Main Components & Their Interactions
a. **User Interfaces** (Blue):
- GUI (Swing)
- CLI
b. **Service Layer** (Green):
- `ServiceFactory` dispatches to concrete `*ServiceImpl` classes
- Business logic (borrow/return, calculate fines, logging)
c. **DAO Layer** (Orange):
- Generic `Dao` interfaces → MySQL‐specific DAO classes
- JDBC calls, transaction management
d. **MySQL Database** (Red):
- Tables (`Book`, `Magazine`, `User`, `Staff`, `BookBorrow`, etc.)
- Triggers for borrow counts and username auto‐fill
e. **External Dependencies** (Purple):
- JDBC driver
- SQL scripts

##### Relationships & Data Flow
- **UI → Services**: UI/CLI makes requests (e.g., “borrow book”) to service interfaces.
- **Services → DAOs**: Services call DAO methods to query/update entities.
- **DAOs → DB**: DAO implementations execute SQL via JDBC.
- **DB Triggers**: MySQL triggers fire on INSERT/UPDATE to maintain counts and auto‐populate fields.
- **Return Path**: Data flows back from DB → DAO → Service → UI.

##### Architectural Patterns & Principles
- **Layered Architecture**: presentation, business, data access, persistence
- **DAO Pattern**: isolating SQL and JDBC from business logic
- **Factory Pattern**: `ServiceFactory` for service instantiation
- **Separation of Concerns**: GUI code is unaware of SQL; service logic is isolated from UI.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        direction TB
        GUI["GUI (Swing)"]:::ui
        Panels["GUI Panels"]:::ui
        CLI["CLI (Console)"]:::ui
    end

    %% Service Layer
    subgraph "Service Layer"
        direction TB
        SvcInt["Service Interfaces"]:::service
        SvcFactory["ServiceFactory"]:::service
        SvcImpl["Service Implementations"]:::service
    end

    %% DAO Layer
    subgraph "DAO Layer"
        direction TB
        DaoInt["DAO Interfaces"]:::dao
        DaoImpl["MySQL-Specific DAO Implementations"]:::dao
    end

    %% Domain Model
    subgraph "Domain/Data Models"
        direction TB
        Entities["Entity Classes"]:::dao
    end

    %% Database
    subgraph "Database Layer"
        direction TB
        DB["MySQL Database"]:::db
        BookTable["Book, User, BookBorrow Tables"]:::db
        Triggers["SQL Triggers"]:::db
    end

    %% External Dependencies
    subgraph "External Dependencies"
        direction TB
        JDBC["JDBC Driver"]:::external
        Scripts["SQL Scripts & Diagrams"]:::external
    end

    %% Relationships
    GUI -->|"user actions"| SvcFactory
    Panels -->|"panel events"| SvcFactory
    CLI -->|"commands"| SvcFactory
    SvcFactory -->|"dispatch to"| SvcImpl
    SvcImpl -->|"uses"| DaoInt
    DaoInt -->|"implemented by"| DaoImpl
    DaoImpl -->|"executes SQL via JDBC"| DB
    DB -->|"- triggers"| Triggers
    Triggers -->|"- update tables"| BookTable
    DB -->|"stores tables"| BookTable
    DaoImpl -->|"reads/writes entities"| Entities
    SvcImpl -->|"operates on entities"| Entities
    JDBC -->|"provides connection"| DaoImpl
    Scripts -->|"loaded on startup"| DB

    %% Click Events
    click GUI "https://github.com/meheralimeer/librarymanagementsystem/tree/main/src/main/java/com/assignment/gui"
    click Panels "https://github.com/meheralimeer/librarymanagementsystem/tree/main/src/main/java/com/assignment/gui/panels"
    click CLI "https://github.com/meheralimeer/librarymanagementsystem/blob/main/src/main/java/com/assignment/cli/LibraryManagementCLI.java"
    click SvcInt "https://github.com/meheralimeer/librarymanagementsystem/tree/main/src/main/java/com/assignment/service"
    click SvcFactory "https://github.com/meheralimeer/librarymanagementsystem/blob/main/src/main/java/com/assignment/service/ServiceFactory.java"
    click SvcImpl "https://github.com/meheralimeer/librarymanagementsystem/tree/main/src/main/java/com/assignment/service/impl"
    click DaoInt "https://github.com/meheralimeer/librarymanagementsystem/tree/main/src/main/java/com/assignment/dao"
    click DaoImpl "https://github.com/meheralimeer/librarymanagementsystem/tree/main/src/main/java/com/assignment/dao/mysql"
    click Entities "https://github.com/meheralimeer/librarymanagementsystem/tree/main/src/main/java/com/assignment/data"
    click Scripts "https://github.com/meheralimeer/librarymanagementsystem/blob/main/src/main/resources/database/mysql/schema.sql"
    click Scripts "https://github.com/meheralimeer/librarymanagementsystem/blob/main/src/main/resources/database/mysql/test_data.sql"
    click Scripts "https://github.com/meheralimeer/librarymanagementsystem/tree/main/src/main/resources/diagrams"

    %% Styles
    classDef ui fill:#cfe2f3,stroke:#084298,color:#084298
    classDef service fill:#d1e7dd,stroke:#0f5132,color:#0f5132
    classDef dao fill:#f8d7da,stroke:#842029,color:#842029
    classDef db fill:#f5c2c7,stroke:#842029,color:#842029
    classDef external fill:#e2e3e5,stroke:#41464b,color:#41464b
```
