Skip to content

D2 ComponentDiagram Spec

Source: d2.component-diagram.json

This schema describes the ComponentDiagram spec for the D2 backend.

Properties

Properties

Field Type Description
type(required) string Type of the diagram. Must be exactly ComponentDiagram.
title string | null Optional diagram title.
elements array[Element] Top-level elements.
boundaries array[Boundary] Top-level boundaries.
relationships array[D2RelationshipSchema] Top-level relationships.
render_options D2RenderOptionsSchema D2-specific render options.
backend(required) string JSON schema backend. Must be exactly d2.
Examples
JSON source
{
  "backend": "d2",
  "type": "ComponentDiagram",
  "title": "Checkout API - Component Diagram",
  "elements": [
    {
      "type": "Component",
      "label": "Checkout Controller",
      "alias": "checkout_controller",
      "description": "Receives checkout requests and orchestrates payment flow.",
      "technology": "FastAPI"
    },
    {
      "type": "Component",
      "label": "Payment Service",
      "alias": "payment_service",
      "description": "Creates payment intents and handles payment state updates.",
      "technology": "Python"
    },
    {
      "type": "ComponentDb",
      "label": "Payment Store",
      "alias": "payment_store",
      "description": "Stores payment records and statuses.",
      "technology": "PostgreSQL"
    },
    {
      "type": "ComponentExt",
      "label": "Payment Gateway API",
      "alias": "payment_gateway_api",
      "description": "External API for payment authorization and capture.",
      "technology": "REST API"
    }
  ],
  "relationships": [
    {
      "type": "REL",
      "from": "checkout_controller",
      "to": "payment_service",
      "label": "Calls",
      "technology": "Python call"
    },
    {
      "type": "REL",
      "from": "payment_service",
      "to": "payment_store",
      "label": "Reads and writes",
      "technology": "SQL"
    },
    {
      "type": "REL",
      "from": "payment_service",
      "to": "payment_gateway_api",
      "label": "Creates payments via",
      "technology": "HTTPS/JSON"
    }
  ]
}
Rendered D2 source
direction: right
__title: ||md
  # Checkout API - Component Diagram
|| {
  near: top-center
}
classes: {
  c4_external: {
    style.fill: "#f7f7f7"
    style.stroke: "#767676"
    style.stroke-dash: "5"
  }
  c4_database: {
    style.fill: "#edf7ff"
    style.stroke: "#2d6f9f"
  }
}
checkout_controller: ||md
  ## Checkout Controller

  [Component: FastAPI]

  Receives checkout requests and orchestrates payment flow.
|| {
  shape: rectangle
}
payment_service: ||md
  ## Payment Service

  [Component: Python]

  Creates payment intents and handles payment state updates.
|| {
  shape: rectangle
}
payment_store: ||md
  ## Payment Store

  [Component: PostgreSQL]

  Stores payment records and statuses.
|| {
  shape: cylinder
  class: ["c4_database"]
}
payment_gateway_api: ||md
  ## Payment Gateway API

  [Component: REST API]

  External API for payment authorization and capture.
|| {
  shape: rectangle
  class: ["c4_external"]
}
checkout_controller -> payment_service: "Calls\n[Python call]"
payment_service -> payment_store: "Reads and writes\n[SQL]"
payment_service -> payment_gateway_api: "Creates payments via\n[HTTPS/JSON]"
Rendered image

ComponentDiagram minimal example

