# mahi-rathod/library-management-system-cli architecture

> Architecture diagram of the GitHub repository mahi-rathod/library-management-system-cli, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mahi-rathod/library-management-system-cli
- Repository: https://github.com/mahi-rathod/library-management-system-cli

## Overview

##### Main Components
- Presentation/UI Layer: Represented by the “ui” package (Main.java) which handles user interactions.
- Business Logic/Service Layer: The “service” package (Library.java) contains the core logic for managing library operations.
- Data Access Layer (DAO): Located in the “dao” package with BookDAO.java, MemberDAO.java, and DatabaseUtil.java to handle JDBC operations.
- Data Models: In the “model” package, with Book.java and LibraryMember.java defining the schema for books and members.
- Database: An external MySQL database that stores tables (“books”, “members”, “borrowed_books”) as defined in the README.

##### Relationships and Data Flow
- The UI layer triggers operations by calling methods on the Service layer.
- The Service layer processes business rules and then delegates data-related operations to the DAO layer.
- The DAO layer interacts via JDBC with the MySQL database using the connection provided by DatabaseUtil.
- The Data Models form the data objects that are passed amongst these layers.

##### Architectural Patterns and Design Principles
- Separation of Concerns: Distinct packages for UI, service, DAO, and model promote modularity.
- Layered Architecture: Clear segregation that makes it easy to change one part (e.g., swapping the database) without affecting the others.
- Use of JDBC for database connectivity indicates a straightforward persistence mechanism without an ORM layer.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Presentation/UI Layer"
        UI["Main.java (UI)"]:::ui
    end

    subgraph "Business Logic/Service Layer"
        Service["Library.java (Service)"]:::service
    end

    subgraph "Data Access (DAO) Layer"
        DAO1["BookDAO.java (DAO)"]:::dao
        DAO2["MemberDAO.java (DAO)"]:::dao
        DAO3["DatabaseUtil.java (DAO)"]:::dao
    end

    subgraph "Data Models"
        Model1["Book.java (Model)"]:::model
        Model2["LibraryMember.java (Model)"]:::model
    end

    DB(("MySQL Database")):::database

    UI -->|"calls"| Service
    Service -->|"delegates"| DAO1
    Service -->|"delegates"| DAO2
    Service -->|"connectsViaJDBC"| DAO3

    DAO1 -->|"executesCRUD"| DB
    DAO2 -->|"executesCRUD"| DB
    DAO3 -->|"providesConnection"| DB

    DAO1 -.->|"mapsTo"| Model1
    DAO2 -.->|"mapsTo"| Model2

    click UI "https://github.com/mahi-rathod/library-management-system-cli/blob/main/src/com/library/ui/Main.java"
    click Service "https://github.com/mahi-rathod/library-management-system-cli/blob/main/src/com/library/service/Library.java"
    click DAO1 "https://github.com/mahi-rathod/library-management-system-cli/blob/main/src/com/library/dao/BookDAO.java"
    click DAO2 "https://github.com/mahi-rathod/library-management-system-cli/blob/main/src/com/library/dao/MemberDAO.java"
    click DAO3 "https://github.com/mahi-rathod/library-management-system-cli/blob/main/src/com/library/dao/DatabaseUtil.java"
    click Model1 "https://github.com/mahi-rathod/library-management-system-cli/blob/main/src/com/library/model/Book.java"
    click Model2 "https://github.com/mahi-rathod/library-management-system-cli/blob/main/src/com/library/model/LibraryMember.java"

    classDef ui fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef service fill:#A9DFBF,stroke:#1D8348,stroke-width:2px;
    classDef dao fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef model fill:#D7BDE2,stroke:#6C3483,stroke-width:2px;
    classDef database fill:#F5B7B1,stroke:#922B21,stroke-width:2px;
```
