# x-ege/xege architecture

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

- Interactive diagram: https://gitdiagram.com/x-ege/xege
- Repository: https://github.com/x-ege/xege

## Overview

EGE is a cross-platform C/C++ graphics library with a beginner-friendly, BGI-like API. Its main workflow is an application opening a graphics window, issuing drawing or image operations, handling input, and presenting pixels through a native platform backend. Separate capabilities include image loading and transformation, text, input, camera capture, and music. The README documents the platform backends and broader feature set; sampled source confirms image operations and native render-target behavior, but does not expose all dispatch wiring, so uncertain links are omitted.

Main entry points: [`src/graphics.cpp`](https://github.com/x-ege/xege/blob/master/src/graphics.cpp) (Graphics API), [`src/image.cpp`](https://github.com/x-ege/xege/blob/master/src/image.cpp) (Image operations), [`src/backend/common/PixelSurface.cpp`](https://github.com/x-ege/xege/blob/master/src/backend/common/PixelSurface.cpp) (Pixel surface), [`src/image_ex.cpp`](https://github.com/x-ege/xege/blob/master/src/image_ex.cpp) (Image extensions)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Public API"]
  node_api_header["BGI API<br/>[graphics.h]"]
  node_graphics["Graphics API<br/>[graphics.cpp]"]
  node_window["Window lifecycle<br/>[window.cpp]"]
end

subgraph group_render["Drawing and Images"]
  node_image["Image operations<br/>[image.cpp]"]
  node_image_ext["Image extensions<br/>[image_ex.cpp]"]
  node_codecs["Image codecs<br/>[stb_image_impl.cpp]"]
  node_resize["Image resizing"]
  node_pixel_surface["Pixel surface<br/>[PixelSurface.cpp]"]
  node_render_interface["Render interface<br/>[RenderTarget.h]"]
end

subgraph group_platform["Platform Backends"]
  node_backend_window["Window interface<br/>[Window.h]"]
  node_cairo["Cairo renderer"]
  node_linux_window["Linux window<br/>[LinuxWindow.cpp]"]
  node_coregraphics["Core Graphics renderer"]
  node_mac_window["macOS window<br/>[MacWindow.h]"]
end

subgraph group_services["Input and Media"]
  node_input["Keyboard and mouse<br/>[keyboard.cpp]"]
  node_text["Font and text<br/>[font.cpp]"]
  node_camera["Camera capture<br/>[camera_capture.cpp]"]
  node_music["Music playback<br/>[music.cpp]"]
end

node_app(("C/C++ application"))
node_external_camera(("Camera devices"))
node_external_audio(("Audio system"))

node_app -->|"calls"| node_api_header
node_api_header -->|"declares API"| node_graphics
node_graphics -->|"manages window"| node_window
node_graphics -->|"draws images"| node_image
node_image -->|"uses pixels"| node_pixel_surface
node_image -->|"loads and saves"| node_codecs
node_image_ext -->|"transforms"| node_image
node_image_ext -->|"resizes"| node_resize
node_pixel_surface -->|"presents pixels"| node_cairo
node_pixel_surface -->|"presents pixels"| node_coregraphics
node_cairo -->|"implements"| node_render_interface
node_coregraphics -->|"implements"| node_render_interface
node_linux_window -->|"implements"| node_backend_window
node_mac_window -->|"implements"| node_backend_window
node_graphics -->|"handles input"| node_input
node_graphics -->|"draws text"| node_text
node_app -.->|"uses camera API"| node_camera
node_camera -.->|"captures frames"| node_external_camera
node_app -.->|"uses music API"| node_music
node_music -.->|"plays audio"| node_external_audio

click node_api_header "https://github.com/x-ege/xege/blob/master/include/graphics.h"
click node_graphics "https://github.com/x-ege/xege/blob/master/src/graphics.cpp"
click node_window "https://github.com/x-ege/xege/blob/master/src/window.cpp"
click node_image "https://github.com/x-ege/xege/blob/master/src/image.cpp"
click node_image_ext "https://github.com/x-ege/xege/blob/master/src/image_ex.cpp"
click node_codecs "https://github.com/x-ege/xege/blob/master/src/stb_image_impl.cpp"
click node_resize "https://github.com/x-ege/xege/blob/master/src/external/stb_image_resize2.h"
click node_pixel_surface "https://github.com/x-ege/xege/blob/master/src/backend/common/PixelSurface.cpp"
click node_render_interface "https://github.com/x-ege/xege/blob/master/src/backend/interface/RenderTarget.h"
click node_backend_window "https://github.com/x-ege/xege/blob/master/src/backend/interface/Window.h"
click node_cairo "https://github.com/x-ege/xege/blob/master/src/backend/linux/CairoRenderTarget.cpp"
click node_linux_window "https://github.com/x-ege/xege/blob/master/src/backend/linux/LinuxWindow.cpp"
click node_coregraphics "https://github.com/x-ege/xege/blob/master/src/backend/macos/CoreGraphicsRenderTarget.cpp"
click node_mac_window "https://github.com/x-ege/xege/blob/master/src/backend/macos/MacWindow.h"
click node_input "https://github.com/x-ege/xege/blob/master/src/keyboard.cpp"
click node_text "https://github.com/x-ege/xege/blob/master/src/font.cpp"
click node_camera "https://github.com/x-ege/xege/blob/master/src/camera_capture.cpp"
click node_music "https://github.com/x-ege/xege/blob/master/src/music.cpp"

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_api_header,node_graphics,node_window toneBlue
class node_image,node_image_ext,node_codecs,node_resize,node_pixel_surface,node_render_interface toneAmber
class node_backend_window,node_cairo,node_linux_window,node_coregraphics,node_mac_window toneMint
class node_input,node_text,node_camera,node_music toneRose
class node_app,node_external_camera,node_external_audio toneIndigo
```

## Components

### Public API

- [BGI API](https://github.com/x-ege/xege/blob/master/include/graphics.h): `include/graphics.h`
- [Graphics API](https://github.com/x-ege/xege/blob/master/src/graphics.cpp): `src/graphics.cpp`
- [Window lifecycle](https://github.com/x-ege/xege/blob/master/src/window.cpp): `src/window.cpp`

### Drawing and Images

- [Image operations](https://github.com/x-ege/xege/blob/master/src/image.cpp): `src/image.cpp`
- [Image extensions](https://github.com/x-ege/xege/blob/master/src/image_ex.cpp): `src/image_ex.cpp`
- [Image codecs](https://github.com/x-ege/xege/blob/master/src/stb_image_impl.cpp): `src/stb_image_impl.cpp`
- [Image resizing](https://github.com/x-ege/xege/blob/master/src/external/stb_image_resize2.h): `src/external/stb_image_resize2.h`
- [Pixel surface](https://github.com/x-ege/xege/blob/master/src/backend/common/PixelSurface.cpp): `src/backend/common/PixelSurface.cpp`
- [Render interface](https://github.com/x-ege/xege/blob/master/src/backend/interface/RenderTarget.h): `src/backend/interface/RenderTarget.h`

### Platform Backends

- [Window interface](https://github.com/x-ege/xege/blob/master/src/backend/interface/Window.h): `src/backend/interface/Window.h`
- [Cairo renderer](https://github.com/x-ege/xege/blob/master/src/backend/linux/CairoRenderTarget.cpp): `src/backend/linux/CairoRenderTarget.cpp`
- [Linux window](https://github.com/x-ege/xege/blob/master/src/backend/linux/LinuxWindow.cpp): `src/backend/linux/LinuxWindow.cpp`
- [Core Graphics renderer](https://github.com/x-ege/xege/blob/master/src/backend/macos/CoreGraphicsRenderTarget.cpp): `src/backend/macos/CoreGraphicsRenderTarget.cpp`
- [macOS window](https://github.com/x-ege/xege/blob/master/src/backend/macos/MacWindow.h): `src/backend/macos/MacWindow.h`

### Input and Media

- [Keyboard and mouse](https://github.com/x-ege/xege/blob/master/src/keyboard.cpp): `src/keyboard.cpp`
- [Font and text](https://github.com/x-ege/xege/blob/master/src/font.cpp): `src/font.cpp`
- [Camera capture](https://github.com/x-ege/xege/blob/master/src/camera_capture.cpp): `src/camera_capture.cpp`
- [Music playback](https://github.com/x-ege/xege/blob/master/src/music.cpp): `src/music.cpp`

### Other components

- **C/C++ application**
- **Camera devices**
- **Audio system**

## Connections

- C/C++ application → BGI API: calls
- BGI API → Graphics API: declares API
- Graphics API → Window lifecycle: manages window
- Graphics API → Image operations: draws images
- Image operations → Pixel surface: uses pixels
- Image operations → Image codecs: loads and saves
- Image extensions → Image operations: transforms
- Image extensions → Image resizing: resizes
- Pixel surface → Cairo renderer: presents pixels
- Pixel surface → Core Graphics renderer: presents pixels
- Cairo renderer → Render interface: implements
- Core Graphics renderer → Render interface: implements
- Linux window → Window interface: implements
- macOS window → Window interface: implements
- Graphics API → Keyboard and mouse: handles input
- Graphics API → Font and text: draws text
- C/C++ application → Camera capture: uses camera API
- Camera capture → Camera devices: captures frames
- C/C++ application → Music playback: uses music API
- Music playback → Audio system: plays audio