JSON source
{
  "backend": "d2",
  "type": "ComponentDiagram",
  "title": "Order Processing API - Component Diagram",
  "elements": [
    {
      "type": "Component",
      "label": "Order Controller",
      "alias": "order_controller",
      "description": "HTTP entrypoint for order submission and status queries.",
      "technology": "FastAPI",
      "properties": {
        "properties": [
          [
            "Owner",
            "Checkout Team"
          ],
          [
            "Runtime",
            "FastAPI"
          ]
        ]
      }
    },
    {
      "type": "Component",
      "label": "Order Application Service",
      "alias": "order_app_service",
      "description": "Coordinates validation, payment, and order creation.",
      "technology": "Python",
      "properties": {
        "properties": [
          [
            "Owner",
            "Checkout Team"
          ],
          [
            "Runtime",
            "Python"
          ]
        ]
      }
    },
    {
      "type": "Component",
      "label": "Inventory Checker",
      "alias": "inventory_checker",
      "description": "Verifies stock availability before an order is confirmed.",
      "technology": "Python",
      "properties": {
        "properties": [
          [
            "Owner",
            "Checkout Team"
          ],
          [
            "Runtime",
            "Python"
          ]
        ]
      }
    },
    {
      "type": "Component",
      "label": "Payment Adapter",
      "alias": "payment_adapter",
      "description": "Wraps external payment provider calls.",
      "technology": "Python",
      "properties": {
        "properties": [
          [
            "Owner",
            "Checkout Team"
          ],
          [
            "Runtime",
            "Python"
          ]
        ]
      }
    },
    {
      "type": "ComponentDb",
      "label": "Order Database",
      "alias": "order_db",
      "description": "Stores orders, line items, and order status history.",
      "technology": "PostgreSQL",
      "properties": {
        "properties": [
          [
            "Owner",
            "Checkout Team"
          ],
          [
            "Runtime",
            "PostgreSQL"
          ]
        ]
      }
    },
    {
      "type": "ComponentExt",
      "label": "Payment Gateway API",
      "alias": "payment_gateway_api",
      "description": "External provider API for payment authorization and capture.",
      "technology": "REST API",
      "properties": {
        "properties": [
          [
            "Owner",
            "Checkout Team"
          ],
          [
            "Runtime",
            "REST API"
          ]
        ]
      }
    },
    {
      "type": "ComponentQueue",
      "label": "Order Events Bus",
      "alias": "order_events_bus",
      "description": "Publishes order-created and order-paid events.",
      "technology": "Kafka",
      "properties": {
        "properties": [
          [
            "Owner",
            "Checkout Team"
          ],
          [
            "Runtime",
            "Kafka"
          ]
        ]
      }
    }
  ],
  "relationships": [
    {
      "type": "REL",
      "from": "order_controller",
      "to": "order_app_service",
      "label": "Invokes",
      "technology": "Python call"
    },
    {
      "type": "REL",
      "from": "order_app_service",
      "to": "inventory_checker",
      "label": "Checks stock via",
      "technology": "Python call"
    },
    {
      "type": "REL",
      "from": "order_app_service",
      "to": "payment_adapter",
      "label": "Requests payment through",
      "technology": "Python call"
    },
    {
      "type": "REL",
      "from": "payment_adapter",
      "to": "payment_gateway_api",
      "label": "Authorizes payment via",
      "technology": "HTTPS/JSON"
    },
    {
      "type": "REL",
      "from": "order_app_service",
      "to": "order_db",
      "label": "Reads and writes",
      "technology": "SQL"
    },
    {
      "type": "REL",
      "from": "order_app_service",
      "to": "order_events_bus",
      "label": "Publishes events to",
      "technology": "Kafka"
    }
  ],
  "render_options": {
    "layout": "dagre",
    "include_properties": true,
    "bidirectional_relationships": "single_edge"
  }
}
Rendered D2 source
direction: right
__title: ||md
  # Order Processing API - Component Diagram
|| {
  near: top-center
}
classes: {
  c4_external: {
    style.fill: "#f7f7f7"
    style.stroke: "#767676"
    style.stroke-dash: "5"
  }
  c4_database: {
    style.fill: "#edf7ff"
    style.stroke: "#2d6f9f"
  }
  c4_queue: {
    style.fill: "#fff6e5"
    style.stroke: "#9b6500"
  }
}
order_controller: ||md
  ## Order Controller

  [Component: FastAPI]

  HTTP entrypoint for order submission and status queries.

  | Property | Value |
  | --- | --- |
  | Owner | Checkout Team |
  | Runtime | FastAPI |
|| {
  shape: rectangle
}
order_app_service: ||md
  ## Order Application Service

  [Component: Python]

  Coordinates validation, payment, and order creation.

  | Property | Value |
  | --- | --- |
  | Owner | Checkout Team |
  | Runtime | Python |
|| {
  shape: rectangle
}
inventory_checker: ||md
  ## Inventory Checker

  [Component: Python]

  Verifies stock availability before an order is confirmed.

  | Property | Value |
  | --- | --- |
  | Owner | Checkout Team |
  | Runtime | Python |
