# heroiclabs/nakama-godot-demo architecture

> Architecture diagram of the GitHub repository heroiclabs/nakama-godot-demo, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/heroiclabs/nakama-godot-demo
- Repository: https://github.com/heroiclabs/nakama-godot-demo

## Overview

#### Purpose and runnable projects
This repository is a multiplayer Godot platformer/demo for Nakama: account authentication, persisted character customization, realtime chat, notifications, and synchronized player movement. The complete runnable client is rooted at `godot/project.godot`; its main scenes are `godot/src/Main/MainMenu.tscn` and `godot/src/Main/GameWorld.tscn`. A smaller learning-oriented variant lives under `tutorial/godot/project.godot`.

#### Client composition and scene flow
The Godot client transitions from login/registration to character management and then the shared game world. Main-menu orchestration is in `godot/src/Main/MainMenu.gd`; authentication forms are `godot/src/UI/LoginAndRegister.gd`, `godot/src/UI/Menus/Login/LoginForm.gd`, and `godot/src/UI/Menus/Register/RegisterForm.gd`. The world scene and lifecycle are `godot/src/Main/GameWorld.gd` and `godot/src/Main/GameWorld.tscn`.

#### Process-wide application services
Godot autoloads provide the application boundary between UI/gameplay and Nakama. `godot/src/Autoload/ServerConnection.gd` owns client/session/socket connectivity; delegate classes separate authentication, storage, and exception concerns in `godot/src/Autoload/Delegates/Authenticator.gd`, `godot/src/Autoload/Delegates/StorageWorker.gd`, and `godot/src/Autoload/Delegates/ExceptionHandler.gd`. `godot/src/Autoload/GameControls.gd` centralizes user/game control state.

#### Identity, characters, and persistence
After email/password authentication, character screens create, list, select, and edit a player profile, including color. The character UI pipeline is centered on `godot/src/UI/Menus/Characters/CharacterMenu.gd`, `godot/src/UI/Menus/Characters/CharacterCreator.gd`, and `godot/src/UI/Menus/Characters/CharacterColorEditor.gd`. Persistence crosses the client/server boundary through the storage delegate and Nakama storage-object API models, notably `godot/addons/com.heroiclabs.nakama/api/NakamaWriteStorageObject.gd`.

#### Realtime gameplay and communication
The world represents local and remote players through `godot/src/World/Characters/Player.gd`, `godot/src/World/Characters/Character.gd`, and `godot/src/World/Level.gd`. Client gameplay and UI feed socket events through `godot/addons/com.heroiclabs.nakama/socket/NakamaSocket.gd`; chat is presented by `godot/src/UI/ChatBox.gd`, while notification display is coordinated by `godot/src/UI/Components/NotificationList.gd` and `godot/src/UI/Elements/Notification.gd`.

#### Nakama client integration boundary
The repository vendors the Godot Nakama client addon rather than relying on a package-resolution step. Its public facade/client transport layers are `godot/addons/com.heroiclabs.nakama/Nakama.gd`, `godot/addons/com.heroiclabs.nakama/client/NakamaClient.gd`, and `godot/addons/com.heroiclabs.nakama/client/NakamaHTTPAdapter.gd`. This layer handles HTTP API calls, session models, serialization, and WebSocket realtime transport, insulating game scripts from protocol details.

#### Server runtime and authoritative RPCs
Local infrastructure is Docker Compose in `nakama/docker-compose.yml`, running Nakama with CockroachDB. Server-side Lua modules implement world control and RPC behavior in `nakama/modules/world_control.lua` and `nakama/modules/world_rpc.lua`; these are the backend extension boundary for synchronized world interactions. Nakama also exposes its admin interface locally. The tutorial has a parallel, self-contained server setup at `tutorial/nakama/docker-compose.yml` and a reduced client/server code path.

