# wagerfield/parallax architecture

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

- Interactive diagram: https://gitdiagram.com/wagerfield/parallax
- Repository: https://github.com/wagerfield/parallax

## Overview

Parallax.js is a browser library that moves scene layers in response to device orientation/motion, falling back to cursor input. Users provide a scene and configuration; the engine selects layers, collects input, transforms it into smoothed and bounded offsets, and applies positions. The single runtime module also covers calibration, runtime setters, lifecycle control, and feature detection. README documents these capabilities, but the source excerpt omits parts of their implementation, so the graph keeps relationships at the module boundary.

Main entry points: [`src/parallax.js`](https://github.com/wagerfield/parallax/blob/master/src/parallax.js) (Parallax instance)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_engine["Parallax engine"]
  node_parallax["Parallax instance<br/>[parallax.js]"]
  node_config["Configuration and methods<br/>[parallax.js]"]
  node_feature["Feature detection<br/>[parallax.js]"]
end

subgraph group_input["Input sources"]
  node_orientation["Device orientation"]
  node_device_motion["Device motion"]
  node_cursor["Cursor input"]
end

subgraph group_motion["Motion processing"]
  node_input_select["Input selection<br/>[parallax.js]"]
  node_calibration["Input calibration<br/>[parallax.js]"]
  node_motion_transform["Motion transform<br/>[parallax.js]"]
  node_smoothing["Smoothing and limits<br/>[parallax.js]"]
end

subgraph group_layers["Layer output"]
  node_layer_select["Layer selection<br/>[parallax.js]"]
  node_depth["Layer depth<br/>[parallax.js]"]
  node_position["Layer positioning<br/>[parallax.js]"]
end

node_user(("Application developer"))
node_scene["Scene and options"]
node_scene_layers["Scene layers"]
node_raf["Animation frame scheduler"]

node_user -->|"configures"| node_scene
node_user -->|"creates"| node_parallax
node_scene -->|"initializes"| node_parallax
node_parallax -->|"reads settings"| node_config
node_parallax -->|"checks support"| node_feature
node_parallax -->|"updates layers"| node_layer_select
node_scene_layers -->|"provides elements"| node_layer_select
node_parallax -->|"registers input"| node_input_select
node_orientation -.->|"supplies events"| node_input_select
node_device_motion -.->|"supplies events"| node_input_select
node_cursor -->|"supplies events"| node_input_select
node_input_select -->|"calibrates input"| node_calibration
node_calibration -->|"provides input"| node_motion_transform
node_motion_transform -->|"computes motion"| node_smoothing
node_parallax -->|"updates each frame"| node_smoothing
node_smoothing -->|"scales by depth"| node_depth
node_layer_select -.->|"provides layers"| node_depth
node_depth -->|"computes offsets"| node_position
node_position -->|"sets positions"| node_scene_layers
node_parallax -->|"requests frames"| node_raf
node_raf -.->|"runs frame callback"| node_parallax
node_config -->|"updates at runtime"| node_parallax

click node_parallax "https://github.com/wagerfield/parallax/blob/master/src/parallax.js"
click node_config "https://github.com/wagerfield/parallax/blob/master/src/parallax.js"
click node_feature "https://github.com/wagerfield/parallax/blob/master/src/parallax.js"
click node_input_select "https://github.com/wagerfield/parallax/blob/master/src/parallax.js"
click node_calibration "https://github.com/wagerfield/parallax/blob/master/src/parallax.js"
click node_motion_transform "https://github.com/wagerfield/parallax/blob/master/src/parallax.js"
click node_smoothing "https://github.com/wagerfield/parallax/blob/master/src/parallax.js"
click node_layer_select "https://github.com/wagerfield/parallax/blob/master/src/parallax.js"
click node_depth "https://github.com/wagerfield/parallax/blob/master/src/parallax.js"
click node_position "https://github.com/wagerfield/parallax/blob/master/src/parallax.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_parallax,node_config,node_feature toneBlue
class node_orientation,node_device_motion,node_cursor toneAmber
class node_input_select,node_calibration,node_motion_transform,node_smoothing toneMint
class node_layer_select,node_depth,node_position,node_raf toneRose
class node_user,node_scene,node_scene_layers toneIndigo
```

## Components

### Parallax engine

- [Parallax instance](https://github.com/wagerfield/parallax/blob/master/src/parallax.js): `src/parallax.js`
- [Configuration and methods](https://github.com/wagerfield/parallax/blob/master/src/parallax.js): `src/parallax.js`
- [Feature detection](https://github.com/wagerfield/parallax/blob/master/src/parallax.js): `src/parallax.js`

### Input sources

- **Device orientation**
- **Device motion**
- **Cursor input**

### Motion processing

- [Input selection](https://github.com/wagerfield/parallax/blob/master/src/parallax.js): `src/parallax.js`
- [Input calibration](https://github.com/wagerfield/parallax/blob/master/src/parallax.js): `src/parallax.js`
- [Motion transform](https://github.com/wagerfield/parallax/blob/master/src/parallax.js): `src/parallax.js`
- [Smoothing and limits](https://github.com/wagerfield/parallax/blob/master/src/parallax.js): `src/parallax.js`

### Layer output

- [Layer selection](https://github.com/wagerfield/parallax/blob/master/src/parallax.js): `src/parallax.js`
- [Layer depth](https://github.com/wagerfield/parallax/blob/master/src/parallax.js): `src/parallax.js`
- [Layer positioning](https://github.com/wagerfield/parallax/blob/master/src/parallax.js): `src/parallax.js`

### Other components

- **Application developer**
- **Scene and options**
- **Scene layers**
- **Animation frame scheduler**

## Connections

- Application developer → Scene and options: configures (evidence: `README.md`)
- Application developer → Parallax instance: creates (evidence: `README.md`)
- Scene and options → Parallax instance: initializes (evidence: `README.md`)
- Parallax instance → Configuration and methods: reads settings (evidence: `src/parallax.js`)
- Parallax instance → Feature detection: checks support (evidence: `src/parallax.js`)
- Parallax instance → Layer selection: updates layers (evidence: `src/parallax.js`)
- Scene layers → Layer selection: provides elements (evidence: `README.md`)
- Parallax instance → Input selection: registers input (evidence: `src/parallax.js`)
- Device orientation → Input selection: supplies events
- Device motion → Input selection: supplies events
- Cursor input → Input selection: supplies events (evidence: `src/parallax.js`)
- Input selection → Input calibration: calibrates input (evidence: `src/parallax.js`)
- Input calibration → Motion transform: provides input (evidence: `src/parallax.js`)
- Motion transform → Smoothing and limits: computes motion (evidence: `src/parallax.js`)
- Parallax instance → Smoothing and limits: updates each frame (evidence: `src/parallax.js`)
- Smoothing and limits → Layer depth: scales by depth (evidence: `src/parallax.js`)
- Layer selection → Layer depth: provides layers (evidence: `src/parallax.js`)
- Layer depth → Layer positioning: computes offsets (evidence: `src/parallax.js`)
- Layer positioning → Scene layers: sets positions (evidence: `src/parallax.js`)
- Parallax instance → Animation frame scheduler: requests frames (evidence: `src/parallax.js`)
- Animation frame scheduler → Parallax instance: runs frame callback
- Configuration and methods → Parallax instance: updates at runtime (evidence: `README.md`)