|| {
  shape: rectangle
}
payment_adapter: ||md
  ## Payment Adapter

  [Component: Python]

  Wraps external payment provider calls.

  | Property | Value |
  | --- | --- |
  | Owner | Checkout Team |
  | Runtime | Python |
|| {
  shape: rectangle
}
order_db: ||md
  ## Order Database

  [Component: PostgreSQL]

  Stores orders, line items, and order status history.

  | Property | Value |
  | --- | --- |
  | Owner | Checkout Team |
  | Runtime | PostgreSQL |
|| {
  shape: cylinder
  class: ["c4_database"]
}
payment_gateway_api: ||md
  ## Payment Gateway API

  [Component: REST API]

  External provider API for payment authorization and capture.

  | Property | Value |
  | --- | --- |
  | Owner | Checkout Team |
  | Runtime | REST API |
|| {
  shape: rectangle
  class: ["c4_external"]
}
order_events_bus: ||md
  ## Order Events Bus

  [Component: Kafka]

  Publishes order-created and order-paid events.

  | Property | Value |
  | --- | --- |
  | Owner | Checkout Team |
  | Runtime | Kafka |
|| {
  shape: queue
  class: ["c4_queue"]
}
order_controller -> order_app_service: "Invokes\n[Python call]"
order_app_service -> inventory_checker: "Checks stock via\n[Python call]"
order_app_service -> payment_adapter: "Requests payment through\n[Python call]"
payment_adapter -> payment_gateway_api: "Authorizes payment via\n[HTTPS/JSON]"
order_app_service -> order_db: "Reads and writes\n[SQL]"
order_app_service -> order_events_bus: "Publishes events to\n[Kafka]"
Rendered image

ComponentDiagram advanced example

Elements

Boundaries

Relationships

Definitions

About labels and aliases

label is a display name for the element.

alias is a unique identifier used for referencing elements in relationships and layouts. If omitted, it is generated automatically.

You can also use label for referencing elements in relationships and layouts, but each label must be unique within the diagram.


D2ComponentBoundarySchema

D2 JSON schema for a generic boundary in a component diagram.

Properties

Field Type Description
type(required) string Discriminator identifying the element type. Must be exactly Boundary.
elements array[Element] Elements may be nested arbitrarily.
boundaries array[Boundary] Boundaries may be nested arbitrarily.
relationships array[D2RelationshipSchema] Relationships declared inside the boundary.
alias string | null Unique identifier for the element. If not provided, it is autogenerated from the label.
classes array[string] Optional D2 classes.
description string | null Optional description text.
direction enum[up | down | left | right] | null Optional D2 layout direction for a container.
icon string | null Optional D2 icon URL.
label(required) string Display name for the element.
link string | null Optional D2 link URL.
near string | null Optional D2 near reference.
properties DiagramElementPropertiesSchema Optional property table metadata.
shape string | null Optional D2 shape.
style D2StyleSchema Optional D2 style attributes.
tooltip string | null Optional D2 tooltip.

D2ComponentContainerBoundarySchema

D2 JSON schema for a container boundary in a component diagram.

Properties

Field Type Description
type(required) string Discriminator identifying the element type. Must be exactly ContainerBoundary.
elements array[Element] Elements may be nested arbitrarily.
boundaries array[Boundary] Boundaries may be nested arbitrarily.
relationships array[D2RelationshipSchema] Relationships declared inside the boundary.
alias string | null Unique identifier for the element. If not provided, it is autogenerated from the label.
classes array[string] Optional D2 classes.
description string | null Optional description text.
direction enum[up | down | left | right] | null Optional D2 layout direction for a container.
icon string | null Optional D2 icon URL.
label(required) string Display name for the element.
link string | null Optional D2 link URL.
near string | null Optional D2 near reference.
properties DiagramElementPropertiesSchema Optional property table metadata.
shape string | null Optional D2 shape.
style D2StyleSchema Optional D2 style attributes.
tooltip string | null Optional D2 tooltip.

D2ComponentDbExtSchema

D2 JSON schema for an external database-like component.

Properties

