Skip to content

The Map ​

The Map is a folder convention, like Next.js routes: the project's folders are its map of the app, so there's no separate schema to keep in sync. The guide is Your project; this page has the exact rules.

The rules ​

text
src/map/
  (main)/                   # the app under test: the groups of everything it owns
    (app_base)/              # its pages - a group, never part of any Checkpoint tag
      dashboard/              # One folder per Checkpoint - "Dashboard"
        _page.block.ts         # arrival hub (definePageBlock) - fixed name, every folder
        _sel.ts                  # selectors for this Checkpoint - fixed name, every folder
        _expect/                  # what a scenario can expect on this page (Expect Blocks) - fixed name
        _methods/                 # this Checkpoint's own action Blocks - fixed name, every
          click-widget.block.ts    # folder. Contents keep their own descriptive names -
    (api)/                          # the app's API Blocks (defineApiBlock), grouped by resource
    (given)/                        # its preconditions (defineGivenBlock): seeds with their undo
      posts/
        seed-note.api.block.ts
  (external)/                     # other people's sites, only the folder itself is fixed.
    docs/                    # a genuinely cross-origin group, same shape - "Docs"
      _page.block.ts
      _sel.ts

A multi-tenant app that lives on subdomains gets one group per tenant (or per host) beside (app_base), so (main)/(acme)/ and (main)/(globex)/ hold the same pages seen from each tenant. A page's url is then a function of mem ((mem) => \https://$.app.test/dashboard`), which waygraph map` doesn't check against the folder; the literal ones still are.

Not just a naming preference - a forced convention. Folder nesting under map/(group)/ must verbatim-match the real site's own URL path segments, (group) parens excluded (purely organizational, same as a Next.js route group): /app/chats lives at map/(main)/(app_base)/app/chats/, never map/(auth)/chats/ for a fabricated grouping that was never a real /auth/* URL. waygraph map [project] (see CLI) enforces this mechanically and exits 1 on a mismatch - don't rely on review alone. Same Block helpers as today's freeform "manual mode" (definePageBlock/defineNavBlock/ defineMethodBlock/etc.) either way - Map only changes where files live and what they're named, never what kind of Block authors them or how they execute. A project adopts it incrementally, folder by folder. Build flows with map() - it can't silently accept a Block that didn't come from a real factory.

Leading underscore = this Checkpoint's own fixed machinery, never a route segment._nav.block.ts/_page.block.ts/_sel.ts/_methods//_expect/ (same private-folder idea as Next.js's own _folder convention) mark "this belongs to the endpoint whose folder it's directly in," so a bare (non-underscore, non-(group)) folder name always means a real child Checkpoint/URL segment - _methods/ can never be mistaken for a sibling endpoint folder the way a bare methods/ structurally could be, since only ONE of those two readings is mechanically distinguishable at a glance. waygraph map's own folder-vs-URL comparison excludes underscore segments the same way it excludes (group) ones - _methods/foo.block.ts compares against the URL as if _methods/ weren't there at all. Individual files inside _methods/ keep their own descriptive names (join-pool.method.block.ts, not _join-pool...) - they're hand-authored per-project content, not fixed convention names; the _methods/ folder boundary alone already marks the whole subtree as non-route.

"waypack" - loading another project's Blocks needs no separate manifest either. A second project depending on a Map-convention project as a plain file: dependency (the same mechanism examples/saucedemo's own "waygraph": "file:../.." already uses) is immediately understandable: waygraph graph node_modules/<loaded-package> correctly discovers its full Checkpoint/edge structure, with nothing generated or maintained separately. Proven end to end in examples/routed-demo-consumer/ against examples/routed-demo/.

Map packages ​

A group under src/map/ that owns its keys is a map you can publish: _keys.ts lives in the group's folder (not in src/states/), and its files import only waygraph, Playwright, node: modules and each other. waygraph check warns on any import that leaves the group.

text
src/map/(external)/hoppscotch/
  _keys.ts            hoppscotch.requestUrl, hoppscotch.expectedStatus, ...
  _page.block.ts  _sel.ts  _methods/  settings/
