# opentibiabr/otclient architecture

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

- Interactive diagram: https://gitdiagram.com/opentibiabr/otclient
- Repository: https://github.com/opentibiabr/otclient

## Overview

1. **What this repository is**
   OTClient Redemption is a cross-platform Tibia/OTServ client. Its architecture is split between a native C++ engine and a large Lua-driven UI/game layer. The repo is not a server; it is the client runtime plus content, scripts, and some helper server-side scripts bundled with certain modules.

2. **Top-level runtime shape**
   Startup begins in `src/main.cpp`, then flows through the framework/application layer into Lua bootstrap files like `init.lua`, `meta.lua`, `otclientrc.lua`, and `data/setup.otml`. Those files define the initial module set, configuration, feature flags, and asset paths. The app then loads modules dynamically rather than hardwiring most UI/game behavior into C++.

3. **Native C++ core vs scripted client layer**
   The `src/framework` and `src/client` trees implement the engine: windowing, rendering, audio, networking, resource loading, Lua binding, and game object models. The `modules/` tree implements the actual product features in Lua/OTUI/OTML. This is the main architectural boundary: C++ provides services and game primitives; Lua modules compose the visible client behavior.

4. **Framework subsystems**
   The framework is organized by capability:  
   - `core`: application lifecycle, events, timers, module manager, config, resource management  
   - `graphics`: OpenGL rendering, textures, shaders, framebuffers, fonts, particles  
   - `sound`: sound sources, channels, OGG playback  
   - `net`: TCP/HTTP/Web connections, packets, login/game protocols, recorder  
   - `ui`: widget/layout system and text/HTML handling  
   - `luaengine`: binding C++ objects/functions into Lua  
   - `platform`: OS-specific windows and mobile/browser backends  
   These subsystems are shared by both generic UI modules and game-specific modules.

5. **Game model and protocol layer**
   `src/client` contains the client-side game domain model: players, creatures, items, containers, map, minimap, outfits, towns, effects, missiles, paperdolls, etc. Networking is centered on `protocolgame` and related packet parsing/sending code. The client maintains local game state from server messages and pushes player actions back through protocol senders.

6. **Module system as the composition layer**
   `modules/modulelib`, `modules/corelib`, `modules/gamelib`, and the many `modules/game_*` folders form the modular application shell. Modules are declared with `.otmod` files and typically pair Lua logic with `.otui` layouts and optional styles/assets. The module manager loads these at runtime, enabling features such as battle, console, inventory, market, cyclopedia, store, minimap, hotkeys, and more.

7. **UI and asset description format**
   The client uses OTUI/OTML as the primary UI/layout/config format, with some HTML/CSS support for richer panels. Visual assets live under `data/images`, fonts under `data/fonts`, styles under `data/styles`, and localized strings under `data/locales`. This means many screens are data-driven and skinnable rather than hardcoded in native code.

8. **Input, interaction, and HUD behavior**
   Keyboard, mouse, joystick, and mobile input are abstracted by the framework and then consumed by modules such as hotkeys, action bars, terminal, and game interface. The HUD and in-game widgets are composed from Lua modules and custom UI widgets in both `src/client` and `modules/game_*`. This is where user actions are translated into protocol commands and client-side state changes.

9. **Protocol and compatibility boundaries**
   The client supports multiple Tibia/OTServ protocol families, including older releases and newer protobuf-based variants. That compatibility lives across `src/client/protocol*`, `src/protobuf`, and feature toggles in `data/setup.otml` plus Lua feature modules. The architecture is therefore version-adaptive: many UI and gameplay modules branch on protocol features instead of assuming one server version.

10. **Platform-specific front ends**
   There are dedicated platform layers for desktop, Android, and browser/WebAssembly.  
   - Android lives under `android/` with a Kotlin activity, native input bridge, and APK packaging assets.  
   - Browser support is under `browser/` with Emscripten-related overlays, shell, and triplet/tooling.  
   - Desktop support is handled through the native windowing backends in `src/framework/platform`.  
   The same module/data model is reused across these targets where possible.

