# umberto-bianchin/progetto_klotski architecture

> Architecture diagram of the GitHub repository umberto-bianchin/progetto_klotski, 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/umberto-bianchin/progetto_klotski
- Repository: https://github.com/umberto-bianchin/progetto_klotski

## Overview

##### Main Components
- User Interface (View): Represented by the Java Swing components (e.g., KlotskiUI, AuthenticationDialog, Board, Block, SavedGamesDialog, etc.) that render the game visuals and manage user interactions.
- Controller Layer: Classes in the Controller package handle user commands (e.g., AuthListener, BoardListener, HomeCommand, NextCommand, RestartCommand, SaveCommand, UndoCommand). These mediate between the View and Model layers.
- Model Layer: Includes domain models (KlotskiModel, Database, Move, Piece, Solver, State) encapsulating business logic, game state management, and database interactions.
- External Services:
- AWS Lambda-based Solver Service invoked via POST requests. This external Node.js service provides the “next best move” functionality.
- MySQL Database for persisting game state or user data.
- Infrastructure/Dependencies:
- Maven build (pom.xml, mvnw scripts) that link all project modules.
- Configuration files and resources (images, styles, etc.) in the resources directory.
- Testing Suite (JUnit tests under src/test) ensuring quality and regression safety.

##### Relationships and Data Flow
- The Controller then updates the Model, which may interact with the Database to store state or retrieve game data.
- For hint or move suggestions, the Model (specifically the Solver class) prepares a POST request and sends it to the AWS Lambda-based solver service. The JSON response is then parsed (using JSON simple) and funneled back into the Model (or directly updates the UI via the Controller).
- User → View (UI interactions).
- View → Controller (event notifications).
- Controller → Model (command invocations) and vice versa for updating the UI.
- Model → External Services (both Database queries and AWS Lambda HTTP POST calls).

##### Architectural Patterns and Technologies
- MVC pattern as the core structural pattern.
- Separation of concerns that isolates UI, application logic, and data access.
- Use of Java Swing (with FlatLaf for a modern look), emphasizing the UI layer.
- AWS Lambda as an external service component communicating via RESTful APIs.
- MySQL database as the repository for game state and possibly user data.
- Maven as a dependency management/build tool tying the project together.

## Diagram (Mermaid)

```mermaid
flowchart TD
    User("User"):::external

    subgraph "User Interface (View)"
        ViewUI["User Interface (View)"]:::view
    end

    subgraph "Controller Layer"
        ControllerLayer["Controller Layer"]:::controller
    end

    subgraph "Model Layer"
        ModelCore["Klotski Model"]:::model
        SolverIntegration["Solver (AWS Lambda Integration)"]:::model
        DatabaseLayer["Database (MySQL Interaction)"]:::model
    end

    subgraph "External Services"
        AWSLambda["AWS Lambda Service"]:::external
        MySQLDB["MySQL Database"]:::external
    end

    subgraph "Infrastructure/Dependencies"
        MavenBuild["Maven Build & Dependencies"]:::infrastructure
        ConfigResources["Configuration & Resources"]:::infrastructure
        TestingSuite["Testing Suite"]:::infrastructure
    end

    %% Main Flow
    User -->|"initiates"| ViewUI
    ViewUI -->|"notifies"| ControllerLayer
    ControllerLayer -->|"invokes"| ModelCore
    ModelCore -->|"solver-request"| SolverIntegration
    SolverIntegration -->|"POST-call"| AWSLambda
    AWSLambda -->|"solver-response"| SolverIntegration
    ModelCore -->|"persist/state"| DatabaseLayer
    DatabaseLayer -->|"query"| MySQLDB
    ModelCore -->|"updates"| ControllerLayer
    ControllerLayer -->|"renders"| ViewUI

    %% Infrastructure Support (dashed connectors)
    MavenBuild --- ViewUI
    MavenBuild --- ControllerLayer
    MavenBuild --- ModelCore
    ConfigResources --- ViewUI
    TestingSuite --- ControllerLayer
    TestingSuite --- ModelCore

    %% Click Events
    click ViewUI "https://github.com/umberto-bianchin/progetto_klotski/tree/master/src/main/java/View"
    click ControllerLayer "https://github.com/umberto-bianchin/progetto_klotski/tree/master/src/main/java/Controller"
    click ModelCore "https://github.com/umberto-bianchin/progetto_klotski/blob/master/src/main/java/Model/KlotskiModel.java"
    click SolverIntegration "https://github.com/umberto-bianchin/progetto_klotski/blob/master/src/main/java/Model/Solver.java"
    click DatabaseLayer "https://github.com/umberto-bianchin/progetto_klotski/blob/master/src/main/java/Model/Database.java"
    click MavenBuild "https://github.com/umberto-bianchin/progetto_klotski/blob/master/pom.xml"
    click ConfigResources "https://github.com/umberto-bianchin/progetto_klotski/tree/master/src/main/resources"
    click TestingSuite "https://github.com/umberto-bianchin/progetto_klotski/tree/master/src/test"

    %% Styles
    classDef view fill:#f9e79f,stroke:#8e44ad,stroke-width:2px;
    classDef controller fill:#aed6f1,stroke:#2471a3,stroke-width:2px;
    classDef model fill:#a9dfbf,stroke:#117864,stroke-width:2px;
    classDef external fill:#f9cfae,stroke:#d35400,stroke-width:2px;
    classDef infrastructure fill:#f5b7b1,stroke:#c0392b,stroke-width:2px;
```
