# c22dev/muguet architecture

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

- Interactive diagram: https://gitdiagram.com/c22dev/muguet
- Repository: https://github.com/c22dev/muguet

## Overview

Muguet runs the game’s WebAssembly as a native Apple-platform app, providing filesystem, host-import, graphics, audio, and input support. The usual workflow is to supply a game ZIP, import its files, configure startup, then launch the game; multiplayer adds a UDP server and in-game synchronization. The excerpts show only parts of the runtime, so some documented capability links are attributed to the README, while unsampled implementation details are not inferred.

Main entry points: [`src/main.rs`](https://github.com/c22dev/muguet/blob/main/src/main.rs) (Runtime Entry), [`src/app.rs`](https://github.com/c22dev/muguet/blob/main/src/app.rs) (App Lifecycle), [`src/mp.rs`](https://github.com/c22dev/muguet/blob/main/src/mp.rs) (Game Synchronization), [`src/input.rs`](https://github.com/c22dev/muguet/blob/main/src/input.rs) (Input State)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_startup["Startup and Game Files"]
  node_launcher["Game Launcher<br/>[Launcher.swift]"]
  node_importer["ZIP Import<br/>[import.rs]"]
  node_configuration["Startup Config<br/>[config.rs]"]
end

subgraph group_runtime["Native Game Runtime"]
  node_entry["Runtime Entry<br/>[main.rs]"]
  node_app["App Lifecycle<br/>[app.rs]"]
  node_wasmhost["Wasm Host<br/>[host.rs]"]
  node_gamefs["Game Filesystem<br/>[fs.rs]"]
  node_gameio["Game I/O<br/>[io.rs]"]
  node_gpu["Graphics Runtime<br/>[gpu.rs]"]
  node_audio["Audio Runtime<br/>[audio.rs]"]
  node_patcher["Multiplayer Hooks<br/>[patch.rs]"]
end

subgraph group_controls["Display and Controls"]
  node_input["Input State<br/>[input.rs]"]
  node_touch["Touch Controls<br/>[touch.rs]"]
  node_gamepad["Gamepad Controls<br/>[pad.rs]"]
  node_keyboard["Keyboard Controls<br/>[keyboard.rs]"]
end

subgraph group_multiplayer["Multiplayer"]
  node_multiplayer["Game Synchronization<br/>[mp.rs]"]
  node_protocol["UDP Protocol<br/>[proto.rs]"]
  node_server["UDP Server<br/>[server.rs]"]
  node_serverbin["Server Command<br/>[muguet-server.rs]"]
end

node_player(("Player"))
node_metal["Metal Graphics"]
node_wasmtime["Wasmtime Engine"]
node_udp["UDP Network"]

node_player -->|"starts or configures"| node_launcher
node_player -->|"supplies game ZIP"| node_entry
node_entry -->|"imports ZIP"| node_importer
node_entry -.->|"loads startup settings"| node_configuration
node_entry -.->|"starts app"| node_app
node_entry -->|"patches Wasm"| node_patcher
node_entry -->|"runs Wasm"| node_wasmtime
node_wasmhost -.->|"handles filesystem calls"| node_gamefs
node_wasmhost -.->|"handles I/O calls"| node_gameio
node_app -->|"creates surface"| node_gpu
node_gpu -->|"renders through"| node_metal
node_app -->|"routes key events"| node_input
node_app -->|"reloads settings"| node_configuration
node_app -->|"reports key presses"| node_multiplayer
node_touch -->|"publishes touch input"| node_input
node_touch -->|"reports key presses"| node_multiplayer
node_gamepad -.->|"publishes controls"| node_input
node_keyboard -.->|"publishes keys"| node_input
node_multiplayer -->|"encodes and decodes"| node_protocol
node_server -->|"uses packet format"| node_protocol
node_serverbin -->|"runs server"| node_server
node_player -->|"starts standalone server"| node_serverbin
node_multiplayer -->|"exchanges game state"| node_udp
node_server -->|"relays player packets"| node_udp

click node_launcher "https://github.com/c22dev/muguet/blob/main/launcher/Launcher.swift"
click node_importer "https://github.com/c22dev/muguet/blob/main/src/import.rs"
click node_configuration "https://github.com/c22dev/muguet/blob/main/src/config.rs"
click node_entry "https://github.com/c22dev/muguet/blob/main/src/main.rs"
click node_app "https://github.com/c22dev/muguet/blob/main/src/app.rs"
click node_wasmhost "https://github.com/c22dev/muguet/blob/main/src/host.rs"
click node_gamefs "https://github.com/c22dev/muguet/blob/main/src/fs.rs"
click node_gameio "https://github.com/c22dev/muguet/blob/main/src/io.rs"
click node_gpu "https://github.com/c22dev/muguet/blob/main/src/gpu.rs"
click node_audio "https://github.com/c22dev/muguet/blob/main/src/audio.rs"
click node_patcher "https://github.com/c22dev/muguet/blob/main/src/patch.rs"
click node_input "https://github.com/c22dev/muguet/blob/main/src/input.rs"
click node_touch "https://github.com/c22dev/muguet/blob/main/src/touch.rs"
click node_gamepad "https://github.com/c22dev/muguet/blob/main/src/pad.rs"
click node_keyboard "https://github.com/c22dev/muguet/blob/main/src/keyboard.rs"
click node_multiplayer "https://github.com/c22dev/muguet/blob/main/src/mp.rs"
click node_protocol "https://github.com/c22dev/muguet/blob/main/src/proto.rs"
click node_server "https://github.com/c22dev/muguet/blob/main/src/server.rs"
click node_serverbin "https://github.com/c22dev/muguet/blob/main/src/bin/muguet-server.rs"

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_launcher,node_importer,node_configuration toneBlue
class node_entry,node_app,node_wasmhost,node_gamefs,node_gameio,node_gpu,node_audio,node_patcher toneAmber
class node_input,node_touch,node_gamepad,node_keyboard toneMint
class node_multiplayer,node_protocol,node_server,node_serverbin toneRose
class node_player,node_metal,node_wasmtime,node_udp toneIndigo
```

## Components

### Startup and Game Files

- [Game Launcher](https://github.com/c22dev/muguet/blob/main/launcher/Launcher.swift): `launcher/Launcher.swift`
- [ZIP Import](https://github.com/c22dev/muguet/blob/main/src/import.rs): `src/import.rs`
- [Startup Config](https://github.com/c22dev/muguet/blob/main/src/config.rs): `src/config.rs`

### Native Game Runtime

- [Runtime Entry](https://github.com/c22dev/muguet/blob/main/src/main.rs): `src/main.rs`
- [App Lifecycle](https://github.com/c22dev/muguet/blob/main/src/app.rs): `src/app.rs`
- [Wasm Host](https://github.com/c22dev/muguet/blob/main/src/host.rs): `src/host.rs`
- [Game Filesystem](https://github.com/c22dev/muguet/blob/main/src/fs.rs): `src/fs.rs`
- [Game I/O](https://github.com/c22dev/muguet/blob/main/src/io.rs): `src/io.rs`
- [Graphics Runtime](https://github.com/c22dev/muguet/blob/main/src/gpu.rs): `src/gpu.rs`
- [Audio Runtime](https://github.com/c22dev/muguet/blob/main/src/audio.rs): `src/audio.rs`
- [Multiplayer Hooks](https://github.com/c22dev/muguet/blob/main/src/patch.rs): `src/patch.rs`

### Display and Controls

- [Input State](https://github.com/c22dev/muguet/blob/main/src/input.rs): `src/input.rs`
- [Touch Controls](https://github.com/c22dev/muguet/blob/main/src/touch.rs): `src/touch.rs`
- [Gamepad Controls](https://github.com/c22dev/muguet/blob/main/src/pad.rs): `src/pad.rs`
- [Keyboard Controls](https://github.com/c22dev/muguet/blob/main/src/keyboard.rs): `src/keyboard.rs`

### Multiplayer

- [Game Synchronization](https://github.com/c22dev/muguet/blob/main/src/mp.rs): `src/mp.rs`
- [UDP Protocol](https://github.com/c22dev/muguet/blob/main/src/proto.rs): `src/proto.rs`
- [UDP Server](https://github.com/c22dev/muguet/blob/main/src/server.rs): `src/server.rs`
- [Server Command](https://github.com/c22dev/muguet/blob/main/src/bin/muguet-server.rs): `src/bin/muguet-server.rs`

### Other components

- **Player**
- **Metal Graphics**
- **Wasmtime Engine**
- **UDP Network**

## Connections

- Player → Game Launcher: starts or configures (evidence: `README.md`)
- Player → Runtime Entry: supplies game ZIP (evidence: `README.md`)
- Runtime Entry → ZIP Import: imports ZIP (evidence: `src/main.rs`)
- Runtime Entry → Startup Config: loads startup settings (evidence: `src/main.rs`)
- Runtime Entry → App Lifecycle: starts app (evidence: `src/main.rs`)
- Runtime Entry → Multiplayer Hooks: patches Wasm (evidence: `src/main.rs`)
- Runtime Entry → Wasmtime Engine: runs Wasm (evidence: `README.md`)
- Wasm Host → Game Filesystem: handles filesystem calls (evidence: `src/host.rs`)
- Wasm Host → Game I/O: handles I/O calls (evidence: `src/host.rs`)
- App Lifecycle → Graphics Runtime: creates surface (evidence: `src/app.rs`)
- Graphics Runtime → Metal Graphics: renders through (evidence: `README.md`)
- App Lifecycle → Input State: routes key events (evidence: `src/app.rs`)
- App Lifecycle → Startup Config: reloads settings (evidence: `src/app.rs`)
- App Lifecycle → Game Synchronization: reports key presses (evidence: `src/app.rs`)
- Touch Controls → Input State: publishes touch input (evidence: `src/touch.rs`)
- Touch Controls → Game Synchronization: reports key presses (evidence: `src/touch.rs`)
- Gamepad Controls → Input State: publishes controls (evidence: `src/pad.rs`)
- Keyboard Controls → Input State: publishes keys (evidence: `src/keyboard.rs`)
- Game Synchronization → UDP Protocol: encodes and decodes (evidence: `src/mp.rs`)
- UDP Server → UDP Protocol: uses packet format (evidence: `src/server.rs`)
- Server Command → UDP Server: runs server (evidence: `README.md`)
- Player → Server Command: starts standalone server (evidence: `README.md`)
- Game Synchronization → UDP Network: exchanges game state (evidence: `README.md`)
- UDP Server → UDP Network: relays player packets (evidence: `src/server.rs`)
