PlantUMLの隠れた機能：plantuml-stdlibを使いこなそう

# PlantUMLとは

ダイアグラムを素早く作成するためのコンポーネントです。

https://plantuml.com/ja/

## plantuml-stdlibとは

公式リリースに含まれているライブラリです。
PlantUML単独では表現的に物足りない場合でも、plantuml-stdlibを利用することで表現の幅を広げることができます。

https://plantuml.com/ja/stdlib

### plantuml-stdlibの構文

以下のURLを参考に、そこからの相対パスで記載します

https://github.com/plantuml/plantuml-stdlib

- 例えば、C4の https://github.com/plantuml/plantuml-stdlib/blob/master/C4/C4_Context.puml を含める場合は、 `<C4/C4_Context>` とします。
- AWSの https://github.com/plantuml/plantuml-stdlib/tree/master/aws/Storage/AmazonS3/AmazonS3.puml を含める場合は、 `<aws/Storage/AmazonS3/AmazonS3>`とします。

## どんなものができますか？


### C4

C4は、システムコンテキスト図、コンテナ図 、コンポーネント図、 コード図の４階層でソフトウェア アーキテクチャを視覚化するためのモデルです。

https://c4model.com/#SystemLandscapeDiagram

```plantuml
!include <C4/C4_Context>

title System Context diagram for Internet Banking System

Person(customer, "Banking Customer", "A customer of the bank, with personal bank accounts.")
System(banking_system, "Internet Banking System", "Allows customers to check their accounts.")

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.")

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")
```

```
!include <C4/C4_Context>

title System Context diagram for Internet Banking System

Person(customer, "Banking Customer", "A customer of the bank, with personal bank accounts.")
System(banking_system, "Internet Banking System", "Allows customers to check their accounts.")

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.")

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")
```

### AWS

AWSのアイコンを描画することもできます。

```plantuml
!include <aws/common>
!include <aws/Messaging/AmazonSES/AmazonSES>
!include <aws/Storage/AmazonS3/AmazonS3>
!include <aws/Storage/AmazonS3/bucket/bucket>

AMAZONS3(s3_internal)
AMAZONS3(s3_partner,"Vendor's S3")
s3_internal <- s3_partner
```

```
!include <aws/common>
!include <aws/Messaging/AmazonSES/AmazonSES>
!include <aws/Storage/AmazonS3/AmazonS3>
!include <aws/Storage/AmazonS3/bucket/bucket>

AMAZONS3(s3_internal)
AMAZONS3(s3_partner,"Vendor's S3")
s3_internal <- s3_partner
```

```plantuml
!include <awslib/AWSCommon>
!include <awslib/InternetOfThings/IoTRule>
!include <awslib/Analytics/KinesisDataStreams>
!include <awslib/ApplicationIntegration/SimpleQueueService>

left to right direction

agent "Published Event" as event

IoTRule(iotRule, "Action Error Rule", "error if Kinesis fails")
KinesisDataStreams(eventStream, "IoT Events", "2 shards")
SimpleQueueService(errorQueue, "Rule Error Queue", "failed Rule actions")

event --> iotRule : JSON message
iotRule --> eventStream : messages
iotRule --> errorQueue : Failed action message
```


```
!include <awslib/AWSCommon>
!include <awslib/InternetOfThings/IoTRule>
!include <awslib/Analytics/KinesisDataStreams>
!include <awslib/ApplicationIntegration/SimpleQueueService>

left to right direction

agent "Published Event" as event

IoTRule(iotRule, "Action Error Rule", "error if Kinesis fails")
KinesisDataStreams(eventStream, "IoT Events", "2 shards")
SimpleQueueService(errorQueue, "Rule Error Queue", "failed Rule actions")

event --> iotRule : JSON message
iotRule --> eventStream : messages
iotRule --> errorQueue : Failed action message
```


### C4とAWSを合体させてみた

C4のようにspriteを指定できる場合、AWSやその他別ライブラリであっても、spriteを埋め込むことができます

```plantuml
!include <C4/C4_Context>

title System Context diagram for Internet Banking System

Person(customer, "Banking Customer", "A customer of the bank, with personal bank accounts.")
System(banking_system, "Internet Banking System", "Allows customers to check their accounts.",$sprite="EC2")

System_Ext(mail_system, "E-mail system", "The internal Microsoft Exchange e-mail system.",$sprite="SimpleEmailService")
System_Ext(mainframe, "Mainframe Banking System", "Stores all of the core banking information.")

Rel(customer, banking_system, "Uses")
Rel_Back(customer, mail_system, "          Sends e-mails to", $sprite="SimpleEmailServiceEmail")
Rel_Neighbor(banking_system, mail_system, "Sends e-mails", "SMTP")
Rel(banking_system, mainframe, "Uses")

!include <awslib/AWSCommon>
!include <awslib/Compute/EC2>
!include <awslib/BusinessApplications/SimpleEmailService>
!include <awslib/BusinessApplications/SimpleEmailServiceEmail>

```

```
!include <C4/C4_Context>

title System Context diagram for Internet Banking System

Person(customer, "Banking Customer", "A customer of the bank, with personal bank accounts.")
System(banking_system, "Internet Banking System", "Allows customers to check their accounts.",$sprite="EC2")

System_Ext(mail_system, "E-mail system", "The internal Microsoft Exchange e-mail system.",$sprite="SimpleEmailService")
System_Ext(mainframe, "Mainframe Banking System", "Stores all of the core banking information.")

Rel(customer, banking_system, "Uses")
Rel_Back(customer, mail_system, "          Sends e-mails to", $sprite="SimpleEmailServiceEmail")
Rel_Neighbor(banking_system, mail_system, "Sends e-mails", "SMTP")
Rel(banking_system, mainframe, "Uses")

!include <awslib/AWSCommon>
!include <awslib/Compute/EC2>
!include <awslib/BusinessApplications/SimpleEmailService>
!include <awslib/BusinessApplications/SimpleEmailServiceEmail>

```

## 構文のドキュメントはどこで参照できますか？

plantuml-stdlibリポジトリで参照できます。

https://github.com/plantuml/plantuml-stdlib