Skip to content

Layer maps

A layer map compares layers and boundaries, not flows. A merlion-layer-map/1 JSON spec lists zones (boundaries) top to bottom, rows (comparison layers) inside each zone, and cards (items) in stable columns, plus optional adjacent zones beside the map. Merlion draws every card in the zone, row and column you wrote it in: nothing is reordered, no edge is drawn, and a column lines up across every row and every zone. The full contract is in specs/layer-map.md.

Three zones compare the same three customer segments row by row; payment and identity providers sit beside the map:

{
"layerMap": 1,
"title": "How the product organisation is layered",
"zones": [
{
"id": "commercial",
"title": "Commercial context",
"rows": [
{
"id": "segments",
"title": "Segments",
"cards": [
{ "id": "enterprise", "label": "Enterprise", "detail": "Annual contracts, procurement review" },
{ "id": "mid-market", "label": "Mid-market", "detail": "Self-serve trial, sales-assisted close" },
{ "id": "developers", "label": "Developers", "detail": "Usage-based, card on file" }
]
}
]
},
{
"id": "delivery",
"title": "Delivery",
"rows": [
{
"id": "services",
"title": "Services",
"cards": [
{ "id": "billing", "label": "Billing", "role": "warn", "detail": "Invoices and usage metering" },
{ "id": "workspaces", "label": "Workspaces" },
{ "id": "public-api", "label": "Public API", "role": "ok" }
]
},
{
"id": "data",
"title": "Data",
"cards": [
{ "id": "ledger", "label": "Ledger", "role": "store" },
null,
{ "id": "event-log", "label": "Event log", "role": "store" }
]
}
]
}
],
"adjacent": [
{
"id": "external",
"title": "External systems",
"rows": [
{ "id": "providers", "title": "Providers", "cards": [{ "id": "payments", "label": "Payment processor" }] }
]
}
]
}
  • Cell k of a row’s cards is column k in every row of every zone, so “Enterprise”, “Billing” and “Ledger” share the first column. null leaves a column empty without moving the cards after it.
  • detail draws below the label in smaller, muted text. Text is plain: ** and <br> draw as written.
  • role takes the built-in roles: accent, ok, warn, danger, muted and store on cards, group and series-1 … series-8 on zones. Without a role, each zone takes the next series tone, as top-level subgraphs do; --no-auto-tone turns that off.
  • Every zone, row and card has an id, unique across the map: it becomes the group’s data-merlion-id.
  • title becomes the SVG’s <title>. The map draws no visible title: the page around it does.

Render it:

Terminal window
merlion render --layer-map organisation.json -o organisation.svg
import { initSync, renderLayerMap } from "@fractalboxdev/merlion-wasm";
const { svg, outline, diagnostics } = renderLayerMap(spec, { width: 960 });

renderLayerMap accepts the spec as an object or as JSON text.

Fitting never moves a card out of its column. At the target width Merlion picks the first of these that keeps every word of every card unbroken, and records it as data-merlion-fit on the SVG:

Fit Adjacent zones Row titles
beside Beside the main map In a gutter left of the cards
below Below the main map In the gutter
stacked Below the main map Above their cards

Cards are at most 240 px wide. Below 72 px per card, the map draws wider than the target and its SVG scales down in its container, so the columns hold on a phone.

The outline, returned as outline and written into the SVG’s <desc>, names every card with its zone and row:

Layer map. How the product organisation is layered. 3 zones, 4 rows, 9 cards.
Beside the map: External systems.
Commercial context / Segments: Enterprise Annual contracts, procurement review
Delivery / Services: Billing Invoices and usage metering

In <merlion-view>, a tap on a card pins it and its popover shows the label, the detail and the zone and row. The arrow keys walk the cards in the order you wrote them and announce each card’s outline line, so a screen-reader user hears the same detail a pointer user reads. A tap on a zone or row title collapses it, and Show all brings it back.

These fail with an error that names the JSON path, line and column:

  • A member the spec does not define, such as "colour" (E021).
  • A zone without rows, or a row whose cells are all null (E021).
  • An id used twice (E025): the message names the first use.
  • An id with characters outside letters, digits, - and _, or a role outside the class-name grammar (E021).

merlion check --layer-map and checkLayerMap report every problem at once.