<!--
  GENERATED FILE - do not edit by hand.
  Source of truth: docs/agents/ in the magma monorepo.
  Regenerate with: npm run sync.agent-docs (from the stencil package).
-->
# Magma patterns catalogue (7 patterns, 6 candidates, 4 building blocks, 6 domains of the design language)

> Generated from the patterns of the magma monorepo. A pattern is the solution to a task that
> spans components (where a message goes, when to ask before acting), the same in every
> product: Magma's default. Each one is defined on a few variables of the situation; read its
> file in `agents/patterns/`, or ask the MCP server: `get_pattern` with the values of the
> variables you know gives the case to follow. Its "Always true" rules hold in every product.
> The domains of the design language (`kind: design-language`) are the rules of composition
> the patterns stand on: the space between two elements, which action weighs more, the style of
> a title, when a surface, how wide. They are read the same way, and each rule says the
> principle it serves and what carries it (a component, a token, a utility, a lint rule): write
> the carrier, not its value; a carrier still planned is not there yet, so write the value the
> case gives.
> `get_guide` serves each domain by its id; the answer of `get_pattern` for a situation
> lists in `rules` the ones its case relies on, and `get_component` the ones that govern a
> component.
> The building blocks (`kind: block`) are the sections of a page that come back in several
> patterns (the head of a page): space, not time. A block has regions in the order of the page
> instead of cases, each saying when it shows; `get_pattern` with the values of its variables
> gives the regions to lay out, and its Layout section says how they stand.
> A product may keep a layer in its own repository, `magma/patterns/<id>.md`, that narrows the
> open choices and adds situations (A product's layer, below); `get_pattern` applies it. A candidate is a need Magma knows
> and has not defined yet: no default covers it, so say which choice you made and why.

## Design language

| Domain | Title | Need | Status |
| ------ | ----- | ---- | ------ |
| [`actions`](patterns/actions.md) | Actions | Tell at a glance which action moves the task forward, which ones stand beside it, and which ones destroy, and find them in the same place on every screen. | decided |
| [`density`](patterns/density.md) | Density | Fit more or less on a screen without changing how its parts relate: more for a product that shows a lot at once, less for a person who needs more room to point. | decided |
| [`rhythm`](patterns/rhythm.md) | Rhythm | Space two elements of a composition by how they relate, so that each one stands nearer to what it belongs to than to its neighbour. | decided |
| [`surfaces`](patterns/surfaces.md) | Surfaces | Give a boundary only to what space cannot separate, so that a surface on the screen means something: an item of a set, a thing that stays put, a dialog; and tell at a glance a page that introduces from a place of work. | decided |
| [`titles`](patterns/titles.md) | Titles | Tell at a glance what a title names, the whole page, a section of it, a dialog, a part or a group of fields, and keep the outline of the page true for whoever navigates it by headings. | decided |
| [`widths`](patterns/widths.md) | Widths and alignment | Give text, forms, pages and dialogs a width that keeps them readable at every size of window and of text, and line them up on one edge. | decided |

## Building blocks

| Block | Title | Need | Status |
| ----- | ----- | ---- | ------ |
| [`app-shell`](patterns/app-shell.md) | Application shell | The person knows which application they are in, reaches each of its sections from any page, and sees who they are signed in as. | decided |
| [`page-header`](patterns/page-header.md) | Page header | The person sees at once what the page holds or is about, where they are, and what they can do with it. | decided |
| [`item-list`](patterns/item-list.md) | Item list | The person sees a set of items, narrows it to the ones they need, knows how many there are, and reaches the rest. | decided |
| [`labels-and-values`](patterns/labels-and-values.md) | Labels and values | The person reads the data of an item, each value under the name of what it is. | decided |

## Data

| Pattern | Title | Need | Status |
| ------- | ----- | ---- | ------ |
| [`choose-items`](patterns/choose-items.md) | Choose items | The person picks items from a long list to use them for something else, such as members to add to a group or documents to attach. | candidate |
| [`concurrent-editing`](patterns/concurrent-editing.md) | Concurrent editing | Two people change the same record at the same time, and neither loses their changes. | candidate |
| [`list-with-filters`](patterns/list-with-filters.md) | List with filters | The person finds the items they need in a long list, by searching, filtering and paging. | decided |
| [`permissions`](patterns/permissions.md) | Permissions | The person sees what their role lets them see and do, and understands why an action is not available. | candidate |
| [`record-detail`](patterns/record-detail.md) | Record detail | The person opens one record to read it and act on it, then goes back to the list as it was. | decided |

## Input

| Pattern | Title | Need | Status |
| ------- | ----- | ---- | ------ |
| [`consent-and-legal`](patterns/consent-and-legal.md) | Consent and legal steps | The person pays, signs or gives consent: steps with legal rules of their own. | candidate |
| [`form-and-validation`](patterns/form-and-validation.md) | Form and validation | The person fills in a form, sees what is wrong and where, and sends it. | candidate |

## Messages and states

| Pattern | Title | Need | Status |
| ------- | ----- | ---- | ------ |
| [`confirm-action`](patterns/confirm-action.md) | Confirm an action | The person is about to do something that cannot be taken back, and must decide knowing what will happen. | decided |
| [`empty-state`](patterns/empty-state.md) | An empty part of the page | The person reaches a part of the page with nothing in it, and must understand why and what to do next. | decided |
| [`error-recovery`](patterns/error-recovery.md) | When something fails | Something did not work, and the person must understand what did not happen and go on without losing their work. | decided |
| [`loading`](patterns/loading.md) | Waiting for something | The person waits for content or for the end of an action, and must know that it is coming and whether they can do something else meanwhile. | decided |
| [`message-placement`](patterns/message-placement.md) | Where a message goes | The person did something or opened a view, and must know what happened without looking for it. | decided |
| [`notification-center`](patterns/notification-center.md) | Notification center | The person comes back to the outcomes that arrived while they were elsewhere, and to what they still have to act on. | candidate |

## A product's layer

A product adapts a pattern in its own repository, one file per pattern, named after it:
`magma/patterns/<id>.md` under the project's root, the file `get_pattern` with the id names in
`layerFile` (also when the project is a folder below the one you work in). The layer fixes the
open choices the pattern leaves to the products, within what each one `may`, and maps the
situations of the product's domain to the cases of the pattern. It never changes an "Always true" rule nor a case: a product
that needs one changed asks Magma for it (`reporting.md`).

```markdown
---
id: message-placement
extends: magma:message-placement
layer: example-backoffice
narrows:
  success-toast-duration: 8000
situations:
  - situation: A protocol number is assigned to a filed document
    case: action-done-elsewhere
    note: the toast carries Copy, so it stays (toast-action-stays)
---

# Where a message goes, in Example Backoffice

## Why

The operators read slowly between two phone calls: 8 seconds instead of 5. (2026-10-29)
```

| Field | What it holds |
| ----- | ------------- |
| `id` | The id of the Magma pattern, the name of the file. |
| `extends` | `magma:<id>`. |
| `layer` | The name of the product, never `magma`. |
| `narrows` | `<open choice>: <value>`, only for the open choices of the pattern. |
| `situations` | `{ situation, case, note }`, with a case of the pattern or a list of them; or `{ situation, use: <pattern> }` when another pattern answers it. |

The body is free: why each choice was made, with its date, for whoever changes it next.
`get_pattern` without arguments lists in `layerErrors` what is wrong in the folder; with the
id it returns the pattern with the layer applied (`narrowed-by` on each choice it fixes, `layer`
on each situation it adds). A layer with an error is not applied: the answer stays Magma's
default until it is fixed. A need no Magma pattern covers, which the product cannot wait for,
may get a pattern of its own in the same folder, in the shape of Magma's files (its own
`layer`, no `extends`, never an id Magma has); a pattern that comes back in two or three
products is proposed to Magma. In Claude Code, the Magma plugin writes and checks a layer with
`/magma:pattern-layer`.
