# rzr/twins architecture

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

- Interactive diagram: https://gitdiagram.com/rzr/twins
- Repository: https://github.com/rzr/twins

## Overview

TWINS is a proof-of-concept digital twin for a robot: clients set joint properties through a WebThing server, which selects simulated or board-backed behavior; an A-Frame page visualizes the twin. The graph includes both runtime branches and the documented visualization and gateway usage. Links to the A-Frame page and gateway are documented at a high level; unsampled page wiring is not inferred beyond that.

Main entry points: [`index.js`](https://github.com/rzr/twins/blob/master/index.js) (Runtime selector), [`lib/index.js`](https://github.com/rzr/twins/blob/master/lib/index.js) (Robot WebThing), [`aframe/index.html`](https://github.com/rzr/twins/blob/master/aframe/index.html) (Visualization page), [`lib/simulator/index.js`](https://github.com/rzr/twins/blob/master/lib/simulator/index.js) (Simulator server)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime and API"]
  node_entry["Runtime selector<br/>[index.js]"]
  node_sim["Simulator server<br/>[index.js]"]
  node_hardware["Robot WebThing<br/>[index.js]"]
  node_webthing["WebThing service"]
end

subgraph group_actuation["Actuation"]
  node_pwmproperty["PWM property<br/>[pwm-property.js]"]
  node_pwm["PWM device"]
end

subgraph group_visual["Visualization"]
  node_visualizer["A-Frame robot<br/>[index.js]"]
  node_viewer["Visualization page<br/>[index.html]"]
end

subgraph group_deployment["Board deployment"]
  node_nuttx["NuttX launcher<br/>[index.js]"]
  node_boardconfig["Board configuration"]
end

node_client(("API client"))
node_gateway["WebThing Gateway"]

node_client -->|"starts"| node_entry
node_entry -->|"selects simulation"| node_sim
node_entry -->|"selects board"| node_hardware
node_sim -->|"starts server"| node_webthing
node_hardware -->|"starts server"| node_webthing
node_hardware -->|"creates properties"| node_pwmproperty
node_pwmproperty -->|"sets duty cycle"| node_pwm
node_client -->|"sets properties"| node_webthing
node_viewer -->|"renders robot"| node_visualizer
node_webthing -.->|"visualizes twin"| node_viewer
node_gateway -.->|"provides gateway view"| node_viewer
node_nuttx -->|"starts app"| node_entry
node_boardconfig -.->|"configures board"| node_hardware

click node_entry "https://github.com/rzr/twins/blob/master/index.js"
click node_sim "https://github.com/rzr/twins/blob/master/lib/simulator/index.js"
click node_hardware "https://github.com/rzr/twins/blob/master/lib/index.js"
click node_pwmproperty "https://github.com/rzr/twins/blob/master/lib/pwm-property.js"
click node_visualizer "https://github.com/rzr/twins/blob/master/aframe/index.js"
click node_viewer "https://github.com/rzr/twins/blob/master/aframe/index.html"
click node_nuttx "https://github.com/rzr/twins/blob/master/extra/nuttx/index.js"
click node_boardconfig "https://github.com/rzr/twins/blob/master/extra/nuttx/configs/nucleo-144/f767-twins/defconfig"

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_entry,node_sim,node_hardware,node_webthing,node_client toneBlue
class node_pwmproperty,node_pwm toneAmber
class node_visualizer,node_viewer toneMint
class node_nuttx,node_boardconfig toneRose
class node_gateway toneIndigo
```

## Components

### Runtime and API

- [Runtime selector](https://github.com/rzr/twins/blob/master/index.js): `index.js`
- [Simulator server](https://github.com/rzr/twins/blob/master/lib/simulator/index.js): `lib/simulator/index.js`
- [Robot WebThing](https://github.com/rzr/twins/blob/master/lib/index.js): `lib/index.js`
- **WebThing service**

### Actuation

- [PWM property](https://github.com/rzr/twins/blob/master/lib/pwm-property.js): `lib/pwm-property.js`
- **PWM device**

### Visualization

- [A-Frame robot](https://github.com/rzr/twins/blob/master/aframe/index.js): `aframe/index.js`
- [Visualization page](https://github.com/rzr/twins/blob/master/aframe/index.html): `aframe/index.html`

### Board deployment

- [NuttX launcher](https://github.com/rzr/twins/blob/master/extra/nuttx/index.js): `extra/nuttx/index.js`
- [Board configuration](https://github.com/rzr/twins/blob/master/extra/nuttx/configs/nucleo-144/f767-twins/defconfig): `extra/nuttx/configs/nucleo-144/f767-twins/defconfig`

### Other components

- **API client**
- **WebThing Gateway**

## Connections

- API client → Runtime selector: starts (evidence: `README.md`)
- Runtime selector → Simulator server: selects simulation (evidence: `index.js`)
- Runtime selector → Robot WebThing: selects board (evidence: `index.js`)
- Simulator server → WebThing service: starts server (evidence: `lib/simulator/index.js`)
- Robot WebThing → WebThing service: starts server (evidence: `lib/index.js`)
- Robot WebThing → PWM property: creates properties (evidence: `lib/index.js`)
- PWM property → PWM device: sets duty cycle (evidence: `lib/pwm-property.js`)
- API client → WebThing service: sets properties (evidence: `README.md`)
- Visualization page → A-Frame robot: renders robot (evidence: `README.md`)
- WebThing service → Visualization page: visualizes twin (evidence: `README.md`)
- WebThing Gateway → Visualization page: provides gateway view (evidence: `README.md`)
- NuttX launcher → Runtime selector: starts app (evidence: `extra/nuttx/index.js`)
- Board configuration → Robot WebThing: configures board
