# ikemen-engine/ikemen-go architecture

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

- Interactive diagram: https://gitdiagram.com/ikemen-engine/ikemen-go
- Repository: https://github.com/ikemen-engine/ikemen-go

## Overview

1. **What this repository is**
   Ikemen GO is a single Go-based game engine for 2D fighting games, designed to load and run M.U.G.E.N-style content. The repo is split between the engine code in `src/`, bundled default game data in `data/`, runtime scripts and assets in `external/`, and build/release tooling under `build/` and `.github/`.

2. **Runtime entry point and core orchestration**
   The executable starts from `src/main.go`, then hands control to the central engine/runtime layer in `src/system.go` and `src/fightscreen.go`. These files likely own the main loop, screen/state switching, match flow, and coordination between input, simulation, audio, rendering, and scripting.

3. **Data-driven gameplay/content boundary**
   Most game behavior is not hardcoded; it comes from content files in `data/` such as `.cmd`, `.air`, `.cns`, `.zss`, and `.const`. This points to a strong separation between engine code and game rules/assets: the engine interprets content describing characters, common fight logic, stages, training/demo behavior, scoring, and tag/guard-break systems.

4. **Script compilation and bytecode layer**
   The files `src/compiler.go`, `src/compiler_functions.go`, `src/bytecode.go`, and `src/script.go` indicate a custom scripting pipeline. Script/source files from the content layer are compiled into an internal bytecode format, which the runtime executes to drive gameplay logic, UI behavior, and possibly stage/storyboard events.

5. **Match simulation and state management**
   Core gameplay state appears to live in `src/state.go`, `src/state_clone.go`, `src/char.go`, `src/stage.go`, `src/camera.go`, `src/anim.go`, `src/model.go`, and `src/stats.go`. These subsystems likely model fighters, stages, animations, camera framing, per-frame state updates, cloning for rollback/replay, and match statistics.

6. **Input, determinism, rollback, and netplay**
   The engine has explicit networking and rollback support in `src/netplay.go` and `src/rollback.go`, with input handled by `src/input.go` and `src/input_sdl.go`. Architecturally, this suggests a deterministic simulation core that can be rewound/resimulated for online play or latency hiding, with local input feeding the same state machine used in offline matches.

7. **Rendering pipeline and backend abstraction**
   Rendering is abstracted behind multiple backend implementations: `src/render.go` with `render_gl33.go`, `render_gles32.go`, and `render_vk.go`. That means the engine supports OpenGL 3.3, OpenGL ES 3.2, and Vulkan through a shared rendering interface, with shaders stored in `src/shaders/` and additional packaged effects in `external/shaders/`.

8. **Font and text rendering**
   Text rendering is treated as a separate subsystem via `src/font.go` and backend-specific font implementations (`font_gl33.go`, `font_gles32.go`, `font_vk.go`). Bundled font assets in `font/` plus shader assets under `src/shaders/` suggest UI text and debug text are rendered through the same graphics pipeline as the rest of the game.

9. **Audio and media**
   Audio is isolated in `src/sound.go`, `src/audio_sdl.go`, `src/music.go`, and `src/sound_xm.go`. The presence of `src/video_ffmpeg.go` shows the engine also integrates FFmpeg for video playback or cutscene-style media. SDL is used for the platform audio layer.

10. **Platform and OS abstraction**
   Cross-platform support is organized through OS-specific utilities such as `src/util_windows.go`, `src/util_linux.go`, `src/util_darwin.go`, `src/util_android.go`, plus `src/util_desktop.go` and `src/util_raw.go`. There are also platform-specific support files like `src/dllsearch_windows.go` and `src/stdout_windows.go`, showing that platform integration is deliberately isolated from the engine core.

11. **UI, menus, and scripted front-end**
   The `external/script/` directory contains Lua scripts like `main.lua`, `menu.lua`, `options.lua`, `start.lua`, `default.lua`, and `debug.lua`. These likely drive the front-end/menu system and debug tooling separately from the fight simulation, giving the UI a scriptable layer distinct from the engine’s internal gameplay scripts.

12. **Bundled default resources and skinning**
   `src/resources/` contains default config/motif/storyboard INI files, while `external/icons/` and `font/` provide packaged assets. The README also notes the default screenpack/motif is externalized, so the engine itself is mostly content-agnostic and can be reskinned by swapping resource packs.

