plantuml样式_自定义PlantUML和C4Model的样式

本文介绍了PlantUml,一个用于绘制UML图的开源项目,以及C4 Model,一种用于描述软件架构图的方法。文章提供了一个样式库,用于美化PlantUml和C4 Model的图表,包括时序图、类图、状态图、用例图、活动图等,并展示了如何自定义样式。
摘要由CSDN通过智能技术生成

RLF1Rjim3BthAxXJaqFioqxEW3K8qdROi1P9Xs6dG9FfMAWiUHBLp7y_oevTUAaEjapoFJu-oRU1fAVO692AzAkcRcNnl0goQGsA3zeg4qkCta1Dr8OYpxqyPoTDTVmT0thbBA6bJBac_nkbxJ1lZRI9SHMeCxXI7_D61aAVA-SnQpaZRY1QHZIC1AeHAcUCEsjx0gCjWhGbpDBQ1zuvu8vWd9B6TE9c50TllE9-lzjzFsxs-yUVujlcr-EFv-FcS3nytJrl7uJePnN5rcZrSa3_Qf2ocfiPtEEVY84MoxKeU7vevGdNGbUmUE9Tvkm1LVJiphP6zR9CgYmio4TS2k1LNCg-MDsJf5X2wt3d_5dwylE8iMv032Zl58O0oKNlJ5XFgGHEKMqZGZkKiJ_lqgGLoBLJ06sfgncL3aykq8JkCCpXe_vKnVe_lL4PjlogsrX-ZzEqrtt7eZs7qOzrGyr0Mqb-BSKGIZ9B1nvBxL6zexKOKwCVwvvcyfh1rNzcp-OiBaV1BVh3lkYv6h0O1FTt00ZvHv24C_7zK_IMt_87txn_

什么是PlantUml

PlantUml是一个支持快速绘制的开源项目.其定义了一套完整的语言用于实现UML关系图的描述.并基于强大的graphviz图形渲染库进行UML图的生成.绘制的UML图还可以导出为图片,以及通用的矢量SVG格式文件.

如以下代码,可实现时序图

@startuml

Alice -> Bob: Authentication Request

Bob --> Alice: Authentication Response

Alice -> Bob: Another authentication Request

Alice

@enduml

c2627f00aa5b2e303b781f7d8979825c.png

可以使用常用的编辑器vscode 或者sublime 或者其他IDE工具继承PlantUml

想了解更多PlantUml或者使用方法,可参考官网http://plantuml.com/zh/,上面详细的中英文说明

什么是C4 Model

C4 Model 在我眼里更像是一个标准,一个方法论。让架构师、程序员、业务人员在讨论IT系统架构时候统一维度,统一标准,更方便的理解和沟通IT系统中的真实问题。强烈推荐!!!

C4 模型由一系列分层的软件架构图组成,这些架构图用于描述上下文(Context)、容器(Container)、组件(Component)和代码(Code)。C4 图的层次结构提供了不同的抽象级别,每种抽象级别都与不同的受众有关

33fc036f8a827b09feb554ee5a7e7238.png

本库只是一个样式库

本库的目的是美化PlantUml和C4 Model所绘制系统架构图的样式,统一审美而产生。

1.时序图

在PlantUml代码中引用

@startuml sequence-sample

!includeurl https://raw.githubusercontent.com/xuanye/plantuml-style-c4/master/core.puml

' 如果使用本地,则需要注释上一行,取消注释下一行

'!include core.puml

' 使用红色箭头,默认为灰色

RED_ARROW

@enduml

66728684e325dffbb3645bc4e07d0302.png

2. 类图

以下为示例

@startuml class-sample

!includeurl https://raw.githubusercontent.com/xuanye/plantuml-style-c4/master/core.puml

' uncomment the following line and comment the first to use locally

'!include core.puml

GREY_ARROW

abstract class BaseClass {

+ AbstractMethod() : void

# VirtualMethod(s:string) : int

}

class SubClass {

+ AbstractMethod() : void

# VirtualMethod(s:string) : int

}

interface IInterfaceA {

}

interface "IInterfaceA`1" {

Value : T <>

}

class ImplementClass {

+ Value : int <>

}

BaseClass

IInterfaceA

"IInterfaceA`1" ""

@enduml

103cc3693669eb3f086fdc5a78b090d0.png

3. 状态图

@startuml state-sample

!includeurl https://raw.githubusercontent.com/xuanye/plantuml-style-c4/master/core.puml

' uncomment the following line and comment the first to use locally

'!include core.puml

GREEN_ARROW

title HTTP Request Parsing States

[*] --> RequestLine

RequestLine : Parse HTTP

RequestLine : request line

RequestLine --> Headers : Ok

RequestLine --> Error : Failure

Headers : Parse HTTP

Headers : headers

Headers --> Host : Ok

Headers --> Error : Failure

Host : Check host

Host : header is present

Host --> Length : Not chunked

