# magiauy/milktea architecture

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

- Interactive diagram: https://gitdiagram.com/magiauy/milktea
- Repository: https://github.com/magiauy/milktea

## Overview

##### Main Components
- User Interface (GUI Layer): Built using JavaFX. It includes FXML layouts (found under src/main/resources/milktea/milktea/GUI) and corresponding Java classes in the GUI package. This layer handles user interactions like logging in, navigating menus, and initiating actions.
- Business Logic (BUS Layer): Encapsulated in the milktea/milktea/BUS directory. These classes implement the core business rules (processing orders, managing inventory, handling invoicing, etc.) and serve as the intermediary between the UI and the data layer.
- Data Access (DAO Layer): Found under milktea/milktea/DAO. These classes are responsible for CRUD operations with the database.
- Domain Models (DTO Layer): Under milktea/milktea/DTO. These classes represent the data entities like Customer, Invoice, Ingredient, etc., and are used across layers to transfer data.
- API Component: Although the project is primarily a desktop JavaFX app, there is an API folder (milktea/milktea/API) containing at least one controller (ApiController.java), which could be used for external integration or to service additional API-based functionalities.
- External Dependencies and Resources:
- MySQL Database: Stores application data.
- Configuration Files: application.properties, connect.json, and the SQL scripts (in the resources/DAO folder) for database setup.
- Third-Party Libraries: Lombok (to reduce boilerplate code), JavaFX (for the GUI), and iText PDF (for generating PDF invoices).

##### Relationships and Interactions
- The GUI initiates user actions. When a user interacts (for example, creating an order or managing inventory), the GUI layer calls the corresponding methods in the Business Logic (BUS) layer.
- The BUS layer implements the core logic and then relies on the DAO layer to interact with the MySQL database, fetching or persisting data.
- The DTO layer is used to represent data as it passes between GUI, BUS, and DAO.
- The API component (ApiController) potentially exposes some of these interactions to an external layer if needed.

##### Architectural Patterns and Design Principles
- Layered Architecture: The clear separation into GUI, Business Logic (BUS), Data Access (DAO), and Data Transfer Objects (DTO) resembles the typical multi-layered (or N-tier) architecture.
- MVC-like Pattern: Although not strictly described as MVC, the separation of the GUI (View + Controller aspects in JavaFX and FXML) from the business logic and data access layers shows a similar separation of concerns.
- Modular Design: Each business domain (e.g., management of customers, orders, inventory, etc.) is split into dedicated classes within the BUS/DAO/DTO layers.
- External configuration management is achieved through various configuration files (connect.json, application.properties) and SQL scripts to manage database schema.

##### Instructing the Principal Software Engineer
- GUI components initiate actions that are handled by the BUS layer.
- The BUS layer then communicates with the DAO to retrieve or update data from the MySQL database.
- DTOs are passed between these modules.
- Detail any external interfaces, such as the API Controller, and how it might interact with other components or even external systems, if applicable.
- Including notes on supporting technologies: indicate that the project uses Maven (pom.xml, mvnw scripts), JavaFX, Lombok, iText PDF for PDFs, and MySQL for persistent storage.
- That any configuration files (connect.json, application.properties) and resource directories (CSS, FXML, fonts) are identified as part of the deployment and runtime environment.
- Design considerations such as modular separation, clear responsibilities for each component, and the flow for user interactions up to the data persistence layer.

## Diagram (Mermaid)

