# nhatcoi/oop-hotelms-app architecture

> Architecture diagram of the GitHub repository nhatcoi/oop-hotelms-app, 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/nhatcoi/oop-hotelms-app
- Repository: https://github.com/nhatcoi/oop-hotelms-app

## Overview

##### Main Components
- User Interface (Presentation Layer):
- JavaFX-based GUI, with FXML files and associated CSS (located under src/main/resources/com/mycompany/app/views and css folders).
- Views are split into different modules (e.g., authentication, guest operations, manager operations, admin views).
- Controllers:
- Located under the “controllers” packages (in hotel_management and week5to6) that manage user actions.
- Subdivided controllers such as AuthController, GuestController, ManagerController, and specialized ones for admin tasks.
- Domain/Entity Layer:
- Contains entity classes like Room, Guest, Staff, Reservation, Payment, and Comment.
- Also includes enums (e.g., RoomStatus, RoomType, UserRole) that define various domain-specific properties.
- Service Layer:
- Contains service interfaces (e.g., RoomService, GuestService, StaffService) and implementations.
- This layer contains the core business logic to process room booking, check-in/out, and management operations.
- Repository/Database Access Layer:
- The “repositories” package (with Database.java) handles data persistence.
- Although the README mentions MySQL as the main DB, the actual data persistence can also include file-based binary storage for room information.
- Utilities and Support Modules:
- Utility classes (e.g., MailSender, Security, FilesUtils, Dialog, ToolFXML, Md5, etc.) provide support functions.
- Configuration:
- JSON config files (config-example.json and config.json) and other artifacts (pom.xml) indicate use of Maven for dependency management and setup.
- Additional/Legacy Code:
- There are directories for week-by-week assignments (week1, week2, week3, etc.) that might not be part of the final product but can be mentioned as examples of learning exercises.

##### Relationships and Interactions
- The UI (JavaFX) sends user interactions (such as login, room booking, etc.) to the corresponding Controller.
- Controllers act as intermediaries by invoking methods in the Service layer.
- The Service layer contains the business rules and logic, accessing the Repository layer to perform CRUD operations on entities.
- The Repository layer interacts with persistent storage (likely MySQL and/or binary files as indicated in the README).
- Utility classes are used across layers for tasks like validation, security (e.g., MD5 hashing), and file operations.
- Configuration files are loaded to set up application parameters (e.g., database connection details).

##### Architectural Patterns and Design Principles
- MVC or layered architecture:
- Separation of concerns between UI, controller, service, and data access layers.
- Modularity:
- Clearly separated packages and distinct functional areas.
- Reusability and Abstraction:
- Use of interfaces for services to allow for flexible implementations.
- Integration of external libraries/technologies:
- JavaFX for GUI, CSS for styling, MySQL for database operations, Maven for build automation.

##### Including Relevant Technologies
- Java (core application language)
- JavaFX (for the GUI)
- MySQL (storing customer, room, and booking details)
- CSS (for styling the UI)
- Maven (pom.xml for dependency management)
- External libraries for additional functions (e.g., MailSender, security utilities)

