# Flowbraid document format

Flowbraid records how the applications, message channels and data stores of a system connect, and draws the record as a graph. A Flowbraid document is one JSON object with `"format": "flowbraid"` and `"version": 1`. This file tells a model or a tool how to write a document that the app accepts and that says what the user asked for. People read the same format, with figures, in the [guide](/guide).

## 1. Output

- Give the document as one JSON object. In a chat, put it in a single code block marked `json`. When you write a file, or the user asks for the JSON alone, write the object with no text or Markdown around it.
- Write keys and type values exactly as this file spells them, in English. Keep the names the user gives as the user wrote them, in whatever language. Write other names, descriptions, notes and labels in the user's language. Write ids, event names and the names of topics, queues and tables as the user's system spells them.
- When you change an existing document, answer with the whole document (section 10).

## 2. Writing principles

- **Only the properties defined here.** The app keeps a property the format does not define, but it neither draws it nor warns about it. Put other information in `notes`, `metadata`, `snippets` or `links`, and do not invent a property for something the format lacks. For example, a node joins a boundary through its own `boundary` property: a `members` list on the boundary is ignored, and the nodes it lists stay outside.
- **Only facts you were given.** Leave out a platform, events, an environment or a point in time (`asOf`) that the request does not give. A missing value reads as "not specified"; a guessed one reads as fact. Add no boundary or cluster the request does not ask for.
- **Check the meaning, not only the validity.** Validation checks the format, not what was asked: a `request` relationship drawn the wrong way round, or a node left out of its boundary, still passes. Before you answer, check the direction of every edge and every membership against the request.
- **Keep what you were not asked to change** when you edit a document (section 10).

## 3. The document

```json
{
  "format": "flowbraid",
  "version": 1,
  "name": "Order Fulfillment Flow",
  "description": "From a placed order to the carrier",
  "nodes": [],
  "edges": [],
  "boundaries": [],
  "clusters": []
}
```

| Property | Required | Type | Meaning |
| --- | --- | --- | --- |
| `format` | yes | string | Always `"flowbraid"` |
| `version` | yes | integer | Always `1` |
| `name` | no | string | The document's title. Give one: the app lists documents by it |
| `description` | no | string | One short line |
| `environment` | no | string | The environment the document describes, such as `production` |
| `asOf` | no | string | The point in time the document describes, as free text such as `2026-10-14` or `v4.2` |
| `status` | no | string | `applied`, the system as it is (the default), or `planned`, a plan not in place yet |
| `notes` | no | string | Markdown: what the document covers, what it leaves out and what it is based on |
| `links` | no | Link[] | Related pages (section 7) |
| `metadata` | no | object | Extra information (section 7) |
| `nodes` | yes | Node[] | The components (section 4) |
| `edges` | yes | Edge[] | The relationships between them (section 5) |
| `boundaries` | no | Boundary[] | Groups of applications and data stores (section 6) |
| `clusters` | no | Cluster[] | Groups of channels (section 6) |

A document may cover one flow or one area rather than the whole system. Say what it covers and what it leaves out in its `description` and `notes`. An edge still needs both of its ends in the document.

### Ids

- Every node, edge, boundary and cluster has an `id`. Ids are unique among the nodes, among the edges, among the boundaries and among the clusters; a node and an edge may share an id.
- Ids are case-sensitive and not empty. Use the recommended pattern `^[a-z0-9][a-z0-9._-]*$`, as in `order-service` or `orders.placed`.
- An id is for references and a name is for people: keep the id when the name changes.

## 4. Nodes

| type | What it is |
| --- | --- |
| `app` | An application or a service |
| `topic` | A pub/sub message channel, such as a Kafka topic or an SNS topic |
| `queue` | A queue message channel, such as an SQS queue or a RabbitMQ queue |
| `store` | A data store: a database, a table, a cache, a storage bucket or a search index |

Topics and queues together are called channels.

