# Flow chart syntax

## Nodes

A node is the most basic building block in a flow chart.

Node definitions consist of a name followed by an optional set of properties. For example, `Start` is the name of below node and it has an `shape` property which is set to `oval`.

```eraser
Start [shape: oval]
```

<Figure src="/assets/48546b3-image.png" alt="" width="150px" />

Node names are required to be unique.

Nodes support `shape`, `icon`, `color`, and `label` properties. More on properties below.

## Groups

A group is a container that can encapsulate nodes and groups.

Group definitions consist of a name followed by `{ }`. For example, `Loop` is the name of the below group and it contains `Issue1`, `Issue2`, and `Issue3` nodes.

```eraser
Loop {
  Issue1, Issue2, Issue3
}
```

<Figure src="/assets/26a8a15-image.png" alt="" width="500px" />

Nodes (or groups) inside a group can be enumerated either with `,` or new lines as separators. Below results in the same but uses new lines to separate each node.

```eraser
Loop {
  Issue1
  Issue2
  Issue3
}
```

Group names are required to be unique.

Groups can be nested. In the below example, the `Outer Loop` group contains the `Inner Loop` group.

```eraser
Outer Loop {
	Inner Loop {
		Issue1
		Issue2    
	}
	Issue3
}
```

<Figure src="/assets/110a93b-image.png" alt="" width="500px" />

Groups support `icon`, `color`, and `label` properties.

## Properties

Properties are key-value pairs enclosed in `[ ]` brackets that can be appended to definitions of nodes and groups. Properties are optional.

Here are the properties that are allowed:

