uml-diagram-design

Original🇨🇳 Chinese
Translated

UML diagram design and drawing. Use this skill when users need to create system architecture diagrams, class diagrams, sequence diagrams, use case diagrams, or other UML diagrams.

3installs
Added on

NPX Install

npx skill4agent add aaaaqwq/claude-code-skills uml-diagram-design

SKILL.md Content (Chinese)

View Translation Comparison →

UML Diagram Design

Feature Description

This skill is dedicated to the design and drawing of UML (Unified Modeling Language) diagrams, including:
  • System architecture design
  • Class diagrams and object diagrams
  • Sequence diagrams and collaboration diagrams
  • Use case diagrams and activity diagrams
  • State diagrams and deployment diagrams
  • Component diagrams and package diagrams

Usage Scenarios

  • "Design a class diagram for an e-commerce system"
  • "Draw a sequence diagram for user login"
  • "Create a system architecture diagram"
  • "Design a database ER diagram"
  • "Draw a business process diagram"
  • "Create a use case diagram to demonstrate system functions"

UML Diagram Types

1. Class Diagram

Used to display classes, attributes, methods and their relationships in the system.
plantuml
@startuml
class User {
  - id: Long
  - username: String
  - email: String
  - password: String
  + login(): boolean
  + logout(): void
  + updateProfile(): void
}

class Order {
  - id: Long
  - orderNumber: String
  - totalAmount: Decimal
  - status: OrderStatus
  + create(): void
  + cancel(): void
  + pay(): boolean
}

class Product {
  - id: Long
  - name: String
  - price: Decimal
  - stock: Integer
  + updateStock(quantity: Integer): void
  + getPrice(): Decimal
}

User "1" -- "*" Order : places
Order "*" -- "*" Product : contains
@enduml
Relationship Types:
  • Association: Solid line, indicating the relationship between classes
  • Aggregation: Hollow diamond, indicating whole-part relationship
  • Composition: Solid diamond, indicating strong whole-part relationship
  • Inheritance: Hollow triangle arrow, indicating is-a relationship
  • Realization: Dashed hollow triangle arrow, indicating interface implementation
  • Dependency: Dashed arrow, indicating usage relationship

2. Sequence Diagram

Displays the interaction order and message passing between objects.
plantuml
@startuml
actor User
participant "Web Browser" as Browser
participant "API Server" as API
participant "Database" as DB

User -> Browser: Enter login information
Browser -> API: POST /api/login
activate API

API -> DB: Query user information
activate DB
DB --> API: Return user data
deactivate DB

alt Authentication Success
    API -> API: Generate JWT Token
    API --> Browser: Return Token
    Browser --> User: Login successful
else Authentication Failed
    API --> Browser: Return error message
    Browser --> User: Display error prompt
end

deactivate API
@enduml
Element Explanations:
  • Actor: Participants (users or external systems)
  • Participant: Objects or components
  • Message: Message passing (synchronous/asynchronous)
  • Activation: Object activation period
  • Alt/Opt/Loop: Condition, optional, loop

3. Use Case Diagram

Displays system functions and relationships between participants.
plantuml
@startuml
left to right direction

actor User as User
actor Admin as Admin

rectangle E-commerce System {
  usecase "Browse Products" as UC1
  usecase "Search Products" as UC2
  usecase "Add to Cart" as UC3
  usecase "Place Order" as UC4
  usecase "Pay Order" as UC5
  usecase "Manage Products" as UC6
  usecase "View Orders" as UC7
  usecase "Process Refunds" as UC8
}

User --> UC1
User --> UC2
User --> UC3
User --> UC4
User --> UC5
User --> UC7

Admin --> UC6
Admin --> UC7
Admin --> UC8

UC4 ..> UC3 : <<include>>
UC5 ..> UC4 : <<include>>
@enduml
Relationship Types:
  • Association: Relationship between participants and use cases
  • Include: Use case that must be executed
  • Extend: Optionally executed use case
  • Generalization: Inheritance relationship between use cases

4. Activity Diagram

Displays the execution flow of business processes or algorithms.
plantuml
@startuml
start

:User submits order;

if (Stock sufficient?) then (Yes)
  :Lock stock;
  :Create order;

  fork
    :Send confirmation email;
  fork again
    :Update stock;
  fork again
    :Record log;
  end fork

  :Wait for payment;

  if (Payment successful?) then (Yes)
    :Confirm order;
    :Arrange shipment;
  else (No)
    :Cancel order;
    :Release stock;
  endif