bash
waygraph map pack hoppscotch [project] [--out <dir>] [--name <package>] [--version <x.y.z>]
# -> .waygraph/packages/hoppscotch: compiled .js + .d.ts, index re-exporting every module, package.json,
#    and waygraph.map.json (its Blocks with routes, its Checkpoints)
cd .waygraph/packages/hoppscotch && npm publish

The pack uses the project's own tsconfig.json and TypeScript and refuses a group that imports outside itself. In another project, npm i waygraph-map-hoppscotch is all it takes: the scanner finds every dependency with a waygraph.map.json, so its Blocks appear in graph, auto, manifest and waygraph run <block>, and flows import them like any module:

typescript
import { HoppscotchRestPage } from "waygraph-map-hoppscotch";   // .nav, .do.setUrl, .expects.status

The scaffold's (external)/hoppscotch and (external)/mailpit are written this way.

Migrating from freeform ("router") to Waygraph Map ​

"Router" isn't a separate mode to turn off - it's this project's own name for today's freeform, folder-organized style (src/blocks/<slug>/, any nesting, any file names). Migrating means moving those files under src/map/(group)/<page-slug>/ with verbatim URL-matching names, nothing more - no engine change, no new Block helpers, no flag to flip. Do it incrementally: the two styles coexist in the same project (and even the same Flow) with no special-casing, since discoverGraph/loadBlockLibrary only ever match the .block.ts filename pattern, never folder depth or naming.

  1. List every real URL your NavBlocks/PageBlocks already navigate to. For each one with a static string url, note its real path. For each one that's click-based (no url field at all) or a dynamic (mem) => string function, note that too - neither is statically checkable by waygraph map, so they can go wherever makes sense; only a literal string url is verified.
  2. Pick your group(s). (main)/(app_base)/ for the app's pages (organizational only, never part of a Checkpoint tag), (main)/(api)/ for its API Blocks, a (main)/(<tenant>)/ per subdomain when the app is multi-tenant; (external)/ for genuinely cross-origin Blocks (mail tools, third-party embeds) - verify with the real URL, not the folder's own current name, since a folder can already be mis-grouped (a real bug this session found: a project's own (external)/docs/ was actually same-origin the whole time).
  3. Create src/map/(group)/<verbatim-url-segments>/ per Checkpoint, git mv each Block/Sel file in, and rename the fixed ones: nav.block.ts -> _nav.block.ts, page.block.ts -> _page.block.ts, your selector file -> _sel.ts (drops its slug - now a fully fixed name), methods/ -> _methods/ (contents keep their own names unchanged). Two Checkpoints sharing one real URL (a DOM-state distinction, not a URL one - e.g. a "joined" vs "not joined" variant of the same page) can't both use the bare fixed names in one folder; give each pair a slug prefix instead (app-home._nav.block.ts / in-pool._nav.block.ts, or similar) rather than nesting either under its own subfolder (that would add a folder segment the real URL doesn't have, and fail step 5).
  4. A dynamic per-instance URL (a real chat/order/ticket id, not a fixed route) - if it's currently a plain string constant, wrap it as url: () => thatConstant instead. A bare string is always treated as a real, checkable static route; a function is correctly treated as dynamic/non-canonical and skipped, matching how you'd actually navigate a real instance of it in practice anyway.
  5. Fix every import the moves break (states/mem-key paths change depth; sibling nav/page/methods imports need their new _-prefixed names) - let the compiler do this for you: tsc --noEmit if the project has one, otherwise waygraph check [project] and waygraph graph [project] (both do real dynamic imports of every Block file and report import failures by name) are just as effective a proof.
  6. Run waygraph map [project]. Exit 0 / "0 violations" is the actual finish line - not a subjective review. A remaining violation names the exact file, its real folder path, and the real URL it doesn't match; fix the folder, not the check.
  7. Diff waygraph graph's node/edge/skipped/orphan counts against before the move. A pure migration changes zero Block behavior - if a count changed, something broke in transit (a bad import silently dropped a Block from discovery is the usual cause), not something to wave off as "close enough."

Once the folder structure is settled, build Flows over these Blocks with map() - it can't silently accept a Block that isn't really a Nav/Page/Method from this package's own factories.

waygraph 0.18.3 (alpha) · Node 24+ · peer @playwright/test ^1.40.0 · syntax may change before 1.0: see what was removed