| Property    | Description               | Value                                                                                                                                                                                                                                            | Default Value         |
| :---------- | :------------------------ | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :-------------------- |
| `shape`     | Shape of node             | Shape names (e.g. `diamond` or `oval`).                                                                                                                                                                                                          | `rectangle`           |
| `icon`      | Icon                      | Icon names (e.g. `aws-ec2`). See [Icons](/icons) page for full list.                                                                                                                                                                          |                       |
| `color`     | Stroke and fill color     | Color name (e.g. `blue`) or hex code (e.g. `"#000000"`- note: must be wrapped in quotes)                                                                                                                                                         |                       |
| `label`     | Text label                | Any string. Enclose in double quotes (e.g. `"Main Server"`) if containing a space. Allows multiple nodes and groups to have the same `label`.                                                                                                    | Name of node or group |
| `link`      | Internal or external link | A fully fledged URL. Enclose in double quotes (e.g. "[https://my-internal-docs.io/api-docs](https://my-internal-docs.io/api-docs)". Supports the full gamut of external links and Eraser-specific links: diagrams, headers, and files in Eraser. |                       |
| `colorMode` | Fill color lightness      | `pastel`, `bold`, `outline`                                                                                                                                                                                                                      | `pastel`              |
| `styleMode` | Embellishments            | `shadow`, `plain`, `watercolor`                                                                                                                                                                                                                  | `shadow`              |
| `typeface`  | Text typeface             | `rough`, `clean`, `mono`                                                                                                                                                                                                                         | `rough`               |

Here is the list of shapes:

* `rectangle` (default), `cylinder`, `diamond`, `document`, `ellipse`, `hexagon`, `oval`, `parallelogram`, `star`, `trapezoid`, `triangle`

Here are the lists of icon names:

* [AWS Icons](/icons#aws-icons)
* [Google Cloud Icons](/icons#google-cloud-icons)
* [Azure Icons](/icons#azure-icons)
* [Tech Logos](/icons#tech-logos)
* [General Icons](/icons#general-icons)

The `label` property is useful if you want the node's (or group's) label and name to be distinct. By default, the `label` is set as the node name. But because node names are required to be distinct, you will need to use the `label` property if you have two nodes with the exact same label.

```eraser
// Names need to be distinct, but labels can overlap
Start_A [label: start]
Start_B [label: start]
```

Refer to [Styling](/styling) for more details and examples on the `colorMode`, `styleMode`, and `typeface` properties.

It is possible to set multiple properties by separating them using `,` like shown below:

```eraser
Start [shape: oval, icon: flag]
```

## Connections

Connections represent relationships between nodes and groups. They can be created between nodes, between groups, and between nodes and groups.

Here is an example of a connection between two nodes:

```eraser
Issue > Bug
```

<Figure src="/assets/3eeeac3-image.png" alt="" width="150px" />

Here are the types of connectors:

| Connector | Syntax | Description |
| --- | --- | --- |
| ![](/assets/c0e10e5-left-to-right-arrow.svg) | `>` | Left-to-right arrow |
| ![](/assets/cdb95bd-right-to-left-arrow.svg) | `<` | Right-to-left arrow |
| ![](/assets/b68e2d9-bi-directional-arrow.svg) | `<>` | Bi-directional arrow |
| ![](/assets/d880fbb-line.svg) | `-` | Line |
| ![](/assets/bc3c932-dotted-line.svg) | `--` | Dotted line |
| ![](/assets/f45d160-dotted-arrow.svg) | `-->` | Dotted arrow |

### Connection label

It is possible to add a label to a connection. Here is an example:

```eraser
Issue > Bug: Triage
```

<Figure src="/assets/9a1104f-Relationship_labels.png" alt="" width="125px" />

### Branching connections

It is possible to create it is possible to create one-to-many connections in a single statement. Here is an example:

```eraser
Issue > Bug, Feature
```

<Figure src="/assets/0896972-image.png" alt="" width="300px" />

### Chained connections

It is also possible to "chain" a sequence of connection statements in a single statement

```eraser
Issue > Bug > Duplicate?
```

<Figure src="/assets/19d4eb8-image.png" alt="" width="125px" />

If a connection statement contains a name that has not been previously defined as a node or a group, a blank node with that name will be created.

### Connection properties

Here are the properties that are allowed on connections (lines):


  <thead>
    <tr>
      <th>
        Property
      </th>

      <th>
        Description
      </th>

      <th>
        Example
      </th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>
        `color`
      </td>

      <td>
        Line color
      </td>

      <td>
        `Issue > Bug: Triage [color: green]`  
        `Issue > Bug: [color: green]`
      </td>
    </tr>
  </tbody>


## Icons

Here's a [list of all the icons you can use with diagram-as-code](/icons).

## Escape string

Certain characters are not allowed in node and group names because they are reserved. You can use these characters, you can wrap the entire node or group name in quotes `" "`.

```eraser
User > "https://localhost:8080": GET
```

## Direction

The direction of the flow chart can be changed using the `direction` statement. Allowed directions are:

* `direction down` (default)
* `direction up`
* `direction right`
* `direction left`

The direction statement can be placed anywhere in the code like this:

```eraser
direction right
```

<Figure src="/assets/c324846c63b87f7837f0c62e8414d58325a849c840a7d04f136d84ebdaf8c794-diagram-export-11-4-2024-9_33_26-AM.png" alt="`direction right` has been applied to the flow chart" />

## Styling

Styles can be applied at the diagram level. Below is an overview of the options and syntax. Refer to [Styling](/styling) for more details and examples.

| Property    | Values                          | Default value | Syntax example     |
| :---------- | :------------------------------ | :------------ | :----------------- |
| `colorMode` | `pastel`, `bold`, `outline`     | `pastel`      | `colorMode bold`   |
| `styleMode` | `shadow`, `plain`, `watercolor` | `shadow`      | `styleMode shadow` |
| `typeface`  | `rough`, `clean`, `mono`        | `rough`       | `typeface clean`   |

## Legends

Legends map a swatch (connection, icon, shape, or color) to a label. Swatches are not tied to actual elements in the diagram.

```eraser
 legend {                                        
    [connection: -->, label: Async]            
    [color: red, label: Error]
    [icon: aws-lambda, label: Lambda]
    [shape: diamond, label: Decision]
  }
```

### Legend properties

| Property | Description                          | Value                                       | Default Value |
| :------- | :----------------------------------- | :------------------------------------------ | :------------ |
| position | Position of the legend on the canvas | Position names (e.g. `top-left` or `right`) | `top-right`   |

```eraser
  legend [position: bottom-left] {  
    [color: red, label: Error]  
  }
```

Here is the list of positions:

`top-left`, `top-right` (default), `bottom-left`, `bottom-right`, `top`, `bottom`, `left`, `right`

### Legend item properties

Each legend item is enclosed in `[ ]` and must include a `label` and at least one swatch property.

| Property   | Description       | Value                                                         |
| :--------- | :---------------- | :------------------------------------------------------------ |
| label      | Text label        | Any string. Enclose in double quotes if containing a space.   |
| connection | Connection swatch | Connection types (e.g. `-->` or `<>`). See Connections above. |
| color      | Color swatch      | Color name (e.g. `blue`) or hex code (e.g. `"#000000"`)       |
| icon       | Icon swatch       | Icon names (e.g. `aws-ec2`). See Icons page for full list.    |
| shape      | Shape swatch      | Shape names (e.g. `diamond` or `oval`).                       |

`color` can be combined with `connection` or `shape`. Other swatch types are mutually exclusive.

```eraser
legend {  
    [connection: -->, color: orange, label: Async backup]  
    [shape: rectangle, color: blue, label: Active]  
}
```
