Declarative Diagrams is an open-source tool for creating diagrams by writing them in YAML. From that text it generates an interactive SVG, a PNG, or a <Diagram /> component for MDX/React sites. Its main use is drawing AWS and Azure architectures with their official icons, although it also works for flow diagrams and has a visual style of its own. That custom style is the one I use for the interactive diagrams on my blog. It also includes an MCP server, a skill, and an agent, so that an AI assistant can create a diagram, see it rendered, and fix it.
Why I built Declarative Diagrams
A while ago I kept running into the same problem. I design architecture solutions for my projects, and I needed three things: AWS and Azure architecture diagrams, which is what teams recognize at a glance; flow diagrams; and a visual style of my own, both for client deliverables and for the interactive diagrams I wanted to publish on my blog. None of the tools I tried covered all of this well. And every change meant opening a visual application, moving boxes by hand, exporting, and pasting the image into the documentation. In the end, the diagram was always out of date.
That is how Declarative Diagrams was born. The idea is simple: if a diagram is a text file, I can version it, review it in a pull request, validate it, and render it wherever it is needed. And, along the way, an AI assistant can write it and fix it.
Creating a diagram with Declarative Diagrams
An architecture diagram with AWS styling is written like this:
# Needs the official AWS icons imported locally: dgm icons update (see docs/icons.md)
type: architecture
look: official
title: GenerativeAI-powered chatbot solution
subtitle: Chatbot solution to provide the sales department of the company with a virtual assistant, which can summarize knowledge base data and help quickly find relevant information.
description: Retrieval-augmented chatbot on AWS - web frontend, authenticated API, RAG Lambda with an LLM provider, and a daily ingestion pipeline.
direction: RIGHT
notesPosition: below
nodes:
- { id: sales, label: Sales representative, icon: lu-user, placement: left }
- { id: corp, label: Corporate storage, icon: lu-files, placement: left }
- id: aws
label: AWS Cloud
kind: cloud
icon: aws-cloud
children:
# three groups by responsibility (how AWS documentation organises such diagrams)
- id: g-web
label: Web delivery
kind: group
children:
- { id: cdn, label: CloudFront, icon: aws-cloudfront }
- { id: web, label: S3, sublabel: Static website, icon: aws-s3 }
- { id: r53, label: Route 53, icon: aws-route53 }
- { id: waf, label: AWS WAF, icon: aws-waf }
- id: g-api
label: Chat backend
kind: group
children:
- { id: apigw, label: API Gateway, icon: aws-api-gateway }
- { id: cognito, label: Cognito, icon: aws-cognito }
- { id: edge, label: Lambda@Edge, icon: aws-lambda, stackWith: cognito }
- { id: orch, label: Lambda, sublabel: Orchestrator, icon: aws-lambda }
- { id: sessions, label: DynamoDB, sublabel: User sessions, icon: aws-dynamodb }
- { id: rag, label: Lambda, sublabel: RAG, icon: aws-lambda }
- { id: ssm, label: SSM Parameter Store, sublabel: API token, icon: aws-res-systems-manager-parameter-store }
- { id: llm, label: Amazon Bedrock, sublabel: AgentCore, icon: aws-bedrock }
- { id: aurora, label: Aurora, sublabel: Embeddings, icon: aws-aurora }
- id: g-data
label: Knowledge base ingestion
kind: group
children:
- { id: sched1, label: EventBridge Scheduler, icon: aws-res-eventbridge-scheduler }
- { id: pipeline, label: ECS, sublabel: Data pipeline, icon: aws-elastic-container-service }
- { id: kb, label: S3, sublabel: Knowledge base, icon: aws-s3 }
- { id: sched2, label: EventBridge Scheduler, icon: aws-res-eventbridge-scheduler }
- id: sfn
label: AWS Step Functions workflow
kind: group
icon: aws-step-functions
color: "#E7157B"
border: solid
children:
- { id: batch, label: SageMaker, sublabel: BatchTransform, icon: aws-sagemaker }
- { id: langchain, label: ECS, sublabel: Langchain, icon: aws-elastic-container-service }
edges:
# 3 · web delivery
- { from: sales, to: cdn, flow: true }
- { from: r53, to: cdn, style: dashed }
- { from: waf, to: cdn, style: dashed }
- { from: cdn, to: web, flow: true }
# 4 · routing and authentication
- { from: cdn, to: apigw, flow: true }
- { from: apigw, to: cognito }
- { from: edge, to: cognito, style: dashed }
# 5 · orchestration and session log
- { from: apigw, to: orch, flow: true }
- { from: orch, to: sessions }
- { from: orch, to: rag, flow: true }
# 6 · RAG query and LLM inference
- { from: rag, to: ssm }
- { from: rag, to: aurora }
- { from: rag, to: llm, flow: true }
# 1 · daily ingestion
- { from: sched1, to: pipeline, style: dashed }
- { from: corp, to: pipeline }
- { from: pipeline, to: kb }
# 2 · embeddings
- { from: sched2, to: sfn, style: dashed }
- { from: kb, to: batch }
- { from: batch, to: langchain }
- { from: langchain, to: aurora }
notes:
- { target: pipeline, text: "Daily data ingestion. EventBridge Scheduler triggers an ECS task every day to fetch data files with a predefined format and creation date from the corporate storage, then copies them to an S3 bucket partitioned by date." }
- { target: sfn, text: "Processing and embeddings. EventBridge Scheduler starts a Step Functions workflow in two steps: a SageMaker BatchTransform job extracts the information from the documents and saves it to S3, then an ECS task generates the embeddings and stores them in Aurora." }
- { target: web, text: "Web frontend delivery and security. A static website is hosted on S3 behind a CloudFront distribution, with its DNS name registered in Route 53. AWS WAF inspects every request as an additional layer of security." }
- { target: cognito, text: "User routing and authentication. API Gateway authenticates users and routes requests to a Lambda function. Authentication is handled by a Cognito user pool, with the help of a Lambda@Edge function." }
- { target: sessions, text: "Orchestration and session log. The orchestrator Lambda is ultimately responsible for returning the response to the client. It first records the session in DynamoDB, then invokes the Retrieval-Augmented Generation (RAG) Lambda." }
- { target: ssm, text: "RAG query and agent inference. The RAG Lambda reads the API token from SSM Parameter Store, retrieves the relevant embeddings from Aurora and sends them with the user's query to Amazon Bedrock AgentCore, which runs the agent and the LLM. The answer goes back to the orchestrator." }
legend:
- { style: solid, label: Request / data path }
- { style: dashed, label: "Trigger or control" }
steps:
- { title: 1 · Daily ingestion, show: [sched1, corp, pipeline, kb] }
- { title: 2 · Embeddings, show: [sched2, kb, sfn, batch, langchain, aurora] }
- { title: 3 · Web delivery, show: [sales, r53, waf, cdn, web] }
- { title: 4 · Routing and auth, show: [cdn, apigw, cognito, edge] }
- { title: 5 · Orchestration, show: [apigw, orch, sessions, rag] }
- { title: 6 · RAG and inference, show: [orch, rag, ssm, aurora, llm] }
variants:
# phone version: the full diagram (same nodes, arrows, notes and scenarios) in a single column; groups are chained top to bottom
narrow:
chain: [g-data, g-web, g-api]
nodes:
sales: { label: Sales rep }
edge: { stackWith: null }
ssm: { label: SSM, sublabel: API token }With the dgm CLI, you validate and render it:
dgm validate examples/aws-genai-chatbot.diagram.yaml # errors and warnings, with suggestions
dgm render examples/aws-genai-chatbot.diagram.yaml -o examples/out/aws-genai-chatbot.svg # interactive SVG
dgm render examples/aws-genai-chatbot.diagram.yaml -o examples/out/aws-genai-chatbot.pngThe result is the following diagram:
The interactive SVG highlights nodes and connections on hover, animates the flows, and lets you explain the architecture step by step, revealing one component at a time. It is what I use most when presenting a solution.
A custom style for my interactive diagrams
This is the part I am most excited about. I wanted the diagrams on my blog to look like my blog: the same colors, the same typography, and the same light or dark mode. And I wanted them to be interactive, not a flat image.
To achieve that, each theme is defined with a seed color, and the rest of the palette is generated automatically, with contrast checks so the text is always readable. A theme is written in a small YAML file:
name: my-blog
extends: distill
seed: { accent: "#5f6f1f", flow: "#c98a1b", neutral: "#f1f0e4" }
dark: { accent: "#a9bb62" }With that, a diagram is embedded in an MDX post in a single line:
import arch from "./architecture.diagram.yaml";
import { Diagram } from "@declarative-diagrams/react";
<Diagram client:visible svg={arch} caption="Figure 1. Reference architecture." />The diagram follows the site’s mode, and the highlighting, the animated flow, and the step-by-step reveal all work inside the post. For a technical article, this makes it possible to explain a flow without asking the reader to imagine anything.
I also included seven base themes (distill, olive, azure, aws, orange, slate, mono), so I can start from one and adjust it.
How it works inside
It is an npm workspaces monorepo written in TypeScript. Each package has a single responsibility:
| Package | What it does |
|---|---|
core |
The specification (validated with Zod), the layout with ELK, the SVG rendering, the themes, the icons, and the PNG export |
cli |
The dgm tool |
react |
The <Diagram /> component and a Vite plugin for MDX |
mcp |
The MCP server for AI agents |
skills/diagram-author |
The skill with the workflow and the AWS and Azure patterns |
site-demo |
An Astro site that hosts the playground |
The journey of rendering a diagram
Icons
Lucide icons (more than 2,400) are included. I do not distribute Azure and AWS icons: each user downloads the packages from the official sites and imports them with dgm icons update. I did not want to redistribute third-party assets, and the project was designed that way from the start.
Ready to be assisted by AI
The MCP server exposes tools such as dgm_search_icons, dgm_validate_diagram, and dgm_render_diagram. The assistant consults the guide, searches for icons (without making them up), writes the specification, validates it, renders a PNG, looks at it, fixes it, and saves it.
That last step, looking at the result, is the one that matters. A model that writes YAML blindly makes layout mistakes it cannot see. With the PNG in front of it, it can correct them. There is also an OpenCode agent (diagram-specialist) that encapsulates the whole process and accepts text, project files, or a reference image, such as a screenshot of the portal or a hand-drawn sketch.
Security
When an assistant writes files, what it writes must be handled with care. The project has an explicit security model: theme values are validated before they go into the SVG, icons pass through an allowlist that blocks scripts and external links, and the MCP server only writes inside the project root without overwriting existing files. The interactive SVG includes a small script, so if you serve it on your own website, do it from your own origin, or use --static if you need a file without scripts.
Try it
- Playground (no installation needed): https://vicentej20.github.io/declarative-diagrams/. Edit the YAML, change the theme, export SVG or PNG, and share links. The AWS and Azure examples are marked with a star and cannot be edited because of the icons.
- Code: https://github.com/VicenteJ20/declarative-diagrams (MIT license).
- Locally:
npm install && npm run buildwith Node 22 or later. It is not yet published on npm.