11. **Content packs and special feature modules**
   Several subsystems are effectively “feature bundles” implemented as modules: action bars, battle, analyzer, cyclopedia, shop/store, wheel of destiny, attached effects, shaders, reward wall, quick loot, tasks, and bot tooling. Some of these also include `serverSIDE` scripts or API helper files, indicating the client sometimes ships companion scripts for specific server integrations or web endpoints.

12. **Build, packaging, and CI**
   The repo is built with CMake/CMake presets on desktop, Gradle for Android, Dockerfiles for containerized builds, and Emscripten-oriented browser packaging. GitHub Actions cover Windows, Ubuntu, browser, Docker, and tests. This makes the architecture multi-target and tooling-heavy, but the runtime design remains the same: native engine + Lua modules + external assets/config.

13. **External integrations**
   Material integrations include Discord RPC, HTTP/HTTPS/WebSocket support, updater API hooks, and optional encryption/build-time toggles. The client can also talk to external web services for status/update functionality and to game servers for protocol/game data. These are optional edges around the core client, not central dependencies.

14. **How to draw the architecture**
   The clean diagram should show: startup/config/bootstrap on the left; native engine core in the center; Lua module and UI layer above it; game protocol/networking and game-state model as the main runtime data path; assets/styles/locales feeding the UI; and platform-specific launchers around the edges for desktop, Android, and browser. The major boundary is C++ service layer vs Lua-driven feature composition.

