aws-architecture-diagram

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

AWS Architecture Diagram Skill

AWS架构图绘制技能

Generate AWS architecture diagrams as native
.drawio
files using official AWS Architecture Icons. Optionally export to PNG, SVG, or PDF with embedded XML (so exported files remain editable in draw.io).
使用官方AWS架构图标生成原生
.drawio
格式的AWS架构图。可选导出为嵌入XML的PNG、SVG或PDF格式(导出后的文件可在draw.io中继续编辑)。

How to create a diagram

如何创建图表

  1. Generate draw.io XML in mxGraphModel format following the rules below
  2. Write the XML to a
    .drawio
    file using the Write tool
  3. If the user requested an export format (png, svg, pdf), export using the draw.io CLI (see Export section)
  4. Open the result with
    open
    (macOS),
    xdg-open
    (Linux), or print the path
  1. 生成draw.io XML:遵循以下规则,生成mxGraphModel格式的XML
  2. 写入XML到文件:使用写入工具将XML保存为
    .drawio
    文件
  3. 若用户要求导出格式(png、svg、pdf),使用draw.io CLI进行导出(见导出章节)
  4. 打开结果:在macOS使用
    open
    ,Linux使用
    xdg-open
    ,或直接输出文件路径

Layout Rules

布局规则

  • Left-to-right flow for data/request path
  • UI/Frontend on the LEFT (users access from left side)
  • Data sources / external systems on the RIGHT
  • Use horizontal lanes for parallel paths (top lane, bottom lane)
  • Minimum 220px horizontal spacing between icons (room for edge labels)
  • Minimum 250px vertical spacing between lanes
  • Secondary/auxiliary services (monitoring, DLQ) go BELOW main flow with 280px+ gap
  • Canvas:
    pageWidth="2400" pageHeight="1400"
    , viewport
    dx="2800" dy="1600"
  • Always include a title block after the background rectangle:
xml
<mxCell value="&lt;b&gt;Diagram Title&lt;/b&gt;&lt;br&gt;Author | Date | Version" style="text;html=1;align=left;verticalAlign=top;whiteSpace=wrap;rounded=0;fontSize=14;spacing=8;" vertex="1" parent="1">
  <mxGeometry x="40" y="30" width="420" height="60" as="geometry" />
</mxCell>
  • 数据/请求路径采用从左到右的流向
  • UI/前端放置在左侧(用户从左侧访问)
  • 数据源/外部系统放置在右侧
  • 使用水平分栏表示并行路径(上方栏、下方栏)
  • 图标间最小水平间距为220px(预留边缘标签空间)
  • 分栏间最小垂直间距为250px
  • 次要/辅助服务(监控、死信队列DLQ)放置在主流程下方,间距需≥280px
  • 画布设置:
    pageWidth="2400" pageHeight="1400"
    ,视口
    dx="2800" dy="1600"
  • 背景矩形后必须包含标题块:
xml
<mxCell value="&lt;b&gt;Diagram Title&lt;/b&gt;&lt;br&gt;Author | Date | Version" style="text;html=1;align=left;verticalAlign=top;whiteSpace=wrap;rounded=0;fontSize=14;spacing=8;" vertex="1" parent="1">
  <mxGeometry x="40" y="30" width="420" height="60" as="geometry" />
</mxCell>

Icon Style