| Property | Required | Applies to | Meaning |
| --- | --- | --- | --- |
| `id` | yes | all | See ids |
| `type` | yes | all | One of the node types above |
| `name` | yes | all | The name the canvas shows. For a channel or a data store, preferably its real name: the topic, queue, table, bucket or index name |
| `platform` | no | all | The product, as a short name (below) |
| `external` | no | all | `true` when the component is outside the owner's control, such as a partner system or a SaaS |
| `boundary` | no | `app`, `store` | The id of the boundary it belongs to (section 6) |
| `cluster` | no | `topic`, `queue` | The id of the cluster it belongs to (section 6) |
| `position` | no | all | Leave it out (section 8) |
| `description`, `notes`, `snippets`, `links`, `tags`, `metadata` | no | all | Common properties (section 7) |

- `platform` is free text. Write a short product name, not a sentence, and leave it out when it is not known. Recommended values for channels: `kafka`, `sns`, `pubsub`, `pulsar`, `sqs`, `rabbitmq`, `activemq`. For data stores: `postgresql`, `mysql`, `dynamodb`, `mongodb`, `redis`, `s3`, `elasticsearch`. An application names its runtime, such as `spring` or `lambda`, or an external system its product.
- The type is the shape of a channel and the platform its implementation: an SQS queue is `"type": "queue", "platform": "sqs"`. A new product never needs a new type.
- An application's role is not a type. Whether it publishes, subscribes, writes or reads shows in its edges, and one application may do all of them.
- `external` means outside the owner's control. It does not mean unknown or left out.
- Draw a data store at the unit that matters to the flow: a database, a table or a bucket. Its inner structure, such as tables or indexes, goes in `notes` or `metadata`, not in nodes.
- Consumer groups, event schemas and environments are not nodes. Put them in `metadata` or `notes`.

## 5. Edges

| Property | Required | Meaning |
| --- | --- | --- |
| `id` | yes | See ids |
| `from` | yes | The id of the node the edge starts at |
| `to` | yes | The id of the node the edge ends at |
| `type` | yes | One of the edge types below |
| `label` | no | A short label for the line |
| `events` | no | The event types it carries, on message edges only |
| `description`, `notes`, `snippets`, `links`, `tags`, `metadata` | no | Common properties (section 7) |

| type | from | to | Meaning |
| --- | --- | --- | --- |
| `publish` | `app` | `topic`, `queue` | The application publishes messages to the channel |
| `subscribe` | `topic`, `queue` | `app` | The application consumes the channel's messages |
| `route` | `topic`, `queue`, `store` | `topic`, `queue`, `store` | Messages or data are forwarded to another channel or data store |
| `write` | `app` | `store` | The application writes to the data store |
| `read` | `store` | `app` | The application reads from the data store |
| `request` | `app` | `app` | The `from` application sends a synchronous request to the `to` application |
| `influence` | any | any | The state or changes of `from` affect `to` |

### Direction

- `publish`, `subscribe`, `route`, `write` and `read` point the way the data flows, not the way control goes. A subscription runs channel → application even when the consumer pulls, and a read runs data store → application even though the application asks.
- `request` points from the application that asks to the one that answers, as for an HTTP, gRPC or GraphQL call. For a webhook or a callback, the sender is the one that asks. A request never points back to the same application. Request and reply over queues is `publish` and `subscribe`.
- `influence` points from what affects to what is affected, for a schema, a setting or load. For a dependency, work out who depends on whom first: it points from what is depended on to what depends on it. Use it only when no other type fits: reading another service's table is a `read`, and calling its API is a `request`. It is the only type that may point back to the same node.
- An application that writes and reads the same data store has both a `write` and a `read`.

### route

Use `route` when what does the forwarding is not drawn as an application of its own: an SNS topic's subscription by an SQS queue, a queue's dead-letter queue, a topic replicated to another cluster, change data capture (data store → topic), a sink connector (topic → data store), bucket event notifications (data store → queue) or a replica (data store → data store). When what forwards matters to the reader, draw it as an `app` with an edge on each side instead.

A dead-letter queue the platform feeds, such as one an SQS queue's redrive policy names, is a `route` from that queue. When an application itself sends the messages it cannot process to a dead-letter queue, that is a `publish` from the application.

### events

