# rouhjp/rouh-mahjong-net architecture

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

- Interactive diagram: https://gitdiagram.com/rouhjp/rouh-mahjong-net
- Repository: https://github.com/rouhjp/rouh-mahjong-net

## Overview

The rouh-mahjong-net project is a Java-based desktop mahjong game that supports both local test play and networked multiplayer matches. The project uses Gradle for building and organizes its code into distinct packages corresponding to specific aspects of the application such as the user interface (UI), core game logic, network communications, scoring, and bot behavior.

##### Main Components
- User Interface (UI) Layer:
- Located primarily in the “app” and “app/view” packages.
- Contains windows, panels (such as AutoResizablePanel, MenuScene, RoomScene, GameResultViewPanel, etc.), and other visual elements for displaying game state and receiving user input.
- Game Engine / Core Game Logic:
- Found in the “game” and “game/event” packages.
- Manages game flow, player actions, rounds, wall generation, and overall game state.
- Implements design patterns such as Observer (e.g., TableObserver, TableObserverAdapter) and possibly MVC to separate the game model from the view.
- Bot / AI Module:
- Present in the “bot” package.
- Facilitates automated players with classes like DiscardingBot, StandardDiscardingBot, and additional AI strategies.
- Network Module:
- Located in the “net” package and supported by utilities in “util/net” and “util/net/msg”.
- Handles networking aspects including room creation, room membership, message conversion, and communication through RoomServer, RoomObserver, etc.
- This module enables multiplayer functionality, including room management and message passing between clients.
- Scoring and Rules Module:
- Found in the “score” package.
- Responsible for calculating hand scores, evaluating winning options, and representing scoring-related metrics.
- Tile and Resource Management:
- “tile” package contains classes for tiles, dice, and related game pieces.
- “src/main/resources/img” holds image assets for dice and tiles, indicative of the resource dependencies for the UI.
- Utility Classes:
- Located in “util” which provides common functionalities (e.g., Lists, Maps) and supportive network messaging utilities.

##### Relationships and Interactions
- UI Layer interacts with the Game Engine by sending and receiving game state changes. For example, a Scene in the “app” package will transition based on game events managed in the “game” packages.
- The Game Engine dispatches events (via classes in “game/event”) that are observed by both the UI (for rendering updates) and the Network Module (for multiplayer synchronization).
- The Bot Module plugs into the Game Engine allowing automated players to register and act within the game loop.
- The Network Module serves as an intermediary for remote players. Components here (such as Room, RoomServer, and RoomObserver) handle connection, message serialization (via util/net/msg) and communication to ensure synchronized gameplay.
- The Scoring Module works closely with the game logic to evaluate game outcomes, compute points, and display them in the UI.
- Utility packages support various common functions (e.g., list and map management) and provide network I/O management.

##### Architectural Patterns and Frameworks
- Separation of Concerns/MVC: The UI and game logic are clearly separated. Game state and business logic are managed separately from the user interface.
- Observer Pattern: Evident in the “game/event” package with components like TableObserver that facilitate event-driven updates.
- Modularization: The project is divided into logical modules: UI, game logic, networking, AI, and scoring.
- Gradle Build System: Shown in the build.gradle and settings.gradle files, which manage dependencies and project configuration.

##### Relevant Technologies
- Java as the programming language.
- Gradle for project build and dependency management.
- Logback (as seen in src/main/resources/logback.xml) is used for logging.
- Native image resources and drawing utilities for the UI.
- Custom network communication protocols and converters for facilitating multiplayer gameplay.

##### Elements
- Data stores or resource nodes for images and configuration files (resources for images, logback config).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% UI / Presentation Layer
    subgraph "UI / Presentation"
        App["Application (UI)"]:::ui
        View["View Components (UI)"]:::ui
    end
    click App "https://github.com/rouhjp/rouh-mahjong-net/tree/master/src/main/java/jp/rouh/mahjong/app"
    click View "https://github.com/rouhjp/rouh-mahjong-net/tree/master/src/main/java/jp/rouh/mahjong/app/view"

    %% Core Game Engine
    subgraph "Core Game Engine"
        GE["Game Engine"]:::engine
        GE_Events["Event Handling"]:::engine
    end
    click GE "https://github.com/rouhjp/rouh-mahjong-net/tree/master/src/main/java/jp/rouh/mahjong/game"
    click GE_Events "https://github.com/rouhjp/rouh-mahjong-net/tree/master/src/main/java/jp/rouh/mahjong/game/event"

    %% Bot / AI Module
    subgraph "Bot / AI Module"
        Bot["Bot / AI Module"]:::bot
    end
    click Bot "https://github.com/rouhjp/rouh-mahjong-net/tree/master/src/main/java/jp/rouh/mahjong/bot"

    %% Network Module
    subgraph "Network Module"
        Net["Network Communications"]:::network
        NetUtil["Network Utilities"]:::network
        NetMsg["Network Msg Converter"]:::network
    end
    click Net "https://github.com/rouhjp/rouh-mahjong-net/tree/master/src/main/java/jp/rouh/mahjong/net"
    click NetUtil "https://github.com/rouhjp/rouh-mahjong-net/tree/master/src/main/java/jp/rouh/util/net"
    click NetMsg "https://github.com/rouhjp/rouh-mahjong-net/tree/master/src/main/java/jp/rouh/util/net/msg"

    %% Scoring and Rules Module
    subgraph "Scoring and Rules Module"
        Score["Scoring Engine"]:::score
    end
    click Score "https://github.com/rouhjp/rouh-mahjong-net/tree/master/src/main/java/jp/rouh/mahjong/score"

    %% Tile and Resource Management
    subgraph "Tile and Resource Management"
        Tile["Tile and Game Pieces"]:::tile
        Resources["Image Assets"]:::tile
    end
    click Tile "https://github.com/rouhjp/rouh-mahjong-net/tree/master/src/main/java/jp/rouh/mahjong/tile"
    click Resources "https://github.com/rouhjp/rouh-mahjong-net/tree/master/src/main/resources/img"

    %% Utility Classes
    subgraph "Utility Classes"
        Utils["Utility Classes"]:::util
    end
    click Utils "https://github.com/rouhjp/rouh-mahjong-net/tree/master/src/main/java/jp/rouh/util"

    %% Interactions
    App -->|"sends_action"| GE
    GE -->|"updates_state"| Bot
    GE -->|"broadcasts_event"| Net
    GE -->|"triggers_scoring"| Score
    GE_Events -->|"observes_update"| View
    Net -->|"processes_msg"| NetMsg
    NetMsg -->|"delivers_msg"| Net
    Score -->|"displays_scores"| View

    %% Utility dependencies (dashed lines)
    App -.-> Utils
    View -.-> Utils
    GE -.-> Utils
    GE_Events -.-> Utils
    Bot -.-> Utils
    Net -.-> Utils
    NetUtil -.-> Utils
    NetMsg -.-> Utils
    Score -.-> Utils
    Tile -.-> Utils
    Resources -.-> Utils

    %% Styles
    classDef ui fill:#e0f7fa,stroke:#006064,stroke-width:2px;
    classDef engine fill:#f1f8e9,stroke:#33691e,stroke-width:2px;
    classDef bot fill:#fce4ec,stroke:#880e4f,stroke-width:2px;
    classDef network fill:#fff3e0,stroke:#ef6c00,stroke-width:2px;
    classDef score fill:#f3e5f5,stroke:#6a1b9a,stroke-width:2px;
    classDef tile fill:#e8eaf6,stroke:#283593,stroke-width:2px;
    classDef util fill:#eceff1,stroke:#37474f,stroke-width:2px;
```