Field Type Description
type(required) string Discriminator identifying the element type. Must be exactly ComponentDbExt.
alias string | null Unique identifier for the element. If not provided, it is autogenerated from the label.
classes array[string] Optional D2 classes.
description string | null Optional description text.
direction enum[up | down | left | right] | null Optional D2 layout direction for a container.
icon string | null Optional D2 icon URL.
label(required) string Display name for the element.
link string | null Optional D2 link URL.
near string | null Optional D2 near reference.
properties DiagramElementPropertiesSchema Optional property table metadata.
shape string | null Optional D2 shape.
style D2StyleSchema Optional D2 style attributes.
technology string | null Optional technology.
tooltip string | null Optional D2 tooltip.

D2ComponentDbSchema

D2 JSON schema for a database-like component.

Properties

Field Type Description
type(required) string Discriminator identifying the element type. Must be exactly ComponentDb.
alias string | null Unique identifier for the element. If not provided, it is autogenerated from the label.
classes array[string] Optional D2 classes.
description string | null Optional description text.
direction enum[up | down | left | right] | null Optional D2 layout direction for a container.
icon string | null Optional D2 icon URL.
label(required) string Display name for the element.
link string | null Optional D2 link URL.
near string | null Optional D2 near reference.
properties DiagramElementPropertiesSchema Optional property table metadata.
shape string | null Optional D2 shape.
style D2StyleSchema Optional D2 style attributes.
technology string | null Optional technology.
tooltip string | null Optional D2 tooltip.

D2ComponentEnterpriseBoundarySchema

D2 JSON schema for an enterprise boundary in component diagrams.

Properties

Field Type Description
type(required) string Discriminator identifying the element type. Must be exactly EnterpriseBoundary.
elements array[Element] Elements may be nested arbitrarily.
boundaries array[Boundary] Boundaries may be nested arbitrarily.
relationships array[D2RelationshipSchema] Relationships declared inside the boundary.
alias string | null Unique identifier for the element. If not provided, it is autogenerated from the label.
classes array[string] Optional D2 classes.
description string | null Optional description text.
direction enum[up | down | left | right] | null Optional D2 layout direction for a container.
icon string | null Optional D2 icon URL.
label(required) string Display name for the element.
link string | null Optional D2 link URL.
near string | null Optional D2 near reference.
properties DiagramElementPropertiesSchema Optional property table metadata.
shape string | null Optional D2 shape.
style D2StyleSchema Optional D2 style attributes.
tooltip string | null Optional D2 tooltip.

D2ComponentExtSchema

D2 JSON schema for an external component.

Properties

Field Type Description
type(required) string Discriminator identifying the element type. Must be exactly ComponentExt.
alias string | null Unique identifier for the element. If not provided, it is autogenerated from the label.
classes array[string] Optional D2 classes.
description string | null Optional description text.
direction enum[up | down | left | right] | null Optional D2 layout direction for a container.
icon string | null Optional D2 icon URL.
label(required) string Display name for the element.
link string | null Optional D2 link URL.
near string | null Optional D2 near reference.
properties DiagramElementPropertiesSchema Optional property table metadata.
shape string | null Optional D2 shape.
style D2StyleSchema Optional D2 style attributes.
technology string | null Optional technology.
tooltip string | null Optional D2 tooltip.

D2ComponentQueueExtSchema

D2 JSON schema for an external queue-like component.

Properties

Field Type Description
type(required) string Discriminator identifying the element type. Must be exactly ComponentQueueExt.
alias string | null Unique identifier for the element. If not provided, it is autogenerated from the label.
classes array[string] Optional D2 classes.
description string | null Optional description text.
direction enum[up | down | left | right] | null Optional D2 layout direction for a container.
icon string | null Optional D2 icon URL.
label(required) string Display name for the element.
link string | null Optional D2 link URL.
near string | null Optional D2 near reference.
properties DiagramElementPropertiesSchema Optional property table metadata.
shape string | null Optional D2 shape.
style D2StyleSchema Optional D2 style attributes.
technology string | null Optional technology.
tooltip string | null Optional D2 tooltip.

D2ComponentQueueSchema

D2 JSON schema for a queue-like component.

Properties