- `events` lists the event types an edge carries, as in `["OrderPlaced"]`. Each is a name, not a reference.
- Only `publish`, `subscribe` and `route` carry events. Put payloads and schemas in `notes`, `snippets` or `metadata`.
- Leave `events` out when the request does not say which events flow: a missing list means "not specified", not "all" or "none". A list that is present holds at least one non-empty name; never write `[]`.
- When an application consumes only some of a channel's events, its `subscribe` lists only those.
- One edge may carry several events. Edges with the same `from`, `to` and `type` may repeat under different ids, when events need notes or snippets of their own.
- When a data store's changes go out as events, the `route` from the data store to the channel carries them.

## 6. Boundaries and clusters

A **boundary** groups applications and data stores into a unit the reader tells apart, such as a system or an environment. A **cluster** groups channels, such as the topics of one broker cluster, or the queues of one account and region on a platform without clusters. Neither is a node.

| Property | Required | Type | Meaning |
| --- | --- | --- | --- |
| `id` | yes | string | See ids |
| `name` | yes | string | The name the canvas shows |
| `description` | no | string | One short line |
| `tags` | no | string[] | Short words |
| `metadata` | no | object | Extra information, such as a cluster's bootstrap servers (section 7) |
| `color` | no | string | A palette color (below) |

Boundaries and clusters have no other properties: no list of members and no notes.

- A node joins a group through its own property: an application or a data store names its boundary's id in `boundary`, and a topic or a queue names its cluster's id in `cluster`. A node belongs to one boundary or one cluster at most, and may belong to none.
- Only applications and data stores join boundaries, and only topics and queues join clusters.
- Put a data store in the boundary of the system that owns it. An application of another system that reads or writes it then shows as an edge crossing the boundary.
- Boundaries do not nest. A group without members is valid.
- A group records membership only. Edges inside a boundary and edges across it read the same way.

### Colors

Boundaries and clusters share the palette: `teal`, `purple`, `olive`, `pink`, `green`, `slate`. Color is presentation: it carries no meaning, and a group without one is valid. Recommended:

- In a new document, give every boundary and every cluster a `color`, each different from the others for as long as the palette lasts. Without colors, the canvas draws the first boundary and the first cluster in the same color.
- When you change an existing document, keep the colors it has.

A color outside the palette is a warning.

## 7. Common properties and extra information

Nodes and edges may also have these properties, and the document may have `notes`, `links` and `metadata`.

| Property | Type | Meaning |
| --- | --- | --- |
| `description` | string | One short line |
| `notes` | string | Markdown details: evidence, background, open questions |
| `snippets` | Snippet[] | Code, as `{ "title": "Event schema", "language": "json", "code": "..." }`. `code` is required, `title` and `language` are optional |
| `links` | Link[] | As `{ "title": "Runbook", "url": "https://..." }`. `url` is required and absolute, `title` is optional |
| `tags` | string[] | Short words for sorting and search, not sentences |
| `metadata` | object | Free keys, each value a string or a list of strings |

- `metadata` values are text: write numbers and booleans as strings, as in `"partitions": "24"`, and put structured values in a snippet with `"language": "json"`. Metadata adds detail and never changes a node's type, an edge's ends, type or events, or a membership.
- A planned document (`"status": "planned"`) draws a plan that is not in place yet, and its `asOf` is when the plan should land. Draw a plan as a copy of the current document changed into the target: delete what goes away, and say why and how in `notes`. A plan in several steps is several planned documents.

## 8. Layout

Leave `position` out in a new document: the app lays out the nodes that have none. Position and color never change what a document means. When you change a document whose nodes have positions, keep them and leave new nodes without one. Pasted into the code editor, the new nodes are placed where they do not overlap the others; opened from a share link or a file, they take the automatic layout's place and may overlap nodes that have positions. A position is `{ "x": 320, "y": 180 }`.

## 9. Validation

The app checks a document when it is saved, imported or opened from a link, in three steps: structure, references, then meaning. **Errors** make a document invalid, and the app does not take it. **Warnings** do not, but each points at a likely mistake: a document you write should have none.