##### Elements
- Flow of data from the user (UI) to Controllers, then to Services, and finally to the Database.
- Interactions between services and utility classes.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        UI["JavaFX Views"]:::presentation
        CSS["CSS Styles"]:::presentation
    end

    %% Controller Layer
    subgraph "Controller Layer"
        GC["Guest Controller"]:::controller
        MC["Manager Controller"]:::controller
        AC["Admin Controller"]:::controller
        W5C["Week5to6 Controller"]:::controller
    end

    %% Service Layer
    subgraph "Service Layer"
        SI["Service Interfaces"]:::service
        SIM["Service Implementations"]:::service
    end

    %% Data Access Layer
    subgraph "Data Access Layer"
        REP["Repository"]:::repository
        DB["Database (MySQL & Binary)"]:::repository
    end

    %% Domain/Entity Layer
    subgraph "Domain Layer"
        ENT["Entities"]:::domain
        EH["Enums (Hotel)"]:::domain
        EW["Enums (Week5to6)"]:::domain
    end

    %% Utility Modules
    subgraph "Utility Modules"
        UTIL1["Utility Modules"]:::utility
        UTIL2["Additional Utilities"]:::utility
    end

    %% Configuration
    subgraph "Configuration"
        POM["Maven (pom.xml)"]:::config
        CONF1["config-example.json"]:::config
        CONF2["config.json"]:::config
    end

    %% Flow connections: Presentation to Controllers
    UI -->|"triggers"| GC
    UI -->|"triggers"| MC
    UI -->|"triggers"| AC
    UI -->|"triggers"| W5C
    CSS -->|"styles"| UI

    %% Controllers invoke Services
    GC -->|"calls"| SI
    MC -->|"calls"| SI
    AC -->|"calls"| SI
    W5C -->|"calls"| SI

    %% Service Layer flow
    SI -->|"delegates"| SIM
    SIM -->|"accesses"| REP

    %% Repository layer to Database
    REP -->|"queries"| DB

    %% Services use Domain entities
    SI -->|"processes"| ENT
    SI -->|"validates with"| EH

    %% Controllers use Domain entities as well
    GC -->|"handles"| ENT
    MC -->|"handles"| ENT
    AC -->|"handles"| ENT

    %% Both Controllers and Services interact with Utilities
    GC ---|"uses"| UTIL1
    SI ---|"uses"| UTIL1
    SI ---|"uses"| UTIL2

    %% Configuration influences Repository and Services
    CONF1 -->|"configures"| REP
    CONF2 -->|"configures"| SI
    POM -->|"builds"| UI

    %% Click Events for Presentation Layer
    click UI "https://github.com/nhatcoi/oop-hotelms-app/tree/main/src/main/resources/com/mycompany/app/views"
    click CSS "https://github.com/nhatcoi/oop-hotelms-app/tree/main/src/main/resources/com/mycompany/app/css"

    %% Click Events for Controller Layer
    click GC "https://github.com/nhatcoi/oop-hotelms-app/tree/main/src/main/java/com/mycompany/app/hotel_management/controllers/guest"
    click MC "https://github.com/nhatcoi/oop-hotelms-app/tree/main/src/main/java/com/mycompany/app/hotel_management/controllers/manager"
    click AC "https://github.com/nhatcoi/oop-hotelms-app/tree/main/src/main/java/com/mycompany/app/hotel_management/controllers/manager/admin"
    click W5C "https://github.com/nhatcoi/oop-hotelms-app/tree/main/src/main/java/com/mycompany/app/week5to6/controllers"

    %% Click Events for Domain/Entity Layer
    click ENT "https://github.com/nhatcoi/oop-hotelms-app/tree/main/src/main/java/com/mycompany/app/hotel_management/entities"
    click EH "https://github.com/nhatcoi/oop-hotelms-app/tree/main/src/main/java/com/mycompany/app/hotel_management/enums"
    click EW "https://github.com/nhatcoi/oop-hotelms-app/tree/main/src/main/java/com/mycompany/app/week5to6/enums"

    %% Click Events for Service Layer
    click SI "https://github.com/nhatcoi/oop-hotelms-app/tree/main/src/main/java/com/mycompany/app/hotel_management/service"
    click SIM "https://github.com/nhatcoi/oop-hotelms-app/tree/main/src/main/java/com/mycompany/app/hotel_management/service/Impl"

    %% Click Events for Data Access Layer
    click REP "https://github.com/nhatcoi/oop-hotelms-app/tree/main/src/main/java/com/mycompany/app/hotel_management/repositories"

    %% Click Events for Utility Modules
    click UTIL1 "https://github.com/nhatcoi/oop-hotelms-app/tree/main/src/main/java/com/mycompany/app/hotel_management/utils"
    click UTIL2 "https://github.com/nhatcoi/oop-hotelms-app/tree/main/src/main/java/com/mycompany/app/week5to6/util"

    %% Click Events for Configuration
    click POM "https://github.com/nhatcoi/oop-hotelms-app/blob/main/pom.xml"
    click CONF1 "https://github.com/nhatcoi/oop-hotelms-app/blob/main/config-example.json"
    click CONF2 "https://github.com/nhatcoi/oop-hotelms-app/blob/main/config.json"

    %% Styling Classes
    classDef presentation fill:#ffcc00,stroke:#000,stroke-width:2px;
    classDef controller fill:#99ccff,stroke:#000,stroke-width:2px;
    classDef service fill:#ccffcc,stroke:#000,stroke-width:2px;
    classDef repository fill:#ff9999,stroke:#000,stroke-width:2px;
    classDef domain fill:#ccccff,stroke:#000,stroke-width:2px;
    classDef utility fill:#ffccff,stroke:#000,stroke-width:2px;
    classDef config fill:#ccffff,stroke:#000,stroke-width:2px;
```