Field Type Description
type(required) string Discriminator identifying the element type. Must be exactly ComponentQueue.
alias string | null Unique identifier for the element. If not provided, it is autogenerated from the label.
classes array[string] Optional D2 classes.
description string | null Optional description text.
direction enum[up | down | left | right] | null Optional D2 layout direction for a container.
icon string | null Optional D2 icon URL.
label(required) string Display name for the element.
link string | null Optional D2 link URL.
near string | null Optional D2 near reference.
properties DiagramElementPropertiesSchema Optional property table metadata.
shape string | null Optional D2 shape.
style D2StyleSchema Optional D2 style attributes.
technology string | null Optional technology.
tooltip string | null Optional D2 tooltip.

D2ComponentSchema

D2 JSON schema for a component.

Properties

Field Type Description
type(required) string Discriminator identifying the element type. Must be exactly Component.
alias string | null Unique identifier for the element. If not provided, it is autogenerated from the label.
classes array[string] Optional D2 classes.
description string | null Optional description text.
direction enum[up | down | left | right] | null Optional D2 layout direction for a container.
icon string | null Optional D2 icon URL.
label(required) string Display name for the element.
link string | null Optional D2 link URL.
near string | null Optional D2 near reference.
properties DiagramElementPropertiesSchema Optional property table metadata.
shape string | null Optional D2 shape.
style D2StyleSchema Optional D2 style attributes.
technology string | null Optional technology.
tooltip string | null Optional D2 tooltip.

D2ComponentSystemBoundarySchema

D2 JSON schema for a system boundary in a component diagram.

Properties

Field Type Description
type(required) string Discriminator identifying the element type. Must be exactly SystemBoundary.
elements array[Element] Elements may be nested arbitrarily.
boundaries array[Boundary] Boundaries may be nested arbitrarily.
relationships array[D2RelationshipSchema] Relationships declared inside the boundary.
alias string | null Unique identifier for the element. If not provided, it is autogenerated from the label.
classes array[string] Optional D2 classes.
description string | null Optional description text.
direction enum[up | down | left | right] | null Optional D2 layout direction for a container.
icon string | null Optional D2 icon URL.
label(required) string Display name for the element.
link string | null Optional D2 link URL.
near string | null Optional D2 near reference.
properties DiagramElementPropertiesSchema Optional property table metadata.
shape string | null Optional D2 shape.
style D2StyleSchema Optional D2 style attributes.
tooltip string | null Optional D2 tooltip.

D2ContainerDbExtSchema

D2 JSON schema for an external database-like container.

Properties

Field Type Description
type(required) string Discriminator identifying the element type. Must be exactly ContainerDbExt.
alias string | null Unique identifier for the element. If not provided, it is autogenerated from the label.
classes array[string] Optional D2 classes.
description string | null Optional description text.
direction enum[up | down | left | right] | null Optional D2 layout direction for a container.
icon string | null Optional D2 icon URL.
label(required) string Display name for the element.
link string | null Optional D2 link URL.
near string | null Optional D2 near reference.
properties DiagramElementPropertiesSchema Optional property table metadata.
shape string | null Optional D2 shape.
style D2StyleSchema Optional D2 style attributes.
technology string | null Optional technology.
tooltip string | null Optional D2 tooltip.

D2ContainerDbSchema

D2 JSON schema for a database-like container.

Properties

Field Type Description
type(required) string Discriminator identifying the element type. Must be exactly ContainerDb.
alias string | null Unique identifier for the element. If not provided, it is autogenerated from the label.
classes array[string] Optional D2 classes.
description string | null Optional description text.
direction enum[up | down | left | right] | null Optional D2 layout direction for a container.
icon string | null Optional D2 icon URL.
label(required) string Display name for the element.
link string | null Optional D2 link URL.
near string | null Optional D2 near reference.
properties DiagramElementPropertiesSchema Optional property table metadata.
shape string | null Optional D2 shape.
style D2StyleSchema Optional D2 style attributes.
technology string | null Optional technology.
tooltip string | null Optional D2 tooltip.

D2ContainerExtSchema

D2 JSON schema for an external container.

Properties