| Code | Severity | When |
| --- | --- | --- |
| `invalid-json` | error | The text is not JSON |
| `invalid-type` | error | A value has the wrong type, such as a number in `metadata`, or `version` is not an integer |
| `missing-property` | error | A required property is missing |
| `invalid-value` | error | `format` is not `"flowbraid"`, or a `type` or the `status` is not one of the listed values |
| `unsupported-version` | error | `version` is not `1` |
| `empty-value` | error | A required string is empty, or `events` is empty or holds an empty name |
| `duplicate-id` | error | Two nodes, two edges, two boundaries or two clusters share an id |
| `invalid` | error | Any other structure error |
| `unknown-node` | error | An edge's `from` or `to` is not the id of a node |
| `self-loop` | error | An edge other than `influence` starts and ends at the same node |
| `unknown-boundary` | error | A node's `boundary` is not the id of a boundary |
| `unknown-cluster` | error | A node's `cluster` is not the id of a cluster |
| `endpoint-pattern` | warning | An edge's ends do not match its type in the table of section 5 |
| `non-message-events` | warning | A `write`, `read`, `request` or `influence` edge has `events` |
| `channel-boundary` | warning | A topic or a queue has a `boundary` |
| `non-channel-cluster` | warning | An application or a data store has a `cluster` |
| `unknown-color` | warning | A boundary's or a cluster's `color` is not in the palette |

Common mistakes:

- A subscription written application → topic, or a read written application → data store (`endpoint-pattern`). Both point the way the data flows.
- `events` on a `write`, `read` or `request` (`non-message-events`).
- A queue, such as a dead-letter queue, put in a boundary (`channel-boundary`). Channels go in clusters.
- An edge to a node that was renamed or deleted (`unknown-node`).
- `"events": []` (`empty-value`). Leave the list out instead.
- A color such as `blue` (`unknown-color`).
- A `request` drawn from the application that answers to the one that asks, or a list of members on a boundary. Neither is reported, so check them yourself.

## 10. Changing an existing document

- Answer with the whole document, not a patch or only the changed part.
- Change only what the request asks for. Keep the rest as it is: the other nodes and edges, ids, names, `position`, colors, the order of arrays and properties, and properties this file does not define.
- Keep an element's id when you rename it. Give a new element an id that no element of its kind uses.
- Add a new element at the end of its array. Add a new document property in the order of the table in section 3.
- When you delete a node, delete the edges that start or end at it. When you delete a boundary or a cluster, remove its id from the nodes that name it.

## 11. Handing the document to the user

Always give the JSON. The user pastes it into the app's document code editor ("Edit document code" in the workspace's editing mode) and saves it, or saves it as a `.json` file and imports it. Pasting replaces the document open in the editor. For a new document, or a plan to keep beside the current one, the user first makes a new document ("New document", or "Duplicate document" with "Planned" ticked for a plan) and pastes into it, or imports the file, which always adds a new document.

When you start from a document the user gave you, whether you change it or draw a plan from it, give the JSON alone, without a link: the user pastes it into that document, or into its planned copy. A link would add yet another copy, and its new nodes may overlap others (section 8).

For a new document, if you can run code, also give a share link. The user opens it, reads the document on the view-only share page and copies it into their workspace with "Copy to my workspace". The share page is `/share` on the site that serves this file, and `/ko/share` is the same page in Korean: use it for a user who writes in Korean. A copy of this file made with the app's "Copy rules for AI" starts with a line that names the site and the share page to use. A link is the share page's address followed by `#deflate=` and the document's JSON without indentation, compressed with zlib and written in base64url. The `=` it may end with can stay or go: the link opens either way. This Python script makes the link from the JSON you give and checks it:

```python
import base64, json, zlib

share_page = "https://example.com/share"  # the share page of the site that serves this file

with open("document.json", encoding="utf-8") as file:
    document = json.load(file)  # the JSON you give the user

text = json.dumps(document, ensure_ascii=False, separators=(",", ":"))
value = base64.urlsafe_b64encode(zlib.compress(text.encode("utf-8"))).decode("ascii")
link = f"{share_page}#deflate={value}"

unpacked = json.loads(zlib.decompress(base64.urlsafe_b64decode(value)).decode("utf-8"))
assert unpacked == document, "the link does not hold the document"
assert len(link) <= 16384, f"the link has {len(link)} characters: give the JSON only"
print(link)
```