Main entry points: [`src/framework/core/application.cpp`](https://github.com/opentibiabr/otclient/blob/main/src/framework/core/application.cpp) (App Core), [`src/framework/core/modulemanager.cpp`](https://github.com/opentibiabr/otclient/blob/main/src/framework/core/modulemanager.cpp) (ModuleMgr), [`modules/game_battle/battle.otmod`](https://github.com/opentibiabr/otclient/blob/main/modules/game_battle/battle.otmod) (Game Features), [`modules/game_interface/interface.otmod`](https://github.com/opentibiabr/otclient/blob/main/modules/game_interface/interface.otmod) (Interface)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_bootstrap["Bootstrap"]
  node_src_main(("Main<br/>entrypoint cpp<br/>[main.cpp]"))
  node_init_lua["Init Lua<br/>bootstrap lua<br/>[init.lua]"]
  node_meta_lua["Meta<br/>bootstrap lua<br/>[meta.lua]"]
  node_setup_otml["Setup<br/>config otml<br/>[setup.otml]"]
end

subgraph group_engine["Native Engine"]
  node_client_app["App Core<br/>lifecycle<br/>[application.cpp]"]
  node_module_mgr["ModuleMgr<br/>module system<br/>[modulemanager.cpp]"]
  node_resource_mgr["Resources<br/>assets runtime"]
  node_ui_core["UI Core<br/>widget system<br/>[uimanager.cpp]"]
  node_graphics_core["Graphics<br/>rendering<br/>[graphics.cpp]"]
  node_sound_core["Sound<br/>audio<br/>[soundmanager.cpp]"]
  node_net_core["Network<br/>transport<br/>[protocol.cpp]"]
  node_lua_engine["Lua Bindings<br/>scripting bridge<br/>[luainterface.cpp]"]
  node_game_model["Game Model<br/>client domain<br/>[game.cpp]"]
  node_protocol_game["Game Protocol<br/>protocol parser<br/>[protocolgame.cpp]"]
end

subgraph group_modules["Lua Modules"]
  node_corelib["Core Lib<br/>lua foundation<br/>[corelib.otmod]"]
  node_gamelib["Game Lib<br/>lua domain<br/>[gamelib.otmod]"]
  node_interface_mod["Interface<br/>ui composition<br/>[interface.otmod]"]
  node_feature_modules["Game Features<br/>feature packs<br/>[battle.otmod]"]
  node_startup_mod["Startup<br/>module bootstrap<br/>[startup.otmod]"]
  node_mods["Mods<br/>lua ui pack<br/>[bot.otmod]"]
end

subgraph group_content["Content"]
  node_assets[("Assets<br/>content pack")]
end

subgraph group_targets["Targets"]
  node_android_main["Android<br/>mobile frontend<br/>[MainActivity.kt]"]
  node_browser_shell["Browser<br/>web frontend<br/>[shell.html]"]
  node_build_cmake["Build<br/>tooling<br/>[CMakeLists.txt]"]
end

node_src_main -->|"starts"| node_client_app
node_src_main -->|"loads"| node_init_lua
node_init_lua -->|"imports"| node_meta_lua
node_init_lua -->|"reads"| node_setup_otml
node_client_app -->|"manages"| node_module_mgr
node_client_app -->|"uses"| node_resource_mgr
node_client_app -->|"hosts"| node_ui_core
node_client_app -->|"renders"| node_graphics_core
node_client_app -->|"plays"| node_sound_core
node_client_app -->|"connects"| node_net_core
node_client_app -->|"binds"| node_lua_engine
node_module_mgr -->|"loads"| node_corelib
node_module_mgr -->|"loads"| node_gamelib
node_module_mgr -->|"loads"| node_startup_mod
node_module_mgr -->|"loads"| node_interface_mod
node_module_mgr -->|"loads"| node_feature_modules
node_module_mgr -->|"loads"| node_mods
node_gamelib -->|"maps to"| node_game_model
node_gamelib -->|"drives"| node_protocol_game
node_interface_mod -->|"builds on"| node_ui_core
node_interface_mod -->|"skins"| node_assets
node_feature_modules -->|"observes"| node_game_model
node_feature_modules -->|"sends"| node_protocol_game
node_feature_modules -->|"uses"| node_assets
node_protocol_game -->|"encodes"| node_net_core
node_game_model -->|"updates from"| node_protocol_game
node_assets -->|"feeds"| node_interface_mod
node_android_main -->|"launches"| node_client_app
node_browser_shell -->|"hosts"| node_client_app
node_build_cmake -->|"builds"| node_src_main

click node_src_main "https://github.com/opentibiabr/otclient/blob/main/src/main.cpp"
click node_init_lua "https://github.com/opentibiabr/otclient/blob/main/init.lua"
click node_meta_lua "https://github.com/opentibiabr/otclient/blob/main/meta.lua"
click node_setup_otml "https://github.com/opentibiabr/otclient/blob/main/data/setup.otml"
click node_client_app "https://github.com/opentibiabr/otclient/blob/main/src/framework/core/application.cpp"
click node_module_mgr "https://github.com/opentibiabr/otclient/blob/main/src/framework/core/modulemanager.cpp"
click node_resource_mgr "https://github.com/opentibiabr/otclient/blob/main/src/framework/core/resourcemanager.cpp"
click node_ui_core "https://github.com/opentibiabr/otclient/blob/main/src/framework/ui/uimanager.cpp"
click node_graphics_core "https://github.com/opentibiabr/otclient/blob/main/src/framework/graphics/graphics.cpp"
click node_sound_core "https://github.com/opentibiabr/otclient/blob/main/src/framework/sound/soundmanager.cpp"
click node_net_core "https://github.com/opentibiabr/otclient/blob/main/src/framework/net/protocol.cpp"
click node_lua_engine "https://github.com/opentibiabr/otclient/blob/main/src/framework/luaengine/luainterface.cpp"
click node_game_model "https://github.com/opentibiabr/otclient/blob/main/src/client/game.cpp"
click node_protocol_game "https://github.com/opentibiabr/otclient/blob/main/src/client/protocolgame.cpp"
click node_corelib "https://github.com/opentibiabr/otclient/blob/main/modules/corelib/corelib.otmod"
click node_gamelib "https://github.com/opentibiabr/otclient/blob/main/modules/gamelib/gamelib.otmod"
click node_interface_mod "https://github.com/opentibiabr/otclient/blob/main/modules/game_interface/interface.otmod"
click node_feature_modules "https://github.com/opentibiabr/otclient/blob/main/modules/game_battle/battle.otmod"
click node_startup_mod "https://github.com/opentibiabr/otclient/blob/main/modules/startup/startup.otmod"
click node_assets "https://github.com/opentibiabr/otclient/tree/main/data/images"
click node_mods "https://github.com/opentibiabr/otclient/blob/main/mods/game_bot/bot.otmod"
click node_android_main "https://github.com/opentibiabr/otclient/blob/main/android/app/src/main/java/com/otclient/MainActivity.kt"
click node_browser_shell "https://github.com/opentibiabr/otclient/blob/main/browser/shell.html"
click node_build_cmake "https://github.com/opentibiabr/otclient/blob/main/CMakeLists.txt"

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_src_main,node_init_lua,node_meta_lua,node_setup_otml toneBlue
class node_client_app,node_module_mgr,node_resource_mgr,node_ui_core,node_graphics_core,node_sound_core,node_net_core,node_lua_engine,node_game_model,node_protocol_game toneAmber
class node_corelib,node_gamelib,node_interface_mod,node_feature_modules,node_startup_mod,node_mods toneMint
class node_assets toneRose
class node_android_main,node_browser_shell,node_build_cmake toneIndigo
```

## Components

### Bootstrap

Startup, config, and module loading

- [Main](https://github.com/opentibiabr/otclient/blob/main/src/main.cpp): entrypoint cpp · Process entry and runtime bootstrap · `src/main.cpp`
- [Init Lua](https://github.com/opentibiabr/otclient/blob/main/init.lua): bootstrap lua · Early scripted startup · `init.lua`
- [Meta](https://github.com/opentibiabr/otclient/blob/main/meta.lua): bootstrap lua · Module metadata and initialization data · `meta.lua`
- [Setup](https://github.com/opentibiabr/otclient/blob/main/data/setup.otml): config otml · Feature flags and asset paths · `data/setup.otml`

### Native Engine

C++ runtime services and game model

- [App Core](https://github.com/opentibiabr/otclient/blob/main/src/framework/core/application.cpp): lifecycle · Application lifecycle and module orchestration · `src/framework/core/application.cpp`
- [ModuleMgr](https://github.com/opentibiabr/otclient/blob/main/src/framework/core/modulemanager.cpp): module system · Loads and coordinates runtime modules · `src/framework/core/modulemanager.cpp`
- [Resources](https://github.com/opentibiabr/otclient/blob/main/src/framework/core/resourcemanager.cpp): assets runtime · Resource loading and unzip/archive access · `src/framework/core/resourcemanager.cpp`
- [UI Core](https://github.com/opentibiabr/otclient/blob/main/src/framework/ui/uimanager.cpp): widget system · Native widget, layout, and text handling · `src/framework/ui/uimanager.cpp`
- [Graphics](https://github.com/opentibiabr/otclient/blob/main/src/framework/graphics/graphics.cpp): rendering · OpenGL rendering, textures, shaders, and fonts · `src/framework/graphics/graphics.cpp`
- [Sound](https://github.com/opentibiabr/otclient/blob/main/src/framework/sound/soundmanager.cpp): audio · Sound channels, sources, and playback · `src/framework/sound/soundmanager.cpp`
- [Network](https://github.com/opentibiabr/otclient/blob/main/src/framework/net/protocol.cpp): transport · Connections, packets, HTTP, and web sockets · `src/framework/net/protocol.cpp`
- [Lua Bindings](https://github.com/opentibiabr/otclient/blob/main/src/framework/luaengine/luainterface.cpp): scripting bridge · Binds C++ objects and functions into Lua · `src/framework/luaengine/luainterface.cpp`
- [Game Model](https://github.com/opentibiabr/otclient/blob/main/src/client/game.cpp): client domain · Client-side objects, map, items, creatures, and player state · `src/client/game.cpp`
- [Game Protocol](https://github.com/opentibiabr/otclient/blob/main/src/client/protocolgame.cpp): protocol parser · Parses and sends gameplay packets · `src/client/protocolgame.cpp`

### Lua Modules

Composable UI and gameplay features

- [Core Lib](https://github.com/opentibiabr/otclient/blob/main/modules/corelib/corelib.otmod): lua foundation · Shared Lua utilities, input, HTTP, and UI primitives · `modules/corelib/corelib.otmod`
- [Game Lib](https://github.com/opentibiabr/otclient/blob/main/modules/gamelib/gamelib.otmod): lua domain · Lua-facing game abstractions and helpers · `modules/gamelib/gamelib.otmod`
- [Interface](https://github.com/opentibiabr/otclient/blob/main/modules/game_interface/interface.otmod): ui composition · Main game HUD and widget composition · `modules/game_interface/interface.otmod`
- [Game Features](https://github.com/opentibiabr/otclient/blob/main/modules/game_battle/battle.otmod): feature packs · Feature modules such as battle, console, inventory, market, minimap, and store · `modules/game_battle/battle.otmod`
- [Startup](https://github.com/opentibiabr/otclient/blob/main/modules/startup/startup.otmod): module bootstrap · Module bootstrap sequence and initial runtime setup · `modules/startup/startup.otmod`
- [Mods](https://github.com/opentibiabr/otclient/blob/main/mods/game_bot/bot.otmod): lua ui pack · Optional client features and bundled add-ons · `mods/game_bot/bot.otmod`

### Content

Assets, styles, locales, and setup

- [Assets](https://github.com/opentibiabr/otclient/tree/main/data/images): content pack · Images, fonts, sounds, styles, and locales · `data/images`

### Targets

Platform front ends and build tooling

- [Android](https://github.com/opentibiabr/otclient/blob/main/android/app/src/main/java/com/otclient/MainActivity.kt): mobile frontend · Android activity and native input bridge · `android/app/src/main/java/com/otclient/MainActivity.kt`
- [Browser](https://github.com/opentibiabr/otclient/blob/main/browser/shell.html): web frontend · Emscripten/browser packaging and shell · `browser/shell.html`
- [Build](https://github.com/opentibiabr/otclient/blob/main/CMakeLists.txt): tooling · CMake-based desktop build and presets · `CMakeLists.txt`

## Connections

- Main → App Core: starts · Native entry boots the application runtime
- Main → Init Lua: loads · Startup hands off to Lua bootstrap
- Init Lua → Meta: imports · Bootstrap metadata is layered early
- Init Lua → Setup: reads · Initial configuration and feature flags
- App Core → ModuleMgr: manages · Application coordinates runtime modules
- App Core → Resources: uses · Application accesses packaged assets and files
- App Core → UI Core: hosts · UI system is attached to the app loop
- App Core → Graphics: renders · Graphics subsystem drives presentation
- App Core → Sound: plays · Audio subsystem provides sound playback
- App Core → Network: connects · Networking services support server communication
- App Core → Lua Bindings: binds · Lua integration exposes engine APIs
- ModuleMgr → Core Lib: loads · Core Lua foundation is loaded first
- ModuleMgr → Game Lib: loads · Game abstractions build on core services
- ModuleMgr → Startup: loads · Startup module assembles initial client state
- ModuleMgr → Interface: loads · Main interface module composes the HUD
- ModuleMgr → Game Features: loads · Feature packs are activated dynamically
- ModuleMgr → Mods: loads · Optional bundled mods extend the client
- Game Lib → Game Model: maps to · Lua domain helpers wrap native game state
- Game Lib → Game Protocol: drives · Lua gameplay logic depends on protocol flow
- Interface → UI Core: builds on · Lua UI is rendered by the native widget system
- Interface → Assets: skins · Layouts and visuals consume packaged content
- Game Features → Game Model: observes · Modules react to local game state
- Game Features → Game Protocol: sends · User actions become protocol commands
- Game Features → Assets: uses · Feature screens use shared styles and images
- Game Protocol → Network: encodes · Game protocol rides on native networking
- Game Model → Game Protocol: updates from · Server messages update local client state
- Assets → Interface: feeds · Content provides UI skinning and localization
- Android → App Core: launches · Android front end starts the same runtime
- Browser → App Core: hosts · Browser packaging targets the same client core
- Build → Main: builds · Desktop build compiles the native entry and engine
