# compumaxx/gba-background-studio architecture

> Architecture diagram of the GitHub repository compumaxx/gba-background-studio, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/compumaxx/gba-background-studio
- Repository: https://github.com/compumaxx/gba-background-studio

## Overview

1. **What this repository is**
   - A desktop editor/converter for **Game Boy Advance background assets**.
   - The core architectural flow is: **import image → convert to GBA-ready tiles/palettes/tilemap → edit visually → preview → export assets**.

2. **Primary runtime and UI stack**
   - The app is written in **Python** and uses **Qt via PySide6 or PySide2** depending on Python version.
   - `ui/qt_compat.py` is the compatibility boundary that lets the same UI code run on modern and legacy Python/Qt combinations.
   - Image and color processing relies on native Python scientific/image libraries listed in `requirements.txt` and reflected in the `core` modules.

3. **Application entry points**
   - `main.py` is the top-level launch point.
   - `core/main.py` likely contains the central application/bootstrap logic used by the GUI.
   - `GBA_Studio_Wizard.bat` is a separate **CLI/batch conversion path** for legacy or non-GUI usage on Windows, using the same translation language set.

4. **Core conversion engine**
   - The `core/` package is the processing pipeline that turns source images into GBA-compatible output.
   - Key responsibilities are split by concern:
     - `image_utils.py` for image handling/preprocessing
     - `quantization.py` for palette reduction/color quantization
     - `palette_utils.py` for palette creation/manipulation
     - `tile_utils.py` and `tile_optimizer.py` for tile slicing and reuse/optimization
     - `final_assets.py` for packaging the final exportable results
   - This is the main boundary between **editor UI** and **asset generation logic**.

5. **Conversion workflow and parameter collection**
   - The conversion dialog subsystem in `ui/dialogs/` gathers user intent before invoking the core pipeline.
   - `conversion_dialog_ui.py`, `conversion_dialog_logic.py`, `conversion_dialog_config.py`, and `conversion_params.py` separate presentation, validation, orchestration, and parameter state.
   - Supporting dialogs such as `convert_bpp_dialogs.py` and `gba_compatibility_dialog.py` expose constraints around GBA formats and compatibility.

6. **Main window as the orchestration layer**
   - `ui/main_window/` is the central UI coordinator.
   - It is split into focused modules:
     - `main.py` for window lifecycle/state
     - `file_ops.py` for open/save/export actions
     - `tab_ops.py` for tab switching and tab-specific actions
     - `toolbar.py` and `menu_bar.py` for command surfaces
     - `view_ops.py` and `utils.py` for shared window behavior
   - This layer connects user actions to conversion, editing, and export flows.

7. **Tab-based editing model**
   - The editor is organized around three main work surfaces:
     - `ui/preview_tab.py` for GBA-like rendering of the current result
     - `ui/edit_tiles_tab.py` for tilemap/tile editing
     - `ui/edit_palettes_tab.py` for palette editing
   - The tabs operate on the same underlying asset state, so changes in one tab propagate to the others.

8. **Tilemap and drawing interaction subsystem**
   - Editing behavior is driven by shared interaction helpers:
     - `ui/tilemap_utils.py` for tilemap-specific manipulation
     - `ui/grid_manager.py` for grid overlays and cell geometry
     - `ui/hover_manager.py` for hover/highlight feedback
     - `ui/shared_utils.py` for reusable UI helpers
   - `ui/palette_grid_view.py` and `ui/color_editor.py` support direct palette manipulation.
   - The interaction model is selection/draw/transform oriented rather than a generic document editor.

9. **Undo/redo and state history**
   - `ui/history_manager.py` captures editing operations for undo/redo.
   - This is a key architectural boundary because tile edits, palette changes, and tilemap operations are treated as reversible state transitions.
   - The history layer sits between the editing widgets and the shared asset model.

10. **Configuration and persistence**
   - `core/config.py`, `core/config_manager.py`, and `ui/main_window/config.py` handle persistent settings such as language, zoom, and last-session behavior.
   - Config is loaded at startup and then used to initialize the window, dialogs, and translation state.
   - `ui/main_window/file_ops.py` also suggests persistent file/session interaction is part of the main window boundary.

11. **Localization system**
   - `utils/translator.py` is the runtime translation layer.
   - Language files live in `lang/*.ini`, with matching translated docs in `docs/`.
   - The translation system is not just documentation—it is a runtime UI concern affecting menus, dialogs, status text, and the CLI wizard.

