C4模型的绘制及示例

环境准备

VsCode + PlantUML插件

brew install --cask temurin
brew install graphviz

相关文献

C4 模型 - 可视化架构设计
使用PlantUML绘制C4模型风格的软件架构图
C4 model技术架构图--context图

代码示例

@startuml C4_Context

' !include https://unpkg.com/plantuml-style-c4@latest/c4_context.puml
' !include https://unpkg.com/plantuml-style-c4@latest/c4_container.puml
' !include https://unpkg.com/plantuml-style-c4@latest/c4_component.puml
' !include https://unpkg.com/plantuml-style-c4@latest/c4.puml

' !include C4-PlantUML/C4_Context.puml
' !include C4-PlantUML/C4_Container.puml
' !include C4-PlantUML/C4_Component.puml
' !include C4-PlantUML/C4.puml

' systemLevel
' Person/Person_Ext System/System_Ext SystemDb/SystemDb_Ext SystemQueue/SystemQueue_Ext
' ($alias, $label, $descr="", $sprite="", $tags="", $link="")
' System_Boundary Enterprise_Boundary
!include https://gitee.com/coder4/C4-PlantUML/raw/master/mirror/C4_Context.puml

' serviceLevel
' Container/Container_Ext ContainerDb/ContainerDb_Ext ContainerQueue/ContainerQueue_Ext
' ($alias, $label, $techn="", $descr="", $sprite="", $tags="", $link="")
!include https://gitee.com/coder4/C4-PlantUML/raw/master/mirror/C4_Container.puml

' modalLevel
' Component ComponentDb ComponentQueue Component_Ext ComponentDb_Ext ComponentQueue_Ext
' ($alias, $label, $techn="", $descr="", $sprite="", $tags="", $link="")
!include https://gitee.com/coder4/C4-PlantUML/raw/master/mirror/C4_Component.puml

' codeLevel
!include https://gitee.com/coder4/C4-PlantUML/raw/master/mirror/C4.puml

!define DEVICONS https://gitee.com/coder4/plantuml-icon-font-sprites/raw/master/mirror/devicons
!include DEVICONS/java.puml
!include DEVICONS/php.puml
!include DEVICONS/mysql.puml
!include DEVICONS/dotnet.puml
!include DEVICONS/redis.puml
!include DEVICONS/rab.puml

' 展示 lengend
' LAYOUT_WITH_LEGEND()
' 垂直布局
' LAYOUT_TOP_DOWN()
' 水平布局
' LAYOUT_LEFT_RIGHT()
' 草稿风格
' LAYOUT_AS_SKETCH()

Person(staff, "员工", "公司内部的员工用户")

AddElementTag("tag_staff_system", $bgColor="Green", $borderColor="#555", $fontColor="white")

System_Boundary(erpSystemBoundary, "ERP管理系统") {
    System(erpSystem, "ERP管理系统", "提供ERP相关的功能及服务", $sprite="dotnet")
    System(staffSystem, "员工数据系统", "提供员工相关的数据服务", $tags="tag_staff_system")
}

System_Boundary(notifySystemBoundary, "消息通知系统") {
    SystemQueue_Ext(mailQueueSystem, "邮件队列服务", "接受邮件类发送投递任务的队列")
    SystemQueue_Ext(smsQueueSystem, "短信队列服务", "接受短信类发送投递任务的队列")
    System_Ext(mailSystem, "邮件服务", "提供 邮件发送 等功能")
    System_Ext(smsSystem, "短信服务", "提供 短信发送 等功能")
}

'关系 from to tag
Rel(staff, erpSystem, "使用")

'关系 布局to在from的方向 D Down U Up L Left R Right
Rel_D(erpSystem, staffSystem, "交互", "json/http")

Rel_D(erpSystem, mailQueueSystem, "投递", "json/http")
Rel_D(erpSystem, smsQueueSystem, "投递", "json/http")

Rel_U(mailSystem, mailQueueSystem, "消费", "binary/tcp")
Rel_U(smsSystem, smsQueueSystem, "消费", "binary/tcp")

' SHOW_FLOATING_LEGEND()

@enduml

C4模型的绘制及示例_第1张图片

你可能感兴趣的:(c4模型)