Skip to content

Architecture

github-actions[bot] edited this page Nov 26, 2026 · 3 revisions

Architecture

Omnisnap is one Go binary, omnisnap, built from cmd/omnisnap. main only calls cli.Main, which returns an exit code and never calls os.Exit, so the whole program is testable as a function (internal/cli/root.go). The npm and PyPI packages and the GitHub Action all run this binary; none of them reimplements anything.

A second binary, omnisnap-lab (cmd/omnisnap-lab), is the ground-truth tooling: the crawl, mutation testing, the dataset and the fingerprint table. It shares the capture pipeline with the product and is never released (Ground truth and the model).

One job, end to end

omnisnap <url> and omnisnap run job.json both end in runJob (internal/cli/run.go). It runs in two halves: capture, which talks to browsers and writes files, and analysis, which reads those files and is pure computation.

flowchart TD
    J[job.json or a URL] --> R[resolve the job<br/>defaults, slugs]
    R --> D[Discovery<br/>installed browsers]
    D --> P[makePlan<br/>baseline + engines]
    P --> L[Launch one browser per engine<br/>Process management + Drivers]
    L --> F[Font parity check]
    F --> C[Capture, per page<br/>baseline run a first,<br/>then the lanes in parallel]
    C -->|<engine>-<run>.json, .png,<br/>.probes.json.gz| B[(Bundle directory)]
    B --> W[writeBundle, per page and engine]
    W --> A[DOM audit<br/>each capture alone]
    W --> PL[pipeline.Run<br/>baseline vs engine]
    PL --> LD[Layout diff<br/>pair runs, masks, match, causes]
    LD --> AP[Appearance diff<br/>SSIM, ink]
    AP --> BR[Blocked-request attribution]
    BR --> IN[Design intent<br/>needs a third family]
    IN --> TR[Triage<br/>KB, consequences, tier,<br/>evidence, score, grouping]
    TR --> S[summary.json +<br/>slug/findings.json]
    A --> S
    S --> V[Viewer<br/>report.html]
Loading

Step by step, with the code that does it:

  1. Resolve and discover. The job gets its defaults and page slugs; discovery lists the installed browsers without launching any (run.go). See Discovery.
  2. Plan. makePlan picks the baseline (a Blink browser, Chrome by default) and the engines to compare (run.go). Fewer than two engine families, or no baseline, is exit code 2.
  3. Launch. One browser per engine, at most --max-browsers (default 3) alive at once: more engines run in consecutive groups, each capturing every page before the next launches. Each browser is each wrapped in a restartable so a crashed browser can be replaced once (run.go). An engine that fails to launch is skipped with its reason. See Process management and Drivers.
  4. Font parity. When the job's fontParity is on (the default), the engines are checked for the same fonts before anything is captured (run.go).
  5. Capture. Per page, capture.RunPage captures the baseline's run a first. If the page is unreachable or a bot wall, nothing else is captured. Then the protocol lanes run in parallel: CDP and BiDi engines together, WebDriver Classic (WebKit) alone, each doing every engine's run a before any run b (run.go, lanes.go). See Capture pipeline.
  6. Analyse. writeBundle reads the captures back and, for each page and each compared engine, runs the DOM audit on both captures and pipeline.Run on the pair (bundle.go). The pipeline is layout diff, then appearance, blocked-request attribution, design intent and triage (internal/pipeline/diff.go).
  7. Write. summary.json, a per-page findings.json with the full evidence, host.json, and the viewer's report.html (bundle.go). See Data contracts and Viewer.

Exit code 0 means the job completed, whatever it found: Omnisnap is report-only (CLI and orchestration).

Why the two halves are separate

Analysis never touches a browser: it reads capture files and returns values. That is why the layout diff, triage and appearance code is tested on committed golden captures (testdata/golden) without a browser, and why --resume can skip the pages whose captures already exist and still rebuild the whole summary.json from the files. (omnisnap merge does not re-analyse: it concatenates finished results from several machines, each with its own baseline; see Merge and PR comment.)

The modules

Module ids are stable; specs, plans and tasks refer to them. The graph is the one in specs/CAPABILITY-MAP.md; arrows point from a module to what it depends on.

flowchart BT
    discovery --> bundle-schema
    process --> discovery
    drivers --> process
    capture --> drivers
    capture --> bundle-schema
    dom-audit --> capture
    layout-diff --> bundle-schema
    appearance-diff --> layout-diff
    triage --> layout-diff
    triage --> appearance-diff
    branded --> capture
    branded --> triage
    ground-truth --> capture
    ground-truth --> triage
    viewer --> bundle-schema
    cli --> capture
    cli --> triage
    cli --> viewer
    install --> discovery
    merge --> bundle-schema
    merge --> viewer
    ci-action --> cli
    ci-action --> merge
    wrappers --> cli
    wrappers --> bundle-schema
Loading

cli depends on every runtime module; the graph shows only its main edges.

Module Package(s) Wiki page
bundle-schema internal/schema, schema/ Data contracts
discovery internal/discovery Discovery
process internal/process Process management
drivers internal/drivers Drivers
capture internal/capture, assets/inject Capture pipeline
dom-audit internal/domaudit DOM audit
layout-diff internal/layoutdiff, internal/selector Layout diff
appearance-diff internal/appearance Appearance diff
triage internal/triage, assets/model Triage
branded internal/branded Branded browsers
ground-truth internal/groundtruth, cmd/omnisnap-lab, tools/train.py Ground truth and the model
viewer internal/viewer Viewer
cli internal/cli, internal/pipeline CLI and orchestration
install internal/install Install
merge internal/merge Merge and PR comment
ci-action action/, .github/workflows/report.yml GitHub Action
wrappers packages/npm, packages/pypi Wrappers

internal/pipeline is the glue between capture files and summary.json: it runs the analysis half for one page pair. It has no spec of its own; its behaviour is the sum of the layout-diff, appearance-diff and triage specs.

Concurrency in one sentence

Pages are captured one after another (per group, when the job has more engines than --max-browsers); within a page, the baseline's first run goes alone, then the CDP+BiDi lane and the Classic lane run in parallel, each sequentially; analysis is sequential per page and engine. A page cannot drift between engines because every engine's run a is taken before any run b.

Spec

specs/CAPABILITY-MAP.md (modules, dependencies, build order) and specs/CONVENTIONS.md (shared rules).

Source files

Clone this wiki locally