else (No)
  :Prompt insufficient stock;
endif

stop
@enduml
Element Explanations:
  • Start/End: Start and end points of the process
  • Activity: Operations to be executed
  • Decision: Conditional judgment
  • Branch/Merge: Parallel execution
  • Swimlane: Responsibility division

5. State Diagram

Displays state changes of an object during its lifecycle.
plantuml
@startuml
[*] --> Pending Payment : Create order

Pending Payment --> Paid : Payment successful
Pending Payment --> Cancelled : Timeout/User cancels

Paid --> Being Prepared : Start preparation
Being Prepared --> Shipped : Ship

Shipped --> Completed : Confirm receipt
Shipped --> Refunding : Apply for refund

Refunding --> Refunded : Refund successful
Refunding --> Shipped : Reject refund

Completed --> [*]
Cancelled --> [*]
Refunded --> [*]

Pending Payment : entry / Lock stock
Pending Payment : exit / Release stock
Paid : entry / Deduct stock
@enduml

6. Component Diagram

Displays the component structure and dependency relationships of the system.
plantuml
@startuml
package "Frontend Layer" {
  [Web Application]
  [Mobile Application]
}

package "API Layer" {
  [API Gateway]
  [Authentication Service]
}

package "Business Layer" {
  [User Service]
  [Order Service]
  [Product Service]
  [Payment Service]
}

package "Data Layer" {
  database "MySQL" as DB
  database "Redis" as Cache
  queue "Message Queue" as MQ
}

[Web Application] --> [API Gateway]
[Mobile Application] --> [API Gateway]

[API Gateway] --> [Authentication Service]
[API Gateway] --> [User Service]
[API Gateway] --> [Order Service]
[API Gateway] --> [Product Service]

[Order Service] --> [Payment Service]
[Order Service] --> DB
[User Service] --> DB
[Product Service] --> DB

[User Service] --> Cache
[Product Service] --> Cache

[Order Service] --> MQ
[Payment Service] --> MQ
@enduml

7. Deployment Diagram

Displays the physical deployment architecture of the system.
plantuml
@startuml
node "User Devices" {
  [Browser]
  [Mobile App]
}

node "Load Balancer" {
  [Nginx]
}

node "Application Server Cluster" {
  node "Server 1" {
    [Node.js Instance 1]
  }
  node "Server 2" {
    [Node.js Instance 2]
  }
}

node "Database Server" {
  database "MySQL Primary"
  database "MySQL Replica"
}

node "Cache Server" {
  database "Redis Cluster"
}

node "File Storage" {
  [OSS/S3]
}

[Browser] --> [Nginx]
[Mobile App] --> [Nginx]
[Nginx] --> [Node.js Instance 1]
[Nginx] --> [Node.js Instance 2]

[Node.js Instance 1] --> [MySQL Primary]
[Node.js Instance 2] --> [MySQL Primary]
[MySQL Primary] --> [MySQL Replica] : Master-slave replication

[Node.js Instance 1] --> [Redis Cluster]
[Node.js Instance 2] --> [Redis Cluster]

[Node.js Instance 1] --> [OSS/S3]
[Node.js Instance 2] --> [OSS/S3]
@enduml

Diagramming Tools

PlantUML

The most popular text-driven UML tool.
Installation:
bash
# Using npm
npm install -g node-plantuml

# Using Java
# Download plantuml.jar
java -jar plantuml.jar diagram.puml
Online Tools:
  • PlantUML Online Server
  • PlantText
  • PlantUML QEditor

Mermaid

Markdown-friendly diagram tool.
mermaid
classDiagram
    class User {
        +String username
        +String email
        +login()
        +logout()
    }

    class Order {
        +String orderNumber
        +Decimal amount
        +create()
        +cancel()
    }

    User "1" --> "*" Order : places

Other Tools

  • Draw.io/diagrams.net: Online diagram tool
  • Lucidchart: Professional diagram software
  • Visual Paradigm: Enterprise-level modeling tool
  • StarUML: Open-source UML tool

Design Best Practices

1. Class Diagram Design

markdown
✓ Follow the Single Responsibility Principle
✓ Use clear naming
✓ Mark key attributes and methods
✓ Display important relationships
✓ Use packages to organize large systems

✗ Avoid over-engineering
✗ Do not include all details
✗ Avoid circular dependencies

2. Sequence Diagram Design

markdown
✓ Arrange participants from left to right
✓ Arrange messages in chronological order
✓ Use clear message names
✓ Mark important conditions and loops
✓ Keep diagrams concise

