# silwyne/wizard-the-beginning-of-story architecture

> Architecture diagram of the GitHub repository silwyne/wizard-the-beginning-of-story, 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/silwyne/wizard-the-beginning-of-story
- Repository: https://github.com/silwyne/wizard-the-beginning-of-story

## Overview

##### Project Type and Purpose
- This is a combat game written in Java. It’s designed for human-to-human combat via socket-based server‐client communication.
- The project is in active development (“In work!”) and focuses on both game mechanics (movement, player state, tiles, and graphics) and online communication (server-client, message parsing, etc.).

##### File Structure to Identify Main Components
- Core Game Engine:
– Main entry point is in “nilian/Main.java”.
– Game logic components spread throughout “Player”, “gamePanel”, “graphics”, “tile”, etc.
- Player and Game State Management:
– Located under “nilian/Player” with classes handling player attributes, movement, orientation, state and suit mechanics.
- Graphics / UI Components:
– “nilian/graphics” contains windows (GameWindow, MainWindow, LoadingWindow) and panels (MenuPanel, OfflineMenuPanel, OnlineMenuPanel) to render the game interface.
- Input Handling:
– “nilian/input/KeyHandler.java” processes player input.
- Game Loader:
– “nilian/loader/MainLoader.java” likely initializes necessary game resources.
- Networking / Online Communication:
– The “nilian/online” directory covers the online functionalities:
- “ConnectionHandler”, “MessageParser”, and “OnlineMode” handle connection logic.
- Under “connector”, there are two sub-components:
▪ “host” (GameServer, ClientHandler, ServerMessageProcessor) for server operations.
▪ “joiner” (GameClient, ClientMessageProcessor) for client-side network interactions.
- “message” subdirectory includes definitions and processing classes for GameMessage, ClientMessage, ServerMessage, and even a .proto file, indicating that message data formats are an integral part of the communication.
- Resource Management:
– “src/main/resources” provides game assets such as player resources, maps, backgrounds, and tiles.

##### Key Architectural Patterns & Design Principles
- Separation of Concerns:
– Different packages are clearly separated to handle game logic, UI/graphics, input, networking, and resources.
- Client–Server Architecture:
– The project encapsulates both the game client (handling display, user input, game loop) and server-side components (handling connections, messaging, and game state distribution).
- Modularization:
– The directory structure shows a modular approach (e.g. splitting out online connectors into host and joiner, having distinct graphics panels for menus and gameplay, and splitting player actions from rendering).
- Communication Protocol:
– The network messaging infrastructure (messages, processors, and protocol definitions) suggests a custom or possibly protocol-buffer-based messaging system over sockets.

- Main Components to Include:
1. Game Client:
– Game Engine (Main.java, game loop)
– Player Module (Player, MovementHandler, PlayerState, etc.)
– UI & Graphics (GamePanel, GameWindow, various MenuPanels)
– Input Handling (KeyHandler)
– Resource Loader (MainLoader and resources from the ‘resources’ directory)
– Network Client (OnlineMode, joiner connector: GameClient, ClientMessageProcessor)
2. Game Server:
– Server-side Network Handling (host connector: GameServer, ClientHandler, ServerMessageProcessor)
– Message Parsing and Processing Modules (MessageParser, MessageMaker, MessageListener, MessageProcessor, MessageWriter)
3. Shared Message Infrastructure:
– Message Definitions (GameMessage, ClientMessage, ServerMessage, .proto file)
– Communication Protocols between client and server.
4. Additional Modules:
– Tile Management (Tile, TileManager)
– Supporting Modules for special game features (Player suit, online render such as OnlinePlayer/OnlineRenderer)

- Relationships and Interactions:
– The Game Client/UI interacts with the Input Handler and Game Engine.
– The Game Engine updates game state via Player and Tile modules.
– User actions are captured by the KeyHandler and possibly dispatched to update the game state.
– When in online mode, the client network module (GameClient) sends messages, utilizing the defined message protocols, to the server.
– The Game Server listens for connections (GameServer) and processes incoming messages through its message processors, then broadcasts updates back to connected game clients.
– The resource loader loads assets from the ‘resources’ directory which are used by several modules (UI, tile, player images, etc.).

- Technology and Frameworks:
– Since it is a Java project, standard Java libraries (for sockets, graphics, etc.) are used.
– The presence of the .proto file suggests potential usage of Protocol Buffers for message serialization.
– Build management is handled by Maven (indicated by pom.xml).

