# peterhellberg/nex architecture

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

- Interactive diagram: https://gitdiagram.com/peterhellberg/nex
- Repository: https://github.com/peterhellberg/nex

## Overview

nex is a Zig host for vex fantasy-console WASM carts. A cart uses the Zig or C SDK and exports boot/update; the host loads and runs it, provides drawing, input, and audio services, then presents its framebuffer through a desktop or terminal backend. Headless execution is another host mode for deterministic frame output. The README establishes these subsystem relationships; source excerpts are limited to the C SDK header and a raylib interop header, so finer call-level wiring is not asserted.

Main entry points: [`src/Console.zig`](https://github.com/peterhellberg/nex/blob/main/src/Console.zig) (Console State), [`src/gfx.zig`](https://github.com/peterhellberg/nex/blob/main/src/gfx.zig) (Drawing and Framebuffer), [`src/main.zig`](https://github.com/peterhellberg/nex/blob/main/src/main.zig) (CLI and Loop), [`src/backend.zig`](https://github.com/peterhellberg/nex/blob/main/src/backend.zig) (Backend Layer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_host["Host Runtime"]
  node_main["CLI and Loop<br/>[main.zig]"]
  node_cart_runtime["Cart Runtime<br/>[cart.zig]"]
  node_headless["Headless Run<br/>[main.zig]"]
end

subgraph group_cart_api["Cart Interface"]
  node_zig_sdk["Zig Cart SDK<br/>[vex.zig]"]
  node_c_sdk["C Cart SDK<br/>[vex.h]"]
end

subgraph group_services["Console Services"]
  node_console["Console State<br/>[Console.zig]"]
  node_graphics["Drawing and Framebuffer<br/>[gfx.zig]"]
  node_font["Bitmap Font<br/>[font.zig]"]
  node_input["Input State<br/>[input.zig]"]
  node_synth["Four-Voice Synth<br/>[synth.zig]"]
end

subgraph group_platform["Platform Output"]
  node_backend_api["Backend Layer<br/>[backend.zig]"]
  node_raylib["Raylib Backend<br/>[raylib.zig]"]
  node_kitty["Kitty Backend<br/>[kitty.zig]"]
end

node_cart_author(("Cart Author"))
node_wasm_cart["WASM Cart"]

node_cart_author -->|"uses"| node_zig_sdk
node_cart_author -->|"uses"| node_c_sdk
node_zig_sdk -->|"builds"| node_wasm_cart
node_c_sdk -->|"builds"| node_wasm_cart
node_main -->|"loads and runs"| node_cart_runtime
node_wasm_cart -->|"calls imports"| node_cart_runtime
node_cart_runtime -->|"provides cart state"| node_console
node_console -->|"holds framebuffer"| node_graphics
node_console -->|"holds input state"| node_input
node_console -->|"holds synth state"| node_synth
node_main -->|"runs platform"| node_backend_api
node_backend_api -->|"selects desktop"| node_raylib
node_backend_api -->|"selects terminal"| node_kitty
node_raylib -->|"presents framebuffer"| node_graphics
node_raylib -->|"feeds input"| node_input
node_kitty -->|"presents framebuffer"| node_graphics
node_kitty -->|"feeds input"| node_input
node_main -->|"supports"| node_headless
node_headless -->|"hashes or dumps"| node_graphics

click node_main "https://github.com/peterhellberg/nex/blob/main/src/main.zig"
click node_cart_runtime "https://github.com/peterhellberg/nex/blob/main/src/cart.zig"
click node_headless "https://github.com/peterhellberg/nex/blob/main/src/main.zig"
click node_zig_sdk "https://github.com/peterhellberg/nex/blob/main/vex.zig"
click node_c_sdk "https://github.com/peterhellberg/nex/blob/main/vex.h"
click node_console "https://github.com/peterhellberg/nex/blob/main/src/Console.zig"
click node_graphics "https://github.com/peterhellberg/nex/blob/main/src/gfx.zig"
click node_font "https://github.com/peterhellberg/nex/blob/main/src/font.zig"
click node_input "https://github.com/peterhellberg/nex/blob/main/src/input.zig"
click node_synth "https://github.com/peterhellberg/nex/blob/main/src/synth.zig"
click node_backend_api "https://github.com/peterhellberg/nex/blob/main/src/backend.zig"
click node_raylib "https://github.com/peterhellberg/nex/blob/main/src/backends/raylib.zig"
click node_kitty "https://github.com/peterhellberg/nex/blob/main/src/backends/kitty.zig"

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_cart_runtime,node_headless toneBlue
class node_zig_sdk,node_c_sdk toneAmber
class node_console,node_graphics,node_font,node_input,node_synth toneMint
class node_backend_api,node_raylib,node_kitty toneRose
class node_cart_author,node_wasm_cart toneIndigo
```

## Components

### Host Runtime

- [CLI and Loop](https://github.com/peterhellberg/nex/blob/main/src/main.zig): `src/main.zig`
- [Cart Runtime](https://github.com/peterhellberg/nex/blob/main/src/cart.zig): `src/cart.zig`
- [Headless Run](https://github.com/peterhellberg/nex/blob/main/src/main.zig): `src/main.zig`

### Cart Interface

- [Zig Cart SDK](https://github.com/peterhellberg/nex/blob/main/vex.zig): `vex.zig`
- [C Cart SDK](https://github.com/peterhellberg/nex/blob/main/vex.h): `vex.h`

### Console Services

- [Console State](https://github.com/peterhellberg/nex/blob/main/src/Console.zig): `src/Console.zig`
- [Drawing and Framebuffer](https://github.com/peterhellberg/nex/blob/main/src/gfx.zig): `src/gfx.zig`
- [Bitmap Font](https://github.com/peterhellberg/nex/blob/main/src/font.zig): `src/font.zig`
- [Input State](https://github.com/peterhellberg/nex/blob/main/src/input.zig): `src/input.zig`
- [Four-Voice Synth](https://github.com/peterhellberg/nex/blob/main/src/synth.zig): `src/synth.zig`

### Platform Output

- [Backend Layer](https://github.com/peterhellberg/nex/blob/main/src/backend.zig): `src/backend.zig`
- [Raylib Backend](https://github.com/peterhellberg/nex/blob/main/src/backends/raylib.zig): `src/backends/raylib.zig`
- [Kitty Backend](https://github.com/peterhellberg/nex/blob/main/src/backends/kitty.zig): `src/backends/kitty.zig`

### Other components

- **Cart Author**
- **WASM Cart**

## Connections

- Cart Author → Zig Cart SDK: uses (evidence: `README.md`)
- Cart Author → C Cart SDK: uses (evidence: `README.md`)
- Zig Cart SDK → WASM Cart: builds (evidence: `README.md`)
- C Cart SDK → WASM Cart: builds (evidence: `vex.h`)
- CLI and Loop → Cart Runtime: loads and runs (evidence: `README.md`)
- WASM Cart → Cart Runtime: calls imports (evidence: `README.md`)
- Cart Runtime → Console State: provides cart state (evidence: `README.md`)
- Console State → Drawing and Framebuffer: holds framebuffer (evidence: `README.md`)
- Console State → Input State: holds input state (evidence: `README.md`)
- Console State → Four-Voice Synth: holds synth state (evidence: `README.md`)
- CLI and Loop → Backend Layer: runs platform (evidence: `README.md`)
- Backend Layer → Raylib Backend: selects desktop (evidence: `README.md`)
- Backend Layer → Kitty Backend: selects terminal (evidence: `README.md`)
- Raylib Backend → Drawing and Framebuffer: presents framebuffer (evidence: `README.md`)
- Raylib Backend → Input State: feeds input (evidence: `README.md`)
- Kitty Backend → Drawing and Framebuffer: presents framebuffer (evidence: `README.md`)
- Kitty Backend → Input State: feeds input (evidence: `README.md`)
- CLI and Loop → Headless Run: supports (evidence: `README.md`)
- Headless Run → Drawing and Framebuffer: hashes or dumps (evidence: `README.md`)