Host --> Chunked : Chunked

Host --> Error : Failure

Length : Check if required,

Length : valid & size

Length --> Error : Failure

Length --> Error : Entity Too Large

Length --> [*] : Ok

Chunked : Parse HTTP

Chunked : chunk header

Chunked --> Error : Failure

Chunked --> [*] : Ok

@enduml

5fdffffe9e51f7802c9a47207c5d1638.png

4. 用例图

@startuml usecase-sample

!includeurl https://raw.githubusercontent.com/xuanye/plantuml-style-c4/master/core.puml

' uncomment the following line and comment the first to use locally

'!include core.puml

' 设置方向

LAYOUT_LEFT_RIGHT

'LAYOUT_TOP_DOWN

'LAYOUT_AS_SKETCH

actor customer

actor clerk

UserCasePackage("checkout","买单") {

customer -- (checkout)

(checkout) .> (payment) : include

(help) .> (checkout) : extends

(checkout) -- clerk

}

@enduml

750e3628bf5c1a5a4b577a603721dca9.png

5. 活动图

@startuml activity-new-sample

!includeurl https://raw.githubusercontent.com/xuanye/plantuml-style-c4/master/core.puml

' uncomment the following line and comment the first to use locally

'!include core.puml

GREEN_ARROW

start

:ClickServlet.handleRequest();

:new page;

if (Page.onSecurityCheck) then (true)

:Page.onInit();

if (isForward?) then (no)

:Process controls;

if (continue processing?) then (no)

stop

endif

if (isPost?) then (yes)

:Page.onPost();<

else (no)

:Page.onGet();

endif

:Page.onRender();

endif

else (false)

endif

if (do redirect?) then (yes)

:redirect process;

else

if (do forward?) then (yes)

:Forward request;

else (no)

:Render page template;

endif

endif

stop

@enduml

16461082cbcab5a55831ee6122e8c772.png

6. 其他组件

@startuml element

!includeurl https://raw.githubusercontent.com/xuanye/plantuml-style-c4/master/core.puml

' uncomment the following line and comment the first to use locally

'!include core.puml

actor actor

agent agent

artifact artifact

boundary boundary

card card

cloud cloud

component component

control control

database database

entity entity

file file

folder folder

frame frame

interface interface

node node

package package

queue queue

stack stack

rectangle rectangle

storage storage

usecase usecase

@enduml

2ee314f3e7b8bda67ea97287f48fb2d9.png

C4 模型

1.System Context

@startuml system-context-diagram

!includeurl https://raw.githubusercontent.com/xuanye/plantuml-style-c4/master/c4_context.puml

' uncomment the following line and comment the first to use locally

'!include c4_context.puml

LAYOUT_WITH_LEGEND

title System Context diagram for Internet Banking System

Actor(customer, "Personal Banking Customer", "A customer of the bank, with personal bank accounts.")

System(banking_system, "Internet Banking System", "Allows customers to view information about their bank accounts, and make payments.")

System_Ext(mail_system, "E-mail system", "The internal Microsoft Exchange e-mail system.")

System_Ext(mainframe, "Mainframe Banking System", "Stores all of the core banking information about customers, accounts, transactions, etc.")

Rel(customer, banking_system, "Uses")

Rel_Back(customer, mail_system, "Sends e-mails to")

Rel_Neighbor(banking_system, mail_system, "Sends e-mails", "SMTP")

Rel(banking_system, mainframe, "Uses")

@enduml

797dd5ff19f3caa141d86acd55a50349.png

2. Container

@startuml container-diagram

!includeurl https://raw.githubusercontent.com/xuanye/plantuml-style-c4/master/c4_container.puml

' uncomment the following line and comment the first to use locally

'!include c4_container.puml

LAYOUT_TOP_DOWN

'LAYOUT_AS_SKETCH

LAYOUT_WITH_LEGEND_CN

LAYOUT_TOP_DOWN

'LAYOUT_AS_SKETCH

LAYOUT_WITH_LEGEND

title Container diagram for Internet Banking System

Actor(customer, Customer, "A customer of the bank, with personal bank accounts")

System_Boundary(c1, "Internet Banking") {

Container(web_app, "Web Application", "Java, Spring MVC", "Delivers the static content and the Internet banking SPA")

Container(spa, "Single-Page App", "JavaScript, Angular", "Provides all the Internet banking functionality to cutomers via their web browser")

Container(mobile_app, "Mobile App", "C#, Xamarin", "Provides a limited subset of the Internet banking functionality to customers via their mobile device")

ContainerDb(database, "Database", "SQL Database", "Stores user registraion information, hased auth credentials, access logs, etc.")

Container(backend_api, "API Application", "Java, Docker Container", "Provides Internet banking functionality via API")

}

System_Ext(email_system, "E-Mail System", "The internal Microsoft Exchange system")

System_Ext(banking_system, "Mainframe Banking System", "Stores all of the core banking information about customers, accounts, transactions, etc.")

