# hajimehoshi/ebiten architecture

> Architecture diagram of the GitHub repository hajimehoshi/ebiten, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hajimehoshi/ebiten
- Repository: https://github.com/hajimehoshi/ebiten

## Overview

##### Project type and purpose
- Ebitengine is an open-source, cross-platform 2D game engine library for Go.
- It provides a simple API for game developers to build and deploy 2D games on desktop (Windows, macOS, Linux, FreeBSD), web (WebAssembly), mobile (Android, iOS), and consoles (Nintendo Switch, Xbox).

##### File structure
- Top-level packages:
- `audio/` (decoding, context, playback)
- `ebitenutil/`, `inpututil/`, `colorm/`, `vector/`, `text/` (utility libraries)
- `mobile/`, `cmd/ebitenmobile` (mobile platform bindings)
- `examples/` (client code exercising the API)
- `internal/` (platform abstraction layers and drivers)
- `internal/graphicsdriver/` holds multiple backends: DirectX, Metal, OpenGL, console drivers.
- `internal/ui/` wraps window creation, event loop, input dispatch per platform.
- `internal/gamepad/`, `internal/vibrate/`, `internal/file/` isolate platform specifics.
- Build and CI config under `.github/` and `.builds/`.

##### README for additional insights
- Confirms supported features: 2D graphics (shaders, composition, offscreen), input (mouse, keyboard, gamepad, touch), audio (MP3, Vorbis, WAV).
- Mentions external dependencies (GLFW, go-gl/gl) and that Cgo is optional.

## Diagram (Mermaid)