Field Type Description
type(required) string Discriminator identifying the element type. Must be exactly ContainerExt.
alias string | null Unique identifier for the element. If not provided, it is autogenerated from the label.
classes array[string] Optional D2 classes.
description string | null Optional description text.
direction enum[up | down | left | right] | null Optional D2 layout direction for a container.
icon string | null Optional D2 icon URL.
label(required) string Display name for the element.
link string | null Optional D2 link URL.
near string | null Optional D2 near reference.
properties DiagramElementPropertiesSchema Optional property table metadata.
shape string | null Optional D2 shape.
style D2StyleSchema Optional D2 style attributes.
technology string | null Optional technology.
tooltip string | null Optional D2 tooltip.

D2ContainerQueueExtSchema

D2 JSON schema for an external queue-like container.

Properties

Field Type Description
type(required) string Discriminator identifying the element type. Must be exactly ContainerQueueExt.
alias string | null Unique identifier for the element. If not provided, it is autogenerated from the label.
classes array[string] Optional D2 classes.
description string | null Optional description text.
direction enum[up | down | left | right] | null Optional D2 layout direction for a container.
icon string | null Optional D2 icon URL.
label(required) string Display name for the element.
link string | null Optional D2 link URL.
near string | null Optional D2 near reference.
properties DiagramElementPropertiesSchema Optional property table metadata.
shape string | null Optional D2 shape.
style D2StyleSchema Optional D2 style attributes.
technology string | null Optional technology.
tooltip string | null Optional D2 tooltip.

D2ContainerQueueSchema

D2 JSON schema for a queue-like container.

Properties

Field Type Description
type(required) string Discriminator identifying the element type. Must be exactly ContainerQueue.
alias string | null Unique identifier for the element. If not provided, it is autogenerated from the label.
classes array[string] Optional D2 classes.
description string | null Optional description text.
direction enum[up | down | left | right] | null Optional D2 layout direction for a container.
icon string | null Optional D2 icon URL.
label(required) string Display name for the element.
link string | null Optional D2 link URL.
near string | null Optional D2 near reference.
properties DiagramElementPropertiesSchema Optional property table metadata.
shape string | null Optional D2 shape.
style D2StyleSchema Optional D2 style attributes.
technology string | null Optional technology.
tooltip string | null Optional D2 tooltip.

D2ContainerSchema

D2 JSON schema for a container.

Properties

Field Type Description
type(required) string Discriminator identifying the element type. Must be exactly Container.
alias string | null Unique identifier for the element. If not provided, it is autogenerated from the label.
classes array[string] Optional D2 classes.
description string | null Optional description text.
direction enum[up | down | left | right] | null Optional D2 layout direction for a container.
icon string | null Optional D2 icon URL.
label(required) string Display name for the element.
link string | null Optional D2 link URL.
near string | null Optional D2 near reference.
properties DiagramElementPropertiesSchema Optional property table metadata.
shape string | null Optional D2 shape.
style D2StyleSchema Optional D2 style attributes.
technology string | null Optional technology.
tooltip string | null Optional D2 tooltip.

D2PersonExtSchema

D2 JSON schema for an external person.

Properties

Field Type Description
type(required) string Discriminator identifying the element type. Must be exactly PersonExt.
alias string | null Unique identifier for the element. If not provided, it is autogenerated from the label.
classes array[string] Optional D2 classes.
description string | null Optional description text.
direction enum[up | down | left | right] | null Optional D2 layout direction for a container.
icon string | null Optional D2 icon URL.
label(required) string Display name for the element.
link string | null Optional D2 link URL.
near string | null Optional D2 near reference.
properties DiagramElementPropertiesSchema Optional property table metadata.
shape string | null Optional D2 shape.
style D2StyleSchema Optional D2 style attributes.
tooltip string | null Optional D2 tooltip.

D2PersonSchema

D2 JSON schema for a person.

Properties

Field Type Description
type(required) string Discriminator identifying the element type. Must be exactly Person.
alias string | null Unique identifier for the element. If not provided, it is autogenerated from the label.
classes array[string] Optional D2 classes.
description string | null Optional description text.
direction enum[up | down | left | right] | null Optional D2 layout direction for a container.
icon string | null Optional D2 icon URL.
label(required) string Display name for the element.
link string | null Optional D2 link URL.
near string | null Optional D2 near reference.
properties DiagramElementPropertiesSchema Optional property table metadata.
shape string | null Optional D2 shape.
style D2StyleSchema Optional D2 style attributes.
tooltip string | null Optional D2 tooltip.

