# dickbalaska/slyther architecture

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

## Overview

1. The Client – a full-featured game client that incorporates game logic, rendering (with both LWJGL 2 and LWJGL 3 variants on different branches), user interfaces (menus, in-game GUI, snake customizations, etc.), local database capabilities (using Hibernate for game statistics and other stored data), and recording/replaying functionality.
2. The Server – a game server that manages network communications, game state updates, message dispatching, and a primitive built‐in server which should generally be avoided in favor of proper server deployment. It includes modules for handling client connections, game simulation (including entity management for snakes, food, and board sectors), and monitoring.
3. The Shared Library (slytherlib) – which encapsulates the common game logic, shared message protocols, network abstractions, and core data models (e.g., entities, configurations, and utilities) that are used by both the client and the server.

##### Main Components and Their Responsibilities
- Client Module:
- GUI and User Interface Elements (found under client/gui and client/gui/element)
- Game Logic and Input Handling (client/game, client/controller)
- Network Management (client/network, handling both incoming messages from the server and sending messages to it)
- Database Management (client/db with Hibernate integration – Database, DatabaseImpl, GameStatistic, etc.)
- Rendering and Resource Management (client/render, textures, and resource files)
- Game Recording and Replay (client/recording)
- Server Module:
- Network Communication and Message Handling (server/network, server/message/...)
- Game Simulation and Entity Management (server/game and server/game/entity)
- Connection and Client Monitor Management (server/server components such as ConnectedClient, ServerNetworkManager, ServerMonitorManager)
- Shared Library (slytherlib):
- Common data structures and game logic (slytherlib/game, slytherlib/game/entity)
- Shared networking classes and messaging protocols (slytherlib/network and its message sub-packages)
- Common utilities and configuration management shared between client and server

##### Relationships and Interactions
- The Client communicates with the Server over a network protocol that is defined in both the client and server packages. The messaging system is implemented in a bidirectional way, with messages for client-to-server communication (e.g., MessageStartLogin, MessageSetTurn) and server-to-client (e.g., MessageNewFood, MessageUpdateMap).
- The Client uses the shared library (slytherlib) for common game functions – both in terms of rendering game entities and following the protocol for communications.
- The Server similarly relies on slytherlib for implementing the game rules, converting messages received from clients into game state updates, and broadcasting messages to all connected clients.
- The Database integration (using Hibernate) on the client (and parts on the server) is responsible for maintaining historical game statistics, user configurations, and possibly other persisted data.

##### Architectural Patterns and Design Principles
- Separation of concerns is evident: the presentation layer (GUI/rendering), networking, game logic, and data persistence are all housed in separate packages.
- The use of client and server modules resembling a client–server architecture, with clear responsibilities and a shared protocol defined in the common library.
- MVC-like organization within the client module:
– Controllers (in client/controller) handle input and game state changes.
– Views (GUI components in client/gui) display the game.
– Model (game entities and database objects under client/game/entity and client/db) represent internal game state.
- Standard networking abstraction: message classes, handlers, and managers on both sides make it clear that the design is modular and allows for extensibility.