图标样式

  • Icons are from draw.io's built-in
    mxgraph.aws4
    stencil library — the official AWS Architecture Icons (https://aws.amazon.com/architecture/icons/)
  • Icon size: 78x78px for main services, 65x65px for secondary
  • Use
    sketch=0
    on all icons
  • Use
    strokeColor=#ffffff
    on all AWS service icons
  • Font size: 12px for labels
  • NO colored backgrounds on group boxes — always
    fillColor=none
  • 图标来自draw.io内置的
    mxgraph.aws4
    模板库——官方AWS架构图标https://aws.amazon.com/architecture/icons/)
  • 图标尺寸:主服务为78x78px,次要服务为65x65px
  • 所有图标均设置
    sketch=0
  • 所有AWS服务图标设置
    strokeColor=#ffffff
  • 标签字体大小:12px
  • 分组框禁止使用彩色背景——始终设置
    fillColor=none

Edge Style — CRITICAL FOR CLEAN DIAGRAMS

边缘样式——对整洁图表至关重要

Base edge style:
edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=2;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;
Edge label rules:
  • Keep labels SHORT (1-2 words max). Detail goes in icon labels, not edge labels.
  • Always add
    labelBackgroundColor=#F5F5F5;fontSize=11;
    to edges with labels
  • For edges WITHOUT labels: omit
    value
    entirely
  • When NOT to label: if the flow is obvious (Lambda → DynamoDB doesn't need "Write")
For edges to services ABOVE or BELOW main flow, use explicit exit/entry points:
  • Exit bottom:
    exitX=0.5;exitY=1;exitDx=0;exitDy=0;
  • Enter top:
    entryX=0.5;entryY=0;entryDx=0;entryDy=0;
  • This prevents draw.io from routing lines through other icons
Edge types:
  • Solid (
    strokeWidth=2
    ): primary data flow
  • Dashed (
    strokeWidth=2;dashed=1;
    ): optional/async
  • Red dashed (
    strokeWidth=2;dashed=1;strokeColor=#DD344C;
    ): error path
Edge attachment (CRITICAL — fixes "green cross" problem):
  • Every edge MUST have both
    source="<cell-id>"
    and
    target="<cell-id>"
    attributes referencing valid cell IDs
  • NEVER create floating/unattached edges — all edges must be bound to shapes at both ends
  • Always include
    exitX/exitY
    and
    entryX/entryY
    to define exact connection points on the shape perimeter
  • Cross-container edges: When source and target are in different containers, set the edge's
    parent="1"
基础边缘样式:
edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=2;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;
边缘标签规则:
  • 标签保持简短(最多1-2个词),详细信息放在图标标签中,而非边缘标签
  • 带标签的边缘需添加
    labelBackgroundColor=#F5F5F5;fontSize=11;
  • 无标签的边缘:完全省略
    value
    属性
  • 无需添加标签的场景:流向明显时(如Lambda → DynamoDB不需要标注“写入”)
连接主流程上方或下方服务的边缘,需使用明确的出入口点:
  • 从底部流出:
    exitX=0.5;exitY=1;exitDx=0;exitDy=0;
  • 从顶部流入:
    entryX=0.5;entryY=0;entryDx=0;entryDy=0;
  • 此设置可避免draw.io将线条穿过其他图标
边缘类型:
  • 实线(
    strokeWidth=2
    ):主要数据流
  • 虚线(
    strokeWidth=2;dashed=1;
    ):可选/异步流程
  • 红色虚线(
    strokeWidth=2;dashed=1;strokeColor=#DD344C;
    ):错误路径
边缘附着(至关重要——解决“绿色十字”问题):
  • 每条边缘必须包含
    source="<cell-id>"
    target="<cell-id>"
    属性,引用有效的单元格ID
  • 禁止创建浮动/未附着的边缘——所有边缘两端必须绑定到形状
  • 始终包含
    exitX/exitY
    entryX/entryY
    定义形状边缘的精确连接点
  • 跨容器边缘:当源和目标位于不同容器中时,将边缘的
    parent="1"

PNG Export Background

PNG导出背景

First element after root cells (lowest z-order):
xml
<mxCell value="" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#F5F5F5;strokeColor=none;" vertex="1" parent="1">
  <mxGeometry x="0" y="0" width="2400" height="1400" as="geometry" />
</mxCell>
根单元格后的第一个元素(最低层级):
xml
<mxCell value="" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#F5F5F5;strokeColor=none;" vertex="1" parent="1">
  <mxGeometry x="0" y="0" width="2400" height="1400" as="geometry" />
</mxCell>

AWS Icon Patterns (VERIFIED WORKING)

AWS图标模式(已验证可用)

resourceIcon (78x78, colored square frame)

resourceIcon(78x78,带彩色方形边框)

ServiceresIconfillColor
Lambda
mxgraph.aws4.lambda
#ED7100
API Gateway
mxgraph.aws4.api_gateway
#E7157B
EventBridge
mxgraph.aws4.eventbridge
#E7157B
SNS
mxgraph.aws4.sns
#E7157B
SES
mxgraph.aws4.simple_email_service
#DD344C
Step Functions
mxgraph.aws4.step_functions
#E7157B
DynamoDB
mxgraph.aws4.dynamodb
#C925D1
RDS
mxgraph.aws4.rds
#C925D1
S3
mxgraph.aws4.s3
#7AA116
CloudFront
mxgraph.aws4.cloudfront
#8C4FFF
Route 53
mxgraph.aws4.route_53
#8C4FFF
ECS
mxgraph.aws4.ecs
#ED7100
EC2
mxgraph.aws4.ec2
#ED7100
Style template:
sketch=0;points=[[0,0,0],[0.25,0,0],[0.5,0,0],[0.75,0,0],[1,0,0],[0,1,0],[0.25,1,0],[0.5,1,0],[0.75,1,0],[1,1,0],[0,0.25,0],[0,0.5,0],[0,0.75,0],[1,0.25,0],[1,0.5,0],[1,0.75,0]];outlineConnect=0;fontColor=#232F3E;fillColor=<COLOR>;strokeColor=#ffffff;dashed=0;verticalLabelPosition=bottom;verticalAlign=top;align=center;html=1;fontSize=12;fontStyle=0;aspect=fixed;shape=mxgraph.aws4.resourceIcon;resIcon=mxgraph.aws4.<SERVICE>
服务resIconfillColor
Lambda
mxgraph.aws4.lambda
#ED7100
API Gateway
mxgraph.aws4.api_gateway
#E7157B
EventBridge
mxgraph.aws4.eventbridge
#E7157B
SNS
mxgraph.aws4.sns
#E7157B
SES
mxgraph.aws4.simple_email_service
#DD344C
Step Functions
mxgraph.aws4.step_functions
#E7157B
DynamoDB
mxgraph.aws4.dynamodb
#C925D1
RDS
mxgraph.aws4.rds
#C925D1
S3
mxgraph.aws4.s3
#7AA116
CloudFront
mxgraph.aws4.cloudfront
#8C4FFF
Route 53
mxgraph.aws4.route_53
#8C4FFF
ECS
mxgraph.aws4.ecs
#ED7100
EC2
mxgraph.aws4.ec2
#ED7100
样式模板:
sketch=0;points=[[0,0,0],[0.25,0,0],[0.5,0,0],[0.75,0,0],[1,0,0],[0,1,0],[0.25,1,0],[0.5,1,0],[0.75,1,0],[1,1,0],[0,0.25,0],[0,0.5,0],[0,0.75,0],[1,0.25,0],[1,0.5,0],[1,0.75,0]];outlineConnect=0;fontColor=#232F3E;fillColor=<COLOR>;strokeColor=#ffffff;dashed=0;verticalLabelPosition=bottom;verticalAlign=top;align=center;html=1;fontSize=12;fontStyle=0;aspect=fixed;shape=mxgraph.aws4.resourceIcon;resIcon=mxgraph.aws4.<SERVICE>

productIcon (70x100, taller with service header bar)

productIcon(70x100,更高,带服务标题栏)

ServiceprIcon
SQS
mxgraph.aws4.sqs
Style template:
sketch=0;outlineConnect=0;fontColor=#232F3E;gradientColor=none;strokeColor=#ffffff;fillColor=#232F3E;dashed=0;verticalLabelPosition=bottom;verticalAlign=top;align=center;html=1;whiteSpace=wrap;fontSize=12;fontStyle=0;shape=mxgraph.aws4.productIcon;prIcon=mxgraph.aws4.<SERVICE>
服务prIcon
SQS
mxgraph.aws4.sqs
样式模板:
sketch=0;outlineConnect=0;fontColor=#232F3E;gradientColor=none;strokeColor=#ffffff;fillColor=#232F3E;dashed=0;verticalLabelPosition=bottom;verticalAlign=top;align=center;html=1;whiteSpace=wrap;fontSize=12;fontStyle=0;shape=mxgraph.aws4.productIcon;prIcon=mxgraph.aws4.<SERVICE>

Standalone shapes (no resIcon needed)

独立形状(无需resIcon)

Shapeshape valuefillColor
Client/Browser
mxgraph.aws4.client
#232F3D
Traditional Server
mxgraph.aws4.traditional_server
#232F3D
Firewall
mxgraph.aws4.generic_firewall
#232F3D
ALB
mxgraph.aws4.application_load_balancer
#8C4FFF
NLB
mxgraph.aws4.network_load_balancer
#8C4FFF
VPC Endpoint
mxgraph.aws4.endpoints
#8C4FFF
形状shape值fillColor
客户端/浏览器
mxgraph.aws4.client
#232F3D
传统服务器
mxgraph.aws4.traditional_server
#232F3D
防火墙
mxgraph.aws4.generic_firewall
#232F3D
ALB
mxgraph.aws4.application_load_balancer
#8C4FFF
NLB
mxgraph.aws4.network_load_balancer
#8C4FFF
VPC端点
mxgraph.aws4.endpoints
#8C4FFF

Group boundaries

分组边界

GroupgrIconstrokeColor
AWS Cloud
mxgraph.aws4.group_aws_cloud_alt
#232F3E
Account
mxgraph.aws4.group_account
#CD2264
On-premise
mxgraph.aws4.group_on_premise
#5A6C86
Corporate DC
mxgraph.aws4.group_corporate_data_center
#388E3C
VPC
mxgraph.aws4.group_vpc2
#8C4FFF
Subnet (public)
mxgraph.aws4.group_security_group
#7AA116
Subnet (private)
mxgraph.aws4.group_security_group
#147EBA
Container nesting (CRITICAL for grouping):
  • ALL group/boundary shapes MUST include
    container=1;dropTarget=1;
    in their style
  • Child cells inside a boundary MUST set
    parent="<boundary-cell-id>"
    instead of
    parent="1"
  • This ensures moving a boundary moves all its children together
  • Child geometry coordinates are relative to the parent container, not the canvas
  • Cross-container edges: When source and target are in different containers, set the edge's
    parent="1"
分组grIconstrokeColor
AWS云
mxgraph.aws4.group_aws_cloud_alt
#232F3E
账户
mxgraph.aws4.group_account
#CD2264
本地环境
mxgraph.aws4.group_on_premise
#5A6C86
企业数据中心
mxgraph.aws4.group_corporate_data_center
#388E3C
VPC
mxgraph.aws4.group_vpc2
#8C4FFF
子网(公有)
mxgraph.aws4.group_security_group
#7AA116
子网(私有)
mxgraph.aws4.group_security_group
#147EBA
容器嵌套(分组至关重要):
  • 所有分组/边界形状必须在样式中包含
    container=1;dropTarget=1;
  • 边界内的子单元格必须设置
    parent="<boundary-cell-id>"
    ,而非
    parent="1"
  • 此设置确保移动边界时会同时移动所有子元素
  • 子元素的几何坐标相对于父容器,而非画布
  • 跨容器边缘:当源和目标位于不同容器中时,将边缘的
    parent="1"

BROKEN Icons — DO NOT USE

不可用图标——请勿使用

  • resIcon=mxgraph.aws4.dynamodb_table
    — renders as empty colored square
  • resIcon=mxgraph.aws4.dynamodb_stream
    — renders as empty colored square
  • resIcon=mxgraph.aws4.general_saml_token
    — renders as black square
  • resIcon=mxgraph.aws4.endpoint
    — may not render
  • resIcon=mxgraph.aws4.kinesis_data_streams
    — unreliable
Alternatives:
  • DynamoDB tables/streams → use
    resIcon=mxgraph.aws4.dynamodb
    with descriptive labels
  • External systems → use
    shape=mxgraph.aws4.traditional_server
  • Browsers/clients → use
    shape=mxgraph.aws4.client
  • resIcon=mxgraph.aws4.dynamodb_table
    —— 渲染为空白彩色正方形
  • resIcon=mxgraph.aws4.dynamodb_stream
    —— 渲染为空白彩色正方形
  • resIcon=mxgraph.aws4.general_saml_token
    —— 渲染为黑色正方形
  • resIcon=mxgraph.aws4.endpoint
    —— 可能无法渲染
  • resIcon=mxgraph.aws4.kinesis_data_streams
    —— 不可靠
替代方案:
  • DynamoDB表/流 → 使用
    resIcon=mxgraph.aws4.dynamodb
    并添加描述性标签
  • 外部系统 → 使用
    shape=mxgraph.aws4.traditional_server
  • 浏览器/客户端 → 使用
    shape=mxgraph.aws4.client

Audience Mode

受众模式

Before generating, assess the target audience:
  • Technical: Use service names, protocol labels (HTTPS, gRPC), CIDR blocks, instance types
  • Non-technical: Use action labels ("Store Data", "Send Notification"), hide implementation details, use numbered flow (① ② ③)
If unclear, ask: "Technical audience or executive/non-technical?"
生成前,评估目标受众:
  • 技术受众:使用服务名称、协议标签(HTTPS、gRPC)、CIDR块、实例类型
  • 非技术受众:使用动作标签(“存储数据”、“发送通知”),隐藏实现细节,使用编号流程(① ② ③)
若不确定,询问:“是面向技术受众还是高管/非技术受众?”

Numbered flow edges (for non-technical mode)

编号流程边缘(非技术模式)

Instead of technical labels, show flow order with circled numbers:
  • Flow A: ① → ② → ③ → ④ (white circled numbers)
  • Flow B: ❶ → ❷ → ❸ → ❹ (black circled numbers for second flow)
Use edge labels:
value="①"
with
fontSize=14;fontStyle=1;labelBackgroundColor=#ffffff;
不使用技术标签,而是用带圈数字显示流程顺序:
  • 流程A:① → ② → ③ → ④(白色带圈数字)
  • 流程B:❶ → ❷ → ❸ → ❹(黑色带圈数字表示第二个流程)
使用边缘标签:
value="①"
并设置
fontSize=14;fontStyle=1;labelBackgroundColor=#ffffff;

Companion Guide

配套指南

After generating the .drawio file, also generate a markdown guide:
  • Same filename with
    .md
    extension
  • Contents: diagram title, flow description (numbered steps), service list with purpose, key design decisions
生成.drawio文件后,还需生成markdown指南:
  • 文件名与.drawio文件相同,扩展名为
    .md
  • 内容:图表标题、流程描述(编号步骤)、服务列表及用途、关键设计决策

Two-Step Edit Approach

两步编辑法

After generating the initial .drawio file:
  1. Export to PNG using the draw.io CLI (see Export section)
  2. Review the PNG visually — check for empty/broken icons, overlapping edges, misaligned labels
  3. Fix issues in the .drawio XML and re-export
This catches rendering problems (wrong stencil names, broken styles) that are invisible in raw XML.
生成初始.drawio文件后:
  1. 导出为PNG:使用draw.io CLI(见导出章节)
  2. 视觉检查PNG:检查是否有空/损坏的图标、重叠的边缘、对齐错误的标签
  3. 修复问题:在.drawio XML中修复问题并重新导出
此步骤可捕获原始XML中不可见的渲染问题(错误的模板名称、损坏的样式)。

Icon Name Gotchas — CRITICAL

图标名称注意事项——至关重要

draw.io stencil names do NOT always match current AWS service names. Services that were renamed keep their legacy stencil names:
AWS Service Namedraw.io resIcon nameWhy
Amazon OpenSearch Service
elasticsearch_service
Renamed from Elasticsearch in 2021;
opensearch_service
also works
Amazon EventBridge
eventbridge
Was CloudWatch Events
AWS Fargate
fargate
Correct
VPC Peering
peering
Resource-level:
shape=mxgraph.aws4.peering;strokeColor=none
— NOT
vpc_peering
or
peering_connection
(those render as blank squares)
Amazon MSK
managed_streaming_for_kafka
NOT
msk
(renders as blank square)
IAM Identity Center
single_sign_on
NOT
iam_identity_center
(renders as blank square)
Rule: Always verify icon names from the reference files. If a service icon renders as an empty box, the stencil name is wrong. Check the draw.io source at
src/main/webapp/js/diagramly/sidebar/Sidebar-AWS4.js
for the canonical name.
Fallback for unmapped services: If a service is NOT found in any reference file, use this generic AWS cloud icon with the service name as label:
sketch=0;outlineConnect=0;fontColor=#232F3E;fillColor=#232F3E;strokeColor=#ffffff;dashed=0;verticalLabelPosition=bottom;verticalAlign=top;align=center;html=1;fontSize=12;fontStyle=0;aspect=fixed;shape=mxgraph.aws4.resourceIcon;resIcon=mxgraph.aws4.general_AWScloud
Never render an unknown service as a plain colored rectangle with no label.
draw.io模板名称并非始终与当前AWS服务名称匹配。已重命名的服务仍保留旧模板名称:
AWS服务名称draw.io resIcon名称原因
Amazon OpenSearch Service
elasticsearch_service
2021年从Elasticsearch重命名;
opensearch_service
也可用
Amazon EventBridge
eventbridge
曾用名CloudWatch Events
AWS Fargate
fargate
名称正确
VPC对等连接
peering
资源级:
shape=mxgraph.aws4.peering;strokeColor=none
—— 请勿使用
vpc_peering
peering_connection
(会渲染为空白正方形)
Amazon MSK
managed_streaming_for_kafka
请勿使用
msk
(会渲染为空白正方形)
IAM身份中心
single_sign_on
请勿使用
iam_identity_center
(会渲染为空白正方形)
规则: 始终从参考文件验证图标名称。如果服务图标渲染为空框,说明模板名称错误。查看draw.io源码
src/main/webapp/js/diagramly/sidebar/Sidebar-AWS4.js
获取标准名称。
未映射服务的 fallback 方案: 如果服务未在任何参考文件中找到,使用以下通用AWS云图标,并将服务名称作为标签:
sketch=0;outlineConnect=0;fontColor=#232F3E;fillColor=#232F3E;strokeColor=#ffffff;dashed=0;verticalLabelPosition=bottom;verticalAlign=top;align=center;html=1;fontSize=12;fontStyle=0;aspect=fixed;shape=mxgraph.aws4.resourceIcon;resIcon=mxgraph.aws4.general_AWScloud
绝不将未知服务渲染为无标签的普通彩色矩形。

Validation Step

验证步骤

After generating XML, verify:
  1. Every
    resIcon=
    value exists in the reference files
  2. Service-level icons have
    strokeColor=#ffffff
  3. Resource-level icons have
    strokeColor=none
  4. No XML comments present
  5. All cell IDs are unique
  6. Every edge has
    <mxGeometry relative="1" as="geometry" />
  7. No icon uses a guessed stencil name — all verified against reference files
  8. Every edge has both
    source
    and
    target
    attributes referencing valid cell IDs (no floating edges)
  9. All group/boundary shapes include
    container=1;dropTarget=1;
    in their style
  10. Children inside boundaries use
    parent="<boundary-id>"
    (not
    parent="1"
    )
生成XML后,验证:
  1. 每个
    resIcon=
    值均存在于参考文件中
  2. 服务级图标设置
    strokeColor=#ffffff
  3. 资源级图标设置
    strokeColor=none
  4. 无XML注释
  5. 所有单元格ID唯一
  6. 每条边缘均包含
    <mxGeometry relative="1" as="geometry" />
  7. 所有图标均使用已验证的模板名称,无猜测名称
  8. 每条边缘均包含
    source
    target
    属性,引用有效的单元格ID(无浮动边缘)
  9. 所有分组/边界形状的样式中包含
    container=1;dropTarget=1;
  10. 边界内的子元素使用
    parent="<boundary-id>"
    (而非
    parent="1"

Export

导出

For PNG/SVG/PDF export using draw.io Desktop CLI:
使用draw.io桌面CLI导出PNG/SVG/PDF:

Multi-page Diagrams

多页图表

For complex architectures, use multiple pages in one .drawio file:
xml
<mxfile>
  <diagram id="overview" name="Overview">...</diagram>
  <diagram id="networking" name="Networking Detail">...</diagram>
  <diagram id="data-flow" name="Data Flow">...</diagram>
</mxfile>
  • Page 1: High-level overview (service-level icons only)
  • Page 2+: Detail views (resource-level icons, subnet layouts, etc.)
对于复杂架构,在一个.drawio文件中使用多个页面:
xml
<mxfile>
  <diagram id="overview" name="Overview">...</diagram>
  <diagram id="networking" name="Networking Detail">...</diagram>
  <diagram id="data-flow" name="Data Flow">...</diagram>
</mxfile>
  • 第1页:高层概述(仅服务级图标)
  • 第2页及以后:详细视图(资源级图标、子网布局等)

Legend / Title Block

图例/标题块

Place in top-left corner, inside the background rectangle:
xml
<mxCell value="&lt;b&gt;Diagram Title&lt;/b&gt;&lt;br&gt;Author | Date | Version" style="text;html=1;align=left;verticalAlign=top;whiteSpace=wrap;rounded=0;fontSize=14;spacing=8;" vertex="1" parent="1">
  <mxGeometry x="40" y="40" width="300" height="50" as="geometry" />
</mxCell>
放置在背景矩形内的左上角:
xml
<mxCell value="&lt;b&gt;Diagram Title&lt;/b&gt;&lt;br&gt;Author | Date | Version" style="text;html=1;align=left;verticalAlign=top;whiteSpace=wrap;rounded=0;fontSize=14;spacing=8;" vertex="1" parent="1">
  <mxGeometry x="40" y="40" width="300" height="50" as="geometry" />
</mxCell>

PNG Export Background Fix

PNG导出背景修复

Place a
#F5F5F5
rectangle covering the entire diagram as the bottom-most element to prevent black background on export.
放置一个覆盖整个图表的
#F5F5F5
矩形作为最底层元素,防止导出时出现黑色背景。

Export CLI

导出CLI

PlatformCLI Path
macOS
/Applications/draw.io.app/Contents/MacOS/draw.io
Linux
drawio
(on PATH via snap/apt)
Windows
"C:\Program Files\draw.io\draw.io.exe"
bash
<CLI> -x -f <format> -e -b 10 -o <output> <input>
Flags:
-x
export,
-f
format (png/svg/pdf),
-e
embed diagram XML,
-b 10
border
Exported files use double extension:
name.drawio.png
— signals embedded XML, re-editable in draw.io.
平台CLI路径
macOS
/Applications/draw.io.app/Contents/MacOS/draw.io
Linux
drawio
(通过snap/apt添加到PATH)
Windows
"C:\Program Files\draw.io\draw.io.exe"
bash
<CLI> -x -f <format> -e -b 10 -o <output> <input>
参数:
-x
导出,
-f
格式(png/svg/pdf),
-e
嵌入图表XML,
-b 10
边框
导出文件使用双重扩展名:
name.drawio.png
—— 表示嵌入了XML,可在draw.io中重新编辑。

XML Well-formedness (CRITICAL)

XML格式正确性(至关重要)

  • NEVER include XML comments (
    <!-- -->
    )
    — they cause parse errors
  • Escape special characters:
    &amp;
    &lt;
    &gt;
    &quot;
  • Always use unique
    id
    values for each mxCell
  • Every edge MUST have
    <mxGeometry relative="1" as="geometry" />
    as child
  • Root structure requires cells
    id="0"
    (root) and
    id="1"
    (default layer, parent="0")
  • 绝不包含XML注释(
    <!-- -->
    —— 会导致解析错误
  • 转义特殊字符:
    &amp;
    &lt;
    &gt;
    &quot;
  • 始终为每个mxCell使用唯一的
    id
  • 每条边缘必须包含
    <mxGeometry relative="1" as="geometry" />
    作为子元素
  • 根结构需要
    id="0"
    (根)和
    id="1"
    (默认图层,parent="0")单元格

Official Reference

官方参考