# webkit/motionmark architecture

> Architecture diagram of the GitHub repository webkit/motionmark, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/webkit/motionmark
- Repository: https://github.com/webkit/motionmark

## Overview

##### Project type and purpose
- Project type: Open-source, browser-based graphics benchmark
- Purpose: Measure performance of various graphics operations (Canvas, SVG, WebGL, WebGPU, CSS, DOM) and report metrics.

##### File structure
- Top-level “MotionMark/” folder containing:
– Static HTML entry points: index.html (benchmark UI), about.html, developer.html
– resources/: core JS/CSS libraries (runner, debug-runner, statistics, extensions, strings)
– tests/: categorized test suites (3d, bouncing-particles, core, dom, simple, svg, template, text), each with HTML harness and JS resources
– unit-tests/: HTML harness plus data and JS unit-test scripts
– version/: version metadata
- Root index.html redirects into MotionMark/
- No backend or server components—runs fully in the browser.

##### README
- Confirms: “MotionMark is a graphics benchmark to measure the performance of graphics operations on the web.”

##### Main components & their interactions
a. Components:
1. User Interface Layer
– Entry HTML pages (index.html, about.html, developer.html)
– CSS (motionmark.css)
– UI JS (motionmark.js, results.js)
2. Benchmark Runner
– Core runner (benchmark-runner.js)
– Debug runner (debug-runner.js)
3. Test Suites
– Test logic (resources/…js under each suite folder)
4. Results Processor
– statistics.js (computes scores, variance, mean)
– strings.js (UI text)
5. Extensions & Configuration
– extensions.js (plugin hooks to add new tests or alter behavior)
6. Unit-Test Harness
– run-unit-tests.html, test-scripts, test data
b. Relationships / Data Flow:
1. User loads index.html → loads CSS + MotionMark runner scripts.
2. Runner initializes and reads “tests/” index → dynamically injects each suite’s HTML and test scripts.
3. Each test executes in browser’s rendering engine (Canvas, SVG, WebGL, WebGPU, DOM).
4. Test run results (timings, frame rates) flow into statistics.js.
5. statistics.js calculates metrics → passes back to runner → results.js updates UI (charts, tables).
6. Optional: debug-runner provides verbose logging instead of normal runner.
7. Developer.html documents extension points (extensions.js).
8. run-unit-tests.html loads unit tests to validate core logic (random, statistics, data import).
c. Architectural patterns and principles:
– Modular separation: UI vs. Core Runner vs. Tests vs. Statistics
– Plugin architecture for new tests via extensions.js
– Single-page, event-driven design (all control in JS)
– “Separation of concerns”: test harnesses isolate test code from runner logic.
d. Key technologies/frameworks:
– JavaScript (ES5/ES6), HTML5, CSS3
– Browser graphics APIs: Canvas2D, SVG, WebGL, WebGPU
– No server code—static hosting (GitHub Pages, CDN).

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "User Interface Layer"
        Index["index.html"]:::frontend
        About["about.html"]:::frontend
        Developer["developer.html"]:::frontend
        UI_CSS["motionmark.css"]:::frontend
        MotionMarkJS["motionmark.js"]:::frontend
        ResultsJS["results.js"]:::frontend
    end

    subgraph "Core Benchmark Engine"
        CORE_RUNNER["benchmark-runner.js"]:::core
        DEBUG_RUNNER["debug-runner.js"]:::core
        GraphJS["graph.js"]:::core
        TestsJS["tests.js"]:::core
    end

    subgraph "Test Suites"
        direction TB
        TS_ALL["3D, Bouncing, Core, DOM, Simple, SVG, Template, Text Tests"]:::tests
    end

    subgraph "Results Processor & Extensions"
        RES_STATS["statistics.js"]:::util
        RES_STRINGS["strings.js"]:::util
        EXTENSIONS["extensions.js"]:::util
    end

    subgraph "Unit-Test Harness"
        UT_HARNESS["run-unit-tests.html"]:::unit
        UT_SCRIPTS["test-data-import.js, test-random.js, test-statistics.js"]:::unit
        UT_DATA["two-suite-single-iteration-test-data.json"]:::unit
    end

    Index -->|"loads"| CORE_RUNNER
    About -->|"loads"| CORE_RUNNER
    Developer -->|"loads"| CORE_RUNNER
    Index -->|"loads"| DEBUG_RUNNER

    CORE_RUNNER -->|"loads test suites"| TS_ALL
    DEBUG_RUNNER -->|"verbose run"| TS_ALL

    TS_ALL -->|"timing data"| RES_STATS
    RES_STATS -->|"metrics"| ResultsJS
    ResultsJS -->|"render charts"| Index

    ResultsJS -->|"hook calls"| EXTENSIONS

    UT_HARNESS -->|"load tests"| UT_SCRIPTS
    UT_SCRIPTS -->|"uses data"| UT_DATA

    click Index "https://github.com/webkit/motionmark/blob/main/MotionMark/index.html"
    click About "https://github.com/webkit/motionmark/blob/main/MotionMark/about.html"
    click Developer "https://github.com/webkit/motionmark/blob/main/MotionMark/developer.html"
    click UI_CSS "https://github.com/webkit/motionmark/blob/main/MotionMark/resources/runner/motionmark.css"
    click MotionMarkJS "https://github.com/webkit/motionmark/blob/main/MotionMark/resources/runner/motionmark.js"
    click ResultsJS "https://github.com/webkit/motionmark/blob/main/MotionMark/resources/runner/results.js"
    click CORE_RUNNER "https://github.com/webkit/motionmark/blob/main/MotionMark/resources/runner/benchmark-runner.js"
    click DEBUG_RUNNER "https://github.com/webkit/motionmark/blob/main/MotionMark/resources/debug-runner/debug-runner.js"
    click GraphJS "https://github.com/webkit/motionmark/blob/main/MotionMark/resources/debug-runner/graph.js"
    click TestsJS "https://github.com/webkit/motionmark/blob/main/MotionMark/resources/debug-runner/tests.js"
    click RES_STATS "https://github.com/webkit/motionmark/blob/main/MotionMark/resources/statistics.js"
    click RES_STRINGS "https://github.com/webkit/motionmark/blob/main/MotionMark/resources/strings.js"
    click EXTENSIONS "https://github.com/webkit/motionmark/blob/main/MotionMark/resources/extensions.js"
    click UT_HARNESS "https://github.com/webkit/motionmark/blob/main/MotionMark/unit-tests/run-unit-tests.html"
    click UT_SCRIPTS "https://github.com/webkit/motionmark/blob/main/MotionMark/unit-tests/tests/test-data-import.js"
    click UT_DATA "https://github.com/webkit/motionmark/blob/main/MotionMark/unit-tests/data/two-suite-single-iteration-test-data.json"

    classDef frontend fill:#bbdefb,stroke:#0d47a1,color:#0d47a1
    classDef core fill:#c8e6c9,stroke:#1b5e20,color:#1b5e20
    classDef tests fill:#ffe0b2,stroke:#e65100,color:#e65100
    classDef util fill:#e1bee7,stroke:#4a148c,color:#4a148c
    classDef unit fill:#eceff1,stroke:#37474f,color:#37474f
```
