---
title: "2. Architecture · glance"
description: "glance has three layers. Only the first touches the page."
canonical: "https://glance.avarok.net/docs/design/02-architecture/"
lastmod: "2026-11-29T20:08:54Z"
tokens: 1656
---

1. [Docs](https://glance.avarok.net/docs/)
2. [Design](https://glance.avarok.net/docs/design/)

# 2\. Architecture

@avarok/glance@0.1.0·Updated 2026-11-29·3 min read·[View as markdown](https://glance.avarok.net/docs/design/02-architecture/index.md)

glance has three layers. Only the first touches the page.

```
 page ──► collector (JS, in page) ──► snapshot buffers ──► core (Rust → wasm32) ──► raw results
                ▲                                              │
                └──────── host calls (hit test, selector) ◄────┘
 raw results ──► API layer (JS) ──► axe-compatible results object, messages, reporters
```

## 2.1 Collector (TypeScript, runs in the page)

One walk of the flattened tree: light DOM, open shadow roots, and slotted nodes in composed order, the same tree assistive technology sees. For each node it appends to flat, typed columns:

- structure: node kind, parent, first child, next sibling, shadow-host and slot links, owning document (for same-origin frames);
- names: tag and attribute names and values interned into one string table, so a rule compares integers, not strings;
- properties the DOM computes and markup does not show: `tabIndex`, `disabled`, `inert`, `checked`, form-control `type` and `value`, `lang` inheritance roots, `labels`;
- the computed styles the rules need, read once per element through `getComputedStyle`, stored as interned value ids;
- layout: one border box per element, client rects for inline elements, client rects for text nodes, and scroll extents only for elements whose overflow is not `visible`.

Context selectors (`include`/`exclude`) and user selectors are resolved by the browser (`querySelectorAll`) and passed as flags, so glance never needs a CSS selector engine of its own to decide scope. The page is read once; every rule shares the read.

The collector reads, never writes. It keeps no state between runs except a `WeakMap` from element to node index, rebuilt on every run.

## 2.2 Core (Rust, `no_std` + `alloc`, compiled to `wasm32-unknown-unknown`)

Pure functions over the snapshot (SBIO): no DOM, no clock, no allocator tricks.

- `snapshot`: the arena. Struct-of-arrays over node indices; strings by id.
- `facts`: one pass computing per-node facts that many rules share: visual hiddenness, hiddenness to assistive technology, explicit and implicit role, focusable and tabbable, language. The accessible name and description are memoised and computed only when a rule asks.
- `aria`: the WAI-ARIA 1.2 and ARIA-in-HTML tables (roles, attributes, value types, allowed, required and prohibited attributes, required context and owned elements) as `const` data.
- `rules`: each rule is a definition (id, tags, impact, an applicability predicate, and its checks grouped any/all/none). Rules do not select nodes themselves: a compiled dispatcher indexes rules by tag and role, walks the nodes once and hands each node to the rules that can apply to it.
- `paint`: colour parsing, alpha compositing, relative luminance and contrast. The background of a text run comes from its ancestors' backgrounds in the snapshot; only a run whose box intersects another painted box that is not an ancestor needs a hit test.
- `results`: a compact list of (rule, node, outcome, check ids, check data) serialised as JSON for the API layer.

Host calls are the only way the core reaches back to the page, defined as a trait (`Host`) and implemented by the wasm bindings with imported JS functions: `elements_from_point(x, y)` for the overlap cases of colour contrast and target size, and `unique_selector(node)` for result targets. Tests implement `Host` over a fixture snapshot without a browser.

## 2.3 API layer (TypeScript)

Reproduces the reference interface ([chapter 1](https://glance.avarok.net/docs/design/01-interface/)): `run`, `configure`, `getRules`, `reset`, `setup`/`teardown`, `runPartial`/`finishRun`, `registerPlugin`, `frameMessenger`, reporters, `version` and `source`. It turns the core's raw results into the results object (order, impact roll-up, `failureSummary`, `helpUrl`, `target`, `ancestry`, `xpath`) with messages written for glance. Rule metadata and messages live in one table (`rules.json`, the single source of truth). The Rust rule list, the TypeScript types, `getRules()` and COMPAT.md are generated from it or checked against it in CI.

## 2.4 Builds

- `glance.js` / `glance.min.js`: one self-contained script. It defines `window.axe` with the wasm module embedded as bytes. This is the string exported as `source`, so tools that inject the reference's `source` (such as @axe-core/playwright and Lighthouse) can inject glance unchanged.
- `axe.js` / `axe.min.js` aliases inside the npm package, so path-based imports resolve.
- The wasm module compiles asynchronously on first `run`. The synchronous APIs (`getRules`, `configure`, `reset`) never need it.

## 2.5 Scope and failure

- Rules glance does not implement are absent from `getRules()`, and COMPAT.md lists them. Naming one in `runOnly` or `rules` throws the same error the reference throws for an unknown rule. Nothing is silently reported as passing.
- Custom checks and rules from `configure` whose `evaluate` is a JS function run in the API layer against the real elements that the rule's selector matches, after the core pass. They are correct but not fast.
- Every error from the core reaches the caller as a rejected `run` promise or the callback's error argument. Nothing is swallowed.

```json
{
  "@context": "https://schema.org",
  "@graph": [
    {
      "@id": "https://thomaspbraun.com/#person",
      "@type": "Person",
      "name": "Thomas Braun",
      "sameAs": [
        "https://github.com/tbraun96",
        "https://x.com/tbraun96"
      ],
      "url": "https://thomaspbraun.com",
      "worksFor": {
        "@type": "Organization",
        "name": "Avarok",
        "url": "https://avarok.net"
      }
    },
    {
      "@id": "https://glance.avarok.net/docs/design/02-architecture/",
      "@type": "WebPage",
      "author": {
        "@id": "https://thomaspbraun.com/#person"
      },
      "dateModified": "2026-11-29T20:08:54Z",
      "description": "glance has three layers. Only the first touches the page.",
      "inLanguage": "en",
      "isPartOf": {
        "@id": "https://glance.avarok.net/#website",
        "@type": "WebSite",
        "name": "glance",
        "url": "https://glance.avarok.net/"
      },
      "name": "2. Architecture · glance",
      "url": "https://glance.avarok.net/docs/design/02-architecture/"
    }
  ]
}
```
