2024-07-06 16:24:08 -05:00
> **Warning**
>
> ## THIS IS AN AUTOGENERATED FILE. DO NOT EDIT.
>
> ## Please edit the corresponding file in [/packages/mermaid/src/docs/syntax/architecture.md](../../packages/mermaid/src/docs/syntax/architecture.md).
2024-09-02 15:16:23 +00:00
# Architecture Diagrams Documentation (v11.1.0+)
2024-07-06 16:24:08 -05:00
> In the context of mermaid-js, the architecture diagram is used to show the relationship between services and resources commonly found within the Cloud or CI/CD deployments. In an architecture diagram, services (nodes) are connected by edges. Related services can be placed within groups to better illustrate how they are organized.
## Example
```mermaid-example
2024-07-22 09:34:36 -05:00
architecture-beta
2024-07-06 16:24:08 -05:00
group api(cloud)[API]
service db(database)[Database] in api
service disk1(disk)[Storage] in api
service disk2(disk)[Storage] in api
service server(server)[Server] in api
2024-07-23 15:31:11 -05:00
db:L -- R:server
disk1:T -- B:server
disk2:T -- B:db
2024-07-06 16:24:08 -05:00
```
```mermaid
2024-07-22 09:34:36 -05:00
architecture-beta
2024-07-06 16:24:08 -05:00
group api(cloud)[API]
service db(database)[Database] in api
service disk1(disk)[Storage] in api
service disk2(disk)[Storage] in api
service server(server)[Server] in api
2024-07-23 15:31:11 -05:00
db:L -- R:server
disk1:T -- B:server
disk2:T -- B:db
2024-07-06 16:24:08 -05:00
```
## Syntax
2024-07-06 16:34:03 -05:00
The building blocks of an architecture are `groups` , `services` , `edges` , and `junctions` .
2024-07-06 16:24:08 -05:00
For supporting components, icons are declared by surrounding the icon name with `()` , while labels are declared by surrounding the text with `[]` .
2024-07-22 09:34:36 -05:00
To begin an architecture diagram, use the keyword `architecture-beta` , followed by your groups, services, edges, and junctions. While each of the 3 building blocks can be declared in any order, care must be taken to ensure the identifier was previously declared by another component.
2024-07-06 16:24:08 -05:00
### Groups
The syntax for declaring a group is:
```
group {group id}({icon name})[{title}] (in {parent id})?
```
Put together:
```
group public_api(cloud)[Public API]
```
creates a group identified as `public_api` , uses the icon `cloud` , and has the label `Public API` .
Additionally, groups can be placed within a group using the optional `in` keyword
```
group private_api(cloud)[Private API] in public_api
```
### Services
2024-07-06 16:34:03 -05:00
The syntax for declaring a service is:
2024-07-06 16:24:08 -05:00
```
service {service id}({icon name})[{title}] (in {parent id})?
```
Put together:
```
service database(db)[Database]
```
creates the service identified as `database` , using the icon `db` , with the label `Database` .
If the service belongs to a group, it can be placed inside it through the optional `in` keyword
```
service database(db)[Database] in private_api
```
### Edges
2024-07-06 16:34:03 -05:00
The syntax for declaring an edge is:
```
2024-07-23 15:31:11 -05:00
{serviceId}{{group}}?:{T|B|L|R} {< }?--{>}? {T|B|L|R}:{serviceId}{{group}}?
2024-07-06 16:34:03 -05:00
```
#### Edge Direction
2024-07-23 15:31:11 -05:00
The side of the service the edge comes out of is specified by adding a colon (`:` ) to the side of the service connecting to the arrow and adding `L|R|T|B`
2024-07-06 16:34:03 -05:00
For example:
```
2024-07-23 15:31:11 -05:00
db:R -- L:server
2024-07-06 16:34:03 -05:00
```
creates an edge between the services `db` and `server` , with the edge coming out of the right of `db` and the left of `server` .
```
2024-07-23 15:31:11 -05:00
db:T -- L:server
2024-07-06 16:34:03 -05:00
```
creates a 90 degree edge between the services `db` and `server` , with the edge coming out of the top of `db` and the left of `server` .
#### Arrows
2024-07-23 15:31:11 -05:00
Arrows can be added to each side of an edge by adding `<` before the direction on the left, and/or `>` after the direction on the right.
2024-07-06 16:34:03 -05:00
For example:
```
2024-07-23 15:31:11 -05:00
subnet:R --> L:gateway
2024-07-06 16:34:03 -05:00
```
creates an edge with the arrow going into the `gateway` service
#### Edges out of Groups
To have an edge go from a group to another group or service within another group, the `{group}` modifier can be added after the `serviceId` .
For example:
```
service server[Server] in groupOne
service subnet[Subnet] in groupTwo
2024-07-23 15:31:11 -05:00
server{group}:B --> T:subnet{group}
2024-07-06 16:34:03 -05:00
```
creates an edge going out of `groupOne` , adjacent to `server` , and into `groupTwo` , adjacent to `subnet` .
It's important to note that `groupId` s cannot be used for specifying edges and the `{group}` modifier can only be used for services within a group.
### Junctions
Junctions are a special type of node which acts as a potential 4-way split between edges.
The syntax for declaring a junction is:
```
junction {junction id} (in {parent id})?
```
```mermaid-example
2024-07-22 09:34:36 -05:00
architecture-beta
2024-07-06 16:34:03 -05:00
service left_disk(disk)[Disk]
service top_disk(disk)[Disk]
service bottom_disk(disk)[Disk]
service top_gateway(internet)[Gateway]
service bottom_gateway(internet)[Gateway]
junction junctionCenter
junction junctionRight
2024-07-23 15:31:11 -05:00
left_disk:R -- L:junctionCenter
top_disk:B -- T:junctionCenter
bottom_disk:T -- B:junctionCenter
junctionCenter:R -- L:junctionRight
top_gateway:B -- T:junctionRight
bottom_gateway:T -- B:junctionRight
2024-07-06 16:34:03 -05:00
```
```mermaid
2024-07-22 09:34:36 -05:00
architecture-beta
2024-07-06 16:34:03 -05:00
service left_disk(disk)[Disk]
service top_disk(disk)[Disk]
service bottom_disk(disk)[Disk]
service top_gateway(internet)[Gateway]
service bottom_gateway(internet)[Gateway]
junction junctionCenter
junction junctionRight
2024-07-23 15:31:11 -05:00
left_disk:R -- L:junctionCenter
top_disk:B -- T:junctionCenter
bottom_disk:T -- B:junctionCenter
junctionCenter:R -- L:junctionRight
top_gateway:B -- T:junctionRight
bottom_gateway:T -- B:junctionRight
2024-07-06 16:34:03 -05:00
```
2024-07-06 16:24:08 -05:00
2024-09-02 13:20:34 +05:30
## Icons
By default, architecture diagram supports the following icons: `cloud` , `database` , `disk` , `internet` , `server` .
Users can use any of the 200,000+ icons available in iconify.design, or add their own custom icons, by following the steps below.
The icon packs available can be found at [icones.js.org ](https://icones.js.org/ ).
2024-09-02 19:51:14 +05:30
We use the name defined when registering the icon pack, to override the prefix field of the iconify pack. This allows the user to use shorter names for the icons. It also allows us to load a particular pack only when it is used in a diagram.
2024-09-02 13:20:34 +05:30
Using JSON file directly from CDN:
```js
import mermaid from 'CDN/mermaid.esm.mjs';
2024-09-02 19:51:14 +05:30
mermaid.registerIconPacks([
{
name: 'logos',
loader: () =>
fetch('https://unpkg.com/@iconify -json/logos/icons.json').then((res) => res.json()),
},
]);
2024-09-02 13:20:34 +05:30
```
Using packages and a bundler:
2024-09-02 19:51:14 +05:30
```bash
npm install @iconify -json/logos
```
With lazy loading
2024-09-02 13:20:34 +05:30
```js
import mermaid from 'mermaid';
2024-09-02 19:51:14 +05:30
mermaid.registerIconPacks([
{
name: 'logos',
loader: () => import('@iconify -json/logos').then((module) => module.icons),
},
]);
2024-09-02 13:20:34 +05:30
```
2024-09-02 19:51:14 +05:30
Without lazy loading
2024-09-02 13:20:34 +05:30
2024-09-02 19:51:14 +05:30
```js
import mermaid from 'mermaid';
import { icons } from '@iconify -json/logos';
mermaid.registerIconPacks([
{
name: icons.prefix, // To use the prefix defined in the icon pack
icons,
},
]);
```
After the icons are installed, they can be used in the architecture diagram by using the format "name:icon-name", where name is the value used when registering the icon pack.
```mermaid-example
2024-09-02 13:20:34 +05:30
architecture-beta
group api(logos:aws-lambda)[API]
service db(logos:aws-aurora)[Database] in api
service disk1(logos:aws-glacier)[Storage] in api
service disk2(logos:aws-s3)[Storage] in api
service server(logos:aws-ec2)[Server] in api
db:L -- R:server
disk1:T -- B:server
disk2:T -- B:db
```
2024-09-02 13:50:50 +05:30
2024-09-02 19:51:14 +05:30
```mermaid
architecture-beta
group api(logos:aws-lambda)[API]
2024-09-02 13:50:50 +05:30
2024-09-02 19:51:14 +05:30
service db(logos:aws-aurora)[Database] in api
service disk1(logos:aws-glacier)[Storage] in api
service disk2(logos:aws-s3)[Storage] in api
service server(logos:aws-ec2)[Server] in api
2024-09-02 13:50:50 +05:30
2024-09-02 19:51:14 +05:30
db:L -- R:server
disk1:T -- B:server
disk2:T -- B:db
```