Rel(customer, web_app, "Uses", "HTTPS")

Rel(customer, spa, "Uses", "HTTPS")

Rel(customer, mobile_app, "Uses")

Rel_Neighbor(web_app, spa, "Delivers")

Rel(spa, backend_api, "Uses", "async, JSON/HTTPS")

Rel(mobile_app, backend_api, "Uses", "async, JSON/HTTPS")

Rel_Back_Neighbor(database, backend_api, "Reads from and writes to", "sync, JDBC")

Rel_Back(customer, email_system, "Sends e-mails to")

Rel_Back(email_system, backend_api, "Sends e-mails using", "sync, SMTP")

Rel_Neighbor(backend_api, banking_system, "Uses", "sync/async, XML/HTTPS")

@enduml

0af80316bb07c49fc87ebfe6bc8722f4.png

3.Component

组件图

@startuml component-diagram

!includeurl https://raw.githubusercontent.com/xuanye/plantuml-style-c4/master/c4_component.puml

' uncomment the following line and comment the first to use locally

'!include c4_component.puml

LAYOUT_WITH_LEGEND

title Component diagram for Internet Banking System - API Application

Container(spa, "Single Page Application", "javascript and angular", "Provides all the internet banking functionality to customers via their web browser.")

Container(ma, "Mobile App", "Xamarin", "Provides a limited subset ot the internet banking functionality to customers via their mobile mobile device.")

ContainerDb(db, "Database", "Relational Database Schema", "Stores user registration information, hashed authentication credentials, access logs, etc.")

System_Ext(mbs, "Mainframe Banking System", "Stores all of the core banking information about customers, accounts, transactions, etc.")

Container_Boundary(api, "API Application") {

Component(sign, "Sign In Controller", "MVC Rest Controlle", "Allows users to sign in to the internet banking system")

Component(accounts, "Accounts Summary Controller", "MVC Rest Controlle", "Provides customers with a summory of their bank accounts")

Component(security, "Security Component", "Spring Bean", "Provides functionality related to singing in, changing passwords, etc.")

Component(mbsfacade, "Mainframe Banking System Facade", "Spring Bean", "A facade onto the mainframe banking system.")

Rel(sign, security, "Uses")

Rel(accounts, mbsfacade, "Uses")

Rel(security, db, "Read & write to", "JDBC")

Rel(mbsfacade, mbs, "Uses", "XML/HTTPS")

}

Rel(spa, sign, "Uses", "JSON/HTTPS")

Rel(spa, accounts, "Uses", "JSON/HTTPS")

Rel(ma, sign, "Uses", "JSON/HTTPS")

Rel(ma, accounts, "Uses", "JSON/HTTPS")

@enduml

fb5c363b2356cac70ff08ad73ec5bd37.png

4 Code

类图上面已经演示过了

5. 扩展图

@startuml system-context-extend-diagram

!includeurl https://raw.githubusercontent.com/xuanye/plantuml-style-c4/master/c4_context.puml

' uncomment the following line and comment the first to use locally

'!include c4_context.puml

'LAYOUT_TOP_DOWN

'LAYOUT_AS_SKETCH

LAYOUT_WITH_LEGEND

title System Landscape diagram for Big Bank plc

Actor(customer, "Personal Banking Customer", "A customer of the bank, with personal bank accounts.")

Enterprise_Boundary(c0, "Big Bank plc") {

System(banking_system, "Internet Banking System", "Allows customers to view information about their bank accounts, and make payments.")

System_Ext(atm, "ATM", "Allows customers to withdraw cash.")

System_Ext(mail_system, "E-mail system", "The internal Microsoft Exchange e-mail system.")

System_Ext(mainframe, "Mainframe Banking System", "Stores all of the core banking information about customers, accounts, transactions, etc.")

Person_Ext(customer_service, "Customer Service Staff", "Customer service staff within the bank.")

Person_Ext(back_office, "Back Office Staff", "Administration and support staff within the bank.")

}

Rel_Neighbor(customer, banking_system, "Uses")

Rel_R(customer, atm, "Withdraws cash using")

Rel_Back(customer, mail_system, "Sends e-mails to")

Rel_R(customer, customer_service, "Asks questions to", "Telephone")

Rel_D(banking_system, mail_system, "Sends e-mail using")

Rel_R(atm, mainframe, "Uses")

Rel_R(banking_system, mainframe, "Uses")

Rel_D(customer_service, mainframe, "Uses")

Rel_U(back_office, mainframe, "Uses")

Lay_D(atm, banking_system)

Lay_D(atm, customer)

Lay_U(mail_system, customer)

@enduml

153636512ad15ff51037cca6d74adc85.png

参考

C4 Model的配色和实现大部分都是直接使用

https://github.com/RicardoNiepel/C4-PlantUML的,只有几个配色略有调整,并抽取出颜色的文件,可单独替换c4_theme 以实现其他配色

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值