# Diagrams

> Draw editable draw.io diagrams that follow the theme.

Diagrams are native draw.io files, drawn with the [drawio-design](https://github.com/MitchStares/drawio-design) skill. Anyone can open and edit them later. One file serves the light and the dark theme.

<Diagram name="docs-loop" alt="A product pull request goes to the docs-update skill, which opens a docs pull request. The docs pull request builds the docs site. Each week a drift check compares written pages with the product code and opens an issue for pages to review." caption="An example diagram: docs/diagrams/docs-loop.drawio" />

## Before you start

- Install the agent skills. The driftless plugin installs drawio-design with it. Refer to [Agent skills](/skills).
- Install the draw.io desktop app. `npm run diagrams` uses it to export. Set `DRAWIO` to its path if `drawio` is not on PATH.

## Draw a new diagram

<Steps>
  <Step title="Ask for it">
    In Claude Code, ask for the diagram and name the page it is for, for example "draw how a request moves through the API, for the API overview page". The `docs-diagram` skill picks the type, states its plan, and builds the file from a script in `docs/diagrams/src/<name>.py`.
  </Step>
  <Step title="Check it">
    The skill runs drawio-design's `check_drawio.py` and renders a preview. It fixes every defect the check names, such as text that does not fit or lines that cross a box.
  </Step>
  <Step title="Export it">
    Run `npm run diagrams -- <name>`. This writes `docs/diagrams/<name>.svg`, with theme tokens in place of colours.
  </Step>
  <Step title="Place it">
    Add the diagram to the page. The alt text says what the diagram shows, not how it looks.

    ```mdx
    <Diagram name="request-flow" alt="A request goes from the browser to the API, then to the database." caption="How a request moves" />
    ```
  </Step>
</Steps>

## Change a diagram

Open `docs/diagrams/<name>.drawio` in draw.io or diagrams.net, or ask Claude Code to edit the XML in place. Do not run the script in `docs/diagrams/src` again: it would overwrite manual edits. Then run `check_drawio.py` and `npm run diagrams -- <name>`.

## How the theme works

1. You draw with colours from the palette in `driftless.config.ts`. The default palette matches drawio-design's default skin.
2. `npm run diagrams` exports each `.drawio` file to SVG.
3. The export changes each palette colour to a `--d-*` token from `src/styles/tokens.css`. Each token has a light and a dark value.

A colour outside the palette stays as drawn, and the export lists it. Set `diagrams.strict: true` to stop the export instead.

<Callout type="tip">
To use your brand colours, make a drawio-design profile, and write `profile: <name>` in a `.diagram-design` file at the repo root. Then put the profile's colours in `diagrams.palette` and the `--d-*` tokens.
</Callout>

## Rules

| Rule | Why |
|---|---|
| Canvas 560px wide | Text draws at about its real size in the page column |
| Light skin only | The site maps colours to theme tokens for dark mode |
| Plain-text labels, in sentence case | HTML labels export as images |
| Accent on one or two items | The accent marks what the diagram is about |
| About 9 boxes at most | Over that, split it into an overview and a detail |
| Dashed outline for a boundary that someone else owns | It shows who runs what |
