AgentSkillsCN

document.codeflow.generate-sequence-diagram

运用Mermaid语法生成序列图。可灵活运用autonumber、activate/deactivate、alt/else、loop、Note、rect等构造元素。当用户提出“生成序列图”、“创建Mermaid图表”、“可视化流程”或“绘制序列图”时,此技能便能大显身手。

SKILL.md
--- frontmatter
name: document.codeflow.generate-sequence-diagram
description: 'Generate sequence diagrams using Mermaid syntax. Use constructs such as autonumber, activate/deactivate, alt/else, loop, Note, and rect. Use when asked to "generate sequence diagram", "create Mermaid diagram", "visualize flow", or create sequence diagrams.'

Sequence Diagram Generation Skill

This skill generates Mermaid sequence diagrams for specified code behavior.

When to Use This Skill

  • Generating a sequence diagram for a specific feature
  • Adding sequence diagrams to existing docs
  • Preparing Mermaid sequence diagram templates

Prerequisites

  • Target feature/file is identified
  • Call chain is understood (if unknown, run document.codeflow.analyze first)

Step-by-Step Workflows

Workflow: Generate Sequence Diagram

  1. Identify entry point of the target feature
  2. Trace function call chain
  3. List participating classes/modules as participant
  4. Represent call order with arrows
  5. Represent branching with alt/else
  6. Represent loops with loop
  7. Mark async processing appropriately
  8. Include error cases

Mermaid Syntax Reference

Basic Template

mermaid
sequenceDiagram
    autonumber
    participant Actor as User/Trigger
    participant A as Class A
    participant B as Class B

    Actor->>A: Action/Event
    activate A
    A->>B: Method call
    activate B
    B-->>A: Return value
    deactivate B

    alt Success
        A-->>Actor: Success response
    else Error
        A-->>Actor: Error message
    end
    deactivate A

Arrow Types

SyntaxMeaning
->>Synchronous message (solid line, arrow)
-->>Response message (dashed line, arrow)
-)Asynchronous message (solid line, open arrow)
--)Asynchronous response (dashed line, open arrow)

Block Syntax

SyntaxPurpose
alt/else/endConditional branching
opt/endOptional processing
loop/endLoop
par/and/endParallel processing
rect rgb(r,g,b)/endHighlight processing group
Note over A,B: textSupplementary note
activate A / deactivate AShow processing duration
autonumberAuto step numbering

Async Processing Example

mermaid
sequenceDiagram
    autonumber
    participant C as Caller
    participant A as AsyncService

    C--)A: Async request
    activate A
    Note right of A: Background processing
    A--)C: Callback/Promise resolved
    deactivate A

Error Handling Example

mermaid
sequenceDiagram
    autonumber
    participant U as User
    participant S as Service

    U->>S: Request
    activate S

    alt Success
        S-->>U: Success response
    else Validation error
        S-->>U: 400 error
    else Server error
        rect rgb(255, 230, 230)
            S-->>U: 500 error
            Note over S: Output error log
        end
    end
    deactivate S

Rules

  • Write labels in Japanese
  • Add step numbers with autonumber
  • Show processing duration with activate/deactivate
  • Add supplementary notes with Note
  • Enclose processing groups with rect
  • Recommend up to 8 participants per diagram (split if more)

Troubleshooting

ProblemSolution
Diagram is too complexSplit into sub-flows and add links via Note
Too many participantsGroup less-relevant components
Mermaid fails to renderCheck special character escaping and unclosed syntax