In Node, `zlib.deflateSync(Buffer.from(JSON.stringify(document))).toString("base64url")` makes the value, without the `=`, and `JSON.parse(zlib.inflateSync(Buffer.from(value, "base64url")).toString())` unpacks it.

- Give the link only when the whole link has at most 16,384 characters. Messengers may cut a longer one off, so give the JSON alone.
- Give the link only after unpacking it again has given back the JSON you give.
- Without a code tool, or when you do not know the site's address, give the JSON alone. Do not write a link by hand.

The app's labels on its Korean pages: "Edit document code" is "문서 코드 편집", "New document" is "새 문서 만들기", "Duplicate document" is "문서 복제", "Planned" is "반영 예정", and "Copy to my workspace" is "내 작업 공간으로 가져오기". Use them when you answer in Korean.

## 12. Complete example

```json
{
  "format": "flowbraid",
  "version": 1,
  "name": "Order Fulfillment Flow",
  "description": "From a placed order to the carrier's delivery updates",
  "notes": "Covers the order event, the shipment records and the calls to the carrier. Payment is left out.",
  "nodes": [
    { "id": "order-service", "type": "app", "name": "Order Service", "platform": "spring", "boundary": "ordering" },
    { "id": "orders-db", "type": "store", "name": "orders", "platform": "postgresql", "boundary": "ordering" },
    { "id": "orders-placed", "type": "topic", "name": "orders.placed", "platform": "kafka", "cluster": "kafka-main" },
    { "id": "fulfillment-service", "type": "app", "name": "Fulfillment Service", "platform": "spring", "boundary": "fulfillment" },
    { "id": "shipments-db", "type": "store", "name": "shipments", "platform": "postgresql", "boundary": "fulfillment" },
    { "id": "support-console", "type": "app", "name": "Support Console", "description": "Looks up shipments for customer support" },
    { "id": "carrier-api", "type": "app", "name": "Carrier API", "external": true }
  ],
  "edges": [
    { "id": "order-writes-orders", "from": "order-service", "to": "orders-db", "type": "write" },
    { "id": "order-publishes-placed", "from": "order-service", "to": "orders-placed", "type": "publish", "events": ["OrderPlaced"] },
    { "id": "fulfillment-subscribes-placed", "from": "orders-placed", "to": "fulfillment-service", "type": "subscribe", "events": ["OrderPlaced"] },
    { "id": "fulfillment-writes-shipments", "from": "fulfillment-service", "to": "shipments-db", "type": "write" },
    { "id": "fulfillment-reads-shipments", "from": "shipments-db", "to": "fulfillment-service", "type": "read" },
    { "id": "support-reads-shipments", "from": "shipments-db", "to": "support-console", "type": "read" },
    { "id": "fulfillment-requests-carrier", "from": "fulfillment-service", "to": "carrier-api", "type": "request", "label": "Create shipment" },
    { "id": "carrier-sends-status", "from": "carrier-api", "to": "fulfillment-service", "type": "request", "label": "Delivery status webhook" }
  ],
  "boundaries": [
    { "id": "ordering", "name": "Ordering", "description": "Takes orders", "color": "teal" },
    { "id": "fulfillment", "name": "Fulfillment", "description": "Ships orders", "color": "purple" }
  ],
  "clusters": [
    { "id": "kafka-main", "name": "kafka-main", "color": "olive", "metadata": { "bootstrapServers": "kafka-main.internal:9092" } }
  ]
}
```

- Order Service writes its orders and publishes `OrderPlaced`, and Fulfillment Service subscribes to it.
- Fulfillment Service writes and reads its shipments table. Support Console, in neither boundary, reads that table directly, so the read crosses the Fulfillment boundary.
- Fulfillment Service calls the carrier's API, and the carrier sends delivery updates back by webhook: two `request` edges, each from the side that sends.
- No node has a `position`, and each boundary and the cluster has a color of its own.
- The platforms and the cluster's address stand in for what a request would give. Leave out what yours does not.
