# nbao261/test architecture

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

- Interactive diagram: https://gitdiagram.com/nbao261/test
- Repository: https://github.com/nbao261/test

## Overview

##### Project’s Main Components
- Presentation (Web) Layer:
- Located in the “web” directory and the build/web folder.
- Contains JSPs (e.g., home.jsp, login-regis.jsp, dashboard.jsp etc.), CSS, and JavaScript assets.
- Represents the client-facing part of the application that interacts with end users.
- Controller Layer:
- Found in “src/java/controller.”
- Includes classes like AdminController, BookingController, LoginController, and others.
- Handles incoming HTTP requests from the presentation layer and routes them to the business logic.
- Data Access Layer:
- Found in “src/java/dao.”
- Contains DAO classes (e.g., BookingDAO, RoomDAO, UserDAO) that interact with the database.
- Data Transfer Objects (DTO):
- Located in “src/java/dto.”
- Used for passing data between layers (e.g., BookingDTO, UserDTO).
- Utility Components:
- Located in “src/java/utils.”
- Includes DBUtils, EmailUtils, PasswordUtils to provide common support functions (database connection, email handling, password hashing, etc.).
- Build and Configuration Setup:
- “build.xml” and “nbproject” folders represent the build/deployment configurations.
- The presence of ScriptLast.sql indicates the database schema or initial dataset.
- External Libraries:
- JAR files (e.g., sqljdbc4.jar, gson-2.10.1.jar) in the WEB-INF/lib directory indicate external dependencies, such as for JDBC connectivity, JSON processing, or other functionalities.

##### Relationships and Interactions
- The client’s browser sends HTTP requests to the web server where the JSP pages are delivered.
- The JSP pages interact with the controllers—they serve as views in the MVC flow.
- Controllers process the requests and typically invoke the DAO layer to read or persist data.
- DAO classes interface with the database as defined by ScriptLast.sql.
- DTOs are used to pass data between controllers and DAOs, ensuring a clean separation of concerns.
- Utility classes support both the data access and business logic processes.
- External libraries (JDBC, JSON, encryption) facilitate integration with external systems and services.

##### Architectural Patterns and Key Design Principles
- MVC Pattern: The clear separation between controllers, views (JSPs), and models (DTOs alongside DAOs) speaks to an MVC architecture.
- Layered Architecture: Presentation, business logic (controllers), and data layers are isolated from one another.
- Modular Design: The division into separate directories (controller, dao, dto, utils) indicates a modular approach which enhances maintainability and testability.

- Use clear labels for each component/layer. For example, “Presentation Layer (JSP, CSS, JS)”, “Controllers (e.g., LoginController, BookingController)”, “Data Access (DAO classes)”, “Models (DTO classes)”, and “Utilities”.
- From the Client/Browser to the Web Layer.
- From the Web Layer to Controllers.
- From Controllers to DAO, indicating data queries and commands.
- Don’t forget the inclusion of build and configuration components that indicate how the project is structured within the development environment.

## Diagram (Mermaid)