D2RelationshipSchema

JSON schema for relationships supported by D2 C4 diagrams.

Properties

Field Type Description
type(required) RelationshipType Type of the relationship.
classes array[string] Optional D2 classes.
description string | null Additional details about the relationship.
from(required) string The source element alias (or unique label).
icon string | null Optional D2 icon URL.
label(required) string The label shown on the relationship edge.
link string | null Optional D2 link URL.
near string | null Optional D2 near reference.
properties DiagramElementPropertiesSchema Optional property table metadata.
style D2StyleSchema Optional D2 style attributes.
technology string | null The technology used in the communication.
to(required) string The destination element alias (or unique label).
tooltip string | null Optional D2 tooltip.

RelationshipType

Relationship types supported by D2 C4 diagrams.

Items

Type Description
BI_REL A bidirectional relationship between two elements.
REL A unidirectional relationship between two elements.

D2SystemDbExtSchema

D2 JSON schema for an external database-like system.

Properties

Field Type Description
type(required) string Discriminator identifying the element type. Must be exactly SystemDbExt.
alias string | null Unique identifier for the element. If not provided, it is autogenerated from the label.
classes array[string] Optional D2 classes.
description string | null Optional description text.
direction enum[up | down | left | right] | null Optional D2 layout direction for a container.
icon string | null Optional D2 icon URL.
label(required) string Display name for the element.
link string | null Optional D2 link URL.
near string | null Optional D2 near reference.
properties DiagramElementPropertiesSchema Optional property table metadata.
shape string | null Optional D2 shape.
style D2StyleSchema Optional D2 style attributes.
tooltip string | null Optional D2 tooltip.

D2SystemDbSchema

D2 JSON schema for a database-like system.

Properties

Field Type Description
type(required) string Discriminator identifying the element type. Must be exactly SystemDb.
alias string | null Unique identifier for the element. If not provided, it is autogenerated from the label.
classes array[string] Optional D2 classes.
description string | null Optional description text.
direction enum[up | down | left | right] | null Optional D2 layout direction for a container.
icon string | null Optional D2 icon URL.
label(required) string Display name for the element.
link string | null Optional D2 link URL.
near string | null Optional D2 near reference.
properties DiagramElementPropertiesSchema Optional property table metadata.
shape string | null Optional D2 shape.
style D2StyleSchema Optional D2 style attributes.
tooltip string | null Optional D2 tooltip.

D2SystemExtSchema

D2 JSON schema for an external software system.

Properties

Field Type Description
type(required) string Discriminator identifying the element type. Must be exactly SystemExt.
alias string | null Unique identifier for the element. If not provided, it is autogenerated from the label.
classes array[string] Optional D2 classes.
description string | null Optional description text.
direction enum[up | down | left | right] | null Optional D2 layout direction for a container.
icon string | null Optional D2 icon URL.
label(required) string Display name for the element.
link string | null Optional D2 link URL.
near string | null Optional D2 near reference.
properties DiagramElementPropertiesSchema Optional property table metadata.
shape string | null Optional D2 shape.
style D2StyleSchema Optional D2 style attributes.
tooltip string | null Optional D2 tooltip.

D2SystemQueueExtSchema

D2 JSON schema for an external queue-like system.

Properties

Field Type Description
type(required) string Discriminator identifying the element type. Must be exactly SystemQueueExt.
alias string | null Unique identifier for the element. If not provided, it is autogenerated from the label.
classes array[string] Optional D2 classes.
description string | null Optional description text.
direction enum[up | down | left | right] | null Optional D2 layout direction for a container.
icon string | null Optional D2 icon URL.
label(required) string Display name for the element.
link string | null Optional D2 link URL.
near string | null Optional D2 near reference.
properties DiagramElementPropertiesSchema Optional property table metadata.
shape string | null Optional D2 shape.
style D2StyleSchema Optional D2 style attributes.
tooltip string | null Optional D2 tooltip.

D2SystemQueueSchema

D2 JSON schema for a queue-like system.

