# wtfblub/netspherepirates architecture

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

- Interactive diagram: https://gitdiagram.com/wtfblub/netspherepirates
- Repository: https://github.com/wtfblub/netspherepirates

## Overview

NetspherePirates is an experimental S4 League patch-34 server emulator. Its user-facing flow is client connections through authentication, then chat and game services for player, channel, room, inventory and match activity; a relay supports peer-to-peer communication. Persistent account/game state and loaded game data underpin those services, while the optional Web API exposes administration and server data. The tree and README establish the product shape; sampled handler and manager references support only some cross-service links, so other important relationships are shown as unverified dashed edges.

Main entry points: [`src/ProudNet/ProudSession.cs`](https://github.com/wtfblub/netspherepirates/blob/dev/src/ProudNet/ProudSession.cs) (ProudNet Transport), [`src/Netsphere.Server.Game/Handlers/RoomHandler.cs`](https://github.com/wtfblub/netspherepirates/blob/dev/src/Netsphere.Server.Game/Handlers/RoomHandler.cs) (Gameplay), [`src/Netsphere.Server.Game/Services/GameDataService.cs`](https://github.com/wtfblub/netspherepirates/blob/dev/src/Netsphere.Server.Game/Services/GameDataService.cs) (Game Data), [`src/Netsphere.Database/GameContext.cs`](https://github.com/wtfblub/netspherepirates/blob/dev/src/Netsphere.Database/GameContext.cs) (Player Records)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_network["Networking"]
  node_relay["P2P Relay<br/>[EventHandler.cs]"]
  node_wire["Protocol Messages"]
  node_transport["ProudNet Transport<br/>[ProudSession.cs]"]
end

subgraph group_services["Game Services"]
  node_auth["Authentication"]
  node_chat["Chat and Social<br/>[ChatHandler.cs]"]
  node_game["Gameplay<br/>[RoomHandler.cs]"]
  node_characters["Characters"]
end

subgraph group_state["Data and State"]
  node_accounts[("Account Records<br/>[AuthContext.cs]")]
  node_playerdata[("Player Records<br/>[GameContext.cs]")]
  node_gamedata["Game Data<br/>[GameDataService.cs]"]
  node_ids["ID Generation"]
  node_database["Database Access<br/>[DatabaseService.cs]"]
  node_resource["Resource Formats<br/>[S4Zip.cs]"]
end

subgraph group_extensions["Extensions"]
  node_webapi["Web API<br/>[WebApiService.cs]"]
  node_plugins["Plugin Host<br/>[MefPluginHost.cs]"]
  node_shopeditor["Shop Editor<br/>[ShopService.cs]"]
end

node_client(("Game Client"))

node_client -.->|"connects"| node_transport
node_transport -.->|"dispatches"| node_auth
node_transport -.->|"dispatches"| node_chat
node_transport -.->|"dispatches"| node_game
node_transport -.->|"dispatches"| node_relay
node_auth -->|"queries"| node_accounts
node_auth -.->|"opens context"| node_database
node_chat -->|"loads settings"| node_playerdata
node_game -->|"loads players"| node_playerdata
node_game -->|"requests items"| node_gamedata
node_characters -->|"saves characters"| node_playerdata
node_characters -->|"allocates IDs"| node_ids
node_gamedata -->|"loads shop data"| node_database
node_relay -.->|"uses sessions"| node_transport
node_game -.->|"sends messages"| node_wire
node_webapi -->|"reads game data"| node_gamedata
node_plugins -.->|"hosts plugin"| node_webapi
node_shopeditor -.->|"edits shop"| node_playerdata
node_resource -.->|"provides resources"| node_gamedata

click node_auth "https://github.com/wtfblub/netspherepirates/blob/dev/src/Netsphere.Server.Auth/Handlers/AuthenticationHandler.cs"
click node_chat "https://github.com/wtfblub/netspherepirates/blob/dev/src/Netsphere.Server.Chat/Handlers/ChatHandler.cs"
click node_game "https://github.com/wtfblub/netspherepirates/blob/dev/src/Netsphere.Server.Game/Handlers/RoomHandler.cs"
click node_relay "https://github.com/wtfblub/netspherepirates/blob/dev/src/Netsphere.Server.Relay/Handlers/EventHandler.cs"
click node_wire "https://github.com/wtfblub/netspherepirates/blob/dev/src/Netsphere.Network/Message/Game/GameMessageFactory.cs"
click node_transport "https://github.com/wtfblub/netspherepirates/blob/dev/src/ProudNet/ProudSession.cs"
click node_accounts "https://github.com/wtfblub/netspherepirates/blob/dev/src/Netsphere.Database/AuthContext.cs"
click node_playerdata "https://github.com/wtfblub/netspherepirates/blob/dev/src/Netsphere.Database/GameContext.cs"
click node_characters "https://github.com/wtfblub/netspherepirates/blob/dev/src/Netsphere.Server.Game/CharacterManager.cs"
click node_gamedata "https://github.com/wtfblub/netspherepirates/blob/dev/src/Netsphere.Server.Game/Services/GameDataService.cs"
click node_ids "https://github.com/wtfblub/netspherepirates/blob/dev/src/Netsphere.Common/IdGeneratorService.cs"
click node_database "https://github.com/wtfblub/netspherepirates/blob/dev/src/Netsphere.Database/DatabaseService.cs"
click node_webapi "https://github.com/wtfblub/netspherepirates/blob/dev/src/plugins/WebApi/WebApiService.cs"
click node_plugins "https://github.com/wtfblub/netspherepirates/blob/dev/src/Netsphere.Common/Plugins/MefPluginHost.cs"
click node_shopeditor "https://github.com/wtfblub/netspherepirates/blob/dev/src/tools/Netsphere.Tools.ShopEditor/Services/ShopService.cs"
click node_resource "https://github.com/wtfblub/netspherepirates/blob/dev/src/Netsphere.Resource/S4Zip.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_relay,node_wire,node_transport,node_client toneBlue
class node_auth,node_chat,node_game,node_characters toneAmber
class node_accounts,node_playerdata,node_gamedata,node_ids,node_database,node_resource toneMint
class node_webapi,node_plugins,node_shopeditor toneRose
```

## Components

### Networking

- [P2P Relay](https://github.com/wtfblub/netspherepirates/blob/dev/src/Netsphere.Server.Relay/Handlers/EventHandler.cs): `src/Netsphere.Server.Relay/Handlers/EventHandler.cs`
- [Protocol Messages](https://github.com/wtfblub/netspherepirates/blob/dev/src/Netsphere.Network/Message/Game/GameMessageFactory.cs): `src/Netsphere.Network/Message/Game/GameMessageFactory.cs`
- [ProudNet Transport](https://github.com/wtfblub/netspherepirates/blob/dev/src/ProudNet/ProudSession.cs): `src/ProudNet/ProudSession.cs`

### Game Services

- [Authentication](https://github.com/wtfblub/netspherepirates/blob/dev/src/Netsphere.Server.Auth/Handlers/AuthenticationHandler.cs): `src/Netsphere.Server.Auth/Handlers/AuthenticationHandler.cs`
- [Chat and Social](https://github.com/wtfblub/netspherepirates/blob/dev/src/Netsphere.Server.Chat/Handlers/ChatHandler.cs): `src/Netsphere.Server.Chat/Handlers/ChatHandler.cs`
- [Gameplay](https://github.com/wtfblub/netspherepirates/blob/dev/src/Netsphere.Server.Game/Handlers/RoomHandler.cs): `src/Netsphere.Server.Game/Handlers/RoomHandler.cs`
- [Characters](https://github.com/wtfblub/netspherepirates/blob/dev/src/Netsphere.Server.Game/CharacterManager.cs): `src/Netsphere.Server.Game/CharacterManager.cs`

### Data and State

- [Account Records](https://github.com/wtfblub/netspherepirates/blob/dev/src/Netsphere.Database/AuthContext.cs): `src/Netsphere.Database/AuthContext.cs`
- [Player Records](https://github.com/wtfblub/netspherepirates/blob/dev/src/Netsphere.Database/GameContext.cs): `src/Netsphere.Database/GameContext.cs`
- [Game Data](https://github.com/wtfblub/netspherepirates/blob/dev/src/Netsphere.Server.Game/Services/GameDataService.cs): `src/Netsphere.Server.Game/Services/GameDataService.cs`
- [ID Generation](https://github.com/wtfblub/netspherepirates/blob/dev/src/Netsphere.Common/IdGeneratorService.cs): `src/Netsphere.Common/IdGeneratorService.cs`
- [Database Access](https://github.com/wtfblub/netspherepirates/blob/dev/src/Netsphere.Database/DatabaseService.cs): `src/Netsphere.Database/DatabaseService.cs`
- [Resource Formats](https://github.com/wtfblub/netspherepirates/blob/dev/src/Netsphere.Resource/S4Zip.cs): `src/Netsphere.Resource/S4Zip.cs`

### Extensions

- [Web API](https://github.com/wtfblub/netspherepirates/blob/dev/src/plugins/WebApi/WebApiService.cs): `src/plugins/WebApi/WebApiService.cs`
- [Plugin Host](https://github.com/wtfblub/netspherepirates/blob/dev/src/Netsphere.Common/Plugins/MefPluginHost.cs): `src/Netsphere.Common/Plugins/MefPluginHost.cs`
- [Shop Editor](https://github.com/wtfblub/netspherepirates/blob/dev/src/tools/Netsphere.Tools.ShopEditor/Services/ShopService.cs): `src/tools/Netsphere.Tools.ShopEditor/Services/ShopService.cs`

### Other components

- **Game Client**

## Connections

- Game Client → ProudNet Transport: connects
- ProudNet Transport → Authentication: dispatches
- ProudNet Transport → Chat and Social: dispatches
- ProudNet Transport → Gameplay: dispatches
- ProudNet Transport → P2P Relay: dispatches
- Authentication → Account Records: queries (evidence: `src/Netsphere.Server.Auth/Handlers/AuthenticationHandler.cs`)
- Authentication → Database Access: opens context (evidence: `src/Netsphere.Server.Auth/Handlers/AuthenticationHandler.cs`)
- Chat and Social → Player Records: loads settings
- Gameplay → Player Records: loads players
- Gameplay → Game Data: requests items
- Characters → Player Records: saves characters (evidence: `src/Netsphere.Server.Game/CharacterManager.cs`)
- Characters → ID Generation: allocates IDs (evidence: `src/Netsphere.Server.Game/CharacterManager.cs`)
- Game Data → Database Access: loads shop data (evidence: `src/Netsphere.Server.Game/Services/GameDataService.cs`)
- P2P Relay → ProudNet Transport: uses sessions
- Gameplay → Protocol Messages: sends messages
- Web API → Game Data: reads game data (evidence: `src/plugins/WebApi/WebApiService.cs`)
- Plugin Host → Web API: hosts plugin
- Shop Editor → Player Records: edits shop
- Resource Formats → Game Data: provides resources
