# pattssun/openwii architecture

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

- Interactive diagram: https://gitdiagram.com/pattssun/openwii
- Repository: https://github.com/pattssun/openwii

## Overview

OpenWii turns motion-capable phones into networked game controllers: players scan a QR code, connect over the local network, choose a browser game, and steer or act with motion and buttons. The server relays controller packets to the browser; shared core modules decode motion, track pointers, and provide game-facing input. Games combine input with game-specific logic and rendering. The README and sampled imports establish the central relay and several game integrations; Mario Kart’s detailed runtime wiring is unsampled, so its internal links are shown as unverified.

Main entry points: [`core/channel.js`](https://github.com/pattssun/openwii/blob/main/core/channel.js) (Input channel), [`public/menu.js`](https://github.com/pattssun/openwii/blob/main/public/menu.js) (Game launcher), [`server.js`](https://github.com/pattssun/openwii/blob/main/server.js) (LAN server), [`games/mario-kart/game.js`](https://github.com/pattssun/openwii/blob/main/games/mario-kart/game.js) (Mario Kart game)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_relay["Pairing and relay"]
  node_relay_server["LAN server<br/>[server.js]"]
  node_launcher["Game launcher<br/>[menu.js]"]
end

subgraph group_engine["Motion engine"]
  node_motion_channel["Input channel<br/>[channel.js]"]
  node_game_link["Socket link<br/>[net.js]"]
  node_pointer["Motion pointer<br/>[pointer.js]"]
  node_orientation["Orientation decoder<br/>[orientation.js]"]
  node_calibration["Device calibration<br/>[calibration.js]"]
  node_gesture["Swing detector<br/>[gesture.js]"]
  node_game_audio["Game audio<br/>[audio.js]"]
end

subgraph group_games["Browser games"]
  node_fruit_game["Fruit Ninja<br/>[game.js]"]
  node_fruit_logic["Fruit gameplay<br/>[logic.js]"]
  node_alien_game["Alien Attack<br/>[game.js]"]
  node_alien_logic["Alien gameplay<br/>[logic.js]"]
  node_drawing_game["Sketch<br/>[game.js]"]
  node_drawing_logic["Drawing logic<br/>[logic.js]"]
  node_shooting_game["Shooting Range<br/>[game.js]"]
  node_shooting_logic["Target logic<br/>[logic.js]"]
  node_golf_game["Golf<br/>[game.js]"]
  node_golf_logic["Golf logic<br/>[logic.js]"]
  node_sword_game["Swordplay<br/>[game.js]"]
  node_sword_logic["Duel logic<br/>[logic.js]"]
end

subgraph group_kart["Mario Kart"]
  node_kart_game["Mario Kart game<br/>[game.js]"]
  node_kart_logic["Race logic<br/>[logic.js]"]
  node_kart_track["Track surfaces<br/>[track.js]"]
  node_kart_surface["Surface track<br/>[surface-track.js]"]
  node_kart_world["Race world<br/>[world.js]"]
  node_stadium_brands["Stadium branding<br/>[stadium-brands.js]"]
  node_stadium_service["Stadium compound<br/>[stadium-service.js]"]
end

node_phone(("Phone controller<br/>[controller.js]"))

node_phone -->|"sends motion"| node_relay_server
node_relay_server -->|"serves browser"| node_launcher
node_relay_server -->|"relays packets"| node_phone
node_launcher -->|"launches game"| node_fruit_game
node_launcher -->|"launches game"| node_alien_game
node_launcher -->|"launches game"| node_drawing_game
node_launcher -->|"launches game"| node_shooting_game
node_launcher -->|"launches game"| node_kart_game
node_relay_server -->|"serves modules"| node_motion_channel
node_motion_channel -->|"receives samples"| node_game_link
node_motion_channel -->|"updates pointer"| node_pointer
node_pointer -->|"decodes axes"| node_orientation
node_motion_channel -->|"creates audio"| node_game_audio
node_fruit_game -->|"runs gameplay"| node_fruit_logic
node_fruit_game -->|"uses pointer"| node_pointer
node_fruit_logic -->|"uses trail"| node_motion_channel
node_alien_game -->|"runs gameplay"| node_alien_logic
node_alien_game -->|"reads controller"| node_motion_channel
node_drawing_game -->|"runs drawing"| node_drawing_logic
node_drawing_game -->|"reads controller"| node_motion_channel
node_shooting_game -->|"runs targets"| node_shooting_logic
node_shooting_game -->|"reads controller"| node_motion_channel
node_golf_game -->|"runs gameplay"| node_golf_logic
node_golf_game -->|"reads controller"| node_motion_channel
node_golf_logic -.->|"uses ball physics"| node_kart_world
node_sword_game -->|"runs duel"| node_sword_logic
node_sword_game -->|"reads controller"| node_motion_channel
node_sword_game -->|"detects swings"| node_gesture
node_kart_game -.->|"uses race rules"| node_kart_logic
node_kart_game -.->|"uses track"| node_kart_track
node_kart_game -.->|"uses world"| node_kart_world
node_kart_track -->|"queries surface"| node_kart_surface
node_stadium_service -->|"queries surface"| node_kart_track
node_stadium_service -->|"uses branding"| node_stadium_brands

click node_phone "https://github.com/pattssun/openwii/blob/main/public/controller.js"
click node_relay_server "https://github.com/pattssun/openwii/blob/main/server.js"
click node_launcher "https://github.com/pattssun/openwii/blob/main/public/menu.js"
click node_motion_channel "https://github.com/pattssun/openwii/blob/main/core/channel.js"
click node_game_link "https://github.com/pattssun/openwii/blob/main/core/net.js"
click node_pointer "https://github.com/pattssun/openwii/blob/main/core/pointer.js"
click node_orientation "https://github.com/pattssun/openwii/blob/main/core/orientation.js"
click node_calibration "https://github.com/pattssun/openwii/blob/main/core/calibration.js"
click node_gesture "https://github.com/pattssun/openwii/blob/main/core/gesture.js"
click node_game_audio "https://github.com/pattssun/openwii/blob/main/core/audio.js"
click node_fruit_game "https://github.com/pattssun/openwii/blob/main/games/fruit-ninja/game.js"
click node_fruit_logic "https://github.com/pattssun/openwii/blob/main/games/fruit-ninja/logic.js"
click node_alien_game "https://github.com/pattssun/openwii/blob/main/games/alien-attack/game.js"
click node_alien_logic "https://github.com/pattssun/openwii/blob/main/games/alien-attack/logic.js"
click node_drawing_game "https://github.com/pattssun/openwii/blob/main/games/drawing/game.js"
click node_drawing_logic "https://github.com/pattssun/openwii/blob/main/games/drawing/logic.js"
click node_shooting_game "https://github.com/pattssun/openwii/blob/main/games/shooting-range/game.js"
click node_shooting_logic "https://github.com/pattssun/openwii/blob/main/games/shooting-range/logic.js"
click node_golf_game "https://github.com/pattssun/openwii/blob/main/games/golf/game.js"
click node_golf_logic "https://github.com/pattssun/openwii/blob/main/games/golf/logic.js"
click node_sword_game "https://github.com/pattssun/openwii/blob/main/games/swordplay/game.js"
click node_sword_logic "https://github.com/pattssun/openwii/blob/main/games/swordplay/logic.js"
click node_kart_game "https://github.com/pattssun/openwii/blob/main/games/mario-kart/game.js"
click node_kart_logic "https://github.com/pattssun/openwii/blob/main/games/mario-kart/logic.js"
click node_kart_track "https://github.com/pattssun/openwii/blob/main/games/mario-kart/track.js"
click node_kart_surface "https://github.com/pattssun/openwii/blob/main/games/mario-kart/surface-track.js"
click node_kart_world "https://github.com/pattssun/openwii/blob/main/games/mario-kart/world.js"
click node_stadium_brands "https://github.com/pattssun/openwii/blob/main/games/mario-kart/stadium-brands.js"
click node_stadium_service "https://github.com/pattssun/openwii/blob/main/games/mario-kart/stadium-service.js"

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_relay_server,node_launcher toneBlue
class node_motion_channel,node_game_link,node_pointer,node_orientation,node_calibration,node_gesture,node_game_audio toneAmber
class node_fruit_game,node_fruit_logic,node_alien_game,node_alien_logic,node_drawing_game,node_drawing_logic,node_shooting_game,node_shooting_logic,node_golf_game,node_golf_logic,node_sword_game,node_sword_logic toneMint
class node_kart_game,node_kart_logic,node_kart_track,node_kart_surface,node_kart_world,node_stadium_brands,node_stadium_service toneRose
class node_phone toneTeal
```

## Components

### Pairing and relay

- [LAN server](https://github.com/pattssun/openwii/blob/main/server.js): `server.js`
- [Game launcher](https://github.com/pattssun/openwii/blob/main/public/menu.js): `public/menu.js`

### Motion engine

- [Input channel](https://github.com/pattssun/openwii/blob/main/core/channel.js): `core/channel.js`
- [Socket link](https://github.com/pattssun/openwii/blob/main/core/net.js): `core/net.js`
- [Motion pointer](https://github.com/pattssun/openwii/blob/main/core/pointer.js): `core/pointer.js`
- [Orientation decoder](https://github.com/pattssun/openwii/blob/main/core/orientation.js): `core/orientation.js`
- [Device calibration](https://github.com/pattssun/openwii/blob/main/core/calibration.js): `core/calibration.js`
- [Swing detector](https://github.com/pattssun/openwii/blob/main/core/gesture.js): `core/gesture.js`
- [Game audio](https://github.com/pattssun/openwii/blob/main/core/audio.js): `core/audio.js`

### Browser games

- [Fruit Ninja](https://github.com/pattssun/openwii/blob/main/games/fruit-ninja/game.js): `games/fruit-ninja/game.js`
- [Fruit gameplay](https://github.com/pattssun/openwii/blob/main/games/fruit-ninja/logic.js): `games/fruit-ninja/logic.js`
- [Alien Attack](https://github.com/pattssun/openwii/blob/main/games/alien-attack/game.js): `games/alien-attack/game.js`
- [Alien gameplay](https://github.com/pattssun/openwii/blob/main/games/alien-attack/logic.js): `games/alien-attack/logic.js`
- [Sketch](https://github.com/pattssun/openwii/blob/main/games/drawing/game.js): `games/drawing/game.js`
- [Drawing logic](https://github.com/pattssun/openwii/blob/main/games/drawing/logic.js): `games/drawing/logic.js`
- [Shooting Range](https://github.com/pattssun/openwii/blob/main/games/shooting-range/game.js): `games/shooting-range/game.js`
- [Target logic](https://github.com/pattssun/openwii/blob/main/games/shooting-range/logic.js): `games/shooting-range/logic.js`
- [Golf](https://github.com/pattssun/openwii/blob/main/games/golf/game.js): `games/golf/game.js`
- [Golf logic](https://github.com/pattssun/openwii/blob/main/games/golf/logic.js): `games/golf/logic.js`
- [Swordplay](https://github.com/pattssun/openwii/blob/main/games/swordplay/game.js): `games/swordplay/game.js`
- [Duel logic](https://github.com/pattssun/openwii/blob/main/games/swordplay/logic.js): `games/swordplay/logic.js`

### Mario Kart

- [Mario Kart game](https://github.com/pattssun/openwii/blob/main/games/mario-kart/game.js): `games/mario-kart/game.js`
- [Race logic](https://github.com/pattssun/openwii/blob/main/games/mario-kart/logic.js): `games/mario-kart/logic.js`
- [Track surfaces](https://github.com/pattssun/openwii/blob/main/games/mario-kart/track.js): `games/mario-kart/track.js`
- [Surface track](https://github.com/pattssun/openwii/blob/main/games/mario-kart/surface-track.js): `games/mario-kart/surface-track.js`
- [Race world](https://github.com/pattssun/openwii/blob/main/games/mario-kart/world.js): `games/mario-kart/world.js`
- [Stadium branding](https://github.com/pattssun/openwii/blob/main/games/mario-kart/stadium-brands.js): `games/mario-kart/stadium-brands.js`
- [Stadium compound](https://github.com/pattssun/openwii/blob/main/games/mario-kart/stadium-service.js): `games/mario-kart/stadium-service.js`

### Other components

- [Phone controller](https://github.com/pattssun/openwii/blob/main/public/controller.js): `public/controller.js`

## Connections

- Phone controller → LAN server: sends motion
- LAN server → Game launcher: serves browser (evidence: `server.js`)
- LAN server → Phone controller: relays packets
- Game launcher → Fruit Ninja: launches game
- Game launcher → Alien Attack: launches game
- Game launcher → Sketch: launches game
- Game launcher → Shooting Range: launches game
- Game launcher → Mario Kart game: launches game
- LAN server → Input channel: serves modules (evidence: `server.js`)
- Input channel → Socket link: receives samples (evidence: `core/channel.js`)
- Input channel → Motion pointer: updates pointer (evidence: `core/channel.js`)
- Motion pointer → Orientation decoder: decodes axes (evidence: `core/pointer.js`)
- Input channel → Game audio: creates audio (evidence: `core/channel.js`)
- Fruit Ninja → Fruit gameplay: runs gameplay (evidence: `games/fruit-ninja/game.js`)
- Fruit Ninja → Motion pointer: uses pointer (evidence: `games/fruit-ninja/game.js`)
- Fruit gameplay → Input channel: uses trail (evidence: `games/fruit-ninja/logic.js`)
- Alien Attack → Alien gameplay: runs gameplay (evidence: `games/alien-attack/game.js`)
- Alien Attack → Input channel: reads controller (evidence: `games/alien-attack/game.js`)
- Sketch → Drawing logic: runs drawing (evidence: `games/drawing/game.js`)
- Sketch → Input channel: reads controller (evidence: `games/drawing/game.js`)
- Shooting Range → Target logic: runs targets (evidence: `games/shooting-range/game.js`)
- Shooting Range → Input channel: reads controller (evidence: `games/shooting-range/game.js`)
- Golf → Golf logic: runs gameplay (evidence: `games/golf/game.js`)
- Golf → Input channel: reads controller (evidence: `games/golf/game.js`)
- Golf logic → Race world: uses ball physics
- Swordplay → Duel logic: runs duel (evidence: `games/swordplay/game.js`)
- Swordplay → Input channel: reads controller (evidence: `games/swordplay/game.js`)
- Swordplay → Swing detector: detects swings (evidence: `games/swordplay/game.js`)
- Mario Kart game → Race logic: uses race rules
- Mario Kart game → Track surfaces: uses track
- Mario Kart game → Race world: uses world
- Track surfaces → Surface track: queries surface (evidence: `games/mario-kart/track.js`)
- Stadium compound → Track surfaces: queries surface (evidence: `games/mario-kart/stadium-service.js`)
- Stadium compound → Stadium branding: uses branding (evidence: `games/mario-kart/stadium-service.js`)