##### Technologies and Frameworks Highlighted
- Java (language) and Gradle (build system)
- LWJGL 2 and LWJGL 3 (for game rendering, depending on branch)
- Hibernate (for database persistence and object–relational mapping)
- Custom networking library code (inside slytherlib and respective network packages in client and server)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Module
    subgraph "Client Module"
        direction TB
        C1["GUI & UI"]
        C1a["GUI Elements"]
        C2["Game Logic & Input"]
        C2a["Game Entities"]
        C3["Controllers"]
        C4["Client Network Manager"]
        C4a["Network Messages"]
        C5["Database (Hibernate)"]
        C6["Recording & Replay"]
        C7["Rendering & Resources"]
        C7a["Textures"]

        C1 -->|"Includes"| C1a
        C2 -->|"Contains"| C2a
        C4 -->|"Handles"| C4a
        C7 -->|"Manages"| C7a
    end

    %% Server Module
    subgraph "Server Module"
        direction TB
        S4["Server Entry"]
        S1["Server Network Manager"]
        S1a["Message Handler"]
        S2["Game Simulation & Entities"]
        S2a["Game Entities"]
        S3["Client/Monitor Management"]

        S4 --> S1
        S1 -->|"Uses"| S1a
        S2 -->|"Manages"| S2a
    end

    %% Shared Library (slytherlib)
    subgraph "Shared Library (slytherlib)"
        direction TB
        SL1["Core Game Logic"]
        SL1a["Game Entities"]
        SL2["Shared Networking & Protocols"]
        SL3["Utilities & Configuration"]

        SL1 --> SL1a
    end

    %% Interactions between modules
    %% Client <--> Server (Network Communication)
    C4 -->|"PlayerCommands"| S1
    S1 -->|"GameStateUpdates"| C4

    %% Client dependencies on Shared Library
    C2 -->|"Uses CommonLogic"| SL1
    C4 -->|"Uses Protocols"| SL2

    %% Server dependencies on Shared Library
    S2 -->|"Implements Rules"| SL1
    S1 -->|"Uses Protocols"| SL2

    %% Styles
    classDef clientNodes fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef serverNodes fill:#AED6F1,stroke:#1F618D,stroke-width:2px;
    classDef sharedNodes fill:#A9DFBF,stroke:#239B56,stroke-width:2px;

    class C1,C1a,C2,C2a,C3,C4,C4a,C5,C6,C7,C7a clientNodes;
    class S1,S1a,S2,S2a,S3,S4 serverNodes;
    class SL1,SL1a,SL2,SL3 sharedNodes;

    %% Click Events for Client Module
    click C1 "https://github.com/dickbalaska/slyther/tree/slyther2/client/src/main/java/net/gegy1000/slyther/client/gui"
    click C1a "https://github.com/dickbalaska/slyther/tree/slyther2/client/src/main/java/net/gegy1000/slyther/client/gui/element"
    click C2 "https://github.com/dickbalaska/slyther/tree/slyther2/client/src/main/java/net/gegy1000/slyther/client/game"
    click C2a "https://github.com/dickbalaska/slyther/tree/slyther2/client/src/main/java/net/gegy1000/slyther/client/game/entity"
    click C3 "https://github.com/dickbalaska/slyther/tree/slyther2/client/src/main/java/net/gegy1000/slyther/client/controller"
    click C4 "https://github.com/dickbalaska/slyther/blob/slyther2/client/src/main/java/net/gegy1000/slyther/client/ClientNetworkManager.java"
    click C4a "https://github.com/dickbalaska/slyther/tree/slyther2/client/src/main/java/net/gegy1000/slyther/network/message"
    click C5 "https://github.com/dickbalaska/slyther/tree/slyther2/client/src/main/java/net/gegy1000/slyther/client/db"
    click C6 "https://github.com/dickbalaska/slyther/tree/slyther2/client/src/main/java/net/gegy1000/slyther/client/recording"
    click C7 "https://github.com/dickbalaska/slyther/tree/slyther2/client/src/main/java/net/gegy1000/slyther/client/render"
    click C7a "https://github.com/dickbalaska/slyther/tree/slyther2/client/src/main/resources/textures"

    %% Click Events for Server Module
    click S1 "https://github.com/dickbalaska/slyther/blob/slyther2/server/src/main/java/net/gegy1000/slyther/network/NetworkManager.java"
    click S1a "https://github.com/dickbalaska/slyther/blob/slyther2/server/src/main/java/net/gegy1000/slyther/network/MessageHandler.java"
    click S2 "https://github.com/dickbalaska/slyther/tree/slyther2/server/src/main/java/net/gegy1000/slyther/server/game"
    click S2a "https://github.com/dickbalaska/slyther/tree/slyther2/server/src/main/java/net/gegy1000/slyther/server/game/entity"
    click S3 "https://github.com/dickbalaska/slyther/blob/slyther2/server/src/main/java/net/gegy1000/slyther/server/ConnectedClient.java"
    click S4 "https://github.com/dickbalaska/slyther/blob/slyther2/server/src/main/java/net/gegy1000/slyther/server/SlytherServer.java"

    %% Click Events for Shared Library Module
    click SL1 "https://github.com/dickbalaska/slyther/tree/slyther2/slytherlib/src/main/java/net/gegy1000/slyther/game"
    click SL1a "https://github.com/dickbalaska/slyther/tree/slyther2/slytherlib/src/main/java/net/gegy1000/slyther/game/entity"
    click SL2 "https://github.com/dickbalaska/slyther/tree/slyther2/slytherlib/src/main/java/net/gegy1000/slyther/network"
    click SL3 "https://github.com/dickbalaska/slyther/tree/slyther2/slytherlib/src/main/java/net/gegy1000/slyther/util"
```