Properties

Field Type Description
type(required) string Discriminator identifying the element type. Must be exactly SystemQueue.
alias string | null Unique identifier for the element. If not provided, it is autogenerated from the label.
classes array[string] Optional D2 classes.
description string | null Optional description text.
direction enum[up | down | left | right] | null Optional D2 layout direction for a container.
icon string | null Optional D2 icon URL.
label(required) string Display name for the element.
link string | null Optional D2 link URL.
near string | null Optional D2 near reference.
properties DiagramElementPropertiesSchema Optional property table metadata.
shape string | null Optional D2 shape.
style D2StyleSchema Optional D2 style attributes.
tooltip string | null Optional D2 tooltip.

D2SystemSchema

D2 JSON schema for a software system.

Properties

Field Type Description
type(required) string Discriminator identifying the element type. Must be exactly System.
alias string | null Unique identifier for the element. If not provided, it is autogenerated from the label.
classes array[string] Optional D2 classes.
description string | null Optional description text.
direction enum[up | down | left | right] | null Optional D2 layout direction for a container.
icon string | null Optional D2 icon URL.
label(required) string Display name for the element.
link string | null Optional D2 link URL.
near string | null Optional D2 near reference.
properties DiagramElementPropertiesSchema Optional property table metadata.
shape string | null Optional D2 shape.
style D2StyleSchema Optional D2 style attributes.
tooltip string | null Optional D2 tooltip.

DiagramElementPropertiesSchema

JSON schema for tabular diagram element properties.

Properties

Field Type Description
header array[string] Header columns. Default: ["Property", "Value"].
properties(required) array[array[string]] List of rows (each row is a list of string values).
show_header boolean Whether to display the header row. Default: true.

D2 Render Options

D2RenderOptionsSchema

Render options for the D2 renderer.

Properties

Field Type Description
auto_number_relationships boolean Auto Number Relationships Default: false.
bidirectional_relationships enum[two_edges | single_edge] Bidirectional Relationships Default: two_edges.
direction enum[up | down | left | right] | null Direction Default: right.
fully_qualified_relationships boolean Fully Qualified Relationships Default: true.
include_properties boolean Include Properties Default: false.
include_technology boolean Include Technology Default: true.
include_type_label boolean Include Type Label Default: true.
layout enum[dagre | elk] Layout Default: dagre.
legend D2LegendSchema
sequence_diagram boolean Sequence Diagram Default: false.
theme integer | null Theme
title_near enum[top-left | top-center | top-right | center-left | center-right | bottom-left | bottom-center | bottom-right] | null Title Near Default: top-center.

D2StyleSchema

D2 style attributes used by D2 render options.

Properties

Field Type Description
animated boolean | null Animated
bold boolean | null Bold
border_radius integer | null Border Radius
double_border boolean | null Double Border
fill string | null Fill
fill_pattern string | null Fill Pattern
font string | null Font
font_color string | null Font Color
font_size integer | null Font Size
italic boolean | null Italic
multiple boolean | null Multiple
opacity number | null Opacity
shadow boolean | null Shadow
stroke string | null Stroke
stroke_dash integer | null Stroke Dash
stroke_width integer | null Stroke Width
text_transform string | null Text Transform
three_d boolean | null Three D
underline boolean | null Underline

D2LegendSchema

Structured D2 legend render options.

Properties

Field Type Description
items array[D2LegendElementSchema|D2LegendRelSchema] Items
label string Label Default: Legend.

D2LegendElementSchema

Schema for a D2 legend node sample.

Properties

Field Type Description
type(required) string Legend item discriminator. Must be exactly element.
alias string | null Optional D2 identifier.
classes array[string] Classes
icon string | null Icon
label(required) string Legend item label.
shape string | null Shape
style D2StyleSchema

D2LegendRelSchema

Schema for a D2 legend relationship sample.

Properties

Field Type Description
type(required) string Legend item discriminator. Must be exactly relationship.
alias string | null Optional D2 identifier.
bidirectional boolean Bidirectional Default: false.
classes array[string] Classes
hide_endpoints boolean | null Hide Endpoints
label(required) string Legend item label.
source string | null Source
style D2StyleSchema
target string | null Target