12. **Assets, library loading, and export outputs**
   - `core/library_loader.py` and `core/final_assets.py` suggest a separation between loading reusable asset/library data and assembling the final export bundle.
   - The app’s output is oriented toward GBA toolchains: tilesets, tilemaps, and palettes rather than a single flattened image.
   - The `assets/` directory holds UI resources like icons, toolbar art, and README screenshots.

13. **Platform/support boundaries**
   - The repo explicitly supports both modern and legacy Windows environments through backend selection and a batch wizard path.
   - The architecture therefore has two user-facing modes:
     - full Qt GUI
     - command-line/batch conversion via `.bat`
   - This dual path is important when drawing the system boundary: the **core conversion engine is shared**, while the UI surface differs.

14. **How to think about the data flow**
   - Source image enters through file/open or conversion dialog.
   - Conversion parameters are collected in the UI and passed to the `core` pipeline.
   - Core modules produce tiles, palettes, and tilemaps.
   - The editing tabs mutate that shared asset state with history tracking.
   - Preview renders the current state in a GBA-like view.
   - Export/file operations package the final assets for external GBA development tools.

Main entry points: [`ui/main_window/main.py`](https://github.com/compumaxx/gba-background-studio/blob/main/ui/main_window/main.py) (Main window), [`core/main.py`](https://github.com/compumaxx/gba-background-studio/blob/main/core/main.py) (Core main), [`core/final_assets.py`](https://github.com/compumaxx/gba-background-studio/blob/main/core/final_assets.py) (Final assets), [`ui/main_window/tab_ops.py`](https://github.com/compumaxx/gba-background-studio/blob/main/ui/main_window/tab_ops.py) (Tab ops)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_grp_core["Core engine"]
  node_n_core_main["Core main<br/>bootstrap<br/>[main.py]"]
  node_n_image_utils["Image utils<br/>preprocess<br/>[image_utils.py]"]
  node_n_quantization["Quantization<br/>palette reduction<br/>[quantization.py]"]
  node_n_palette_utils["Palette utils<br/>palette ops<br/>[palette_utils.py]"]
  node_n_tile_utils["Tile utils<br/>tiling<br/>[tile_utils.py]"]
  node_n_tile_optimizer["Tile optimizer<br/>tile reuse<br/>[tile_optimizer.py]"]
  node_n_final_assets[("Final assets<br/>export bundle<br/>[final_assets.py]")]
  node_n_library_loader["Library loader<br/>asset loading<br/>[library_loader.py]"]
end

subgraph group_grp_ui["Qt UI"]
  node_n_main_window["Main window<br/>ui coordinator<br/>[main.py]"]
  node_n_file_ops["File ops<br/>open/save/export<br/>[file_ops.py]"]
  node_n_tab_ops["Tab ops<br/>tab control<br/>[tab_ops.py]"]
  node_n_preview_tab(("Preview tab<br/>render view<br/>[preview_tab.py]"))
  node_n_tiles_tab(("Tiles tab<br/>tile editor<br/>[edit_tiles_tab.py]"))
  node_n_palettes_tab(("Palettes tab<br/>palette editor"))
  node_n_dialogs["Dialogs<br/>conversion setup"]
  node_n_conv_logic["Conversion logic<br/>workflow"]
  node_n_conv_params["Conv params<br/>state"]
  node_n_grid_interaction["Grid tools<br/>interaction<br/>[grid_manager.py]"]
  node_n_history[("History<br/>undo/redo<br/>[history_manager.py]")]
end

subgraph group_grp_support["Support systems"]
  node_n_qt_compat["Qt compat<br/>compat layer<br/>[qt_compat.py]"]
  node_n_config_core["Core config<br/>settings<br/>[config.py]"]
  node_n_config_mgr["Config manager<br/>settings load<br/>[config_manager.py]"]
  node_n_translator["Translator<br/>localization<br/>[translator.py]"]
end

subgraph group_grp_entry["Entry points"]
  node_n_main_py["main.py<br/>launcher<br/>[main.py]"]
  node_n_batch_wizard["Wizard batch<br/>batch launcher"]
end

node_n_main_py -->|"launches"| node_n_main_window
node_n_batch_wizard -->|"uses"| node_n_core_main
node_n_main_window -->|"depends on"| node_n_qt_compat
node_n_main_window -->|"loads"| node_n_config_mgr
node_n_main_window -->|"localizes"| node_n_translator
node_n_config_mgr -->|"persists"| node_n_config_core
node_n_core_main -->|"orchestrates"| node_n_image_utils
node_n_core_main -->|"orchestrates"| node_n_quantization
node_n_core_main -->|"orchestrates"| node_n_tile_utils
node_n_core_main -->|"produces"| node_n_final_assets
node_n_image_utils -->|"feeds"| node_n_quantization
node_n_quantization -->|"uses"| node_n_palette_utils
node_n_tile_utils -->|"feeds"| node_n_tile_optimizer
node_n_tile_optimizer -->|"packages"| node_n_final_assets
node_n_library_loader -->|"augments"| node_n_final_assets
node_n_dialogs -->|"delegates"| node_n_conv_logic
node_n_conv_logic -->|"populates"| node_n_conv_params
node_n_conv_params -->|"invokes"| node_n_core_main
node_n_main_window -->|"routes"| node_n_file_ops
node_n_main_window -->|"routes"| node_n_tab_ops
node_n_tab_ops -->|"switches"| node_n_preview_tab
node_n_tab_ops -->|"switches"| node_n_tiles_tab
node_n_tab_ops -->|"switches"| node_n_palettes_tab
node_n_tiles_tab -->|"uses"| node_n_grid_interaction
node_n_palettes_tab -->|"uses"| node_n_grid_interaction
node_n_tiles_tab -->|"records"| node_n_history
node_n_palettes_tab -->|"records"| node_n_history
node_n_preview_tab -->|"renders"| node_n_final_assets
node_n_file_ops -->|"exports"| node_n_final_assets
node_n_translator -->|"drives text"| node_n_dialogs
node_n_translator -->|"drives text"| node_n_batch_wizard

click node_n_main_py "https://github.com/compumaxx/gba-background-studio/blob/main/main.py"
click node_n_batch_wizard "https://github.com/compumaxx/gba-background-studio/blob/main/GBA_Studio_Wizard.bat"
click node_n_core_main "https://github.com/compumaxx/gba-background-studio/blob/main/core/main.py"
click node_n_image_utils "https://github.com/compumaxx/gba-background-studio/blob/main/core/image_utils.py"
click node_n_quantization "https://github.com/compumaxx/gba-background-studio/blob/main/core/quantization.py"
click node_n_palette_utils "https://github.com/compumaxx/gba-background-studio/blob/main/core/palette_utils.py"
click node_n_tile_utils "https://github.com/compumaxx/gba-background-studio/blob/main/core/tile_utils.py"
click node_n_tile_optimizer "https://github.com/compumaxx/gba-background-studio/blob/main/core/tile_optimizer.py"
click node_n_final_assets "https://github.com/compumaxx/gba-background-studio/blob/main/core/final_assets.py"
click node_n_library_loader "https://github.com/compumaxx/gba-background-studio/blob/main/core/library_loader.py"
click node_n_qt_compat "https://github.com/compumaxx/gba-background-studio/blob/main/ui/qt_compat.py"
click node_n_config_core "https://github.com/compumaxx/gba-background-studio/blob/main/core/config.py"
click node_n_config_mgr "https://github.com/compumaxx/gba-background-studio/blob/main/core/config_manager.py"
click node_n_translator "https://github.com/compumaxx/gba-background-studio/blob/main/utils/translator.py"
click node_n_main_window "https://github.com/compumaxx/gba-background-studio/blob/main/ui/main_window/main.py"
click node_n_file_ops "https://github.com/compumaxx/gba-background-studio/blob/main/ui/main_window/file_ops.py"
click node_n_tab_ops "https://github.com/compumaxx/gba-background-studio/blob/main/ui/main_window/tab_ops.py"
click node_n_preview_tab "https://github.com/compumaxx/gba-background-studio/blob/main/ui/preview_tab.py"
click node_n_tiles_tab "https://github.com/compumaxx/gba-background-studio/blob/main/ui/edit_tiles_tab.py"
click node_n_palettes_tab "https://github.com/compumaxx/gba-background-studio/blob/main/ui/edit_palettes_tab.py"
click node_n_dialogs "https://github.com/compumaxx/gba-background-studio/blob/main/ui/dialogs/conversion_dialog.py"
click node_n_conv_logic "https://github.com/compumaxx/gba-background-studio/blob/main/ui/dialogs/conversion_dialog_logic.py"
click node_n_conv_params "https://github.com/compumaxx/gba-background-studio/blob/main/ui/dialogs/conversion_params.py"
click node_n_grid_interaction "https://github.com/compumaxx/gba-background-studio/blob/main/ui/grid_manager.py"
click node_n_history "https://github.com/compumaxx/gba-background-studio/blob/main/ui/history_manager.py"

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_n_core_main,node_n_image_utils,node_n_quantization,node_n_palette_utils,node_n_tile_utils,node_n_tile_optimizer,node_n_final_assets,node_n_library_loader toneBlue
class node_n_main_window,node_n_file_ops,node_n_tab_ops,node_n_preview_tab,node_n_tiles_tab,node_n_palettes_tab,node_n_dialogs,node_n_conv_logic,node_n_conv_params,node_n_grid_interaction,node_n_history toneAmber
class node_n_qt_compat,node_n_config_core,node_n_config_mgr,node_n_translator toneMint
class node_n_main_py,node_n_batch_wizard toneRose
```

## Components

### Core engine

Image conversion, tile/palette processing, and export assembly.

- [Core main](https://github.com/compumaxx/gba-background-studio/blob/main/core/main.py): bootstrap · Application bootstrap and central runtime wiring. · `core/main.py`
- [Image utils](https://github.com/compumaxx/gba-background-studio/blob/main/core/image_utils.py): preprocess · Source image handling and preprocessing. · `core/image_utils.py`
- [Quantization](https://github.com/compumaxx/gba-background-studio/blob/main/core/quantization.py): palette reduction · Color quantization and palette reduction logic. · `core/quantization.py`
- [Palette utils](https://github.com/compumaxx/gba-background-studio/blob/main/core/palette_utils.py): palette ops · Palette creation and manipulation helpers. · `core/palette_utils.py`
- [Tile utils](https://github.com/compumaxx/gba-background-studio/blob/main/core/tile_utils.py): tiling · Tile slicing and tilemap-oriented helpers. · `core/tile_utils.py`
- [Tile optimizer](https://github.com/compumaxx/gba-background-studio/blob/main/core/tile_optimizer.py): tile reuse · Tile deduplication and optimization for GBA output. · `core/tile_optimizer.py`
- [Final assets](https://github.com/compumaxx/gba-background-studio/blob/main/core/final_assets.py): export bundle · Assembles exportable tiles, palettes, and tilemaps. · `core/final_assets.py`
- [Library loader](https://github.com/compumaxx/gba-background-studio/blob/main/core/library_loader.py): asset loading · Loads reusable library or preset asset data. · `core/library_loader.py`

### Qt UI

Main window, dialogs, tabs, and editing interactions.

- [Main window](https://github.com/compumaxx/gba-background-studio/blob/main/ui/main_window/main.py): ui coordinator · Window lifecycle and top-level UI coordination. · `ui/main_window/main.py`
- [File ops](https://github.com/compumaxx/gba-background-studio/blob/main/ui/main_window/file_ops.py): open/save/export · File actions and session-level persistence from the main window. · `ui/main_window/file_ops.py`
- [Tab ops](https://github.com/compumaxx/gba-background-studio/blob/main/ui/main_window/tab_ops.py): tab control · Tab switching and tab-specific action routing. · `ui/main_window/tab_ops.py`
- [Preview tab](https://github.com/compumaxx/gba-background-studio/blob/main/ui/preview_tab.py): render view · GBA-like preview of current assets. · `ui/preview_tab.py`
- [Tiles tab](https://github.com/compumaxx/gba-background-studio/blob/main/ui/edit_tiles_tab.py): tile editor · Tilemap and tile editing workspace. · `ui/edit_tiles_tab.py`
- [Palettes tab](https://github.com/compumaxx/gba-background-studio/blob/main/ui/edit_palettes_tab.py): palette editor · Palette editing workspace. · `ui/edit_palettes_tab.py`
- [Dialogs](https://github.com/compumaxx/gba-background-studio/blob/main/ui/dialogs/conversion_dialog.py): conversion setup · Conversion dialog orchestration and validation. · `ui/dialogs/conversion_dialog.py`
- [Conversion logic](https://github.com/compumaxx/gba-background-studio/blob/main/ui/dialogs/conversion_dialog_logic.py): workflow · Dialog-side orchestration, validation, and parameter flow. · `ui/dialogs/conversion_dialog_logic.py`
- [Conv params](https://github.com/compumaxx/gba-background-studio/blob/main/ui/dialogs/conversion_params.py): state · Conversion parameter state passed into the core pipeline. · `ui/dialogs/conversion_params.py`
- [Grid tools](https://github.com/compumaxx/gba-background-studio/blob/main/ui/grid_manager.py): interaction · Grid geometry, hover feedback, and shared editing helpers. · `ui/grid_manager.py`
- [History](https://github.com/compumaxx/gba-background-studio/blob/main/ui/history_manager.py): undo/redo · Reversible editing state transitions. · `ui/history_manager.py`

### Support systems

Compatibility, configuration, and localization boundaries.

- [Qt compat](https://github.com/compumaxx/gba-background-studio/blob/main/ui/qt_compat.py): compat layer · PySide6/PySide2 compatibility boundary. · `ui/qt_compat.py`
- [Core config](https://github.com/compumaxx/gba-background-studio/blob/main/core/config.py): settings · Persistent application configuration. · `core/config.py`
- [Config manager](https://github.com/compumaxx/gba-background-studio/blob/main/core/config_manager.py): settings load · Configuration lifecycle and persistence orchestration. · `core/config_manager.py`
- [Translator](https://github.com/compumaxx/gba-background-studio/blob/main/utils/translator.py): localization · Runtime translation layer for UI and wizard text. · `utils/translator.py`

### Entry points

Desktop and batch launch surfaces.

- [main.py](https://github.com/compumaxx/gba-background-studio/blob/main/main.py): launcher · Top-level GUI entry point. · `main.py`
- [Wizard batch](https://github.com/compumaxx/gba-background-studio/blob/main/GBA_Studio_Wizard.bat): batch launcher · Windows batch conversion path for legacy or non-GUI use. · `GBA_Studio_Wizard.bat`

## Connections

- main.py → Main window: launches · Starts the Qt desktop application.
- Wizard batch → Core main: uses · Batch path invokes the shared conversion runtime.
- Main window → Qt compat: depends on · Window code runs through the Qt backend compatibility boundary.
- Main window → Config manager: loads · Initializes window state from persisted settings.
- Main window → Translator: localizes · Applies runtime language text to UI surfaces.
- Config manager → Core config: persists · Loads and saves app settings.
- Core main → Image utils: orchestrates · Bootstraps the asset conversion pipeline.
- Core main → Quantization: orchestrates · Coordinates palette reduction.
- Core main → Tile utils: orchestrates · Coordinates tile slicing and tilemap generation.
- Core main → Final assets: produces · Collects the finished export bundle.
- Image utils → Quantization: feeds · Preprocessed image data enters quantization.
- Quantization → Palette utils: uses · Builds and adjusts palettes from quantized colors.
- Tile utils → Tile optimizer: feeds · Tile extraction is refined by reuse optimization.
- Tile optimizer → Final assets: packages · Optimized tiles are assembled into exportable assets.
- Library loader → Final assets: augments · Reusable library data can be folded into the final output.
- Dialogs → Conversion logic: delegates · UI dialogs hand off workflow orchestration and validation.
- Conversion logic → Conv params: populates · Collects user intent into parameter state.
- Conv params → Core main: invokes · Parameters are passed into the shared conversion engine.
- Main window → File ops: routes · Window actions are routed through file/session operations.
- Main window → Tab ops: routes · Window actions are routed through tab orchestration.
- Tab ops → Preview tab: switches · Coordinates the preview surface.
- Tab ops → Tiles tab: switches · Coordinates the tile editing surface.
- Tab ops → Palettes tab: switches · Coordinates the palette editing surface.
- Tiles tab → Grid tools: uses · Tile editing relies on shared grid and hover helpers.
- Palettes tab → Grid tools: uses · Palette editing uses the shared interaction helpers.
- Tiles tab → History: records · Tile edits are tracked for undo/redo.
- Palettes tab → History: records · Palette edits are tracked for undo/redo.
- Preview tab → Final assets: renders · Preview reflects the current assembled asset state.
- File ops → Final assets: exports · File operations package the final GBA-ready outputs.
- Translator → Dialogs: drives text · Translation strings affect dialog content.
- Translator → Wizard batch: drives text · Localization also affects batch/wizard messaging.