```mermaid
flowchart TB
  subgraph "Application Layer"
    App["Game Code (examples/)"]:::application
  end

  subgraph "API Layer"
    GraphicsAPI["graphics.go"]:::api
    ImageAPI["image.go"]:::api
    InputAPI["input.go"]:::api
    UIAPI["gameforui.go"]:::api
  end

  subgraph "Subsystems"
    subgraph "Graphics Subsystem"
      GraphicsCore["internal/graphics/"]:::subsystem
      GraphicsCmd["GraphicsCommand Queue"]:::subsystem
    end
    subgraph "Input Subsystem"
      InputRoot["input.go"]:::subsystem
      InputUtil["inpututil/inpututil.go"]:::subsystem
      UIInputGLFW["internal/ui/input_glfw.go"]:::subsystem
      UIInputJS["internal/ui/input_js.go"]:::subsystem
      UIInputMobile["internal/ui/input_mobile.go"]:::subsystem
      UIInputPS5["internal/ui/input_playstation5.go"]:::subsystem
    end
    subgraph "Audio Subsystem"
      AudioRoot["audio/"]:::subsystem
      AudioGo["audio.go"]:::subsystem
      AudioCtx["context.go"]:::subsystem
      AudioLoop["loop.go"]:::subsystem
      AudioMP3["mp3/"]:::subsystem
      AudioVorbis["vorbis/"]:::subsystem
      AudioWav["wav/"]:::subsystem
      AudioConv["audio/internal/convert/"]:::subsystem
    end
    subgraph "Text & Vector Subsystems"
      TextV1["text/"]:::subsystem
      TextV2["text/v2/"]:::subsystem
      Vector["vector/"]:::subsystem
    end
    subgraph "Gamepad & Manager"
      GamepadDB["internal/gamepaddb/"]:::subsystem
      Gamepad["internal/gamepad/"]:::subsystem
    end
  end

  subgraph "Platform Abstraction"
    UI["internal/ui/"]:::subsystem
    File["internal/file/"]:::subsystem
    EbitenMobileCmd["cmd/ebitenmobile/"]:::subsystem
    Mobile["mobile/"]:::subsystem
  end

  subgraph "Graphics Drivers"
    GL["internal/graphicsdriver/opengl/"]:::driver
    DX["internal/graphicsdriver/directx/"]:::driver
    Metal["internal/graphicsdriver/metal/"]:::driver
    PS5["internal/graphicsdriver/playstation5/"]:::driver
  end

  subgraph "External Dependencies"
    GLFW["GLFW (go-gl/glfw)"]:::external
    OpenGL["OpenGL (go-gl)"]:::external
    DirectX12["DirectX12"]:::external
    MetalAPI["Metal"]:::external
    WASM["WASM (syscall/js)"]:::external
    MobileBind["Java/ObjC (gomobile)"]:::external
  end

  %% Connections
  App -->|uses| GraphicsAPI
  App -->|uses| ImageAPI
  App -->|calls| InputAPI
  App -->|renders| UIAPI

  InputAPI -->|polls| InputRoot
  InputRoot --> InputUtil
  InputRoot --> UIInputGLFW
  InputRoot --> UIInputJS
  InputRoot --> UIInputMobile
  InputRoot --> UIInputPS5
  InputRoot --> GamepadDB
  GamepadDB --> Gamepad

  GraphicsAPI --> GraphicsCmd
  GraphicsCmd --> GraphicsCore
  GraphicsCmd --> GL
  GraphicsCmd --> DX
  GraphicsCmd --> Metal
  GraphicsCmd --> PS5

  GL --> OpenGL
  DX --> DirectX12
  Metal --> MetalAPI
  PS5 --> MetalAPI

  AudioRoot --> AudioGo
  AudioGo --> AudioCtx
  AudioCtx --> AudioLoop
  AudioCtx --> AudioConv

  API_files(("Asset Loading")):::api --> File

  API_files --> AudioRoot
  API_files --> TextV1
  API_files --> TextV2
  API_files --> Vector

  File --> ExamplesResources["examples/resources/"]:::subsystem

  UI --> InputRoot
  UI --> UIInputGLFW

  EbitenMobileCmd --> Mobile
  Mobile --> UIInputMobile
  Mobile --> AudioRoot

  WASM --> UI
  WASM --> InputRoot

  %% Click Events
  click App "https://github.com/hajimehoshi/ebiten/tree/main/examples/"
  click GraphicsAPI "https://github.com/hajimehoshi/ebiten/blob/main/graphics.go"
  click ImageAPI "https://github.com/hajimehoshi/ebiten/blob/main/image.go"
  click InputAPI "https://github.com/hajimehoshi/ebiten/blob/main/input.go"
  click UIAPI "https://github.com/hajimehoshi/ebiten/blob/main/gameforui.go"
  click AudioRoot "https://github.com/hajimehoshi/ebiten/tree/main/audio/"
  click AudioGo "https://github.com/hajimehoshi/ebiten/blob/main/audio.go"
  click AudioCtx "https://github.com/hajimehoshi/ebiten/blob/main/context.go"
  click AudioLoop "https://github.com/hajimehoshi/ebiten/blob/main/loop.go"
  click AudioMP3 "https://github.com/hajimehoshi/ebiten/tree/main/mp3/"
  click AudioVorbis "https://github.com/hajimehoshi/ebiten/tree/main/vorbis/"
  click AudioWav "https://github.com/hajimehoshi/ebiten/tree/main/wav/"
  click AudioConv "https://github.com/hajimehoshi/ebiten/tree/main/audio/internal/convert/"
  click TextV1 "https://github.com/hajimehoshi/ebiten/tree/main/text/"
  click TextV2 "https://github.com/hajimehoshi/ebiten/tree/main/text/v2/"
  click Vector "https://github.com/hajimehoshi/ebiten/tree/main/vector/"
  click InputUtil "https://github.com/hajimehoshi/ebiten/blob/main/inpututil/inpututil.go"
  click UIInputGLFW "https://github.com/hajimehoshi/ebiten/blob/main/internal/ui/input_glfw.go"
  click UIInputJS "https://github.com/hajimehoshi/ebiten/blob/main/internal/ui/input_js.go"
  click UIInputMobile "https://github.com/hajimehoshi/ebiten/blob/main/internal/ui/input_mobile.go"
  click UIInputPS5 "https://github.com/hajimehoshi/ebiten/blob/main/internal/ui/input_playstation5.go"
  click GamepadDB "https://github.com/hajimehoshi/ebiten/tree/main/internal/gamepaddb/"
  click Gamepad "https://github.com/hajimehoshi/ebiten/tree/main/internal/gamepad/"
  click GraphicsCore "https://github.com/hajimehoshi/ebiten/tree/main/internal/graphics/"
  click GraphicsCmd "https://github.com/hajimehoshi/ebiten/tree/main/internal/graphicscommand/"
  click GL "https://github.com/hajimehoshi/ebiten/tree/main/internal/graphicsdriver/opengl/"
  click DX "https://github.com/hajimehoshi/ebiten/tree/main/internal/graphicsdriver/directx/"
  click Metal "https://github.com/hajimehoshi/ebiten/tree/main/internal/graphicsdriver/metal/"
  click PS5 "https://github.com/hajimehoshi/ebiten/tree/main/internal/graphicsdriver/playstation5/"
  click UI "https://github.com/hajimehoshi/ebiten/tree/main/internal/ui/"
  click File "https://github.com/hajimehoshi/ebiten/tree/main/internal/file/"
  click EbitenMobileCmd "https://github.com/hajimehoshi/ebiten/tree/main/cmd/ebitenmobile/"
  click Mobile "https://github.com/hajimehoshi/ebiten/tree/main/mobile/"

  %% Styles
  classDef application fill:#FFD700,stroke:#333,stroke-width:1px
  classDef api fill:#8FBC8F,stroke:#333,stroke-width:1px
  classDef subsystem fill:#87CEFA,stroke:#333,stroke-width:1px
  classDef driver fill:#FFB6C1,stroke:#333,stroke-width:1px
  classDef external fill:#D3D3D3,stroke:#333,stroke-width:1px
```
