# andymutale/rosegold-xr architecture

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

## Overview

Rosegold XR is a browser-based 3D Pac-Man prototype with mobile controls and experimental room-scale AR. The runtime starts in `src/main.ts`: it creates the game and Three.js scene, connects keyboard/swipe input, and drives rendering and HUD updates. In AR, it scans room geometry, optionally generates a maze sized to a detected floor, and places the board using hit-test or floor-fitting data. The graph preserves the major gameplay, rendering, validation, and XR modules listed in the source index. Some runtime-loop details are unsampled; those relationships are omitted rather than inferred.

Main entry points: [`src/main.ts`](https://github.com/andymutale/rosegold-xr/blob/main/src/main.ts) (Runtime coordinator), [`src/game/game.ts`](https://github.com/andymutale/rosegold-xr/blob/main/src/game/game.ts) (Game controller), [`src/ui/hud.ts`](https://github.com/andymutale/rosegold-xr/blob/main/src/ui/hud.ts) (Game HUD), [`src/input/keyboardInput.ts`](https://github.com/andymutale/rosegold-xr/blob/main/src/input/keyboardInput.ts) (Keyboard controls)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_orchestration["Runtime orchestration"]
  node_main["Runtime coordinator<br/>[main.ts]"]
end

subgraph group_gameplay["Game rules"]
  node_game["Game controller<br/>[game.ts]"]
  node_maze["Maze parsing<br/>[maze.ts]"]
  node_movement["Player movement<br/>[movement.ts]"]
  node_ghost["Ghost movement<br/>[ghostMovement.ts]"]
  node_pellets["Pellet scoring<br/>[pellets.ts]"]
  node_roommaze["Room maze generation"]
  node_types["Game data types<br/>[types.ts]"]
end

subgraph group_presentation["Controls and display"]
  node_keyboard["Keyboard controls<br/>[keyboardInput.ts]"]
  node_swipe["Swipe controls<br/>[swipeInput.ts]"]
  node_scene["Three.js scene<br/>[scene.ts]"]
  node_board["Maze board renderer<br/>[boardRenderer.ts]"]
  node_character["Character renderer"]
  node_coordinates["World coordinates<br/>[coordinates.ts]"]
  node_marker["Placement marker<br/>[placementMarker.ts]"]
  node_hud["Game HUD<br/>[hud.ts]"]
  node_schemas["State validation<br/>[schemas.ts]"]
end

subgraph group_xr["Room-scale XR"]
  node_arsession["AR session adapter<br/>[arSession.ts]"]
  node_hittest["Surface hit testing<br/>[hitTest.ts]"]
  node_room["Room understanding"]
end

node_player(("Player"))
node_browser{{"Browser XR"}}

node_player -->|"presses keys"| node_keyboard
node_player -->|"swipes screen"| node_swipe
node_keyboard -->|"requests direction"| node_game
node_swipe -->|"requests direction"| node_game
node_main -->|"creates and steps"| node_game
node_main -->|"generates layout"| node_roommaze
node_game -->|"parses layout"| node_maze
node_game -->|"moves player"| node_movement
node_game -->|"scores pellets"| node_pellets
node_game -->|"moves ghost"| node_ghost
node_game -->|"uses game types"| node_types
node_main -->|"creates scene"| node_scene
node_main -->|"creates and draws"| node_board
node_main -->|"creates renderer"| node_character
node_main -->|"updates status"| node_hud
node_board -->|"maps grid cells"| node_coordinates
node_character -->|"maps positions"| node_coordinates
node_hud -->|"counts remaining"| node_pellets
node_hud -->|"validates state"| node_schemas
node_main -->|"creates AR session"| node_arsession
node_main -->|"queries placement"| node_hittest
node_main -->|"creates room scan"| node_room
node_main -->|"places marker"| node_marker
node_arsession -->|"requests WebXR"| node_browser
node_browser -.->|"provides room data"| node_room

click node_main "https://github.com/andymutale/rosegold-xr/blob/main/src/main.ts"
click node_game "https://github.com/andymutale/rosegold-xr/blob/main/src/game/game.ts"
click node_maze "https://github.com/andymutale/rosegold-xr/blob/main/src/game/maze.ts"
click node_movement "https://github.com/andymutale/rosegold-xr/blob/main/src/game/movement.ts"
click node_ghost "https://github.com/andymutale/rosegold-xr/blob/main/src/game/ghostMovement.ts"
click node_pellets "https://github.com/andymutale/rosegold-xr/blob/main/src/game/pellets.ts"
click node_roommaze "https://github.com/andymutale/rosegold-xr/blob/main/src/game/generateRoomMaze.ts"
click node_types "https://github.com/andymutale/rosegold-xr/blob/main/src/game/types.ts"
click node_keyboard "https://github.com/andymutale/rosegold-xr/blob/main/src/input/keyboardInput.ts"
click node_swipe "https://github.com/andymutale/rosegold-xr/blob/main/src/input/swipeInput.ts"
click node_scene "https://github.com/andymutale/rosegold-xr/blob/main/src/render/scene.ts"
click node_board "https://github.com/andymutale/rosegold-xr/blob/main/src/render/boardRenderer.ts"
click node_character "https://github.com/andymutale/rosegold-xr/blob/main/src/render/characterRenderer.ts"
click node_coordinates "https://github.com/andymutale/rosegold-xr/blob/main/src/render/coordinates.ts"
click node_marker "https://github.com/andymutale/rosegold-xr/blob/main/src/render/placementMarker.ts"
click node_hud "https://github.com/andymutale/rosegold-xr/blob/main/src/ui/hud.ts"
click node_schemas "https://github.com/andymutale/rosegold-xr/blob/main/src/validation/schemas.ts"
click node_arsession "https://github.com/andymutale/rosegold-xr/blob/main/src/xr/arSession.ts"
click node_hittest "https://github.com/andymutale/rosegold-xr/blob/main/src/xr/hitTest.ts"
click node_room "https://github.com/andymutale/rosegold-xr/blob/main/src/xr/roomUnderstanding.ts"

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_browser toneBlue
class node_game,node_maze,node_movement,node_ghost,node_pellets,node_roommaze,node_types toneAmber
class node_keyboard,node_swipe,node_scene,node_board,node_character,node_coordinates,node_marker,node_hud,node_schemas toneMint
class node_arsession,node_hittest,node_room toneRose
class node_player toneIndigo
```

## Components

### Runtime orchestration

- [Runtime coordinator](https://github.com/andymutale/rosegold-xr/blob/main/src/main.ts): `src/main.ts`

### Game rules

- [Game controller](https://github.com/andymutale/rosegold-xr/blob/main/src/game/game.ts): `src/game/game.ts`
- [Maze parsing](https://github.com/andymutale/rosegold-xr/blob/main/src/game/maze.ts): `src/game/maze.ts`
- [Player movement](https://github.com/andymutale/rosegold-xr/blob/main/src/game/movement.ts): `src/game/movement.ts`
- [Ghost movement](https://github.com/andymutale/rosegold-xr/blob/main/src/game/ghostMovement.ts): `src/game/ghostMovement.ts`
- [Pellet scoring](https://github.com/andymutale/rosegold-xr/blob/main/src/game/pellets.ts): `src/game/pellets.ts`
- [Room maze generation](https://github.com/andymutale/rosegold-xr/blob/main/src/game/generateRoomMaze.ts): `src/game/generateRoomMaze.ts`
- [Game data types](https://github.com/andymutale/rosegold-xr/blob/main/src/game/types.ts): `src/game/types.ts`

### Controls and display

- [Keyboard controls](https://github.com/andymutale/rosegold-xr/blob/main/src/input/keyboardInput.ts): `src/input/keyboardInput.ts`
- [Swipe controls](https://github.com/andymutale/rosegold-xr/blob/main/src/input/swipeInput.ts): `src/input/swipeInput.ts`
- [Three.js scene](https://github.com/andymutale/rosegold-xr/blob/main/src/render/scene.ts): `src/render/scene.ts`
- [Maze board renderer](https://github.com/andymutale/rosegold-xr/blob/main/src/render/boardRenderer.ts): `src/render/boardRenderer.ts`
- [Character renderer](https://github.com/andymutale/rosegold-xr/blob/main/src/render/characterRenderer.ts): `src/render/characterRenderer.ts`
- [World coordinates](https://github.com/andymutale/rosegold-xr/blob/main/src/render/coordinates.ts): `src/render/coordinates.ts`
- [Placement marker](https://github.com/andymutale/rosegold-xr/blob/main/src/render/placementMarker.ts): `src/render/placementMarker.ts`
- [Game HUD](https://github.com/andymutale/rosegold-xr/blob/main/src/ui/hud.ts): `src/ui/hud.ts`
- [State validation](https://github.com/andymutale/rosegold-xr/blob/main/src/validation/schemas.ts): `src/validation/schemas.ts`

### Room-scale XR

- [AR session adapter](https://github.com/andymutale/rosegold-xr/blob/main/src/xr/arSession.ts): `src/xr/arSession.ts`
- [Surface hit testing](https://github.com/andymutale/rosegold-xr/blob/main/src/xr/hitTest.ts): `src/xr/hitTest.ts`
- [Room understanding](https://github.com/andymutale/rosegold-xr/blob/main/src/xr/roomUnderstanding.ts): `src/xr/roomUnderstanding.ts`

### Other components

- **Player**
- **Browser XR**

## Connections

- Player → Keyboard controls: presses keys
- Player → Swipe controls: swipes screen
- Keyboard controls → Game controller: requests direction (evidence: `src/main.ts`)
- Swipe controls → Game controller: requests direction (evidence: `src/main.ts`)
- Runtime coordinator → Game controller: creates and steps (evidence: `src/main.ts`)
- Runtime coordinator → Room maze generation: generates layout (evidence: `src/main.ts`)
- Game controller → Maze parsing: parses layout (evidence: `src/game/game.ts`)
- Game controller → Player movement: moves player (evidence: `src/game/game.ts`)
- Game controller → Pellet scoring: scores pellets (evidence: `src/game/game.ts`)
- Game controller → Ghost movement: moves ghost (evidence: `src/game/game.ts`)
- Game controller → Game data types: uses game types (evidence: `src/game/game.ts`)
- Runtime coordinator → Three.js scene: creates scene (evidence: `src/main.ts`)
- Runtime coordinator → Maze board renderer: creates and draws (evidence: `src/main.ts`)
- Runtime coordinator → Character renderer: creates renderer (evidence: `src/main.ts`)
- Runtime coordinator → Game HUD: updates status (evidence: `src/main.ts`)
- Maze board renderer → World coordinates: maps grid cells (evidence: `src/render/boardRenderer.ts`)
- Character renderer → World coordinates: maps positions (evidence: `src/render/characterRenderer.ts`)
- Game HUD → Pellet scoring: counts remaining (evidence: `src/ui/hud.ts`)
- Game HUD → State validation: validates state (evidence: `src/ui/hud.ts`)
- Runtime coordinator → AR session adapter: creates AR session (evidence: `src/main.ts`)
- Runtime coordinator → Surface hit testing: queries placement (evidence: `src/main.ts`)
- Runtime coordinator → Room understanding: creates room scan (evidence: `src/main.ts`)
- Runtime coordinator → Placement marker: places marker (evidence: `src/main.ts`)
- AR session adapter → Browser XR: requests WebXR (evidence: `src/xr/arSession.ts`)
- Browser XR → Room understanding: provides room data
