# zawlwintun816/library_system architecture

> Architecture diagram of the GitHub repository zawlwintun816/library_system, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-03-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/zawlwintun816/library_system
- Repository: https://github.com/zawlwintun816/library_system

## Overview

This is a **single-user desktop application**: a **JavaFX GUI client** that performs **CRUD + search/sort** against a **MySQL database** using **JDBC**. There is no web server/backend service layer in this repo—your “system” is primarily:
- A Java module/app (UI + data access logic)
- FXML-based views/resources
- A relational database schema initialized by an SQL script

##### Build / packaging
- `pom.xml` → Maven build, dependencies (likely JavaFX + MySQL JDBC driver).

##### Application code
- `src/main/java/com/mylibrary/LibraryUI.java`
- Likely the **JavaFX Application entry point** (launches UI, loads FXML).
- Also (per README) contains **DB credentials** and likely **JDBC connection + queries** (important: this implies **UI and data access are coupled** in this learning project).
- `src/main/java/com/mylibrary/Book.java`
- Domain model / DTO used by TableView and DB mapping.

##### UI resources
- `src/main/resources/com/mylibrary/primary.fxml`
- `src/main/resources/com/mylibrary/secondary.fxml`

##### Database artifacts
- `src/main/resources/database/query_to_run.sql`

##### README → runtime interactions to show (key flows)
- Books in a **JavaFX TableView** (Read)
- / Update / Delete book records (Write)
- Search by title/keyword (Parameterized query)
- Sort by fields (ORDER BY)
- Data integrity across related tables (constraints/foreign keys)

Also: “update username/password in `LibraryUI`” implies the app directly opens DB connections (no intermediary service).

##### Desktop App: Library Management System (Java Module)
- JavaFX UI
- Domain model (`Book`)
- JDBC data access (likely inside `LibraryUI`)
##### MySQL Database
- Schema created by `query_to_run.sql`
- Tables: Books (+ Borrowers, Loans as per README)
##### (Optional but accurate) Local Resources
- FXML files on classpath
- SQL script (used only during setup, not runtime)

- User → JavaFX UI: “clicks, forms, table interactions”
- JavaFX UI → JDBC/Data Access: “CRUD commands, search, sort”
- JDBC/Data Access → MySQL: “SQL queries via JDBC”
- MySQL → JDBC/Data Access: “ResultSets”
- App → FXML resources: “load primary.fxml/secondary.fxml at startup/navigation”

Decompose the app into concrete code/resources from the repo:

**Inside: `com.mylibrary` module**
- `LibraryUI` (Entry Point)
- Responsibilities: JavaFX lifecycle, scene navigation, DB connection config, query execution (per README)
- `Book` (Model)
- Fields correspond to table columns; used by TableView
- `FXML Views`
- `primary.fxml`
- `secondary.fxml`
- “JDBC / MySQL Connector”
- As an external library dependency brought by Maven (even if the exact artifact isn’t listed here, JDBC driver is implied)

- `LibraryUI` → `primary.fxml` / `secondary.fxml`: “FXMLLoader loads views”
- `LibraryUI` ↔ `Book`: “map ResultSet rows ↔ Book objects; bind to TableView”
- `LibraryUI` → JDBC Driver → MySQL: “connect, execute prepared statements”
- FXML Views → `LibraryUI` (or “Event Handlers in LibraryUI”): “button actions trigger CRUD/search/sort”

Because the README emphasizes integrity across books/borrowers/loans, add a **mini ERD**:
- Tables (from `query_to_run.sql`): at minimum **Books**; likely **Borrowers** and **Loans**
- Primary keys, foreign keys (Loans → Books, Loans → Borrowers)
- Cardinalities (Borrower 1..* Loans, Book 1..* Loans)

Even if the UI currently focuses on books, the schema’s relational integrity is part of the system’s “architecture”.

##### Relationships & interactions to be explicit about (avoid ambiguity)
- Protocol/tech: **JDBC**
- Data: **SQL queries**, **ResultSet**, **Book objects**
- Operations: **Create/Read/Update/Delete**, **Search**, **Sort**

**configuration location**:
- “DB credentials in `LibraryUI`” (a note or callout)

From the tree + README, the likely pattern is:
- **2-tier architecture** (Desktop client + DB)
- Some **MVC-ish separation** (FXML views + model `Book`), but with probable **UI/Data Access coupling** (DB config in `LibraryUI`)

- UI layer (JavaFX/FXML)
- Model (`Book`)
- Data access (JDBC) — likely not isolated into DAO classes in this repo (since none appear)

##### ERD: Books / Borrowers / Loans + relationships

That set will be the “best and most accurate” representation of what exists in this repository without inventing non-existent services.

## Diagram (Mermaid)

