# villagerjj/openterragb architecture

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

- Interactive diagram: https://gitdiagram.com/villagerjj/openterragb
- Repository: https://github.com/villagerjj/openterragb

## Overview

OpenTerraGB is a Game Boy Terraria-like game. The main gameplay loop handles player input and world interaction, with world generation and block storage, inventory/crafting, and screen presentation as distinct concerns. The README documents the 512×192 world limit and SRAM-bank use. The sampled main excerpt shows world generation and SRAM-backed block access, but much of the game is concentrated in that file; connections to separate screen, player, and storage modules are left out where the available evidence does not show calls.

Main entry points: [`src/main.c`](https://github.com/villagerjj/openterragb/blob/main/src/main.c) (Gameplay loop), [`src/sram`](https://github.com/villagerjj/openterragb/tree/main/src/sram) (World SRAM banks)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Game runtime"]
  node_game["Gameplay loop<br/>[main.c]"]
  node_playerlogic["Player state<br/>[player.c]"]
end

subgraph group_world["World and terrain"]
  node_worldgen["World generation<br/>[main.c]"]
  node_blockaccess["Block access<br/>[main.c]"]
  node_worldtiles["World tile data<br/>[worldtiles.c]"]
  node_sram[("World SRAM banks")]
end

subgraph group_items["Items and crafting"]
  node_inventory["Inventory operations<br/>[inventory.c]"]
  node_crafting["Crafting<br/>[Crafting.c]"]
  node_itemids["Item identifiers<br/>[itemIDs.h]"]
end

subgraph group_screens["Screens and assets"]
  node_title["Title screen<br/>[Titlescreen.c]"]
  node_titletiles["Title tile data<br/>[Titletiles.c]"]
  node_loading["Loading screen<br/>[loadingscreen.c]"]
  node_inventoryui["Inventory tiles<br/>[InvTiles.c]"]
  node_cursor["Cursor<br/>[Cursor.c]"]
  node_numbers["Number tiles<br/>[numbers.c]"]
end

node_player(("Player input"))

node_player -->|"provides input"| node_game
node_game -->|"generates terrain"| node_worldgen
node_worldgen -->|"writes blocks"| node_blockaccess
node_blockaccess -->|"reads/writes"| node_sram

click node_game "https://github.com/villagerjj/openterragb/blob/main/src/main.c"
click node_playerlogic "https://github.com/villagerjj/openterragb/blob/main/src/player.c"
click node_worldgen "https://github.com/villagerjj/openterragb/blob/main/src/main.c"
click node_blockaccess "https://github.com/villagerjj/openterragb/blob/main/src/main.c"
click node_worldtiles "https://github.com/villagerjj/openterragb/blob/main/src/worldtiles.c"
click node_sram "https://github.com/villagerjj/openterragb/tree/main/src/sram"
click node_inventory "https://github.com/villagerjj/openterragb/blob/main/src/inventory.c"
click node_crafting "https://github.com/villagerjj/openterragb/blob/main/src/Crafting.c"
click node_itemids "https://github.com/villagerjj/openterragb/blob/main/src/include/itemIDs.h"
click node_title "https://github.com/villagerjj/openterragb/blob/main/src/Titlescreen.c"
click node_titletiles "https://github.com/villagerjj/openterragb/blob/main/src/Titletiles.c"
click node_loading "https://github.com/villagerjj/openterragb/blob/main/src/loadingscreen.c"
click node_inventoryui "https://github.com/villagerjj/openterragb/blob/main/src/InvTiles.c"
click node_cursor "https://github.com/villagerjj/openterragb/blob/main/src/Cursor.c"
click node_numbers "https://github.com/villagerjj/openterragb/blob/main/src/numbers.c"

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_game,node_playerlogic toneBlue
class node_worldgen,node_blockaccess,node_worldtiles,node_sram toneAmber
class node_inventory,node_crafting,node_itemids toneMint
class node_title,node_titletiles,node_loading,node_inventoryui,node_cursor,node_numbers toneRose
class node_player toneIndigo
```

## Components

### Game runtime

- [Gameplay loop](https://github.com/villagerjj/openterragb/blob/main/src/main.c): `src/main.c`
- [Player state](https://github.com/villagerjj/openterragb/blob/main/src/player.c): `src/player.c`

### World and terrain

- [World generation](https://github.com/villagerjj/openterragb/blob/main/src/main.c): `src/main.c`
- [Block access](https://github.com/villagerjj/openterragb/blob/main/src/main.c): `src/main.c`
- [World tile data](https://github.com/villagerjj/openterragb/blob/main/src/worldtiles.c): `src/worldtiles.c`
- [World SRAM banks](https://github.com/villagerjj/openterragb/tree/main/src/sram): `src/sram`

### Items and crafting

- [Inventory operations](https://github.com/villagerjj/openterragb/blob/main/src/inventory.c): `src/inventory.c`
- [Crafting](https://github.com/villagerjj/openterragb/blob/main/src/Crafting.c): `src/Crafting.c`
- [Item identifiers](https://github.com/villagerjj/openterragb/blob/main/src/include/itemIDs.h): `src/include/itemIDs.h`

### Screens and assets

- [Title screen](https://github.com/villagerjj/openterragb/blob/main/src/Titlescreen.c): `src/Titlescreen.c`
- [Title tile data](https://github.com/villagerjj/openterragb/blob/main/src/Titletiles.c): `src/Titletiles.c`
- [Loading screen](https://github.com/villagerjj/openterragb/blob/main/src/loadingscreen.c): `src/loadingscreen.c`
- [Inventory tiles](https://github.com/villagerjj/openterragb/blob/main/src/InvTiles.c): `src/InvTiles.c`
- [Cursor](https://github.com/villagerjj/openterragb/blob/main/src/Cursor.c): `src/Cursor.c`
- [Number tiles](https://github.com/villagerjj/openterragb/blob/main/src/numbers.c): `src/numbers.c`

### Other components

- **Player input**

## Connections

- Player input → Gameplay loop: provides input (evidence: `src/main.c`)
- Gameplay loop → World generation: generates terrain (evidence: `src/main.c`)
- World generation → Block access: writes blocks (evidence: `src/main.c`)
- Block access → World SRAM banks: reads/writes (evidence: `src/main.c`)