✗ Avoid too many participants
✗ Do not omit return messages
✗ Avoid crossing message lines

3. Use Case Diagram Design

markdown
✓ Describe functions from the user's perspective
✓ Keep use case granularity appropriate
✓ Clarify participant roles
✓ Mark key relationships
✗ Avoid technical jargon
✗ Do not over-refine
✗ Avoid missing important use cases

Practical Application Scenarios

E-commerce System Design

plantuml
@startuml
' Core domain model

class User {
  - id: Long
  - username: String
  - email: String
  - phone: String
  + register()
  + login()
  + updateProfile()
}

class Product {
  - id: Long
  - name: String
  - description: String
  - price: Decimal
  - stock: Integer
  + updateStock()
  + getPrice()
}

class Order {
  - id: Long
  - orderNumber: String
  - totalAmount: Decimal
  - status: OrderStatus
  - createdAt: DateTime
  + create()
  + cancel()
  + pay()
  + ship()
}

class OrderItem {
  - id: Long
  - quantity: Integer
  - price: Decimal
  + calculateSubtotal()
}

class Payment {
  - id: Long
  - amount: Decimal
  - method: PaymentMethod
  - status: PaymentStatus
  + process()
  + refund()
}

class Address {
  - id: Long
  - province: String
  - city: String
  - detail: String
  - phone: String
}

enum OrderStatus {
  PENDING
  PAID
  SHIPPED
  COMPLETED
  CANCELLED
}

enum PaymentMethod {
  ALIPAY
  WECHAT
  CREDIT_CARD
}

User "1" -- "*" Order : places
User "1" -- "*" Address : has
Order "1" *-- "*" OrderItem : contains
OrderItem "*" -- "1" Product : references
Order "1" -- "1" Payment : pays with
Order "1" -- "1" Address : ships to
@enduml

Microservices Architecture Diagram

plantuml
@startuml
!define RECTANGLE class

package "Client" {
  [Web Frontend]
  [Mobile App]
}

package "API Gateway Layer" {
  [API Gateway]
  [Authentication Center]
}

package "Microservices Layer" {
  RECTANGLE "User Service" {
    [User Management]
    [Permission Management]
  }

  RECTANGLE "Product Service" {
    [Product Management]
    [Inventory Management]
  }

  RECTANGLE "Order Service" {
    [Order Management]
    [Order Status]
  }

  RECTANGLE "Payment Service" {
    [Payment Processing]
    [Refund Processing]
  }
}

package "Infrastructure Layer" {
  database "MySQL Cluster"
  database "Redis Cluster"
  queue "Kafka"
  [Configuration Center]
  [Service Registry]
}

[Web Frontend] --> [API Gateway]
[Mobile App] --> [API Gateway]

[API Gateway] --> [Authentication Center]
[API Gateway] --> [User Management]
[API Gateway] --> [Product Management]
[API Gateway] --> [Order Management]

[Order Management] --> [Payment Processing]
[Order Management] --> [Inventory Management]

[User Management] --> [MySQL Cluster]
[Product Management] --> [MySQL Cluster]
[Order Management] --> [MySQL Cluster]

[User Management] --> [Redis Cluster]
[Product Management] --> [Redis Cluster]

[Order Management] --> [Kafka]
[Payment Processing] --> [Kafka]

[User Management] --> [Configuration Center]
[Product Management] --> [Configuration Center]
[Order Management] --> [Configuration Center]

[User Management] --> [Service Registry]
[Product Management] --> [Service Registry]
[Order Management] --> [Service Registry]
@enduml

Document Integration

Embed in Markdown

markdown
# System Design Document

## Class Diagram

\`\`\`plantuml
@startuml
class User {
  +login()
}
@enduml
\`\`\`

## Sequence Diagram

\`\`\`mermaid
sequenceDiagram
    User->>API: Request
    API->>DB: Query
    DB-->>API: Return
    API-->>User: Response
\`\`\`

Use in Code Comments

java
/**
 * User Service Class
 *
 * @startuml
 * class UserService {
 *   +register(user: User): boolean
 *   +login(username: String, password: String): Token
 * }
 * @enduml
 */
public class UserService {
    // Implementation code
}

Notes

  • Choose the appropriate diagram type
  • Keep diagrams concise and clear
  • Use consistent naming conventions
  • Update documents in a timely manner
  • Consider diagram readability
  • Avoid over-engineering
  • Use version control to manage diagram files
  • Maintain communication with the team