# dinhnguyenhd/swing-jdbc architecture

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

- Interactive diagram: https://gitdiagram.com/dinhnguyenhd/swing-jdbc
- Repository: https://github.com/dinhnguyenhd/swing-jdbc

## Overview

##### Main components
- GUI (Presentation Layer): Represented by files in the "GUI" folder (e.g., ViewAction.java). This layer is responsible for user interaction using Java Swing.
- BUS (Business Logic Layer): Found in the "BUS" folder (e.g., TableAction.java). This layer contains the core business rules and operations that coordinate between the GUI and DAO.
- DAO (Data Access Layer): Located in the "DAO" folder with files such as DaoAction.java and SQLConnection.java. This layer manages all database interactions using JDBC.
- Entity (Domain Model): Contains domain classes like Students.java. These represent the data entities used by the business layer.
- Database: While not a code component, "students.sql" indicates the schema or SQL commands for setting up the relational database which the DAO interacts with.

##### Relationships and interactions
- The GUI layer (Swing interface) captures user input and sends requests to the Business layer.
- The Business layer processes requests, applies business rules, and makes calls to the DAO layer to perform CRUD operations.
- The DAO layer manages the database connections and data retrieval/insertion based on the business logic.
- The Entity layer acts as the data model throughout this process, ensuring that data is consistently structured between application and database.
- Additionally, the database, represented via the SQL script, is the persistent store that supports the DAO.

##### Architectural patterns and design principles
- 3-Layered Architecture: Clear separation into Presentation (GUI), Business (BUS), and Data Access (DAO) ensures modularity and easier maintenance.
- MVC principles: Although this is a desktop application, the separation of concerns mirrors the MVC pattern, where the GUI serves as the view (and controller responsibilities), the BUS is analogous to the model’s business logic, and the DAO manages data persistence.
- Loose coupling between layers achieved by ensuring each layer knows as little as necessary about the others.

##### Relevant technologies, frameworks, and libraries
- Java Swing for the graphical user interface.
- JDBC for database connectivity.
- Eclipse project structure (noted by the .project and .settings directories) which suggests using the Eclipse IDE to manage the project.
- SQL for database schema definition and operations (via students.sql).

##### Elements
- Clear labels for each component (GUI, BUS, DAO, Entity, Database).

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Presentation Layer"
        GUI["GUI"] 
    end

    subgraph "Business Logic Layer"
        BUS["BUS"]
    end

    subgraph "Data Access Layer"
        DAO1["DaoAction"]
        DAO2["SQLConnection"]
    end

    subgraph "Domain Model"
        ENTITY["Entity"]
    end

    DATABASE["Database"]

    GUI -->|"sendsRequest"| BUS
    BUS -->|"callsDAO"| DAO1
    DAO1 -->|"usesSQLConnection"| DAO2
    DAO1 -->|"mapsEntity"| ENTITY
    BUS -->|"usesEntity"| ENTITY
    DAO1 -->|"CRUDOperations"| DATABASE
    DAO1 -->|"returnsData"| BUS
    BUS -->|"updatesGUI"| GUI

    click GUI "https://github.com/dinhnguyenhd/swing-jdbc/blob/main/3Layers/src/GUI/ViewAction.java"
    click BUS "https://github.com/dinhnguyenhd/swing-jdbc/blob/main/3Layers/src/BUS/TableAction.java"
    click DAO1 "https://github.com/dinhnguyenhd/swing-jdbc/blob/main/3Layers/src/DAO/DaoAction.java"
    click DAO2 "https://github.com/dinhnguyenhd/swing-jdbc/blob/main/3Layers/src/DAO/SQLConnection.java"
    click ENTITY "https://github.com/dinhnguyenhd/swing-jdbc/blob/main/3Layers/src/Entity/Students.java"
    click DATABASE "https://github.com/dinhnguyenhd/swing-jdbc/blob/main/students.sql"

    classDef gui fill:#ffcccc,stroke:#880000,stroke-width:2px;
    classDef bus fill:#ffffcc,stroke:#888800,stroke-width:2px;
    classDef dao fill:#ccffcc,stroke:#008800,stroke-width:2px;
    classDef entity fill:#cce5ff,stroke:#000088,stroke-width:2px;
    classDef db fill:#f9d5b4,stroke:#d2691e,stroke-width:2px;

    class GUI gui;
    class BUS bus;
    class DAO1,DAO2 dao;
    class ENTITY entity;
    class DATABASE db;
```
