# adelinchelariu/battleshipgame architecture

> Architecture diagram of the GitHub repository adelinchelariu/battleshipgame, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/adelinchelariu/battleshipgame
- Repository: https://github.com/adelinchelariu/battleshipgame

## Overview

BattleshipGame is a WPF multiplayer client, a TCP server that manages lobby and independent matches, and a shared library for game rules and wire messages. The main workflow is connect, join the lobby, challenge and accept an opponent, place fleets, then exchange timed attacks until a result or rematch. Chat and disconnect handling are additional paths. The graph uses README-described capabilities and sampled source references; unsampled implementation details are not expanded beyond those documented relationships.

Main entry points: [`BattleshipClient/Client.cs`](https://github.com/adelinchelariu/battleshipgame/blob/main/BattleshipClient/Client.cs) (Client networking), [`BattleshipServer/GameSession.cs`](https://github.com/adelinchelariu/battleshipgame/blob/main/BattleshipServer/GameSession.cs) (Game session), [`BattleshipClient/MainWindow.xaml.cs`](https://github.com/adelinchelariu/battleshipgame/blob/main/BattleshipClient/MainWindow.xaml.cs) (Game window), [`BattleshipServer/LobbyManager.cs`](https://github.com/adelinchelariu/battleshipgame/blob/main/BattleshipServer/LobbyManager.cs) (Lobby manager)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Desktop client"]
  node_connect["Connect dialog"]
  node_lobbyui["Lobby window"]
  node_gameui["Game window<br/>[MainWindow.xaml.cs]"]
  node_chatui["Game chat<br/>[ChatWindow.xaml.cs]"]
  node_clientnet["Client networking<br/>[Client.cs]"]
end

subgraph group_server["Game server"]
  node_server["TCP listener<br/>[Server.cs]"]
  node_handler["Client handler<br/>[ClientHandler.cs]"]
  node_lobby["Lobby manager<br/>[LobbyManager.cs]"]
  node_session["Game session<br/>[GameSession.cs]"]
end

subgraph group_shared["Shared rules"]
  node_protocol["Wire protocol<br/>[Protocol.cs]"]
  node_board["Board rules<br/>[Board.cs]"]
  node_ship["Ship model<br/>[Ship.cs]"]
end

node_player(("Player"))

node_player -->|"starts connection"| node_connect
node_connect -->|"configures"| node_clientnet
node_clientnet -->|"connects via TCP"| node_server
node_server -->|"creates handlers"| node_handler
node_server -->|"registers clients"| node_lobby
node_handler -.->|"routes messages"| node_lobby
node_lobby -->|"sends updates"| node_handler
node_lobby -->|"starts match"| node_session
node_player -->|"challenges players"| node_lobbyui
node_lobbyui -->|"sends lobby actions"| node_clientnet
node_clientnet -->|"raises lobby events"| node_lobbyui
node_player -->|"places and attacks"| node_gameui
node_gameui -->|"sends game actions"| node_clientnet
node_clientnet -->|"raises game events"| node_gameui
node_session -->|"uses connections"| node_handler
node_session -->|"applies game rules"| node_board
node_session -->|"builds messages"| node_protocol
node_clientnet -->|"parses messages"| node_protocol
node_gameui -->|"manages grids"| node_board
node_board -->|"tracks ships"| node_ship
node_player -->|"chats in match"| node_chatui
node_chatui -->|"sends chat"| node_clientnet
node_clientnet -->|"delivers chat"| node_chatui
node_session -.->|"relays match chat"| node_chatui

click node_connect "https://github.com/adelinchelariu/battleshipgame/blob/main/BattleshipClient/ConnectDialog.xaml.cs"
click node_lobbyui "https://github.com/adelinchelariu/battleshipgame/blob/main/BattleshipClient/LobbyWindow.xaml.cs"
click node_gameui "https://github.com/adelinchelariu/battleshipgame/blob/main/BattleshipClient/MainWindow.xaml.cs"
click node_chatui "https://github.com/adelinchelariu/battleshipgame/blob/main/BattleshipClient/ChatWindow.xaml.cs"
click node_clientnet "https://github.com/adelinchelariu/battleshipgame/blob/main/BattleshipClient/Client.cs"
click node_server "https://github.com/adelinchelariu/battleshipgame/blob/main/BattleshipServer/Server.cs"
click node_handler "https://github.com/adelinchelariu/battleshipgame/blob/main/BattleshipServer/ClientHandler.cs"
click node_lobby "https://github.com/adelinchelariu/battleshipgame/blob/main/BattleshipServer/LobbyManager.cs"
click node_session "https://github.com/adelinchelariu/battleshipgame/blob/main/BattleshipServer/GameSession.cs"
click node_protocol "https://github.com/adelinchelariu/battleshipgame/blob/main/Shared/Protocol.cs"
click node_board "https://github.com/adelinchelariu/battleshipgame/blob/main/Shared/Board.cs"
click node_ship "https://github.com/adelinchelariu/battleshipgame/blob/main/Shared/Ship.cs"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_connect,node_lobbyui,node_gameui,node_chatui,node_clientnet toneBlue
class node_server,node_handler,node_lobby,node_session toneAmber
class node_protocol,node_board,node_ship toneMint
class node_player toneIndigo
```

## Components

### Desktop client

- [Connect dialog](https://github.com/adelinchelariu/battleshipgame/blob/main/BattleshipClient/ConnectDialog.xaml.cs): `BattleshipClient/ConnectDialog.xaml.cs`
- [Lobby window](https://github.com/adelinchelariu/battleshipgame/blob/main/BattleshipClient/LobbyWindow.xaml.cs): `BattleshipClient/LobbyWindow.xaml.cs`
- [Game window](https://github.com/adelinchelariu/battleshipgame/blob/main/BattleshipClient/MainWindow.xaml.cs): `BattleshipClient/MainWindow.xaml.cs`
- [Game chat](https://github.com/adelinchelariu/battleshipgame/blob/main/BattleshipClient/ChatWindow.xaml.cs): `BattleshipClient/ChatWindow.xaml.cs`
- [Client networking](https://github.com/adelinchelariu/battleshipgame/blob/main/BattleshipClient/Client.cs): `BattleshipClient/Client.cs`

### Game server

- [TCP listener](https://github.com/adelinchelariu/battleshipgame/blob/main/BattleshipServer/Server.cs): `BattleshipServer/Server.cs`
- [Client handler](https://github.com/adelinchelariu/battleshipgame/blob/main/BattleshipServer/ClientHandler.cs): `BattleshipServer/ClientHandler.cs`
- [Lobby manager](https://github.com/adelinchelariu/battleshipgame/blob/main/BattleshipServer/LobbyManager.cs): `BattleshipServer/LobbyManager.cs`
- [Game session](https://github.com/adelinchelariu/battleshipgame/blob/main/BattleshipServer/GameSession.cs): `BattleshipServer/GameSession.cs`

### Shared rules

- [Wire protocol](https://github.com/adelinchelariu/battleshipgame/blob/main/Shared/Protocol.cs): `Shared/Protocol.cs`
- [Board rules](https://github.com/adelinchelariu/battleshipgame/blob/main/Shared/Board.cs): `Shared/Board.cs`
- [Ship model](https://github.com/adelinchelariu/battleshipgame/blob/main/Shared/Ship.cs): `Shared/Ship.cs`

### Other components

- **Player**

## Connections

- Player → Connect dialog: starts connection (evidence: `README.md`)
- Connect dialog → Client networking: configures (evidence: `BattleshipClient/ConnectDialog.xaml.cs`)
- Client networking → TCP listener: connects via TCP (evidence: `README.md`)
- TCP listener → Client handler: creates handlers (evidence: `BattleshipServer/Server.cs`)
- TCP listener → Lobby manager: registers clients (evidence: `BattleshipServer/Server.cs`)
- Client handler → Lobby manager: routes messages (evidence: `BattleshipServer/LobbyManager.cs`)
- Lobby manager → Client handler: sends updates (evidence: `BattleshipServer/LobbyManager.cs`)
- Lobby manager → Game session: starts match (evidence: `BattleshipServer/LobbyManager.cs`)
- Player → Lobby window: challenges players (evidence: `README.md`)
- Lobby window → Client networking: sends lobby actions (evidence: `BattleshipClient/LobbyWindow.xaml.cs`)
- Client networking → Lobby window: raises lobby events (evidence: `BattleshipClient/LobbyWindow.xaml.cs`)
- Player → Game window: places and attacks (evidence: `README.md`)
- Game window → Client networking: sends game actions (evidence: `BattleshipClient/MainWindow.xaml.cs`)
- Client networking → Game window: raises game events (evidence: `BattleshipClient/MainWindow.xaml.cs`)
- Game session → Client handler: uses connections (evidence: `BattleshipServer/GameSession.cs`)
- Game session → Board rules: applies game rules (evidence: `BattleshipServer/GameSession.cs`)
- Game session → Wire protocol: builds messages (evidence: `BattleshipServer/GameSession.cs`)
- Client networking → Wire protocol: parses messages (evidence: `BattleshipClient/Client.cs`)
- Game window → Board rules: manages grids (evidence: `BattleshipClient/MainWindow.xaml.cs`)
- Board rules → Ship model: tracks ships (evidence: `Shared/Board.cs`)
- Player → Game chat: chats in match (evidence: `README.md`)
- Game chat → Client networking: sends chat (evidence: `BattleshipClient/ChatWindow.xaml.cs`)
- Client networking → Game chat: delivers chat (evidence: `BattleshipClient/ChatWindow.xaml.cs`)
- Game session → Game chat: relays match chat