```mermaid
graph TD
    subgraph "User Interface (GUI Layer)"
        GUI_Java["GUI - Java Classes"]:::gui
        GUI_FXML["GUI - FXML Layouts & Resources"]:::gui
    end

    subgraph "Business Logic (BUS Layer)"
        BUS["BUS - Business Logic"]:::bus
    end

    subgraph "Data Access (DAO Layer)"
        DAO_Java["DAO - Data Access Classes"]:::dao
        DAO_SQL["DAO - Database SQL Scripts"]:::dao
    end

    subgraph "Domain Models (DTO Layer)"
        DTO["DTO - Domain Models"]:::dto
    end

    subgraph "API Component"
        APIController["API Controller"]:::api
    end

    subgraph "External Config & Dependencies"
        AppConfig["Application Properties"]:::config
        ConnectConf["Database Connection"]:::config
        Maven["Maven Build Script (pom.xml)"]:::config
        MavenWrapper["Maven Wrapper (mvnw)"]:::config
        MavenCmd["Maven Wrapper Cmd (mvnw.cmd)"]:::config
        MavenFiles["Maven Wrapper Files (.mvn)"]:::config
    end

    DB["MySQL Database"]:::db

    %% Core Layered Interactions
    GUI_Java -->|"initiates"| BUS
    GUI_FXML -->|"initiates"| BUS
    BUS -->|"calls"| DAO_Java
    DAO_Java -->|"CRUDOperations"| DB
    DAO_SQL -->|"setup"| DB

    %% DTO Usage between Layers (dotted lines)
    GUI_Java -.->|"usesDTO"| DTO
    BUS -.->|"usesDTO"| DTO
    DAO_Java -.->|"usesDTO"| DTO

    %% API Integration
    APIController -->|"integrates"| BUS

    %% External Configurations influence layers
    AppConfig -->|"configures"| BUS
    ConnectConf -->|"configures"| DAO_Java

    %% Build & Dependency Management supporting the project
    Maven ---|"builds"| BUS
    Maven ---|"builds"| DAO_Java
    MavenWrapper ---|"builds"| BUS
    MavenCmd ---|"builds"| DAO_Java
    MavenFiles ---|"builds"| BUS

    %% Class Definitions for Colours
    classDef gui fill:#ADD8E6,stroke:#000000,stroke-width:1px,color:#000000;
    classDef bus fill:#90EE90,stroke:#000000,stroke-width:1px,color:#000000;
    classDef dao fill:#FFFF99,stroke:#000000,stroke-width:1px,color:#000000;
    classDef dto fill:#D3D3D3,stroke:#000000,stroke-width:1px,color:#000000;
    classDef api fill:#FFB6C1,stroke:#000000,stroke-width:1px,color:#000000;
    classDef db fill:#FFA07A,stroke:#000000,stroke-width:1px,color:#000000;
    classDef config fill:#E6E6FA,stroke:#000000,stroke-width:1px,color:#000000;

    %% Click Events for Component Mappings
    click GUI_Java "https://github.com/magiauy/milktea/tree/master/src/main/java/milktea/milktea/GUI"
    click GUI_FXML "https://github.com/magiauy/milktea/tree/master/src/main/resources/milktea/milktea/GUI"
    click BUS "https://github.com/magiauy/milktea/tree/master/src/main/java/milktea/milktea/BUS"
    click DAO_Java "https://github.com/magiauy/milktea/tree/master/src/main/java/milktea/milktea/DAO"
    click DAO_SQL "https://github.com/magiauy/milktea/tree/master/src/main/resources/milktea/milktea/DAO"
    click DTO "https://github.com/magiauy/milktea/tree/master/src/main/java/milktea/milktea/DTO"
    click APIController "https://github.com/magiauy/milktea/blob/master/src/main/java/milktea/milktea/API/ApiController.java"
    click AppConfig "https://github.com/magiauy/milktea/blob/master/src/main/resources/application.properties"
    click ConnectConf "https://github.com/magiauy/milktea/blob/master/connect.json"
    click Maven "https://github.com/magiauy/milktea/blob/master/pom.xml"
    click MavenWrapper "https://github.com/magiauy/milktea/tree/master/mvnw"
    click MavenCmd "https://github.com/magiauy/milktea/blob/master/mvnw.cmd"
    click MavenFiles "https://github.com/magiauy/milktea/blob/master/.mvn"
```
