# ggreborn/cafeservergo architecture

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

- Interactive diagram: https://gitdiagram.com/ggreborn/cafeservergo
- Repository: https://github.com/ggreborn/cafeservergo

## Overview

CafeServerGo is a TCP game server for Café game clients. The principal workflow is a client connection, request parsing and command handling, game-state updates, and responses over the same session. Its command tree also covers player/account actions, café construction and operations, waiters, achievements, and social and cooperative gameplay. The excerpts establish server startup, client transport, database setup, and some state and simulation behavior; wiring among unsampled command handlers is shown only at the dispatcher boundary.

Main entry points: [`internal/commands/commands.go`](https://github.com/ggreborn/cafeservergo/blob/main/internal/commands/commands.go) (Command dispatcher), [`internal/server/server.go`](https://github.com/ggreborn/cafeservergo/blob/main/internal/server/server.go) (TCP server), [`internal/client/client.go`](https://github.com/ggreborn/cafeservergo/blob/main/internal/client/client.go) (Client sessions), [`internal/managers/game.go`](https://github.com/ggreborn/cafeservergo/blob/main/internal/managers/game.go) (Game manager)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Server runtime"]
  node_main["Application entry<br/>[main.go]"]
  node_server["TCP server<br/>[server.go]"]
  node_sessions["Client sessions<br/>[client.go]"]
  node_protocol["Request parsing<br/>[request.go]"]
end

subgraph group_commands["Game commands"]
  node_router["Command dispatcher<br/>[commands.go]"]
  node_playercmd["Player commands"]
  node_cafecmd["Café commands"]
  node_editorcmd["Café editor"]
  node_waitercmd["Waiter commands"]
  node_socialcmd["Social and co-op"]
  node_achievementcmd["Progress and games"]
end

subgraph group_state["Game state"]
  node_gamemanager["Game manager<br/>[game.go]"]
  node_locations["Cafe locations<br/>[location.go]"]
  node_cafestate["Cafe state<br/>[cafe.go]"]
  node_playerstate["Player state<br/>[player.go]"]
  node_simulation["Customer simulation<br/>[customer.go]"]
end

subgraph group_persistence["Persistence"]
  node_database[("Game database<br/>[database.go]")]
  node_auth["Authentication<br/>[auth.go]"]
end

node_player(("Game client"))

node_player -->|"opens TCP connection"| node_server
node_main -->|"configures and runs"| node_server
node_server -->|"creates manager"| node_gamemanager
node_server -->|"connects database"| node_database
node_server -->|"creates sessions"| node_sessions
node_server -->|"starts handling"| node_router
node_sessions -->|"parses requests"| node_protocol
node_router -->|"dispatches"| node_playercmd
node_router -->|"dispatches"| node_cafecmd
node_router -->|"dispatches"| node_editorcmd
node_router -->|"dispatches"| node_waitercmd
node_router -->|"dispatches"| node_socialcmd
node_router -->|"dispatches"| node_achievementcmd
node_gamemanager -->|"saves game state"| node_database
node_gamemanager -->|"manages locations"| node_locations
node_locations -->|"holds café state"| node_cafestate
node_cafestate -->|"hosts customer activity"| node_simulation
node_auth -->|"reads and updates accounts"| node_database
node_sessions -->|"sends responses"| node_player

click node_main "https://github.com/ggreborn/cafeservergo/blob/main/main.go"
click node_server "https://github.com/ggreborn/cafeservergo/blob/main/internal/server/server.go"
click node_sessions "https://github.com/ggreborn/cafeservergo/blob/main/internal/client/client.go"
click node_protocol "https://github.com/ggreborn/cafeservergo/blob/main/internal/types/requests/request.go"
click node_router "https://github.com/ggreborn/cafeservergo/blob/main/internal/commands/commands.go"
click node_playercmd "https://github.com/ggreborn/cafeservergo/tree/main/internal/commands/player"
click node_cafecmd "https://github.com/ggreborn/cafeservergo/tree/main/internal/commands/cafe"
click node_editorcmd "https://github.com/ggreborn/cafeservergo/tree/main/internal/commands/editor"
click node_waitercmd "https://github.com/ggreborn/cafeservergo/tree/main/internal/commands/waiters"
click node_socialcmd "https://github.com/ggreborn/cafeservergo/tree/main/internal/commands/friends"
click node_achievementcmd "https://github.com/ggreborn/cafeservergo/tree/main/internal/commands/achievements"
click node_gamemanager "https://github.com/ggreborn/cafeservergo/blob/main/internal/managers/game.go"
click node_locations "https://github.com/ggreborn/cafeservergo/blob/main/internal/managers/location.go"
click node_cafestate "https://github.com/ggreborn/cafeservergo/blob/main/internal/models/cafe/cafe.go"
click node_playerstate "https://github.com/ggreborn/cafeservergo/blob/main/internal/models/player/player.go"
click node_simulation "https://github.com/ggreborn/cafeservergo/blob/main/internal/agents/customer.go"
click node_database "https://github.com/ggreborn/cafeservergo/blob/main/internal/database/database.go"
click node_auth "https://github.com/ggreborn/cafeservergo/blob/main/internal/database/auth.go"

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_main,node_server,node_sessions,node_protocol,node_player toneBlue
class node_router,node_playercmd,node_cafecmd,node_editorcmd,node_waitercmd,node_socialcmd,node_achievementcmd toneAmber
class node_gamemanager,node_locations,node_cafestate,node_playerstate,node_simulation toneMint
class node_database,node_auth toneRose
```

## Components

### Server runtime

- [Application entry](https://github.com/ggreborn/cafeservergo/blob/main/main.go): `main.go`
- [TCP server](https://github.com/ggreborn/cafeservergo/blob/main/internal/server/server.go): `internal/server/server.go`
- [Client sessions](https://github.com/ggreborn/cafeservergo/blob/main/internal/client/client.go): `internal/client/client.go`
- [Request parsing](https://github.com/ggreborn/cafeservergo/blob/main/internal/types/requests/request.go): `internal/types/requests/request.go`

### Game commands

- [Command dispatcher](https://github.com/ggreborn/cafeservergo/blob/main/internal/commands/commands.go): `internal/commands/commands.go`
- [Player commands](https://github.com/ggreborn/cafeservergo/tree/main/internal/commands/player): `internal/commands/player`
- [Café commands](https://github.com/ggreborn/cafeservergo/tree/main/internal/commands/cafe): `internal/commands/cafe`
- [Café editor](https://github.com/ggreborn/cafeservergo/tree/main/internal/commands/editor): `internal/commands/editor`
- [Waiter commands](https://github.com/ggreborn/cafeservergo/tree/main/internal/commands/waiters): `internal/commands/waiters`
- [Social and co-op](https://github.com/ggreborn/cafeservergo/tree/main/internal/commands/friends): `internal/commands/friends`
- [Progress and games](https://github.com/ggreborn/cafeservergo/tree/main/internal/commands/achievements): `internal/commands/achievements`

### Game state

- [Game manager](https://github.com/ggreborn/cafeservergo/blob/main/internal/managers/game.go): `internal/managers/game.go`
- [Cafe locations](https://github.com/ggreborn/cafeservergo/blob/main/internal/managers/location.go): `internal/managers/location.go`
- [Cafe state](https://github.com/ggreborn/cafeservergo/blob/main/internal/models/cafe/cafe.go): `internal/models/cafe/cafe.go`
- [Player state](https://github.com/ggreborn/cafeservergo/blob/main/internal/models/player/player.go): `internal/models/player/player.go`
- [Customer simulation](https://github.com/ggreborn/cafeservergo/blob/main/internal/agents/customer.go): `internal/agents/customer.go`

### Persistence

- [Game database](https://github.com/ggreborn/cafeservergo/blob/main/internal/database/database.go): `internal/database/database.go`
- [Authentication](https://github.com/ggreborn/cafeservergo/blob/main/internal/database/auth.go): `internal/database/auth.go`

### Other components

- **Game client**

## Connections

- Game client → TCP server: opens TCP connection
- Application entry → TCP server: configures and runs
- TCP server → Game manager: creates manager
- TCP server → Game database: connects database
- TCP server → Client sessions: creates sessions
- TCP server → Command dispatcher: starts handling
- Client sessions → Request parsing: parses requests
- Command dispatcher → Player commands: dispatches
- Command dispatcher → Café commands: dispatches
- Command dispatcher → Café editor: dispatches
- Command dispatcher → Waiter commands: dispatches
- Command dispatcher → Social and co-op: dispatches
- Command dispatcher → Progress and games: dispatches
- Game manager → Game database: saves game state
- Game manager → Cafe locations: manages locations
- Cafe locations → Cafe state: holds café state
- Cafe state → Customer simulation: hosts customer activity
- Authentication → Game database: reads and updates accounts
- Client sessions → Game client: sends responses
