uml-modeling について
uml-modelingは、ソフトウェア設計文書向けのUML図を作成するスキルです。要件分析、システム設計、アーキテクチャ記録に携わる開発者を対象に、PlantUMLとMermaidの例を示し、文書確認、構文検証、UML 2.5への準拠を求めます。
主な機能
- 01構造図と振る舞い図を幅広く扱う
- 02PlantUMLとMermaidの例を掲載
- 03設計目的に応じた図の選択を案内
- 04文書確認を優先し構文検証を要求
- 05作図とレビューのワークフローを提示
活用シーン
- 01クラス図やコンポーネント図によるシステム構造の記録
- 02シーケンス図によるAPIやプロトコルの流れの説明
- 03アクティビティ図やユースケース図によるプロセスと要件の表現
- 04状態機械図によるライフサイクル遷移の記録
インストール
コマンドをコピーしてターミナルで実行します。
$
npx skills add https:/ / github.com/ melodic-software/ claude-code-plugins --skill uml-modelingインストール後、Claude Code で/uml-modelingを入力して読み込まれたか確認します。
詳細
UML モデリングスキル
このスキルを使用する場面
以下の場合にこのスキルを使用します。
- UML モデリングタスク - クラス図、シーケンス図、アクティビティ図、ユースケース図、状態図などの UML 図の生成に取り組む場合
- 計画や設計 - UML モデリングの手法についてガイダンスが必要な場合
- ベストプラクティス - 確立されたパターンや標準に従いたい場合
概要
ソフトウェア設計ドキュメント用に、PlantUML および Mermaid の記法を使って UML 図を作成します。
必須:ドキュメントを最優先するアプローチ
UML 図を作成する前に、以下を行います。
- UML 標準に関するガイダンスを得るため、
docs-managementスキルを呼び出します - 適切な記法(PlantUML/Mermaid)を使って図の構文を検証します
- すべてのガイダンスを UML 2.5 仕様に基づかせます
UML 図の種類
構造図
| 図 | 目的 | 使用場面 |
|---|---|---|
| クラス図 | クラス、属性、メソッド、関係を示す | ドメインモデリング、設計 |
| コンポーネント図 | コンポーネントと依存関係を示す | アーキテクチャのドキュメント作成 |
| 配置図 | 物理的な配置を示す | インフラストラクチャの計画 |
| オブジェクト図 | オブジェクトのインスタンスを示す | 特定のシナリオ |
| パッケージ図 | 名前空間/モジュールを示す | コードの整理 |
振る舞い図
| 図 | 目的 | 使用場面 |
|---|---|---|
| ユースケース図 | アクターとシステムのやり取りを示す | 要件 |
| シーケンス図 | 時間の経過に沿ったメッセージの流れを示す | API 設計、プロトコル |
| アクティビティ図 | ワークフローとプロセスを示す | ビジネスプロセス |
| ステートマシン図 | 状態遷移を示す | ライフサイクルのモデリング |
| コミュニケーション図 | オブジェクト間のやり取りを示す | デザインパターン |
クラス図
PlantUML の構文
@startuml
skinparam classAttributeIconSize 0
abstract class Entity {
+Id: Guid
+CreatedAt: DateTimeOffset
+UpdatedAt: DateTimeOffset
}
class Order extends Entity {
-_lineItems: List<LineItem>
+CustomerId: Guid
+Status: OrderStatus
+Total: Money
--
+AddItem(product: Product, quantity: int): Result<LineItem>
+RemoveItem(lineItemId: Guid): Result
+Submit(): Result
+Cancel(): Result
}
class LineItem extends Entity {
+ProductId: Guid
+ProductName: string
+Quantity: int
+UnitPrice: Money
+LineTotal: Money
}
enum OrderStatus {
Draft
Submitted
Paid
Shipped
Delivered
Cancelled
}
class Money <<value object>> {
+Amount: decimal
+Currency: string
+{static} Zero: Money
+Add(other: Money): Money
+Multiply(factor: decimal): Money
}
Order "1" *-- "0..*" LineItem : contains
Order --> OrderStatus
Order --> Money
LineItem --> Money
@enduml
Mermaid クラス図
classDiagram
class Entity {
<<abstract>>
+Guid Id
+DateTimeOffset CreatedAt
+DateTimeOffset UpdatedAt
}
class Order {
-List~LineItem~ _lineItems
+Guid CustomerId
+OrderStatus Status
+Money Total
+AddItem(Product, int) Result~LineItem~
+RemoveItem(Guid) Result
+Submit() Result
+Cancel() Result
}
class LineItem {
+Guid ProductId
+string ProductName
+int Quantity
+Money UnitPrice
+Money LineTotal
}
class OrderStatus {
<<enumeration>>
Draft
Submitted
Paid
Shipped
Delivered
Cancelled
}
Entity <|-- Order
Entity <|-- LineItem
Order "1" *-- "0..*" LineItem : contains
Order --> OrderStatus
関係の種類
// UML Relationship Reference
public static class UMLRelationships
{
// Association: uses, knows about
// Customer --> Order (Customer uses Order)
// Aggregation: has-a (shared ownership)
// Team o-- Player (Team has Players, Players can exist independently)
// Composition: contains (exclusive ownership)
// Order *-- LineItem (Order contains LineItems, LineItems cannot exist without Order)
// Inheritance: is-a
// Dog --|> Animal (Dog extends Animal)
// Implementation: implements
// UserService ..|> IUserService (UserService implements IUserService)
// Dependency: depends on
// Controller ..> Service (Controller depends on Service)
}
シーケンス図
PlantUML の構文
@startuml
title Order Submission Flow
actor Customer
participant "API Gateway" as API
participant "Order Service" as Orders
participant "Payment Service" as Payment
participant "Notification Service" as Notify
database "Order DB" as DB
queue "Message Bus" as Bus
Customer -> API: POST /orders/{id}/submit
activate API
API -> Orders: SubmitOrder(orderId)
activate Orders
Orders -> DB: GetOrder(orderId)
activate DB
DB --> Orders: Order
deactivate DB
alt Order is valid
Orders -> Payment: ProcessPayment(order)
activate Payment
Payment --> Orders: PaymentResult
deactivate Payment
alt Payment successful
Orders -> DB: UpdateStatus(Paid)
Orders -> Bus: Publish(OrderSubmitted)
Bus -> Notify: OrderSubmitted
activate Notify
Notify -> Notify: SendConfirmation()
deactivate Notify
Orders --> API: Success
API --> Customer: 200 OK
else Payment failed
Orders --> API: PaymentFailed
API --> Customer: 402 Payment Required
end
else Order invalid
Orders --> API: ValidationError
API --> Customer: 400 Bad Request
end
deactivate Orders
deactivate API
@enduml
Mermaid シーケンス図
sequenceDiagram
participant C as Customer
participant A as API Gateway
participant O as Order Service
participant P as Payment Service
participant D as Database
C->>A: POST /orders/{id}/submit
activate A
A->>O: SubmitOrder(orderId)
activate O
O->>D: GetOrder(orderId)
D-->>O: Order
alt Order valid
O->>P: ProcessPayment(order)
P-->>O: PaymentResult
alt Payment successful
O->>D: UpdateStatus(Paid)
O-->>A: Success
A-->>C: 200 OK
else Payment failed
O-->>A: PaymentFailed
A-->>C: 402 Payment Required
end
else Order invalid
O-->>A: ValidationError
A-->>C: 400 Bad Request
end
deactivate O
deactivate A
アクティビティ図
PlantUML の構文
@startuml
title Order Processing Workflow
start
:Customer submits order;
:Validate order;
if (Order valid?) then (yes)
:Calculate totals;
:Reserve inventory;
fork
:Process payment;
fork again
:Send confirmation email;
end fork
if (Payment successful?) then (yes)
:Confirm inventory;
:Create shipment;
:Update order status;
stop
else (no)
:Release inventory;
:Notify customer;
stop
endif
else (no)
:Return validation errors;
stop
endif
@enduml
ユースケース図
PlantUML の構文
@startuml
left to right direction
actor Customer
actor "Warehouse Staff" as Warehouse
actor Admin
rectangle "E-Commerce System" {
usecase "Browse Products" as UC1
usecase "Add to Cart" as UC2
usecase "Checkout" as UC3
usecase "Track Order" as UC4
usecase "Process Refund" as UC5
usecase "Manage Inventory" as UC6
usecase "Fulfill Order" as UC7
usecase "Generate Reports" as UC8
Customer --> UC1
Customer --> UC2
Customer --> UC3
Customer --> UC4
Customer --> UC5
Warehouse --> UC6
Warehouse --> UC7
Admin --> UC6
Admin --> UC8
UC3 ..> UC2 : <<include>>
UC5 ..> UC4 : <<extend>>
}
@enduml
ステートマシン図
PlantUML の構文
@startuml
title Order State Machine
[*] --> Draft : Create
Draft --> Submitted : Submit
Draft --> Cancelled : Cancel
Submitted --> Paid : PaymentReceived
Submitted --> Cancelled : Cancel
Submitted --> Draft : RequiresChanges
Paid --> Shipped : Ship
Paid --> Refunded : Refund
Shipped --> Delivered : Deliver
Shipped --> Returned : Return
Delivered --> Completed : Finalize
Delivered --> Returned : Return
Returned --> Refunded : ProcessReturn
Completed --> [*]
Refunded --> [*]
Cancelled --> [*]
@enduml
Mermaid ステート図
stateDiagram-v2
[*] --> Draft : Create
Draft --> Submitted : Submit
Draft --> Cancelled : Cancel
Submitted --> Paid : PaymentReceived
Submitted --> Cancelled : Cancel
Submitted --> Draft : RequiresChanges
Paid --> Shipped : Ship
Paid --> Refunded : Refund
Shipped --> Delivered : Deliver
Shipped --> Returned : Return
Delivered --> Completed : Finalize
Delivered --> Returned : Return
Returned --> Refunded : ProcessReturn
Completed --> [*]
Refunded --> [*]
Cancelled --> [*]
コンポーネント図
PlantUML の構文
@startuml
title System Components
package "Presentation Layer" {
[Web Application] as Web
[Mobile App] as Mobile
}
package "API Layer" {
[API Gateway] as Gateway
[GraphQL Server] as GraphQL
}
package "Business Layer" {
[Order Service] as Orders
[Payment Service] as Payment
[Notification Service] as Notify
[User Service] as Users
}
package "Data Layer" {
database "Order DB" as OrderDB
database "User DB" as UserDB
queue "Message Bus" as Bus
}
package "External" {
[Payment Provider] as PaymentExt
[Email Service] as EmailExt
}
Web --> Gateway
Mobile --> Gateway
Gateway --> GraphQL
Gateway --> Orders
Gateway --> Users
Orders --> OrderDB
Orders --> Bus
Users --> UserDB
Payment --> PaymentExt
Notify --> EmailExt
Notify --> Bus
@enduml
ベストプラクティス
一般的なガイドライン
- 図の焦点を絞る:1 つの図につき 1 つの概念を扱います
- 一貫した記法を使う:プロジェクトごとに PlantUML または Mermaid を選びます
- 意味のある名前を付ける:明確で説明的なラベルを付けます
- 凡例を含める:複雑な図には凡例を付けます
- バージョン管理する:コードとともにリポジトリに保存します
図の選択ガイド
| 必要なもの | 図の種類 |
|---|---|
| データ構造、ドメインモデル | クラス図 |
| API のフロー、プロトコル | シーケンス図 |
| ビジネスプロセス | アクティビティ図 |
| アクター間のやり取り | ユースケース図 |
| ライフサイクル、状態遷移 | ステートマシン図 |
| システム構造 | コンポーネント図 |
| インフラストラクチャ | 配置図 |
ワークフロー
UML 図を作成する際は、以下の手順に従います。
- 目的を特定する:その図はどのような問いに答えるものですか?
- 図の種類を選択する:最も適切な種類を選びます
- テキストで下書きする:PlantUML または Mermaid の記法を使います
- 正確性を確認する:コードや要件と照らし合わせて検証します
- コンテキストを追加する:必要に応じてタイトル、注記、凡例を加えます
- レンダリングして検証する:図が正しくレンダリングされることを確認します
参考資料
詳しい記法ガイドについては、以下を参照してください。
最終更新日: 2025-12-26
コメント
Markdown 対応