architecture-diagrams
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseArchitecture Diagrams
架构图生成工具
Portable Claude Agent Skill
Professional architecture diagram generator using the Diagrams Python library. Produces publication-quality diagrams with real cloud provider icons (AWS, Azure, GCP, K8s, OnPrem, Generic).
Portability: This entire folder is self-contained. Copy it to or any project's directory. Run once per location.
architecture-diagrams/~/.claude/skills/.claude/skills/./scripts/setup.sh可移植的Claude Agent技能
基于Diagrams Python库的专业架构图生成工具。可生成带有真实云服务商图标(AWS、Azure、GCP、K8s、OnPrem、通用类)的出版级架构图。
可移植性:整个文件夹是自包含的。你可以将其复制到或任何项目的目录下。每个安装位置只需运行一次。
architecture-diagrams/~/.claude/skills/.claude/skills/./scripts/setup.shInstallation & Setup
安装与设置
System Prerequisite
系统前置要求
Graphviz must be installed system-wide (provides the binary):
dotbash
undefined必须在系统全局安装Graphviz(提供二进制文件):
dotbash
undefinedUbuntu/Debian
Ubuntu/Debian
sudo apt install graphviz
sudo apt install graphviz
macOS
macOS
brew install graphviz
brew install graphviz
RHEL/Fedora
RHEL/Fedora
sudo dnf install graphviz
undefinedsudo dnf install graphviz
undefinedOne-Time Setup (Per Installation Location)
一次性设置(每个安装位置仅需执行一次)
bash
cd <path-to>/architecture-diagrams/
chmod +x scripts/setup.sh
./scripts/setup.shThis creates , installs Python dependencies, and verifies graphviz.
.venv/bash
cd <path-to>/architecture-diagrams/
chmod +x scripts/setup.sh
./scripts/setup.sh该脚本会创建虚拟环境、安装Python依赖并验证Graphviz是否正常运行。
.venv/Automated Setup Check
自动化设置检查
bash
cd <path-to>/architecture-diagrams/
if [ ! -d ".venv" ]; then
./scripts/setup.sh
fi
echo "Skill ready"bash
cd <path-to>/architecture-diagrams/
if [ ! -d ".venv" ]; then
./scripts/setup.sh
fi
echo "Skill ready"Quick Start
快速开始
bash
undefinedbash
undefined1. Navigate to your project directory
1. 导航到你的项目目录
cd ~/projects/my-project/
cd ~/projects/my-project/
2. Set skill path for convenience
2. 为方便使用,设置技能路径
SKILL_DIR=~/.claude-wa/.claude/skills/architecture-diagrams
SKILL_DIR=~/.claude-wa/.claude/skills/architecture-diagrams
3. Verify setup
3. 验证设置是否完成
if [ ! -d "$SKILL_DIR/.venv" ]; then cd "$SKILL_DIR" && ./scripts/setup.sh && cd -; fi
if [ ! -d "$SKILL_DIR/.venv" ]; then cd "$SKILL_DIR" && ./scripts/setup.sh && cd -; fi
4. Activate venv
4. 激活虚拟环境
source "$SKILL_DIR/.venv/bin/activate"
source "$SKILL_DIR/.venv/bin/activate"
5. Create a diagram script in your project
5. 在项目中创建一个架构图脚本
cat > my-diagram.py << 'EOF'
from diagrams import Diagram, Cluster
from diagrams.aws.compute import EC2
from diagrams.aws.network import ELB
with Diagram("My Architecture", show=False):
lb = ELB("Load Balancer")
with Cluster("Web Tier"):
web = [EC2("Web 1"), EC2("Web 2")]
lb >> web
EOF
cat > my-diagram.py << 'EOF'
from diagrams import Diagram, Cluster
from diagrams.aws.compute import EC2
from diagrams.aws.network import ELB
with Diagram("My Architecture", show=False):
lb = ELB("Load Balancer")
with Cluster("Web Tier"):
web = [EC2("Web 1"), EC2("Web 2")]
lb >> web
EOF
6. Generate PNG (output goes to ./output/png/ in current directory)
6. 生成PNG格式图(输出文件会保存在当前目录的./output/png/下)
python "$SKILL_DIR/scripts/generate.py" my-diagram.py
python "$SKILL_DIR/scripts/generate.py" my-diagram.py
Output: ~/projects/my-project/output/png/my-diagram.png
输出路径示例: ~/projects/my-project/output/png/my-diagram.png
undefinedundefinedFile Structure
文件结构
architecture-diagrams/ <-- Skill root (portable)
SKILL.md # This file
requirements.txt # Python deps (diagrams, graphviz)
.venv/ # Python virtual environment (created by setup.sh)
scripts/
setup.sh # Creates .venv and installs deps
generate.py # Runs diagram script, outputs to cwd/output/png/
src/
templates/ # Starter templates — copy these
basic-template.py # Minimal template with TODOs
examples/ # Working example diagrams
cisco-network.py # Network topology with routers, switches, firewall
aws-architecture.py # AWS cloud architecture with VPC, ALB, RDS
kubernetes-cluster.py # K8s cluster with namespaces, services, monitoring
docs/
icon-reference.md # Index with top icons + navigation (load this first)
icons/ # Provider-specific icon catalogs (load on demand, all ≤450 lines)
generic.md # Generic infrastructure (26 icons)
aws.md # Amazon Web Services (562 icons)
azure-compute-network.md # Azure: Compute, Network, Database, Storage (~400 icons)
azure-app-devops.md # Azure: App Services, DevOps, Identity, Integration, IoT (~240 icons)
azure-web-security.md # Azure: Management, Security, Web Services (~170 icons)
gcp.md # Google Cloud Platform (144 icons)
kubernetes.md # Kubernetes (69 icons)
onprem.md # On-Premise tools (211 icons)
saas.md # SaaS providers (42 icons)
programming.md # Languages & frameworks (81 icons)
elastic-firebase.md # Elastic Stack, Firebase (~109 icons)
digitalocean-ibm.md # DigitalOcean, IBM Cloud (~309 icons)
oracle-openstack.md # Oracle OCI, OpenStack (~415 icons)
outscale-alibaba-misc.md # Outscale, Alibaba, GIS, Custom, C4 (~220 icons)architecture-diagrams/ <-- 技能根目录(可移植)
SKILL.md # 本说明文件
requirements.txt # Python依赖(diagrams、graphviz)
.venv/ # Python虚拟环境(由setup.sh创建)
scripts/
setup.sh # 创建虚拟环境并安装依赖
generate.py # 运行架构图脚本,输出到当前目录的output/png/
src/
templates/ # 入门模板 — 可直接复制使用
basic-template.py # 带TODO提示的极简模板
examples/ # 可用的示例架构图
cisco-network.py # 包含路由器、交换机、防火墙的网络拓扑图
aws-architecture.py # 包含VPC、ALB、RDS的AWS云架构图
kubernetes-cluster.py # 包含命名空间、服务、监控的K8s集群图
docs/
icon-reference.md # 图标索引(包含常用图标和导航,建议先查看)
icons/ # 各服务商专属图标目录(按需加载,每个文件≤450行)
generic.md # 通用基础设施图标(26个)
aws.md # 亚马逊云服务图标(562个)
azure-compute-network.md # Azure:计算、网络、数据库、存储类图标(约400个)
azure-app-devops.md # Azure:应用服务、DevOps、身份认证、集成、IoT类图标(约240个)
azure-web-security.md # Azure:管理、安全、Web服务类图标(约170个)
gcp.md # 谷歌云平台图标(144个)
kubernetes.md # Kubernetes图标(69个)
onprem.md # 本地部署工具图标(211个)
saas.md # SaaS服务商图标(42个)
programming.md # 编程语言与框架图标(81个)
elastic-firebase.md # Elastic Stack、Firebase类图标(约109个)
digitalocean-ibm.md # DigitalOcean、IBM云图标(约309个)
oracle-openstack.md # Oracle OCI、OpenStack类图标(约415个)
outscale-alibaba-misc.md # Outscale、阿里云、GIS、自定义、C4类图标(约220个)Output Path Behavior
输出路径规则
Diagrams are generated in relative to your current working directory (not the skill directory). This means output appears in your project folder:
./output/png/bash
undefined架构图会生成在相对于你当前工作目录的目录下(而非技能目录)。这意味着输出文件会保存在你的项目文件夹中:
./output/png/bash
undefinedFrom your project directory
从你的项目目录执行
cd ~/projects/my-project/
python <skill>/scripts/generate.py diagram.py
cd ~/projects/my-project/
python <skill>/scripts/generate.py diagram.py
Output: ~/projects/my-project/output/png/diagram.png
输出路径: ~/projects/my-project/output/png/diagram.png
Custom output directory
自定义输出目录
python <skill>/scripts/generate.py diagram.py --output-dir ./diagrams/
python <skill>/scripts/generate.py diagram.py --output-dir ./diagrams/
Output: ~/projects/my-project/diagrams/diagram.png
输出路径: ~/projects/my-project/diagrams/diagram.png
Absolute path
绝对路径输出
python <skill>/scripts/generate.py diagram.py --output-dir /tmp/diagrams/
python <skill>/scripts/generate.py diagram.py --output-dir /tmp/diagrams/
Output: /tmp/diagrams/diagram.png
输出路径: /tmp/diagrams/diagram.png
undefinedundefinedIcon Reference (Progressive Disclosure)
图标参考(渐进式加载)
2634 icons across 17 providers, organized for efficient context loading:
- Start with — Main index (~130 lines) with navigation table, top 30 most-used icons, and quick-start imports
docs/icon-reference.md - Load provider files on demand from — Only load the specific provider file you need (e.g.,
docs/icons/for AWS icons)docs/icons/aws.md
| Provider File | Icons | When to Load |
|---|---|---|
| 26 | Network devices, OS, compute, storage |
| 562 | AWS cloud architecture |
| Azure (split): | 810 | Microsoft Azure - load as needed |
| ~400 | Azure compute, network, database, storage |
| ~240 | Azure app services, DevOps, identity, IoT |
| ~170 | Azure management, security, web |
| 144 | GCP architecture |
| 69 | K8s clusters, pods, services |
| 211 | Self-hosted infra, databases, CI/CD |
| 42 | SaaS providers |
| 81 | Languages, frameworks |
| Other Clouds (split): | 689 | Other cloud providers - load as needed |
| ~109 | Elastic Stack, Firebase |
| ~309 | DigitalOcean, IBM Cloud |
| ~415 | Oracle OCI, OpenStack |
| ~220 | Outscale, Alibaba, GIS, Custom, C4 |
总计2634个图标,覆盖17个服务商,按类别组织以提升加载效率:
- 先查看— 主索引(约130行),包含导航表、30个最常用图标和快速导入示例
docs/icon-reference.md - 按需加载服务商文件 — 仅加载你需要的服务商图标文件(例如,使用AWS图标时加载)
docs/icons/aws.md
| 服务商文件 | 图标数量 | 使用场景 |
|---|---|---|
| 26 | 网络设备、操作系统、计算、存储类 |
| 562 | AWS云架构设计 |
| Azure(拆分文件): | 810 | 微软Azure相关场景 - 按需加载 |
| ~400 | Azure计算、网络、数据库、存储类 |
| ~240 | Azure应用服务、DevOps、身份认证、IoT类 |
| ~170 | Azure管理、安全、Web服务类 |
| 144 | GCP架构设计 |
| 69 | K8s集群、Pod、服务类 |
| 211 | 自托管基础设施、数据库、CI/CD类 |
| 42 | SaaS服务商类 |
| 81 | 编程语言、框架类 |
| 其他云服务商(拆分文件): | 689 | 其他云服务商场景 - 按需加载 |
| ~109 | Elastic Stack、Firebase类 |
| ~309 | DigitalOcean、IBM云类 |
| ~415 | Oracle OCI、OpenStack类 |
| ~220 | Outscale、阿里云、GIS、自定义、C4类 |
Core Concepts
核心概念
Diagram Context Manager
图形容器上下文
Every diagram uses the context manager:
Diagrampython
from diagrams import Diagram, Cluster, Edge
with Diagram(
"Diagram Title", # Title shown on diagram
filename="output-name", # Output filename (no extension)
outformat="png", # png, jpg, svg, pdf, dot
show=False, # Don't auto-open
direction="TB", # TB, BT, LR, RL
graph_attr={...}, # Graphviz attributes
):
# nodes and connections here每个架构图都需要使用上下文管理器:
Diagrampython
from diagrams import Diagram, Cluster, Edge
with Diagram(
"Diagram Title", # 架构图标题
filename="output-name", # 输出文件名(无扩展名)
outformat="png", # 输出格式:png、jpg、svg、pdf、dot
show=False, # 生成后不自动打开
direction="TB", # 布局方向:TB、BT、LR、RL
graph_attr={...}, # Graphviz属性
):
# 在此处定义节点和连接关系Direction
布局方向
| Value | Meaning | Best For |
|---|---|---|
| Top to bottom | Hierarchical architectures, network topologies |
| Bottom to top | Data flow upward |
| Left to right | Pipelines, data flow, timelines |
| Right to left | Reverse flows |
| 参数值 | 含义 | 适用场景 |
|---|---|---|
| 从上到下 | 分层架构、网络拓扑图 |
| 从下到上 | 数据向上流动的场景 |
| 从左到右 | 流水线、数据流、时间线 |
| 从右到左 | 反向数据流场景 |
Graph Attributes
图属性配置
python
graph_attr = {
"fontsize": "14", # Title font size
"bgcolor": "#ffffff", # Background color
"pad": "0.5", # Padding around diagram
"nodesep": "0.6", # Horizontal spacing
"ranksep": "0.8", # Vertical spacing between ranks
"splines": "spline", # Edge routing: spline, ortho, curved, polyline
"concentrate": "true", # Merge parallel edges
}python
graph_attr = {
"fontsize": "14", # 标题字体大小
"bgcolor": "#ffffff", # 背景颜色
"pad": "0.5", # 图周围的内边距
"nodesep": "0.6", # 节点间水平间距
"ranksep": "0.8", # 不同层级间的垂直间距
"splines": "spline", # 连接线样式:spline、ortho、curved、polyline
"concentrate": "true", # 合并平行连接线
}Node Providers Quick Reference
节点服务商快速参考
Generic (Network Infrastructure)
通用类(网络基础设施)
python
from diagrams.generic.network import Firewall, Router, Switch, Subnet, VPN
from diagrams.generic.compute import Rack
from diagrams.generic.database import SQL
from diagrams.generic.storage import Storage
from diagrams.generic.device import Mobile, Tablet
from diagrams.generic.place import Datacenter
from diagrams.generic.os import Ubuntu, Windows, LinuxGeneral, Debian, RedHat, CentOS
from diagrams.generic.virtualization import Vmware, Virtualbox, Qemu
from diagrams.generic.blank import Blank # Invisible node for layout controlpython
from diagrams.generic.network import Firewall, Router, Switch, Subnet, VPN
from diagrams.generic.compute import Rack
from diagrams.generic.database import SQL
from diagrams.generic.storage import Storage
from diagrams.generic.device import Mobile, Tablet
from diagrams.generic.place import Datacenter
from diagrams.generic.os import Ubuntu, Windows, LinuxGeneral, Debian, RedHat, CentOS
from diagrams.generic.virtualization import Vmware, Virtualbox, Qemu
from diagrams.generic.blank import Blank # 用于布局控制的不可见节点AWS
AWS
python
undefinedpython
undefinedCompute
计算类
from diagrams.aws.compute import EC2, ECS, Lambda, Fargate, ElasticBeanstalk, Batch
from diagrams.aws.compute import EC2, ECS, Lambda, Fargate, ElasticBeanstalk, Batch
Database
数据库类
from diagrams.aws.database import RDS, Aurora, Dynamodb, ElastiCache, Neptune, Redshift
from diagrams.aws.database import RDS, Aurora, Dynamodb, ElastiCache, Neptune, Redshift
Network
网络类
from diagrams.aws.network import ELB, Route53, CloudFront, VPC, APIGateway, DirectConnect
from diagrams.aws.network import ELB, Route53, CloudFront, VPC, APIGateway, DirectConnect
Storage
存储类
from diagrams.aws.storage import S3, EFS, FSx
from diagrams.aws.storage import S3, EFS, FSx
Security
安全类
from diagrams.aws.security import Cognito, WAF, IAM, KMS, CertificateManager
from diagrams.aws.security import Cognito, WAF, IAM, KMS, CertificateManager
Integration
集成类
from diagrams.aws.integration import SQS, SNS, Eventbridge, StepFunctions
from diagrams.aws.integration import SQS, SNS, Eventbridge, StepFunctions
Management
管理类
from diagrams.aws.management import Cloudwatch, Cloudformation, Cloudtrail, AutoScaling
from diagrams.aws.management import Cloudwatch, Cloudformation, Cloudtrail, AutoScaling
Analytics
分析类
from diagrams.aws.analytics import Kinesis, Athena, Glue, EMR
from diagrams.aws.analytics import Kinesis, Athena, Glue, EMR
General
通用类
from diagrams.aws.general import Users, Client
undefinedfrom diagrams.aws.general import Users, Client
undefinedAzure
Azure
python
from diagrams.azure.compute import VM, FunctionApps, ContainerInstances, KubernetesServices
from diagrams.azure.database import CosmosDb, SQLDatabases, CacheForRedis
from diagrams.azure.network import LoadBalancers, ApplicationGateway, DNS, VirtualNetworks
from diagrams.azure.storage import BlobStorage, StorageAccounts
from diagrams.azure.security import KeyVaults, ActiveDirectory
from diagrams.azure.integration import ServiceBus, EventGrid
from diagrams.azure.web import AppServicespython
from diagrams.azure.compute import VM, FunctionApps, ContainerInstances, KubernetesServices
from diagrams.azure.database import CosmosDb, SQLDatabases, CacheForRedis
from diagrams.azure.network import LoadBalancers, ApplicationGateway, DNS, VirtualNetworks
from diagrams.azure.storage import BlobStorage, StorageAccounts
from diagrams.azure.security import KeyVaults, ActiveDirectory
from diagrams.azure.integration import ServiceBus, EventGrid
from diagrams.azure.web import AppServicesGCP
GCP
python
from diagrams.gcp.compute import GCE, GKE, Functions, Run, AppEngine
from diagrams.gcp.database import SQL as GcpSQL, Spanner, Firestore, BigTable, Memorystore
from diagrams.gcp.network import LoadBalancing, CDN, DNS as GcpDNS, VPC as GcpVPC
from diagrams.gcp.storage import GCS
from diagrams.gcp.analytics import BigQuery, PubSub, Dataflow
from diagrams.gcp.security import IAP, KMS as GcpKMSpython
from diagrams.gcp.compute import GCE, GKE, Functions, Run, AppEngine
from diagrams.gcp.database import SQL as GcpSQL, Spanner, Firestore, BigTable, Memorystore
from diagrams.gcp.network import LoadBalancing, CDN, DNS as GcpDNS, VPC as GcpVPC
from diagrams.gcp.storage import GCS
from diagrams.gcp.analytics import BigQuery, PubSub, Dataflow
from diagrams.gcp.security import IAP, KMS as GcpKMSKubernetes
Kubernetes
python
from diagrams.k8s.compute import Pod, Deployment, StatefulSet, ReplicaSet, Job, CronJob, DaemonSet
from diagrams.k8s.network import Ingress, Service, NetworkPolicy
from diagrams.k8s.storage import PV, PVC, StorageClass
from diagrams.k8s.rbac import ServiceAccount, Role, ClusterRole
from diagrams.k8s.infra import Node as K8sNode, Master
from diagrams.k8s.clusterconfig import HPA, ConfigMap, Secret
from diagrams.k8s.podconfig import Containerpython
from diagrams.k8s.compute import Pod, Deployment, StatefulSet, ReplicaSet, Job, CronJob, DaemonSet
from diagrams.k8s.network import Ingress, Service, NetworkPolicy
from diagrams.k8s.storage import PV, PVC, StorageClass
from diagrams.k8s.rbac import ServiceAccount, Role, ClusterRole
from diagrams.k8s.infra import Node as K8sNode, Master
from diagrams.k8s.clusterconfig import HPA, ConfigMap, Secret
from diagrams.k8s.podconfig import ContainerOn-Premise
本地部署类
python
undefinedpython
undefinedNetwork
网络类
from diagrams.onprem.network import Nginx, HAProxy, Traefik, Istio, Envoy, Consul, Kong, Apache
from diagrams.onprem.network import Nginx, HAProxy, Traefik, Istio, Envoy, Consul, Kong, Apache
Database
数据库类
from diagrams.onprem.database import PostgreSQL, MySQL, MongoDB, Cassandra, Redis as OnPremRedis
from diagrams.onprem.database import Neo4J, CockroachDB, InfluxDB, Clickhouse
from diagrams.onprem.database import PostgreSQL, MySQL, MongoDB, Cassandra, Redis as OnPremRedis
from diagrams.onprem.database import Neo4J, CockroachDB, InfluxDB, Clickhouse
Queue
消息队列类
from diagrams.onprem.queue import Kafka, RabbitMQ, ActiveMQ, Celery, Nats
from diagrams.onprem.queue import Kafka, RabbitMQ, ActiveMQ, Celery, Nats
Container
容器类
from diagrams.onprem.container import Docker
from diagrams.onprem.container import Docker
CI/CD
CI类
from diagrams.onprem.ci import Jenkins, GithubActions, GitlabCI, CircleCI
from diagrams.onprem.cd import Spinnaker, Tekton
from diagrams.onprem.gitops import ArgoCD, Flux
from diagrams.onprem.ci import Jenkins, GithubActions, GitlabCI, CircleCI
from diagrams.onprem.cd import Spinnaker, Tekton
from diagrams.onprem.gitops import ArgoCD, Flux
Monitoring
监控类
from diagrams.onprem.monitoring import Prometheus, Grafana, Datadog, Splunk, Nagios
from diagrams.onprem.logging import Loki, Fluentbit
from diagrams.onprem.tracing import Jaeger, Tempo
from diagrams.onprem.monitoring import Prometheus, Grafana, Datadog, Splunk, Nagios
from diagrams.onprem.logging import Loki, Fluentbit
from diagrams.onprem.tracing import Jaeger, Tempo
IAC
基础设施即代码类
from diagrams.onprem.iac import Terraform, Ansible
from diagrams.onprem.iac import Terraform, Ansible
VCS
版本控制类
from diagrams.onprem.vcs import Git, Github, Gitlab
from diagrams.onprem.vcs import Git, Github, Gitlab
Analytics
分析类
from diagrams.onprem.analytics import Spark, Hadoop, Flink
from diagrams.onprem.analytics import Spark, Hadoop, Flink
Auth/Security
认证/安全类
from diagrams.onprem.security import Vault, Trivy
from diagrams.onprem.security import Vault, Trivy
Workflow
工作流类
from diagrams.onprem.workflow import Airflow, Kubeflow, Nifi
from diagrams.onprem.workflow import Airflow, Kubeflow, Nifi
In-Memory
内存存储类
from diagrams.onprem.inmemory import Redis, Memcached
from diagrams.onprem.inmemory import Redis, Memcached
Compute
计算类
from diagrams.onprem.compute import Server, Nomad
undefinedfrom diagrams.onprem.compute import Server, Nomad
undefinedCustom Icons
自定义图标
python
from diagrams.custom import Custompython
from diagrams.custom import CustomUse any local PNG/JPG image as a node icon
使用本地PNG/JPG图片作为节点图标
my_service = Custom("My Service", "./path/to/icon.png")
undefinedmy_service = Custom("My Service", "./path/to/icon.png")
undefinedClusters (Grouping)
集群(节点分组)
python
with Cluster("VPC"):
with Cluster("Public Subnet"):
web = EC2("Web")
with Cluster("Private Subnet"):
api = EC2("API")
db = RDS("Database")Cluster attributes:
python
with Cluster("Styled Group", graph_attr={
"bgcolor": "#e8f4fd", # Background color
"style": "dashed", # solid, dashed, dotted, rounded
"color": "#2196F3", # Border color
"penwidth": "2.0", # Border width
"fontsize": "12", # Label font size
"fontcolor": "#333333", # Label color
"labeljust": "l", # Label alignment: l, r, c
}):
passpython
with Cluster("VPC"):
with Cluster("Public Subnet"):
web = EC2("Web")
with Cluster("Private Subnet"):
api = EC2("API")
db = RDS("Database")集群属性配置:
python
with Cluster("Styled Group", graph_attr={
"bgcolor": "#e8f4fd", # 背景颜色
"style": "dashed", # 边框样式:solid、dashed、dotted、rounded
"color": "#2196F3", # 边框颜色
"penwidth": "2.0", # 边框宽度
"fontsize": "12", # 标签字体大小
"fontcolor": "#333333", # 标签颜色
"labeljust": "l", # 标签对齐方式:l、r、c
}):
passEdges (Connections)
连接线(节点关系)
Basic Connections
基础连接
python
undefinedpython
undefinedForward direction
正向连接
node_a >> node_b
node_a >> node_b
Backward direction
反向连接
node_a << node_b
node_a << node_b
Bidirectional (no arrows)
双向连接(无箭头)
node_a - node_b
node_a - node_b
One-to-many
一对多连接
node_a >> [node_b, node_c, node_d]
node_a >> [node_b, node_c, node_d]
Chain
链式连接
node_a >> node_b >> node_c
undefinednode_a >> node_b >> node_c
undefinedStyled Edges
样式化连接线
python
from diagrams import Edge
node_a >> Edge(
label="HTTPS", # Text label on the edge
color="blue", # Edge color (name or hex)
style="dashed", # solid, dashed, dotted, bold
minlen="2", # Minimum edge length (ranks)
) >> node_bpython
from diagrams import Edge
node_a >> Edge(
label="HTTPS", # 连接线标签
color="blue", # 连接线颜色(名称或十六进制值)
style="dashed", # 连接线样式:solid、dashed、dotted、bold
minlen="2", # 最小连接线长度(层级间)
) >> node_bEdge Style Patterns
连接线样式规范
| Connection Type | Color | Style | Example |
|---|---|---|---|
| Synchronous API | | | REST/gRPC calls |
| Async messaging | | | Kafka, SQS, events |
| Database access | | | SQL queries |
| Replication | | | DB replication |
| Monitoring | | | Metrics/logs |
| External API | | | Third-party |
| Cache | | | Redis/Memcached |
| Storage | | | S3, NFS, iSCSI |
| 连接类型 | 颜色 | 样式 | 示例场景 |
|---|---|---|---|
| 同步API调用 | | | REST/gRPC调用 |
| 异步消息传递 | | | Kafka、SQS、事件通知 |
| 数据库访问 | | | SQL查询 |
| 数据复制 | | | 数据库同步 |
| 监控数据 | | | 指标/日志采集 |
| 外部API调用 | | | 第三方服务调用 |
| 缓存访问 | | | Redis/Memcached访问 |
| 存储访问 | | | S3、NFS、iSCSI访问 |
Output Formats
输出格式
| Format | Flag | Use Case |
|---|---|---|
| PNG | | Documentation, presentations |
| SVG | | Scalable web embedding |
| Print-quality documents | |
| JPG | | Compressed images |
| DOT | | Graphviz source for manual editing |
python
undefined| 格式 | 参数值 | 适用场景 |
|---|---|---|
| PNG | | 文档、演示文稿 |
| SVG | | 可缩放的网页嵌入 |
| 印刷级文档 | |
| JPG | | 压缩图片 |
| DOT | | Graphviz源文件(用于手动编辑) |
python
undefinedSingle format
单一输出格式
with Diagram("Title", outformat="svg"): ...
with Diagram("Title", outformat="svg"): ...
Multiple formats at once
同时输出多种格式
with Diagram("Title", outformat=["png", "svg", "pdf"]): ...
undefinedwith Diagram("Title", outformat=["png", "svg", "pdf"]): ...
undefinedGenerate Script Usage
生成脚本使用说明
bash
undefinedbash
undefinedSet skill path
设置技能路径
SKILL=~/.claude-wa/.claude/skills/architecture-diagrams
SKILL=~/.claude-wa/.claude/skills/architecture-diagrams
Activate venv first
先激活虚拟环境
source "$SKILL/.venv/bin/activate"
source "$SKILL/.venv/bin/activate"
Generate from example (output in ./output/png/)
生成示例图(输出到./output/png/)
python "$SKILL/scripts/generate.py" "$SKILL/src/examples/cisco-network.py"
python "$SKILL/scripts/generate.py" "$SKILL/src/examples/cisco-network.py"
Custom output name
自定义输出文件名
python "$SKILL/scripts/generate.py" "$SKILL/src/examples/cisco-network.py" --name my-network
python "$SKILL/scripts/generate.py" "$SKILL/src/examples/cisco-network.py" --name my-network
SVG format
生成SVG格式
python "$SKILL/scripts/generate.py" "$SKILL/src/examples/aws-architecture.py" --outformat svg
python "$SKILL/scripts/generate.py" "$SKILL/src/examples/aws-architecture.py" --outformat svg
Custom output directory
自定义输出目录
python "$SKILL/scripts/generate.py" "$SKILL/src/examples/aws-architecture.py" --output-dir ./my-diagrams/
python "$SKILL/scripts/generate.py" "$SKILL/src/examples/aws-architecture.py" --output-dir ./my-diagrams/
Generate in a project directory
在项目目录中生成
cd ~/projects/my-project/
python "$SKILL/scripts/generate.py" my-diagram.py
cd ~/projects/my-project/
python "$SKILL/scripts/generate.py" my-diagram.py
Output: ~/projects/my-project/output/png/my-diagram.png
输出路径: ~/projects/my-project/output/png/my-diagram.png
undefinedundefinedCommon Diagram Patterns
常见架构图模式
Network Topology
网络拓扑图
Layout: . Use for Router, Switch, Firewall, VPN, Subnet. Cluster for DMZ, Internal, Management zones. See .
TBdiagrams.generic.networksrc/examples/cisco-network.py布局方向:。使用中的Router、Switch、Firewall、VPN、Subnet节点。用Cluster分组DMZ区、内部区、管理区。参考示例。
TBdiagrams.generic.networksrc/examples/cisco-network.pyCloud Architecture
云架构图
Layout: . Use AWS/Azure/GCP provider icons. Cluster for VPC, subnets, AZs. Edge labels for protocols. See .
TBsrc/examples/aws-architecture.py布局方向:。使用AWS/Azure/GCP服务商图标。用Cluster分组VPC、子网、可用区。为连接线添加协议标签。参考示例。
TBsrc/examples/aws-architecture.pyKubernetes Cluster
Kubernetes集群图
Layout: . Use for Pod, Deployment, Service, Ingress. Cluster for namespaces. OnPrem for monitoring stack (Prometheus, Grafana). See .
TBdiagrams.k8ssrc/examples/kubernetes-cluster.py布局方向:。使用中的Pod、Deployment、Service、Ingress节点。用Cluster分组命名空间。使用OnPrem类图标表示监控栈(Prometheus、Grafana)。参考示例。
TBdiagrams.k8ssrc/examples/kubernetes-cluster.pyMicroservices
微服务架构图
Layout: or . Mix providers: OnPrem for services, AWS for infra. Cluster for service groups. Edge styles differentiate sync/async/data flows.
TBLR布局方向:或。混合使用不同服务商图标:用OnPrem类表示服务,用AWS类表示基础设施。用Cluster分组服务集群。通过连接线样式区分同步/异步/数据流。
TBLRCI/CD Pipeline
CI/CD流水线图
Layout: . Use and . Linear flow with branching for environments.
LRdiagrams.onprem.cidiagrams.onprem.cd布局方向:。使用和类图标。采用线性流布局,为不同环境添加分支。
LRdiagrams.onprem.cidiagrams.onprem.cdCommon Mistakes
常见错误
| Mistake | Fix |
|---|---|
| Activate venv first: |
| Install graphviz: |
| Diagram opens in viewer | Set |
| File saved in wrong directory | Output goes to |
| Import error for provider class | Check exact class name at diagrams.mingrammer.com/docs/nodes/ |
| Cluttered edges overlapping | Use |
| Nodes too close together | Increase |
| Diagram too large/small | Adjust |
| Custom icon not found | Path must be relative to the script's working directory |
| Multiple outputs not working | Pass list to outformat: |
| 错误 | 解决方法 |
|---|---|
| 先激活虚拟环境: |
| 安装Graphviz: |
| 生成后自动打开查看器 | 在Diagram()中设置 |
| 文件保存到错误目录 | 输出文件默认保存在 |
| 服务商类导入错误 | 访问diagrams.mingrammer.com/docs/nodes/检查类名是否正确 |
| 连接线重叠混乱 | 在graph_attr中设置 |
| 节点间距过近 | 在graph_attr中增大 |
| 图过大/过小 | 调整 |
| 自定义图标无法显示 | 图标路径必须是相对于脚本工作目录的路径 |
| 无法同时输出多种格式 | 为outformat传入列表: |
Troubleshooting
故障排除
| Issue | Solution |
|---|---|
| Ensure Python 3.7+ and graphviz binary are installed |
| Try |
| Blank/empty output | Verify nodes are defined inside the |
| Permission denied on output | Check write permissions for |
| Slow generation | Large diagrams with many nodes are normal — reduce clusters or nodes |
| Update graphviz: |
| 问题 | 解决方法 |
|---|---|
| 确保安装了Python 3.7+和Graphviz二进制文件 |
| 尝试使用 |
| 输出空白图 | 确保节点定义在 |
| 输出目录权限不足 | 检查 |
| 生成速度慢 | 包含大量节点的大型图生成速度慢是正常现象 — 可减少Cluster或节点数量 |
| 更新Graphviz: |