13. **Build, packaging, and release pipeline**
   The repo includes Go module metadata (`go.mod`, `go.sum`), a `Makefile`, platform build scripts in `build/`, and Android Docker support under `build/docker/android/`. GitHub workflows handle linting, release automation, and wiki/script documentation generation, which supports a multi-platform release process rather than a single-target desktop app.

14. **How the major flows connect**
   A typical flow is: startup loads config and packaged resources, scripts/content are compiled or interpreted, the main loop processes input, updates the deterministic fight state, optionally synchronizes via rollback/netplay, and renders/audio-playback are dispatched through the selected backend. The key architecture boundary is between the Go engine runtime and the external content packs that define characters, stages, UI, and game rules.

Main entry points: [`src/state.go`](https://github.com/ikemen-engine/ikemen-go/blob/develop/src/state.go) (State), [`src/fightscreen.go`](https://github.com/ikemen-engine/ikemen-go/blob/develop/src/fightscreen.go) (Fight Screen), [`src/system.go`](https://github.com/ikemen-engine/ikemen-go/blob/develop/src/system.go) (System), [`src/util_desktop.go`](https://github.com/ikemen-engine/ikemen-go/blob/develop/src/util_desktop.go) (Platform Utils)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime_core["Runtime Core"]
  node_main(("Main<br/>entrypoint<br/>[main.go]"))
  node_system["System<br/>runtime core<br/>[system.go]"]
  node_fightscreen["Fight Screen<br/>match loop<br/>[fightscreen.go]"]
  node_state["State<br/>[state.go]"]
  node_clone["State Clone<br/>rollback state<br/>[state_clone.go]"]
  node_character["Character<br/>fighter logic<br/>[char.go]"]
  node_stage["Stage<br/>[stage.go]"]
  node_camera["Camera<br/>view framing<br/>[camera.go]"]
  node_anim["Animation<br/>anim system<br/>[anim.go]"]
end

subgraph group_content_scripts["Content & Scripts"]
  node_compiler["Compiler<br/>[compiler.go]"]
  node_bytecode["Bytecode<br/>script VM<br/>[bytecode.go]"]
  node_script["Script Runtime<br/>script exec<br/>[script.go]"]
  node_resources["Defaults<br/>packaged config<br/>[defaultConfig.ini]"]
  node_data["Game Data<br/>content packs<br/>[common.cmd]"]
  node_menu["Lua UI<br/>frontend scripts<br/>[main.lua]"]
end

subgraph group_presentation_media["Presentation & Media"]
  node_render["Render API<br/>graphics facade<br/>[render.go]"]
  node_font["Font System<br/>text rendering<br/>[font.go]"]
  node_sound["Sound<br/>audio system<br/>[sound.go]"]
  node_video["Video<br/>ffmpeg media<br/>[video_ffmpeg.go]"]
end

subgraph group_platform_build["Platform & Build"]
  node_platform["Platform Utils<br/>os abstraction<br/>[util_desktop.go]"]
  node_build["Build Tools<br/>packaging<br/>[build.sh]"]
end

node_main -->|"starts"| node_system
node_system -->|"switches to"| node_fightscreen
node_fightscreen -->|"updates"| node_state
node_state -->|"snapshots"| node_clone
node_state -->|"contains"| node_character
node_state -->|"contains"| node_stage
node_state -->|"drives"| node_camera
node_state -->|"uses"| node_anim
node_compiler -->|"emits"| node_bytecode
node_script -->|"executes"| node_bytecode
node_data -->|"feeds"| node_compiler
node_resources -->|"bootstraps"| node_system
node_menu -->|"controls"| node_system
node_fightscreen -->|"draws via"| node_render
node_fightscreen -->|"plays via"| node_sound
node_render -->|"includes"| node_font
node_render -->|"depends on"| node_platform
node_sound -->|"depends on"| node_platform
node_video -->|"depends on"| node_platform
node_build -->|"targets"| node_platform

click node_main "https://github.com/ikemen-engine/ikemen-go/blob/develop/src/main.go"
click node_system "https://github.com/ikemen-engine/ikemen-go/blob/develop/src/system.go"
click node_fightscreen "https://github.com/ikemen-engine/ikemen-go/blob/develop/src/fightscreen.go"
click node_state "https://github.com/ikemen-engine/ikemen-go/blob/develop/src/state.go"
click node_clone "https://github.com/ikemen-engine/ikemen-go/blob/develop/src/state_clone.go"
click node_character "https://github.com/ikemen-engine/ikemen-go/blob/develop/src/char.go"
click node_stage "https://github.com/ikemen-engine/ikemen-go/blob/develop/src/stage.go"
click node_camera "https://github.com/ikemen-engine/ikemen-go/blob/develop/src/camera.go"
click node_anim "https://github.com/ikemen-engine/ikemen-go/blob/develop/src/anim.go"
click node_compiler "https://github.com/ikemen-engine/ikemen-go/blob/develop/src/compiler.go"
click node_bytecode "https://github.com/ikemen-engine/ikemen-go/blob/develop/src/bytecode.go"
click node_script "https://github.com/ikemen-engine/ikemen-go/blob/develop/src/script.go"
click node_resources "https://github.com/ikemen-engine/ikemen-go/blob/develop/src/resources/defaultConfig.ini"
click node_data "https://github.com/ikemen-engine/ikemen-go/blob/develop/data/common.cmd"
click node_menu "https://github.com/ikemen-engine/ikemen-go/blob/develop/external/script/main.lua"
click node_render "https://github.com/ikemen-engine/ikemen-go/blob/develop/src/render.go"
click node_font "https://github.com/ikemen-engine/ikemen-go/blob/develop/src/font.go"
click node_sound "https://github.com/ikemen-engine/ikemen-go/blob/develop/src/sound.go"
click node_video "https://github.com/ikemen-engine/ikemen-go/blob/develop/src/video_ffmpeg.go"
click node_platform "https://github.com/ikemen-engine/ikemen-go/blob/develop/src/util_desktop.go"
click node_build "https://github.com/ikemen-engine/ikemen-go/blob/develop/build/build.sh"

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_system,node_fightscreen,node_state,node_clone,node_character,node_stage,node_camera,node_anim toneBlue
class node_compiler,node_bytecode,node_script,node_resources,node_data,node_menu toneAmber
class node_render,node_font,node_sound,node_video toneMint
class node_platform,node_build toneRose
```

## Components

### Runtime Core

Main executable, match loop, simulation, rollback, and gameplay state.

- [Main](https://github.com/ikemen-engine/ikemen-go/blob/develop/src/main.go): entrypoint · Process entry that initializes the engine and hands off to the runtime. · `src/main.go`
- [System](https://github.com/ikemen-engine/ikemen-go/blob/develop/src/system.go): runtime core · Central orchestration for startup, mode switching, and frame flow. · `src/system.go`
- [Fight Screen](https://github.com/ikemen-engine/ikemen-go/blob/develop/src/fightscreen.go): match loop · Fight-state controller coordinating simulation, input, and presentation. · `src/fightscreen.go`
- [State](https://github.com/ikemen-engine/ikemen-go/blob/develop/src/state.go): simulation state · Per-frame gameplay state and update logic for match execution. · `src/state.go`
- [State Clone](https://github.com/ikemen-engine/ikemen-go/blob/develop/src/state_clone.go): rollback state · Cloning support for deterministic resimulation and rollback. · `src/state_clone.go`
- [Character](https://github.com/ikemen-engine/ikemen-go/blob/develop/src/char.go): fighter logic · Fighter-side behavior, animation, and move/state integration. · `src/char.go`
- [Stage](https://github.com/ikemen-engine/ikemen-go/blob/develop/src/stage.go): stage logic · Stage definition, interactions, and stage-specific runtime behavior. · `src/stage.go`
- [Camera](https://github.com/ikemen-engine/ikemen-go/blob/develop/src/camera.go): view framing · Match camera and framing logic used by gameplay and rendering. · `src/camera.go`
- [Animation](https://github.com/ikemen-engine/ikemen-go/blob/develop/src/anim.go): anim system · Animation playback and timing primitives used by fighters and stages. · `src/anim.go`

### Content & Scripts

Data-driven fight content, front-end scripts, and bundled defaults.

- [Compiler](https://github.com/ikemen-engine/ikemen-go/blob/develop/src/compiler.go): script compiler · Compiles content scripts into the engine's internal executable form. · `src/compiler.go`
- [Bytecode](https://github.com/ikemen-engine/ikemen-go/blob/develop/src/bytecode.go): script VM · Internal bytecode representation used by the script runtime. · `src/bytecode.go`
- [Script Runtime](https://github.com/ikemen-engine/ikemen-go/blob/develop/src/script.go): script exec · Executes compiled scripts and exposes gameplay-facing script behavior. · `src/script.go`
- [Defaults](https://github.com/ikemen-engine/ikemen-go/blob/develop/src/resources/defaultConfig.ini): packaged config · Bundled default config, motif, and storyboard resources. · `src/resources/defaultConfig.ini`
- [Game Data](https://github.com/ikemen-engine/ikemen-go/blob/develop/data/common.cmd): content packs · Data-driven rules and content such as commands, states, and training logic. · `data/common.cmd`
- [Lua UI](https://github.com/ikemen-engine/ikemen-go/blob/develop/external/script/main.lua): frontend scripts · Scripted menus, options, debug tools, and startup UI flow. · `external/script/main.lua`

### Presentation & Media

Rendering, fonts, audio, video, and asset-backed UI presentation.

- [Render API](https://github.com/ikemen-engine/ikemen-go/blob/develop/src/render.go): graphics facade · Backend-agnostic rendering interface for the engine. · `src/render.go`
- [Font System](https://github.com/ikemen-engine/ikemen-go/blob/develop/src/font.go): text rendering · Text rendering and font integration across backends. · `src/font.go`
- [Sound](https://github.com/ikemen-engine/ikemen-go/blob/develop/src/sound.go): audio system · Audio playback, music, and sound effect coordination. · `src/sound.go`
- [Video](https://github.com/ikemen-engine/ikemen-go/blob/develop/src/video_ffmpeg.go): ffmpeg media · FFmpeg-backed media playback for video or cutscene content. · `src/video_ffmpeg.go`

### Platform & Build

OS abstraction, packaging, release automation, and build tooling.

- [Platform Utils](https://github.com/ikemen-engine/ikemen-go/blob/develop/src/util_desktop.go): os abstraction · OS-specific utilities and desktop/platform integration points. · `src/util_desktop.go`
- [Build Tools](https://github.com/ikemen-engine/ikemen-go/blob/develop/build/build.sh): packaging · Scripts and workflows for builds, release, and documentation generation. · `build/build.sh`

## Connections

- Main → System: starts · Entry point initializes the runtime orchestration layer.
- System → Fight Screen: switches to · System delegates match flow to the fight screen controller.
- Fight Screen → State: updates · Fight loop advances deterministic gameplay state each frame.
- State → State Clone: snapshots · State can be cloned for rollback and resimulation.
- State → Character: contains · Core state includes fighter logic and per-character updates.
- State → Stage: contains · Match state includes stage simulation and interactions.
- State → Camera: drives · Simulation influences camera framing and visibility.
- State → Animation: uses · Runtime state relies on animation timing and playback.
- Compiler → Bytecode: emits · Script sources are compiled into internal bytecode.
- Script Runtime → Bytecode: executes · Script runtime interprets compiled bytecode.
- Game Data → Compiler: feeds · Content files provide the rule data consumed by compilation/runtime.
- Defaults → System: bootstraps · Packaged defaults seed startup configuration and UI assets.
- Lua UI → System: controls · Lua front-end scripts drive menus and startup navigation.
- Fight Screen → Render API: draws via · Match screen renders through the graphics abstraction.
- Fight Screen → Sound: plays via · Match screen routes audio and music through the sound subsystem.
- Render API → Font System: includes · Text rendering is layered on top of the graphics backend.
- Render API → Platform Utils: depends on · Rendering and windowing rely on platform utilities.
- Sound → Platform Utils: depends on · Audio and media integration use OS-specific support layers.
- Video → Platform Utils: depends on · Video playback integrates with the platform layer.
- Build Tools → Platform Utils: targets · Build and release tooling targets multiple operating systems.