```mermaid
flowchart TD
  %% =========================
  %% Diagram A: Context / Container (2-tier)
  %% =========================
  subgraph CTX["A) Context / Container View (Desktop 2-tier)"]
    direction TB

    User["User (Library Admin)"]:::actor

    subgraph APPCTX["Desktop App: Library Management System (Java Module)"]
      direction TB
      UICTX["JavaFX UI (Forms + TableView)"]:::ui
      DACCTX["Data Access (JDBC logic; coupled in app)"]:::logic
      ModelCTX["Domain Model (Book objects)"]:::model
      ResCTX["Local Resources (classpath)"]:::resource
    end

    DB[("MySQL Database\n(library schema)")]:::db
    SQLINIT["Schema Init Script\n(query_to_run.sql)\n(setup-time)"]:::resource

    User -->|"clicks,forms,table_interactions"| UICTX
    UICTX -->|"CRUD+search+sort_commands"| DACCTX
    DACCTX -->|"SQL_queries_via_JDBC"| DB
    DB -->|"ResultSets/rows"| DACCTX
    DACCTX -->|"maps_rows_to_Book"| ModelCTX
    UICTX -->|"binds_TableView_to_Book_list"| ModelCTX
    UICTX -->|"loads_FXML_views"| ResCTX

    SQLINIT -.->|"creates_tables+seed_data"| DB
  end

  %% =========================
  %% Diagram B: App Component (code/resources)
  %% =========================
  subgraph COMP["B) Component View (inside Desktop App)"]
    direction TB

    subgraph BUILD["Build / Packaging (build-time)"]
      direction TB
      POM["pom.xml\n(Maven build + dependencies)"]:::build
      MODINFO["module-info.java\n(Java module boundary)"]:::build
    end

    subgraph MODULE["Java Module: com.mylibrary"]
      direction TB

      subgraph CODE["Java Code"]
        direction TB
        LibraryUI["LibraryUI\n(JavaFX Application / Main)\n(UI+lifecycle+DB_config+queries)"]:::logic
        Book["Book\n(Domain Model / DTO)"]:::model
        DAComp["Data Access\n(implemented in LibraryUI)"]:::logic
      end

      subgraph VIEWS["FXML Views (resources)"]
        direction TB
        PrimaryFXML["primary.fxml\n(Primary scene)"]:::ui
        SecondaryFXML["secondary.fxml\n(Secondary scene)"]:::ui
      end
    end

    JDBC["JDBC / MySQL Connector (driver)"]:::external
    MySQL[("MySQL Server")]:::db
    SchemaSQL["query_to_run.sql\n(schema+seed; setup-time)"]:::resource

    %% Build-time wiring
    POM -.->|"brings_in"| JDBC
    MODINFO -.->|"requires/exports"| LibraryUI

    %% Runtime wiring
    LibraryUI -->|"FXMLLoader_loads"| PrimaryFXML
    LibraryUI -->|"FXMLLoader_loads"| SecondaryFXML

    PrimaryFXML -->|"UI_events(trigger_handlers)"| LibraryUI
    SecondaryFXML -->|"UI_events(trigger_handlers)"| LibraryUI

    LibraryUI <-->|"maps_ResultSet_rows<->objects"| Book
    LibraryUI -->|"delegates_calls"| DAComp
    DAComp -->|"connect+PreparedStatements"| JDBC
    JDBC -->|"JDBC_protocol"| MySQL
    MySQL -->|"ResultSet"| JDBC
    SchemaSQL -.->|"initializes_schema"| MySQL

    NoteCreds["Note: DB credentials configured in LibraryUI"]:::note
    NoteCreds -.->|"config_location"| LibraryUI
  end

  %% =========================
  %% Diagram C: Mini ERD (schema integrity)
  %% =========================
  subgraph ERD["C) Database ERD (from query_to_run.sql)"]
    direction TB

    Books[("Books\nPK: book_id\ncols: title, author, ...")]:::db
    Borrowers[("Borrowers\nPK: borrower_id\ncols: name, ...")]:::db
    Loans[("Loans\nPK: loan_id\nFK: book_id -> Books\nFK: borrower_id -> Borrowers\ncols: loan_date, return_date, ...")]:::db

    Borrowers -->|"1_to_many"| Loans
    Books -->|"1_to_many"| Loans
  end

  %% =========================
  %% Cross-diagram alignment links (light)
  %% =========================
  APPCTX -.->|"same_app"| LibraryUI
  DB -.->|"same_database"| MySQL

  %% =========================
  %% Click events (from component mapping)
  %% =========================
  click POM "https://github.com/zawlwintun816/library_system/blob/main/pom.xml"
  click MODINFO "https://github.com/zawlwintun816/library_system/blob/main/src/main/java/module-info.java"
  click LibraryUI "https://github.com/zawlwintun816/library_system/blob/main/src/main/java/com/mylibrary/LibraryUI.java"
  click Book "https://github.com/zawlwintun816/library_system/blob/main/src/main/java/com/mylibrary/Book.java"
  click PrimaryFXML "https://github.com/zawlwintun816/library_system/blob/main/src/main/resources/com/mylibrary/primary.fxml"
  click SecondaryFXML "https://github.com/zawlwintun816/library_system/blob/main/src/main/resources/com/mylibrary/secondary.fxml"
  click SchemaSQL "https://github.com/zawlwintun816/library_system/blob/main/src/main/resources/database/query_to_run.sql"
  click SQLINIT "https://github.com/zawlwintun816/library_system/blob/main/src/main/resources/database/query_to_run.sql"

  %% =========================
  %% Styles
  %% =========================
  classDef actor fill:#FFF3BF,stroke:#B08900,stroke-width:2px,color:#1f2328
  classDef ui fill:#D6ECFF,stroke:#1D4ED8,stroke-width:2px,color:#0b1b3a
  classDef logic fill:#E9D5FF,stroke:#7C3AED,stroke-width:2px,color:#1f2328
  classDef model fill:#D1FAE5,stroke:#059669,stroke-width:2px,color:#0b2a1c
  classDef db fill:#FFE4E6,stroke:#BE123C,stroke-width:2px,color:#2b0a12
  classDef resource fill:#F3F4F6,stroke:#6B7280,stroke-width:2px,color:#111827
  classDef external fill:#FEEBC8,stroke:#C2410C,stroke-width:2px,color:#1f2328
  classDef build fill:#E5E7EB,stroke:#374151,stroke-width:2px,stroke-dasharray: 6 4,color:#111827
  classDef note fill:#FFF7ED,stroke:#9A3412,stroke-width:2px,stroke-dasharray: 4 4,color:#111827
```
