# dieg0r01/explo-kittens-distributed-sys architecture

> Architecture diagram of the GitHub repository dieg0r01/explo-kittens-distributed-sys, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dieg0r01/explo-kittens-distributed-sys
- Repository: https://github.com/dieg0r01/explo-kittens-distributed-sys

## Overview

##### Project type and purpose
- This is a Java-based, turn-based multiplayer card game (“Exploding Kittens”) implemented as a client–server application.
- Clients provide a GUI for players; the server manages rooms, game sessions and enforces game rules concurrently using thread pools.

##### File structure
- Top-level src/ contains three logical modules:
- DomainModel: all card definitions, deck and player data structures.
- BusinessLogic: game rules, turn/order management, hand and priority managers.
- Client: split into GUI (presentation) and ClientNetwork (socket I/O).
- Server: split into ServerNetwork (connection handling) and GameLogic (room and session management).

##### Key insights from the README
- Uses ExecutorService (newCachedThreadPool for client connections; newSingleThreadExecutor per game/session) for concurrency.
- RoomManager centralizes thread-safe room creation/joining.
- GameSession runs in its own thread, invoking BusinessLogic and DomainModel classes.
- Simple text-based protocol (“CREATE”, “JOIN”, “START”, “EXIT”) over TCP sockets with ObjectInputStream/PrintStream.

##### Main components
a. Client Side
- GUI Layer: Swing/Java GUI + CardImages (view)
- ClientNetwork: ClientNet (socket connector)
b. Network Layer
- TCP Socket connection
c. Server Side
- ServerNetwork
– ServerNet (listener + global ExecutorService)
– ClientHandler (per‐client SingleThreadExecutor + I/O streams)
- GameLogic
– RoomManager (create/join rooms)
– Room (holds players, game settings)
– GameSession (per-room SingleThreadExecutor)
- BusinessLogic (Game, TurnManager, HandManager, etc.)
- DomainModel (Card, Deck, Player, CardFactory, etc.)

##### Relationships & interactions
- GUI → ClientNet sends user commands over TCP
- ServerNet accepts incoming sockets → spawns ClientHandler
- ClientHandler registers with RoomManager (CREATE/JOIN)
- RoomManager assigns players to a Room
- On “START”, RoomManager triggers a GameSession
- GameSession invokes BusinessLogic classes, manipulating DomainModel objects
- GameSession sends state updates back to clients via their ClientHandler streams

##### Architectural patterns & design principles
- Layered architecture: Presentation (GUI), Network, Server Logic, Business Logic, Domain Model
- Concurrency via ExecutorService pools (cached vs. single-threaded)
- Command/message protocol for client–server communication
- Separation of concerns: DomainModel is pure data, BusinessLogic is rule engine, ServerNetwork handles I/O

##### Relevant technologies & frameworks
- Java SE sockets (java.net.ServerSocket, Socket)
- java.util.concurrent.ExecutorService
- ObjectInputStream / PrintStream for message marshalling
- Swing or JavaFX for GUI (inferred by CardImages folder)

## Diagram (Mermaid)