```mermaid
flowchart TD

    %% Top Level: Client and External Database
    Client["Client/Browser"]:::client
    DB["Database"]:::database

    %% Presentation Layer
    subgraph "Presentation Layer"
        JSP1["Home Page (home.jsp)"]:::presentation
        JSP2["Login/Register (login-regis.jsp)"]:::presentation
        JSP3["Dashboard (dashboard.jsp)"]:::presentation
    end

    %% Controller Layer
    subgraph "Controller Layer"
        LC["LoginController"]:::controller
        BC["BookingController"]:::controller
    end

    %% Data Transfer Objects (DTO)
    subgraph "DTO Layer"
        UDTO["UserDTO"]:::dto
        BDTO["BookingDTO"]:::dto
    end

    %% Data Access Layer (DAO)
    subgraph "Data Access Layer"
        UDAO["UserDAO"]:::dao
        BDAO["BookingDAO"]:::dao
    end

    %% Utility Components
    subgraph "Utility Components"
        DBU["DBUtils"]:::utils
        EU["EmailUtils"]:::utils
        PU["PasswordUtils"]:::utils
    end

    %% Build and Configuration Setup
    subgraph "Build/Configuration"
        BX["build.xml"]:::build
        NP["nbproject"]:::build
        SQL["ScriptLast.sql"]:::build
    end

    %% External Libraries
    subgraph "External Libraries"
        GSON["gson-2.10.1.jar"]:::external
        SQLJ["sqljdbc4.jar"]:::external
    end

    %% Connections: Client to Presentation
    Client --> JSP1
    Client --> JSP2
    Client --> JSP3

    %% Presentation to Controllers
    JSP1 -->|"request"| LC
    JSP2 -->|"request"| LC
    JSP3 -->|"request"| BC

    %% Controllers to DTOs and then to DAOs
    LC -->|"data"| UDTO
    UDTO -->|"transfer"| UDAO

    BC -->|"data"| BDTO
    BDTO -->|"transfer"| BDAO

    %% DAOs connect to Database
    UDAO -->|"query"| DB
    BDAO -->|"query"| DB

    %% Utility Components support
    DBU --- UDAO
    DBU --- BDAO
    EU --- LC
    PU --- LC

    %% External Libraries support
    GSON --- LC
    GSON --- BC
    SQLJ --- UDAO
    SQLJ --- BDAO

    %% Build and Configuration influence (dashed connections)
    BX --- JSP1
    NP --- LC
    SQL --- DB

    %% Click Events for Presentation Layer
    click JSP1 "https://github.com/nbao261/test/blob/main/web/home.jsp"
    click JSP2 "https://github.com/nbao261/test/blob/main/web/login-regis.jsp"
    click JSP3 "https://github.com/nbao261/test/blob/main/build/web/admin/dashboard.jsp"

    %% Click Events for Controller Layer
    click LC "https://github.com/nbao261/test/blob/main/src/java/controller/LoginController.java"
    click BC "https://github.com/nbao261/test/blob/main/src/java/controller/BookingController.java"

    %% Click Events for Data Access Layer
    click UDAO "https://github.com/nbao261/test/blob/main/src/java/dao/UserDAO.java"
    click BDAO "https://github.com/nbao261/test/blob/main/src/java/dao/BookingDAO.java"

    %% Click Events for DTO Layer
    click UDTO "https://github.com/nbao261/test/blob/main/src/java/dto/UserDTO.java"
    click BDTO "https://github.com/nbao261/test/blob/main/src/java/dto/BookingDTO.java"

    %% Click Events for Utility Components
    click DBU "https://github.com/nbao261/test/blob/main/src/java/utils/DBUtils.java"
    click EU "https://github.com/nbao261/test/blob/main/src/java/utils/EmailUtils.java"
    click PU "https://github.com/nbao261/test/blob/main/src/java/utils/PasswordUtils.java"

    %% Click Events for Build and Configuration Setup
    click BX "https://github.com/nbao261/test/blob/main/build.xml"
    click NP "https://github.com/nbao261/test/blob/main/nbproject/project.xml"
    click SQL "https://github.com/nbao261/test/blob/main/ScriptLast.sql"

    %% Click Events for External Libraries
    click GSON "https://github.com/nbao261/test/blob/main/build/web/WEB-INF/lib/gson-2.10.1.jar"
    click SQLJ "https://github.com/nbao261/test/blob/main/build/web/WEB-INF/lib/sqljdbc4.jar"

    %% Styles
    classDef client fill:#DCE775,stroke:#333,stroke-width:2px;
    classDef presentation fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef controller fill:#FFD700,stroke:#000,stroke-width:2px;
    classDef dao fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef dto fill:#87CEFA,stroke:#000,stroke-width:2px;
    classDef utils fill:#FFA07A,stroke:#000,stroke-width:2px;
    classDef build fill:#DDA0DD,stroke:#000,stroke-width:2px;
    classDef external fill:#C0C0C0,stroke:#000,stroke-width:2px;
    classDef database fill:#F08080,stroke:#000,stroke-width:2px;
```
