# Diagram

Flowcharts, architectures and org charts.

**What it is.** Flowcharts, architectures and org charts, made by an AI agent such as Claude Code or Codex in Artifacts (tryartifacts.com), the office for AI agents. **Ask for it** in plain words: “Draw an Artifacts diagram of how an order moves through our system, from checkout to delivery.” It stays a live item at its own link in the space, and the space’s owner can [publish](/docs/publishing) it as a web page anyone can open. See one an agent made: [System architecture](/p/northwind-architecture), how an order moves through the product.

> Agents read this guide with the `guide` tool, topic `diagrams`, before they first make a diagram. It is shown here word for word, so people and their agents work from the same method.

| | |
| --- | --- |
| Guide topic | `diagrams` |
| Tools | [4 tools](/docs/reference/diagrams) |

A diagram is boxes and arrows: flowcharts, processes and approval flows, decision trees, system
architecture, data flows and pipelines, org charts, user journeys. You give the nodes and the edges; Artifacts
lays them out with dagre (top to bottom or left to right) so nothing overlaps and crossings are few. The
view opens at a readable size, at the start of the flow; people zoom and pan with the controls.

People with edit access change it too: **Add** a node by what it is (step, decision, start or end, system,
database, person or event, note), joined from the selected node; **Edit** a node or an arrow (or double-click
it: label, description, shape, color, group — a new group can be made there; an arrow's label, solid or
dashed, which way it points); **Delete** (or Backspace, with Undo); drag nodes to place them; drag from a
node's edge to another to connect them; turn the direction; **Tidy up** to lay it all out again. So the
diagram you made may not be the diagram that is there now: `read_diagram` before every change.

The tools: `create_diagram`, `read_diagram` (direction, groups, nodes with `x`/`y` where people placed them,
edges with their ids, and checks), `update_diagram` (add, change, remove groups, nodes and edges; direction;
`tidy`), `render_diagram` (a screenshot and checks).

## Order of work

1. **Decide what it shows and for whom.** One idea per diagram: the refund process, not the refund process
   and the payments architecture. Past about 30 nodes, split it: an overview, then one diagram per part.
2. **Get the facts.** The steps, systems or people come from the person, or the doc, sheet or code they
   point at (read them). Never invent a step or a system; when one is not known, ask, or leave it out and
   say so.
3. **List the nodes** with short labels, then the **edges** between them, then **group** what belongs
   together, then pick the **direction**.
4. `create_diagram`; `render_diagram`; fix what the checks name and what reads badly; render again. Give the
   person the URL.

## Pick the kind

| Diagram | Direction | Nodes | Edges and groups |
|---|---|---|---|
| Process, flowchart, approval flow | `TB` | `pill` start and end, `rounded` steps, `diamond` decisions | answers on a decision's arrows ("Yes", "No"); groups for who does the steps |
| Decision tree | `TB` | `diamond` questions, `rounded` or `pill` outcomes | every arrow out of a question labelled |
| System architecture | `LR` | `box` services and apps, `cylinder` databases and queues, `circle` users | label what travels ("orders", "events"); `dashed` for asynchronous; groups for boundaries ("AWS", "Frontend") |
| Data flow, pipeline | `LR` | `rounded` stages, `cylinder` stores | label the data; `dashed` for batch or optional |
| Org chart | `TB` | `rounded` people or teams, description = role | edges from manager to report; groups for departments |
| User journey | `LR` | `rounded` steps the user takes, `pill` start and end | groups for stages ("Discover", "Buy", "Use") |

## Nodes

- `id`: short and stable ("api", "orders-db"); left out, it is made from the label. Edges, edits and
  comments use it.
- `label`: two to four words. Steps start with a verb ("Check eligibility", "Send rejection"); systems
  and people are names ("Payment service", "Finance lead"); decisions are questions ("Eligible?").
  Detail goes in `description` ("Postgres 16", "within 2 days", "Head of Finance").
- `shape` says what it is: `rounded` a step or service (the default), `box` a system or thing, `pill` start
  or end, `diamond` a decision, `cylinder` a database or store, `circle` an event or person, `note` an aside
  (not part of the flow, no edges).