##### Elements
– Game Client’s core modules: Game Engine, Player Module, UI/Graphics, Input Handler, Networking Client.
– Game Server’s core modules: Server Network Handler, Client Message Processor.
– Shared Modules: Message definitions and protocol.
– Show interactions between Input → Game Engine, Game Engine → UI/Graphics.
- Notations for dependencies:
– Indicate use of common resources (assets) loaded via the loader.
– Highlight the asynchronous/socket communication channels between server and client.

## Diagram (Mermaid)

```mermaid
graph TD
  %% Game Client Subgraph
  subgraph "Game Client"
    A["Game Engine (nilian/Main.java)"]
    B["Player Module (nilian/Player)"]
    C["Player Suit Handling (nilian/Player/suit)"]
    D["UI & Graphics - Windows/Panels (nilian/graphics)"]
    E["In-game Panels (nilian/gamePanel)"]
    F["Input Handling (KeyHandler)"]
    G["Game Resource Loader (nilian/loader/MainLoader.java)"]
    G2["Game Assets (src/main/resources)"]
    H["Network Client - Online Mode Core (nilian/online/OnlineMode.java)"]
    I["Connector Joiner (nilian/online/connector/joiner)"]
    J["Tile Management (nilian/tile)"]
  end

  %% Game Server Subgraph
  subgraph "Game Server"
    K["Network Server - Connector Host (nilian/online/connector/host)"]
  end

  %% Shared Message Infrastructure Subgraph
  subgraph "Shared Message Infra"
    L["Message Definitions & Processing (nilian/online/message)"]
    M["Connector Message Handling (nilian/online/connector/message)"]
  end

  %% Connections within Game Client
  F -->|"triggers"| A
  A -->|"updates"| B
  B -->|"manages"| C
  A -->|"renders"| D
  A -->|"displays"| E
  A -->|"utilizes"| J
  A -->|"loads"| G
  G -->|"provides"| G2
  A -->|"initiates"| H
  H -->|"delegates"| I

  %% Network Communication between Client and Server
  I -->|"sends"| K
  
  %% Shared Message Infra interactions
  H -->|"formats"| L
  K -->|"processes"| L
  I -->|"dispatches"| M
  K -->|"routes"| M

  %% Class Definitions for Color Coding
  classDef clientComponents fill:#BBDEFB,stroke:#0D47A1,stroke-width:2px;
  classDef serverComponents fill:#FFCDD2,stroke:#B71C1C,stroke-width:2px;
  classDef sharedComponents fill:#C8E6C9,stroke:#1B5E20,stroke-width:2px;
  classDef tileComponents fill:#E1BEE7,stroke:#6A1B9A,stroke-width:2px;

  class A,B,C,D,E,F,G,H,I,G2 clientComponents;
  class K serverComponents;
  class L,M sharedComponents;
  class J tileComponents;

  %% Click Events
  click A "https://github.com/silwyne/wizard-the-beginning-of-story/blob/main/src/main/java/nilian/Main.java"
  click B "https://github.com/silwyne/wizard-the-beginning-of-story/tree/main/src/main/java/nilian/Player"
  click C "https://github.com/silwyne/wizard-the-beginning-of-story/tree/main/src/main/java/nilian/Player/suit"
  click D "https://github.com/silwyne/wizard-the-beginning-of-story/tree/main/src/main/java/nilian/graphics"
  click E "https://github.com/silwyne/wizard-the-beginning-of-story/tree/main/src/main/java/nilian/gamePanel"
  click F "https://github.com/silwyne/wizard-the-beginning-of-story/blob/main/src/main/java/nilian/input/KeyHandler.java"
  click G "https://github.com/silwyne/wizard-the-beginning-of-story/blob/main/src/main/java/nilian/loader/MainLoader.java"
  click G2 "https://github.com/silwyne/wizard-the-beginning-of-story/tree/main/src/main/resources"
  click H "https://github.com/silwyne/wizard-the-beginning-of-story/blob/main/src/main/java/nilian/online/OnlineMode.java"
  click I "https://github.com/silwyne/wizard-the-beginning-of-story/tree/main/src/main/java/nilian/online/connector/joiner"
  click K "https://github.com/silwyne/wizard-the-beginning-of-story/tree/main/src/main/java/nilian/online/connector/host"
  click L "https://github.com/silwyne/wizard-the-beginning-of-story/tree/main/src/main/java/nilian/online/message"
  click M "https://github.com/silwyne/wizard-the-beginning-of-story/tree/main/src/main/java/nilian/online/connector/message"
  click J "https://github.com/silwyne/wizard-the-beginning-of-story/tree/main/src/main/java/nilian/tile"
```