```mermaid
flowchart TB
  %% Client Layer
  subgraph "Client Layer"
    GUI["GUI (Swing)"]:::client
    CardImages["CardImages"]:::client
    ClientNet["ClientNet"]:::client
  end

  GUI -->|"user commands"| ClientNet

  %% Network Layer
  subgraph "Network Layer"
    Socket["TCP Socket"]:::network
  end

  ClientNet -->|"TCP"| Socket

  %% Server Network
  subgraph "Server Network"
    ServerNet["ServerNet"]:::network
    ClientHandler["ClientHandler"]:::network
  end

  Socket --> ServerNet
  ServerNet -->|"spawn ClientHandler\nCachedThreadPool"| ClientHandler

  %% Server Logic
  subgraph "Server Logic"
    subgraph "GameLogic"
      RoomManager["RoomManager"]:::logic
      Room["Room"]:::logic
      GameSession["GameSession\n(SingleThreadExecutor)"]:::thread
    end
  end

  ClientHandler -->|"REGISTER/CREATE/JOIN"| RoomManager
  RoomManager --> Room
  RoomManager -->|"start"| GameSession

  %% Business Logic
  subgraph "Business Logic"
    Game["Game"]:::logic
    TurnManager["TurnManager"]:::logic
    HandManager["HandManager"]:::logic
    PriorityManager["PriorityManager"]:::logic
    TurnPriorityManager["TurnPriorityManager"]:::logic
    PlayerManager["PlayerManager"]:::logic
  end

  GameSession --> Game
  GameSession --> TurnManager
  GameSession --> HandManager
  GameSession --> PriorityManager
  GameSession --> TurnPriorityManager
  GameSession --> PlayerManager

  %% Domain Model
  subgraph "Domain Model"
    CType["C_Type"]:::domain
    Card["Card"]:::domain
    CardFactory["CardFactory"]:::domain
    CardStack["CardStack"]:::domain
    MainDeck["MainDeck"]:::domain
    DiscardDeck["DiscardDeck"]:::domain
    PlayerModel["Player"]:::domain
    CardsFolder["Cards"]:::domain
  end

  Game --> CType
  Game --> Card
  Game --> CardFactory
  Game --> CardStack
  Game --> MainDeck
  Game --> DiscardDeck
  Game --> PlayerModel
  Game --> CardsFolder

  GameSession -->|"state updates"| ClientHandler

  %% Application Entry
  Main["Main"]:::domain
  Main --> GUI
  Main --> ServerNet

  %% Click Events
  click GUI "https://github.com/dieg0r01/explo-kittens-distributed-sys/tree/master/src/Client/GUI"
  click CardImages "https://github.com/dieg0r01/explo-kittens-distributed-sys/tree/master/src/Client/GUI/CardImages"
  click ClientNet "https://github.com/dieg0r01/explo-kittens-distributed-sys/blob/master/src/Client/ClientNetwork/ClientNet.java"
  click ServerNet "https://github.com/dieg0r01/explo-kittens-distributed-sys/blob/master/src/Server/ServerNetwork/ServerNet.java"
  click ClientHandler "https://github.com/dieg0r01/explo-kittens-distributed-sys/blob/master/src/Server/ServerNetwork/ClientHandler.java"
  click RoomManager "https://github.com/dieg0r01/explo-kittens-distributed-sys/blob/master/src/Server/GameLogic/RoomManager.java"
  click Room "https://github.com/dieg0r01/explo-kittens-distributed-sys/blob/master/src/Server/GameLogic/Room.java"
  click GameSession "https://github.com/dieg0r01/explo-kittens-distributed-sys/blob/master/src/Server/GameLogic/GameSession.java"
  click Game "https://github.com/dieg0r01/explo-kittens-distributed-sys/blob/master/src/BusinessLogic/Game.java"
  click TurnManager "https://github.com/dieg0r01/explo-kittens-distributed-sys/blob/master/src/BusinessLogic/TurnManager.java"
  click HandManager "https://github.com/dieg0r01/explo-kittens-distributed-sys/blob/master/src/BusinessLogic/HandManager.java"
  click PriorityManager "https://github.com/dieg0r01/explo-kittens-distributed-sys/blob/master/src/BusinessLogic/PriorityManager.java"
  click TurnPriorityManager "https://github.com/dieg0r01/explo-kittens-distributed-sys/blob/master/src/BusinessLogic/TurnPriorityManager.java"
  click PlayerManager "https://github.com/dieg0r01/explo-kittens-distributed-sys/blob/master/src/BusinessLogic/PlayerManager.java"
  click CType "https://github.com/dieg0r01/explo-kittens-distributed-sys/blob/master/src/DomainModel/C_Type.java"
  click Card "https://github.com/dieg0r01/explo-kittens-distributed-sys/blob/master/src/DomainModel/Card.java"
  click CardFactory "https://github.com/dieg0r01/explo-kittens-distributed-sys/blob/master/src/DomainModel/CardFactory.java"
  click CardStack "https://github.com/dieg0r01/explo-kittens-distributed-sys/blob/master/src/DomainModel/CardStack.java"
  click MainDeck "https://github.com/dieg0r01/explo-kittens-distributed-sys/blob/master/src/DomainModel/MainDeck.java"
  click DiscardDeck "https://github.com/dieg0r01/explo-kittens-distributed-sys/blob/master/src/DomainModel/DiscardDeck.java"
  click PlayerModel "https://github.com/dieg0r01/explo-kittens-distributed-sys/blob/master/src/DomainModel/Player.java"
  click CardsFolder "https://github.com/dieg0r01/explo-kittens-distributed-sys/tree/master/src/DomainModel/Cards"
  click Main "https://github.com/dieg0r01/explo-kittens-distributed-sys/blob/master/src/Main.java"

  %% Styles
  classDef client fill:#D6EAF8,stroke:#1F618D,color:#1B4F72
  classDef network fill:#D5F5E3,stroke:#196F3D,color:#145A32
  classDef logic fill:#FAD7A0,stroke:#B9770E,color:#7E5109
  classDef domain fill:#F5B7B1,stroke:#943126,color:#641E16
  classDef thread fill:#E8DAEF,stroke:#6C3483,color:#4A235A
```