Main entry points: [`godot/src/Autoload/ServerConnection.gd`](https://github.com/heroiclabs/nakama-godot-demo/blob/master/godot/src/Autoload/ServerConnection.gd) (Server Connection), [`nakama/docker-compose.yml`](https://github.com/heroiclabs/nakama-godot-demo/blob/master/nakama/docker-compose.yml) (Nakama Runtime), [`godot/addons/com.heroiclabs.nakama/socket/NakamaSocket.gd`](https://github.com/heroiclabs/nakama-godot-demo/blob/master/godot/addons/com.heroiclabs.nakama/socket/NakamaSocket.gd) (Nakama Socket), [`godot/src/Main/MainMenu.gd`](https://github.com/heroiclabs/nakama-godot-demo/blob/master/godot/src/Main/MainMenu.gd) (Main Menu)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_godot["Godot Client"]
  node_main_menu["Main Menu<br/>scene orchestration<br/>[MainMenu.gd]"]
  node_auth_forms["Login &amp; Registration<br/>auth UI"]
  node_character_menu["Character Management<br/>character UI<br/>[CharacterMenu.gd]"]
  node_character_creator["Character Creator<br/>character UI"]
  node_color_editor["Color Editor<br/>character UI"]
  node_game_world["Game World<br/>world scene<br/>[GameWorld.gd]"]
  node_world_entities["Players &amp; Level<br/>gameplay entities<br/>[Player.gd]"]
  node_chat_notifications["Chat &amp; Notifications<br/>realtime UI<br/>[ChatBox.gd]"]
end

subgraph group_autoload["App Services"]
  node_server_connection{{"Server Connection<br/>autoload service"}}
  node_authenticator["Authenticator<br/>auth delegate<br/>[Authenticator.gd]"]
  node_storage_worker["Storage Worker<br/>storage delegate<br/>[StorageWorker.gd]"]
  node_game_controls["Game Controls<br/>autoload state<br/>[GameControls.gd]"]
end

subgraph group_nakama_addon["Nakama Godot Addon"]
  node_nakama_client{{"Nakama Client<br/>API facade<br/>[NakamaClient.gd]"}}
  node_http_adapter["HTTP Adapter<br/>HTTP transport"]
  node_nakama_socket["Nakama Socket<br/>WebSocket transport<br/>[NakamaSocket.gd]"]
  node_storage_model["Storage Write Model<br/>API model"]
end

subgraph group_backend["Nakama Backend"]
  node_nakama_runtime{{"Nakama Runtime<br/>game server<br/>[docker-compose.yml]"}}
  node_world_modules["World Lua Modules<br/>authoritative RPCs<br/>[world_control.lua]"]
  node_cockroachdb[("CockroachDB<br/>database<br/>[docker-compose.yml]")]
end

subgraph group_tutorial["Tutorial Variant"]
  node_tutorial_client["Tutorial Godot Client<br/>learning client<br/>[project.godot]"]
  node_tutorial_backend{{"Tutorial Nakama Stack<br/>learning backend<br/>[docker-compose.yml]"}}
end

node_main_menu -->|"presents"| node_auth_forms
node_main_menu -->|"routes to"| node_character_menu
node_main_menu -->|"enters"| node_game_world
node_auth_forms -->|"authenticates through"| node_authenticator
node_character_menu -->|"creates profiles"| node_character_creator
node_character_creator -->|"edits color"| node_color_editor
node_character_menu -->|"loads and saves profiles"| node_storage_worker
node_storage_worker -->|"builds writes"| node_storage_model
node_authenticator -->|"uses"| node_server_connection
node_storage_worker -->|"uses"| node_server_connection
node_server_connection -->|"owns API client"| node_nakama_client
node_server_connection -->|"owns realtime socket"| node_nakama_socket
node_nakama_client -->|"sends API calls via"| node_http_adapter
node_nakama_client -->|"HTTP API"| node_nakama_runtime
node_nakama_socket -->|"WebSocket realtime"| node_nakama_runtime
node_game_world -->|"hosts"| node_world_entities
node_game_world -->|"reads control state"| node_game_controls
node_world_entities -->|"synchronizes movement"| node_nakama_socket
node_chat_notifications -->|"sends and receives events"| node_nakama_socket
node_nakama_runtime -->|"loads"| node_world_modules
node_nakama_runtime -->|"persists data"| node_cockroachdb
node_tutorial_client -.->|"connects to"| node_tutorial_backend

click node_main_menu "https://github.com/heroiclabs/nakama-godot-demo/blob/master/godot/src/Main/MainMenu.gd"
click node_auth_forms "https://github.com/heroiclabs/nakama-godot-demo/blob/master/godot/src/UI/LoginAndRegister.gd"
click node_character_menu "https://github.com/heroiclabs/nakama-godot-demo/blob/master/godot/src/UI/Menus/Characters/CharacterMenu.gd"
click node_character_creator "https://github.com/heroiclabs/nakama-godot-demo/blob/master/godot/src/UI/Menus/Characters/CharacterCreator.gd"
click node_color_editor "https://github.com/heroiclabs/nakama-godot-demo/blob/master/godot/src/UI/Menus/Characters/CharacterColorEditor.gd"
click node_game_world "https://github.com/heroiclabs/nakama-godot-demo/blob/master/godot/src/Main/GameWorld.gd"
click node_world_entities "https://github.com/heroiclabs/nakama-godot-demo/blob/master/godot/src/World/Characters/Player.gd"
click node_chat_notifications "https://github.com/heroiclabs/nakama-godot-demo/blob/master/godot/src/UI/ChatBox.gd"
click node_server_connection "https://github.com/heroiclabs/nakama-godot-demo/blob/master/godot/src/Autoload/ServerConnection.gd"
click node_authenticator "https://github.com/heroiclabs/nakama-godot-demo/blob/master/godot/src/Autoload/Delegates/Authenticator.gd"
click node_storage_worker "https://github.com/heroiclabs/nakama-godot-demo/blob/master/godot/src/Autoload/Delegates/StorageWorker.gd"
click node_game_controls "https://github.com/heroiclabs/nakama-godot-demo/blob/master/godot/src/Autoload/GameControls.gd"
click node_nakama_client "https://github.com/heroiclabs/nakama-godot-demo/blob/master/godot/addons/com.heroiclabs.nakama/client/NakamaClient.gd"
click node_http_adapter "https://github.com/heroiclabs/nakama-godot-demo/blob/master/godot/addons/com.heroiclabs.nakama/client/NakamaHTTPAdapter.gd"
click node_nakama_socket "https://github.com/heroiclabs/nakama-godot-demo/blob/master/godot/addons/com.heroiclabs.nakama/socket/NakamaSocket.gd"
click node_storage_model "https://github.com/heroiclabs/nakama-godot-demo/blob/master/godot/addons/com.heroiclabs.nakama/api/NakamaWriteStorageObject.gd"
click node_nakama_runtime "https://github.com/heroiclabs/nakama-godot-demo/blob/master/nakama/docker-compose.yml"
click node_world_modules "https://github.com/heroiclabs/nakama-godot-demo/blob/master/nakama/modules/world_control.lua"
click node_cockroachdb "https://github.com/heroiclabs/nakama-godot-demo/blob/master/nakama/docker-compose.yml"
click node_tutorial_client "https://github.com/heroiclabs/nakama-godot-demo/blob/master/tutorial/godot/project.godot"
click node_tutorial_backend "https://github.com/heroiclabs/nakama-godot-demo/blob/master/tutorial/nakama/docker-compose.yml"

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_menu,node_auth_forms,node_character_menu,node_character_creator,node_color_editor,node_game_world,node_world_entities,node_chat_notifications toneBlue
class node_server_connection,node_authenticator,node_storage_worker,node_game_controls toneAmber
class node_nakama_client,node_http_adapter,node_nakama_socket,node_storage_model toneMint
class node_nakama_runtime,node_world_modules,node_cockroachdb toneRose
class node_tutorial_client,node_tutorial_backend toneIndigo
```

## Components

### Godot Client

Runnable multiplayer client.

- [Main Menu](https://github.com/heroiclabs/nakama-godot-demo/blob/master/godot/src/Main/MainMenu.gd): scene orchestration · Routes login, characters, and world entry. · `godot/src/Main/MainMenu.gd`
- [Login & Registration](https://github.com/heroiclabs/nakama-godot-demo/blob/master/godot/src/UI/LoginAndRegister.gd): auth UI · `godot/src/UI/LoginAndRegister.gd`
- [Character Management](https://github.com/heroiclabs/nakama-godot-demo/blob/master/godot/src/UI/Menus/Characters/CharacterMenu.gd): character UI · Lists, creates, selects, and edits profiles. · `godot/src/UI/Menus/Characters/CharacterMenu.gd`
- [Character Creator](https://github.com/heroiclabs/nakama-godot-demo/blob/master/godot/src/UI/Menus/Characters/CharacterCreator.gd): character UI · `godot/src/UI/Menus/Characters/CharacterCreator.gd`
- [Color Editor](https://github.com/heroiclabs/nakama-godot-demo/blob/master/godot/src/UI/Menus/Characters/CharacterColorEditor.gd): character UI · `godot/src/UI/Menus/Characters/CharacterColorEditor.gd`
- [Game World](https://github.com/heroiclabs/nakama-godot-demo/blob/master/godot/src/Main/GameWorld.gd): world scene · Shared world lifecycle and scene. · `godot/src/Main/GameWorld.gd`
- [Players & Level](https://github.com/heroiclabs/nakama-godot-demo/blob/master/godot/src/World/Characters/Player.gd): gameplay entities · Local and remote characters inhabit the level. · `godot/src/World/Characters/Player.gd`
- [Chat & Notifications](https://github.com/heroiclabs/nakama-godot-demo/blob/master/godot/src/UI/ChatBox.gd): realtime UI · `godot/src/UI/ChatBox.gd`

### App Services

Process-wide Godot autoloads.

- [Server Connection](https://github.com/heroiclabs/nakama-godot-demo/blob/master/godot/src/Autoload/ServerConnection.gd): autoload service · Owns Nakama client, session, and socket connectivity. · `godot/src/Autoload/ServerConnection.gd`
- [Authenticator](https://github.com/heroiclabs/nakama-godot-demo/blob/master/godot/src/Autoload/Delegates/Authenticator.gd): auth delegate · `godot/src/Autoload/Delegates/Authenticator.gd`
- [Storage Worker](https://github.com/heroiclabs/nakama-godot-demo/blob/master/godot/src/Autoload/Delegates/StorageWorker.gd): storage delegate · `godot/src/Autoload/Delegates/StorageWorker.gd`
- [Game Controls](https://github.com/heroiclabs/nakama-godot-demo/blob/master/godot/src/Autoload/GameControls.gd): autoload state · Centralizes user and game control state. · `godot/src/Autoload/GameControls.gd`

### Nakama Godot Addon

Vendored protocol integration.

- [Nakama Client](https://github.com/heroiclabs/nakama-godot-demo/blob/master/godot/addons/com.heroiclabs.nakama/client/NakamaClient.gd): API facade · Provides authenticated HTTP API access and sessions. · `godot/addons/com.heroiclabs.nakama/client/NakamaClient.gd`
- [HTTP Adapter](https://github.com/heroiclabs/nakama-godot-demo/blob/master/godot/addons/com.heroiclabs.nakama/client/NakamaHTTPAdapter.gd): HTTP transport · `godot/addons/com.heroiclabs.nakama/client/NakamaHTTPAdapter.gd`
- [Nakama Socket](https://github.com/heroiclabs/nakama-godot-demo/blob/master/godot/addons/com.heroiclabs.nakama/socket/NakamaSocket.gd): WebSocket transport · Carries realtime gameplay and communication events. · `godot/addons/com.heroiclabs.nakama/socket/NakamaSocket.gd`
- [Storage Write Model](https://github.com/heroiclabs/nakama-godot-demo/blob/master/godot/addons/com.heroiclabs.nakama/api/NakamaWriteStorageObject.gd): API model · Serializes character storage-object writes. · `godot/addons/com.heroiclabs.nakama/api/NakamaWriteStorageObject.gd`

### Nakama Backend

Local authoritative server runtime.

- [Nakama Runtime](https://github.com/heroiclabs/nakama-godot-demo/blob/master/nakama/docker-compose.yml): game server · Authentication, storage, realtime services, and RPC host. · `nakama/docker-compose.yml`
- [World Lua Modules](https://github.com/heroiclabs/nakama-godot-demo/blob/master/nakama/modules/world_control.lua): authoritative RPCs · Server extensions for synchronized world interactions. · `nakama/modules/world_control.lua`
- [CockroachDB](https://github.com/heroiclabs/nakama-godot-demo/blob/master/nakama/docker-compose.yml): database · Persists Nakama server data. · `nakama/docker-compose.yml`

### Tutorial Variant

Reduced self-contained learning path.

- [Tutorial Godot Client](https://github.com/heroiclabs/nakama-godot-demo/blob/master/tutorial/godot/project.godot): learning client · `tutorial/godot/project.godot`
- [Tutorial Nakama Stack](https://github.com/heroiclabs/nakama-godot-demo/blob/master/tutorial/nakama/docker-compose.yml): learning backend · `tutorial/nakama/docker-compose.yml`

## Connections

- Main Menu → Login & Registration: presents
- Main Menu → Character Management: routes to
- Main Menu → Game World: enters
- Login & Registration → Authenticator: authenticates through
- Character Management → Character Creator: creates profiles
- Character Creator → Color Editor: edits color
- Character Management → Storage Worker: loads and saves profiles
- Storage Worker → Storage Write Model: builds writes
- Authenticator → Server Connection: uses
- Storage Worker → Server Connection: uses
- Server Connection → Nakama Client: owns API client
- Server Connection → Nakama Socket: owns realtime socket
- Nakama Client → HTTP Adapter: sends API calls via
- Nakama Client → Nakama Runtime: HTTP API
- Nakama Socket → Nakama Runtime: WebSocket realtime
- Game World → Players & Level: hosts
- Game World → Game Controls: reads control state
- Players & Level → Nakama Socket: synchronizes movement
- Chat & Notifications → Nakama Socket: sends and receives events
- Nakama Runtime → World Lua Modules: loads
- Nakama Runtime → CockroachDB: persists data
- Tutorial Godot Client → Tutorial Nakama Stack: connects to