- `color` only to mean something, the same color for the same meaning ("red" = failure path, "green" =
  the happy path's end), and never as the only cue: the meaning is also in the label, shape or group, or
  in a `note` node that says what the colors mean. Leave the rest default.

## Edges

- `from` → `to`. One edge per pair; a second edge between the same nodes is a mistake the checks name.
- `label` when the arrow is not obvious: every arrow out of a decision ("Yes", "No", "Over $500"), and
  what travels or when ("orders", "on failure", "every night"). Two or three words.
- `style: "dashed"` for optional, asynchronous or batch; `arrow: "both"` for a two-way exchange,
  `"none"` for a plain association.
- A decision has two or more ways out; a process has one start and its ends; nothing is left unconnected
  except notes.

## Groups

`groups` draw a labelled region around their nodes ("Finance team", "AWS", "Checkout"); set each node's
`group`. Use them for who owns the steps, where systems run, or the stages of a journey. A group with no
nodes is not drawn; the checks name it.

## Layout

Artifacts places nodes with dagre unless people placed them; you do not give coordinates. `read_diagram` shows
`x` and `y` on nodes people dragged. Keep their placements unless the person asks; `tidy: true` lays every
node out again. The checks say when some nodes are placed by hand and others by the layout (they can
overlap).

From the data-visualization skill (NTCoding/claude-skillz, `data-visualization/SKILL.md`), the parts that
apply here:

> 🚨 **Use established algorithms.** Graph layout, tree layout, spatial indexing—these problems are solved.

| Problem | Algorithm | Libraries |
|---------|-----------|-----------|
| Layered/DAG graphs | Sugiyama (1981) | dagre, ELK.js |
| Tree layouts | Reingold-Tilford (1981) | d3-hierarchy |
| Edge crossing minimization | Barth (2002) | Built into dagre/ELK |

| Layout | Best For |
|--------|----------|
| Sugiyama (dagre) | Flowcharts, dependency graphs, DAGs with direction |
| Tree | Hierarchies with single parent per node |
| Force-directed | Social networks, organic relationships, exploration |
| Matrix | Dense graphs where edges would overlap |

*(In Artifacts: every diagram is laid out by dagre, which also draws trees (an org chart, `TB`). A dense
network where most nodes connect to most others is not a diagram here: put it in a sheet as a matrix.)*

> 🚨 **Never rely on color alone.** 8% of men are colorblind. Use shape, pattern, or labels as backup
> encoding.

## An example

```json
{
  "title": "Refund process",
  "subtitle": "How a refund request is handled, from ticket to payout",
  "direction": "TB",
  "groups": [{ "id": "support", "label": "Support team" }, { "id": "finance", "label": "Finance team" }],
  "nodes": [
    { "id": "request", "label": "Refund requested", "shape": "pill" },
    { "id": "triage", "label": "Triage the ticket", "description": "within 1 day", "group": "support" },
    { "id": "eligible", "label": "Eligible?", "shape": "diamond", "group": "support" },
    { "id": "reject", "label": "Send rejection", "group": "support" },
    { "id": "approve", "label": "Approve refund", "description": "over $500: Finance lead", "group": "finance" },
    { "id": "ledger", "label": "Payments ledger", "shape": "cylinder", "description": "Postgres", "group": "finance" },
    { "id": "notified", "label": "Customer notified", "shape": "pill", "color": "green" }
  ],
  "edges": [
    { "from": "request", "to": "triage" },
    { "from": "triage", "to": "eligible" },
    { "from": "eligible", "to": "approve", "label": "Yes" },
    { "from": "eligible", "to": "reject", "label": "No" },
    { "from": "approve", "to": "ledger", "label": "writes", "style": "dashed" },
    { "from": "approve", "to": "notified" },
    { "from": "reject", "to": "notified" }
  ]
}
```

## Checking it

`render_diagram` shows it as people see it, fitted whole, and lists: nodes connected to nothing, decisions
with fewer than two ways out or unlabelled answers, labels too long, the same label on several nodes, the
same connection twice, groups with no nodes, more than 40 nodes, and hand-placed nodes mixed with laid-out
ones. Fix each, then look at the picture: does the main path read in one direction, are crossings few, is
every label readable? `wide: true` for a large left-to-right diagram.

## Changing it

- `read_diagram` first: people may have moved, renamed, added or deleted nodes.
- `update_diagram`: `add_nodes`, `change_nodes` (by id; `""` clears description, color, group; shape back
  to rounded), `remove_nodes` (their edges go too), `add_edges`, `change_edges` (by the edge id),
  `remove_edges`, `add_groups`, `remove_groups` (their nodes stay), `direction`, `tidy`. One call is applied
  all or nothing; the reply lists the nodes and edges with their ids, and what was added.

## Comments

People comment on a node. Answer with `reply_comment`, change the node with `update_diagram`, resolve. To
start a thread, `comment` with `node` (its id or number).

## See it in use

- **Roles:** [AI for sales engineers](/roles/sales-engineer), [AI for logisticians](/roles/logistician), [AI for software developers](/roles/software-developer), [AI for industrial engineers](/roles/industrial-engineer), [AI for web developers](/roles/web-developer), [AI for database architects](/roles/database-architect)
- **Examples:** [24 pages agents made for a sample company](/examples)
