# peterhellberg/vex architecture

> Architecture diagram of the GitHub repository peterhellberg/vex, 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/vex
- Repository: https://github.com/peterhellberg/vex

## Overview

Vex is a minimal WASM fantasy console: cart authors build modules exporting boot/update and importing the console API; a host runs update at 60 fps, accepts input, renders a 320×180 framebuffer, and provides audio. The native and browser hosts are interchangeable. The graph also preserves the documented browser reload and input capabilities and the tracker audio library. Native implementation detail is concentrated in cmd/vex/main.c; browser implementation detail is limited to README and server excerpts, so browser-side links reflect documented behavior rather than inspected JavaScript internals.

Main entry points: [`cmd/vex/main.c`](https://github.com/peterhellberg/vex/blob/main/cmd/vex/main.c) (Native runtime), [`cmd/vex-web/assets/vex.js`](https://github.com/peterhellberg/vex/blob/main/cmd/vex-web/assets/vex.js) (Canvas host), [`cmd/vex-web/main.go`](https://github.com/peterhellberg/vex/blob/main/cmd/vex-web/main.go) (Web server), [`base/c/cart.c`](https://github.com/peterhellberg/vex/blob/main/base/c/cart.c) (C example cart)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cart["Cart SDK"]
  node_sdk["Console API<br/>[vex.h]"]
  node_c_cart["C example cart<br/>[cart.c]"]
  node_cpp_cart["C++ example cart<br/>[cart.cpp]"]
end

subgraph group_native["Native Host"]
  node_native_host["Native runtime<br/>[main.c]"]
  node_native_api["Native API bindings<br/>[main.c]"]
  node_framebuffer[("Framebuffer<br/>[main.c]")]
  node_native_input["Native input<br/>[main.c]"]
  node_native_audio["Native audio<br/>[main.c]"]
end

subgraph group_web["Browser Host"]
  node_web_server["Web server<br/>[main.go]"]
  node_web_page["Browser page<br/>[index.html]"]
  node_web_host["Canvas host<br/>[vex.js]"]
  node_web_input["Browser input<br/>[vex.js]"]
  node_reload["Reload events<br/>[main.go]"]
end

subgraph group_audio["Cart Audio"]
  node_tracker["Music tracker<br/>[mus.h]"]
end

node_author(("Cart author"))
node_wasm["WASM cart"]
node_browser(("Browser user"))

node_author -->|"writes"| node_c_cart
node_author -->|"writes"| node_cpp_cart
node_c_cart -->|"uses API"| node_sdk
node_cpp_cart -->|"uses API"| node_sdk
node_c_cart -->|"compiles to"| node_wasm
node_cpp_cart -.->|"compiles to"| node_wasm
node_wasm -->|"loads cart"| node_native_host
node_native_host -->|"links imports"| node_native_api
node_native_host -->|"calls update"| node_native_host
node_native_api -->|"draws into"| node_framebuffer
node_native_input -->|"supplies input"| node_native_api
node_native_api -->|"triggers tones"| node_native_audio
node_native_host -->|"renders"| node_framebuffer
node_browser -->|"opens"| node_web_page
node_web_server -->|"serves page"| node_web_page
node_web_server -->|"serves script"| node_web_host
node_web_server -->|"serves cart"| node_wasm
node_web_page -->|"loads host"| node_web_host
node_web_host -->|"runs cart"| node_wasm
node_web_input -->|"supplies input"| node_web_host
node_web_server -->|"publishes changes"| node_reload
node_reload -->|"reloads cart"| node_web_host
node_tracker -->|"uses tone API"| node_sdk
node_tracker -.->|"plays notes via"| node_native_audio

click node_sdk "https://github.com/peterhellberg/vex/blob/main/vex.h"
click node_c_cart "https://github.com/peterhellberg/vex/blob/main/base/c/cart.c"
click node_cpp_cart "https://github.com/peterhellberg/vex/blob/main/base/cpp/cart.cpp"
click node_native_host "https://github.com/peterhellberg/vex/blob/main/cmd/vex/main.c"
click node_native_api "https://github.com/peterhellberg/vex/blob/main/cmd/vex/main.c"
click node_framebuffer "https://github.com/peterhellberg/vex/blob/main/cmd/vex/main.c"
click node_native_input "https://github.com/peterhellberg/vex/blob/main/cmd/vex/main.c"
click node_native_audio "https://github.com/peterhellberg/vex/blob/main/cmd/vex/main.c"
click node_web_server "https://github.com/peterhellberg/vex/blob/main/cmd/vex-web/main.go"
click node_web_page "https://github.com/peterhellberg/vex/blob/main/cmd/vex-web/assets/index.html"
click node_web_host "https://github.com/peterhellberg/vex/blob/main/cmd/vex-web/assets/vex.js"
click node_web_input "https://github.com/peterhellberg/vex/blob/main/cmd/vex-web/assets/vex.js"
click node_reload "https://github.com/peterhellberg/vex/blob/main/cmd/vex-web/main.go"
click node_tracker "https://github.com/peterhellberg/vex/blob/main/mus.h"

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_sdk,node_c_cart,node_cpp_cart,node_browser toneBlue
class node_native_host,node_native_api,node_framebuffer,node_native_input,node_native_audio toneAmber
class node_web_server,node_web_page,node_web_host,node_web_input,node_reload toneMint
class node_tracker toneRose
class node_author,node_wasm toneIndigo
```

## Components

### Cart SDK

- [Console API](https://github.com/peterhellberg/vex/blob/main/vex.h): `vex.h`
- [C example cart](https://github.com/peterhellberg/vex/blob/main/base/c/cart.c): `base/c/cart.c`
- [C++ example cart](https://github.com/peterhellberg/vex/blob/main/base/cpp/cart.cpp): `base/cpp/cart.cpp`

### Native Host

- [Native runtime](https://github.com/peterhellberg/vex/blob/main/cmd/vex/main.c): `cmd/vex/main.c`
- [Native API bindings](https://github.com/peterhellberg/vex/blob/main/cmd/vex/main.c): `cmd/vex/main.c`
- [Framebuffer](https://github.com/peterhellberg/vex/blob/main/cmd/vex/main.c): `cmd/vex/main.c`
- [Native input](https://github.com/peterhellberg/vex/blob/main/cmd/vex/main.c): `cmd/vex/main.c`
- [Native audio](https://github.com/peterhellberg/vex/blob/main/cmd/vex/main.c): `cmd/vex/main.c`

### Browser Host

- [Web server](https://github.com/peterhellberg/vex/blob/main/cmd/vex-web/main.go): `cmd/vex-web/main.go`
- [Browser page](https://github.com/peterhellberg/vex/blob/main/cmd/vex-web/assets/index.html): `cmd/vex-web/assets/index.html`
- [Canvas host](https://github.com/peterhellberg/vex/blob/main/cmd/vex-web/assets/vex.js): `cmd/vex-web/assets/vex.js`
- [Browser input](https://github.com/peterhellberg/vex/blob/main/cmd/vex-web/assets/vex.js): `cmd/vex-web/assets/vex.js`
- [Reload events](https://github.com/peterhellberg/vex/blob/main/cmd/vex-web/main.go): `cmd/vex-web/main.go`

### Cart Audio

- [Music tracker](https://github.com/peterhellberg/vex/blob/main/mus.h): `mus.h`

### Other components

- **Cart author**
- **WASM cart**
- **Browser user**

## Connections

- Cart author → C example cart: writes (evidence: `base/c/cart.c`)
- Cart author → C++ example cart: writes (evidence: `base/cpp/cart.cpp`)
- C example cart → Console API: uses API (evidence: `base/c/cart.c`)
- C++ example cart → Console API: uses API (evidence: `base/cpp/cart.cpp`)
- C example cart → WASM cart: compiles to (evidence: `README.md`)
- C++ example cart → WASM cart: compiles to
- WASM cart → Native runtime: loads cart (evidence: `cmd/vex/main.c`)
- Native runtime → Native API bindings: links imports (evidence: `cmd/vex/main.c`)
- Native runtime → Native runtime: calls update (evidence: `cmd/vex/main.c`)
- Native API bindings → Framebuffer: draws into (evidence: `cmd/vex/main.c`)
- Native input → Native API bindings: supplies input (evidence: `cmd/vex/main.c`)
- Native API bindings → Native audio: triggers tones (evidence: `cmd/vex/main.c`)
- Native runtime → Framebuffer: renders (evidence: `README.md`)
- Browser user → Browser page: opens (evidence: `README.md`)
- Web server → Browser page: serves page (evidence: `cmd/vex-web/main.go`)
- Web server → Canvas host: serves script (evidence: `cmd/vex-web/main.go`)
- Web server → WASM cart: serves cart (evidence: `cmd/vex-web/main.go`)
- Browser page → Canvas host: loads host (evidence: `README.md`)
- Canvas host → WASM cart: runs cart (evidence: `README.md`)
- Browser input → Canvas host: supplies input (evidence: `README.md`)
- Web server → Reload events: publishes changes (evidence: `cmd/vex-web/main.go`)
- Reload events → Canvas host: reloads cart (evidence: `README.md`)
- Music tracker → Console API: uses tone API (evidence: `mus.h`)
- Music tracker → Native audio: plays notes via
