generate-interface-uml

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Interface UML Generator

接口UML生成器

This skill helps generate PlantUML sequence diagrams and class diagrams for new interfaces, based on existing similar interfaces in the codebase.
本Skill可基于代码库中已有的相似接口,为新接口生成PlantUML时序图和类图。

When to Use

使用场景

User wants to create UML diagrams (sequence diagrams, class diagrams) for:
  • New API interfaces
  • New method implementations
  • Interface call chains
  • IPC communication flows
用户希望为以下内容创建UML图(时序图、类图)时:
  • 新API接口
  • 新方法实现
  • 接口调用链
  • IPC通信流程

Workflow

工作流程

Step 1: Gather Basic Information

步骤1:收集基础信息

Start with what the user provides (often just an interface name), then ask questions to collect:
Essential Information:
  1. Interface name(s) - e.g.,
    AddGlocalBlackList
    ,
    RemoveGlocalBlackList
  2. Parameters - What are the input parameters and their types?
  3. Return type - What does the interface return?
  4. Reference interface - Is there an existing similar interface to use as a template?
Optional Information (ask if needed): 5. Output directory - Where should the PlantUML files be saved? 6. Diagram types - Sequence diagram? Class diagram? Both? 7. Call chain destination - Which class/method does it ultimately call?
从用户提供的内容(通常只是接口名称)开始,然后通过提问收集以下信息:
必要信息:
  1. 接口名称 - 例如:
    AddGlocalBlackList
    RemoveGlocalBlackList
  2. 参数 - 输入参数及其类型是什么?
  3. 返回类型 - 接口返回什么内容?
  4. 参考接口 - 是否有可作为模板的现有相似接口?
可选信息(按需询问): 5. 输出目录 - PlantUML文件应保存到哪里? 6. 图类型 - 时序图?类图?还是两者都要? 7. 调用链目标 - 它最终调用哪个类/方法?

Step 2: Analyze Reference Interface

步骤2:分析参考接口

Search the codebase for the reference interface to understand the call chain:
bash
undefined
在代码库中搜索参考接口以理解其调用链:
bash
undefined

Find the reference interface implementation

查找参考接口的实现

grep -r "SetFocusAppInfo" --include=".h" --include=".cpp"

**Key files to examine:**
- Client-side interfaces: `RSInterfaces`, `RSRenderInterface`
- IPC layer: `RSIClientToRenderConnection`, `RSClientToRenderConnection`
- Service-side: `RSRenderPipelineAgent`, `RSMainThread`
- Target class: Where the interface ultimately executes
grep -r "SetFocusAppInfo" --include=".h" --include=".cpp"

**需检查的关键文件:**
- 客户端接口:`RSInterfaces`、`RSRenderInterface`
- IPC层:`RSIClientToRenderConnection`、`RSClientToRenderConnection`
- 服务端:`RSRenderPipelineAgent`、`RSMainThread`
- 目标类:接口最终执行的类

Step 3: Generate PlantUML Diagrams

步骤3:生成PlantUML图

Sequence Diagram Template

时序图模板

plantuml
@startuml InterfaceName序列图
title InterfaceName 接口调用时序图

autonumber
skinparam maxMessageSize 150
skinparam boxPadding 10

actor "客户端应用" as Client
box "客户端进程 (Client Process)" #LightBlue
    participant "RSInterfaces" as RSInterfaces
    participant "RSRenderInterface" as RSRenderInterface
    participant "RSRenderPipelineClient\n(IPC Proxy)" as IPCProxy
end box

box "跨进程通信 (IPC)" #LightYellow
    participant "Binder/Hipc\n通信通道" as Binder
end box

box "服务端进程 (Render Service)" #LightGreen
    participant "RSClientToRenderConnection\n(IPC Stub)" as IPCStub
    participant "RSRenderPipelineAgent" as Agent
    participant "RSMainThread" as MainThread
    participant "TargetClass\n(在RSMainThread线程中执行)" as Target
end box

== 客户端调用流程 ==

Client -> RSInterfaces: InterfaceName(params)
activate RSInterfaces

RSInterfaces -> RSRenderInterface: InterfaceName(params)
activate RSRenderInterface

RSRenderInterface -> IPCProxy: InterfaceName(params)
activate IPCProxy

== 跨进程IPC调用 ==

IPCProxy -> Binder: IPC调用\nInterfaceName
activate Binder

Binder -> IPCStub: 接收IPC调用\nInterfaceName
activate IPCStub

== 服务端处理流程 ==

IPCStub -> Agent: InterfaceName(params)
activate Agent

Agent -> Agent: ScheduleMainThreadTask(\nlambda任务)

Agent -> MainThread: PostTask(\n执行InterfaceName)
activate MainThread

MainThread -> Target: TargetMethod(params)
activate Target

note right of Target
    描述具体操作
end note

Target --> MainThread: 返回
deactivate Target

MainThread --> Agent: 任务完成
deactivate MainThread

Agent --> IPCStub: 返回结果\n(ERR_OK)
deactivate Agent

IPCStub --> Binder: 返回IPC结果
deactivate IPCStub

Binder --> IPCProxy: 返回IPC结果
deactivate Binder

IPCProxy --> RSRenderInterface: 返回结果
deactivate IPCProxy

RSRenderInterface --> RSInterfaces: 返回结果
deactivate RSRenderInterface

RSInterfaces --> Client: 返回结果
deactivate RSInterfaces

@enduml
plantuml
@startuml InterfaceName序列图
title InterfaceName 接口调用时序图

autonumber
skinparam maxMessageSize 150
skinparam boxPadding 10

actor "客户端应用" as Client
box "客户端进程 (Client Process)" #LightBlue
    participant "RSInterfaces" as RSInterfaces
    participant "RSRenderInterface" as RSRenderInterface
    participant "RSRenderPipelineClient\n(IPC Proxy)" as IPCProxy
end box

box "跨进程通信 (IPC)" #LightYellow
    participant "Binder/Hipc\n通信通道" as Binder
end box

box "服务端进程 (Render Service)" #LightGreen
    participant "RSClientToRenderConnection\n(IPC Stub)" as IPCStub
    participant "RSRenderPipelineAgent" as Agent
    participant "RSMainThread" as MainThread
    participant "TargetClass\n(在RSMainThread线程中执行)" as Target
end box

== 客户端调用流程 ==

Client -> RSInterfaces: InterfaceName(params)
activate RSInterfaces

RSInterfaces -> RSRenderInterface: InterfaceName(params)
activate RSRenderInterface

RSRenderInterface -> IPCProxy: InterfaceName(params)
activate IPCProxy

== 跨进程IPC调用 ==

IPCProxy -> Binder: IPC调用\nInterfaceName
activate Binder

Binder -> IPCStub: 接收IPC调用\nInterfaceName
activate IPCStub

== 服务端处理流程 ==

IPCStub -> Agent: InterfaceName(params)
activate Agent

Agent -> Agent: ScheduleMainThreadTask(\nlambda任务)

Agent -> MainThread: PostTask(\n执行InterfaceName)
activate MainThread

MainThread -> Target: TargetMethod(params)
activate Target

note right of Target
    描述具体操作
end note

Target --> MainThread: 返回
deactivate Target

MainThread --> Agent: 任务完成
deactivate MainThread

Agent --> IPCStub: 返回结果\n(ERR_OK)
deactivate Agent

IPCStub --> Binder: 返回IPC结果
deactivate IPCStub

Binder --> IPCProxy: 返回IPC结果
deactivate Binder

IPCProxy --> RSRenderInterface: 返回结果
deactivate IPCProxy

RSRenderInterface --> RSInterfaces: 返回结果
deactivate RSRenderInterface

RSInterfaces --> Client: 返回结果
deactivate RSInterfaces

@enduml

Class Diagram Template

类图模板

plantuml
@startuml InterfaceName类图
title InterfaceName系列接口涉及的类关系图

skinparam classAttributeIconSize 0
skinparam class {
    BackgroundColor<<client>> LightBlue
    BackgroundColor<<service>> LightGreen
    BackgroundColor<<static>> LightYellow
    BorderColor Black
}

package "客户端 (Client)" <<client>> {
    class RSInterfaces {
        + {static} GetInstance(): RSInterfaces&
        + InterfaceName(params): ReturnType
        --
        - renderInterface_: RSRenderInterface*
    }

    class RSRenderInterface {
        + InterfaceName(params): ReturnType
        --
        - renderPipelineClient_: RSRenderPipelineClient*
    }

    RSInterfaces --> RSRenderInterface
}

package "IPC通信层" {
    interface RSIClientToRenderConnection {
        + InterfaceName(params, ErrorCode&): ErrCode
    }

    class RSClientToRenderConnection {
        + InterfaceName(params, ErrorCode&): ErrCode
        --
        - renderPipelineAgent_: sptr<RSRenderPipelineAgent>
    }

    RSClientToRenderConnection ..|> RSIClientToRenderConnection
}

package "服务端 (Render Service)" <<service>> {
    class RSRenderPipelineAgent {
        + InterfaceName(params, ErrorCode&): ErrCode
        --
        - rsRenderPipeline_: std::shared_ptr<RSRenderPipeline>
    }

    class RSMainThread {
        + PostTask(RSTask): void
        + ScheduleTask(Task): std::future<Return>
        --
        - mainThreadId_: std::thread::id
    }
}

package "TargetClass (静态类)" <<static>> {
    class TargetClass {
        + {static} TargetMethod(params): void
        --
        - {static} member_: Type
    }
}

RSRenderInterface --> RSIClientToRenderConnection: 通过IPC调用
RSClientToRenderConnection --> RSRenderPipelineAgent
RSRenderPipelineAgent ..> RSMainThread: ScheduleMainThreadTask
RSRenderPipelineAgent ..> TargetClass: 调用静态方法

@enduml
plantuml
@startuml InterfaceName类图
title InterfaceName系列接口涉及的类关系图

skinparam classAttributeIconSize 0
skinparam class {
    BackgroundColor<<client>> LightBlue
    BackgroundColor<<service>> LightGreen
    BackgroundColor<<static>> LightYellow
    BorderColor Black
}

package "客户端 (Client)" <<client>> {
    class RSInterfaces {
        + {static} GetInstance(): RSInterfaces&
        + InterfaceName(params): ReturnType
        --
        - renderInterface_: RSRenderInterface*
    }

    class RSRenderInterface {
        + InterfaceName(params): ReturnType
        --
        - renderPipelineClient_: RSRenderPipelineClient*
    }

    RSInterfaces --> RSRenderInterface
}

package "IPC通信层" {
    interface RSIClientToRenderConnection {
        + InterfaceName(params, ErrorCode&): ErrCode
    }

    class RSClientToRenderConnection {
        + InterfaceName(params, ErrorCode&): ErrCode
        --
        - renderPipelineAgent_: sptr<RSRenderPipelineAgent>
    }

    RSClientToRenderConnection ..|> RSIClientToRenderConnection
}

package "服务端 (Render Service)" <<service>> {
    class RSRenderPipelineAgent {
        + InterfaceName(params, ErrorCode&): ErrCode
        --
        - rsRenderPipeline_: std::shared_ptr<RSRenderPipeline>
    }

    class RSMainThread {
        + PostTask(RSTask): void
        + ScheduleTask(Task): std::future<Return>
        --
        - mainThreadId_: std::thread::id
    }
}

package "TargetClass (静态类)" <<static>> {
    class TargetClass {
        + {static} TargetMethod(params): void
        --
        - {static} member_: Type
    }
}

RSRenderInterface --> RSIClientToRenderConnection: 通过IPC调用
RSClientToRenderConnection --> RSRenderPipelineAgent
RSRenderPipelineAgent ..> RSMainThread: ScheduleMainThreadTask
RSRenderPipelineAgent ..> TargetClass: 调用静态方法

@enduml

Step 4: Save PlantUML Files

步骤4:保存PlantUML文件

Write the generated PlantUML files to the specified directory:
  • Use descriptive filenames:
    InterfaceName_sequence.puml
    ,
    InterfaceName_ClassDiagram.puml
  • Include UTF-8 BOM for Chinese character support if needed
  • Save to user-specified output directory
将生成的PlantUML文件保存到指定目录:
  • 使用描述性文件名:
    InterfaceName_sequence.puml
    InterfaceName_ClassDiagram.puml
  • 若需要支持中文,可添加UTF-8 BOM
  • 保存到用户指定的输出目录

Step 5: Optional - Create Comparison Diagram

步骤5:可选 - 创建对比图

If comparing with existing interfaces, create a comparison diagram showing:
  • Parameter differences
  • Call chain differences
  • Target class differences
若需与现有接口对比,可创建对比图展示:
  • 参数差异
  • 调用链差异
  • 目标类差异

Questions to Ask User

需向用户询问的问题

  1. Interface names: What are the interface names you want to generate UML for?
  2. Reference interface: Which existing interface should be used as a reference?
  3. Parameters: What are the parameter types for the new interface(s)?
  4. Return type: What should the interface return?
  5. Target class: Which class does the interface ultimately call? (e.g., ScreenSpecialLayerInfo, RSMainThread)
  6. Thread requirement: Does it need to execute in a specific thread? (e.g., RSMainThread thread)
  7. Output directory: Where should the PlantUML files be saved?
  1. 接口名称:你想要为哪些接口生成UML图?
  2. 参考接口:有哪些现有相似接口可作为模板?
  3. 参数:新接口的参数类型是什么?
  4. 返回类型:接口应返回什么内容?
  5. 目标类:接口最终调用哪个类?(例如:ScreenSpecialLayerInfo、RSMainThread)
  6. 线程要求:是否需要在特定线程中执行?(例如:RSMainThread线程)
  7. 输出目录:PlantUML文件应保存到哪里?

Example Usage

使用示例

User provides:
Generate UML for AddGlocalBlackList, RemoveGlocalBlackList, SetGlocalBlackList
Ask follow-up questions:
  1. "What should be the parameter type?" →
    const std::vector<NodeId>&
  2. "Which existing interface is similar?" →
    SetFocusAppInfo
  3. "Which class does it ultimately call?" →
    ScreenSpecialLayerInfo
  4. "What's the output directory?" → Current code directory
Generate output:
  • AddGlocalBlackList_sequence.puml
  • RemoveGlocalBlackList_sequence.puml
  • SetGlocalBlackList_sequence.puml
  • InterfaceName_ClassDiagram.puml
用户提供:
Generate UML for AddGlocalBlackList, RemoveGlocalBlackList, SetGlocalBlackList
后续提问:
  1. “参数类型是什么?” →
    const std::vector<NodeId>&
  2. “有哪些相似的现有接口?” →
    SetFocusAppInfo
  3. “最终调用哪个类?” →
    ScreenSpecialLayerInfo
  4. “输出目录是什么?” → 当前代码目录
生成输出:
  • AddGlocalBlackList_sequence.puml
  • RemoveGlocalBlackList_sequence.puml
  • SetGlocalBlackList_sequence.puml
  • InterfaceName_ClassDiagram.puml

Tips

提示

  • Use Chinese for diagram titles and notes if the codebase uses Chinese
  • Include
    autonumber
    for sequence diagrams
  • Use color coding to distinguish client/service/static layers
  • Add notes to explain key operations
  • Group related steps with
    == Section Name ==
  • 若代码库使用中文,可在图标题和注释中使用中文
  • 时序图中加入
    autonumber
  • 使用颜色编码区分客户端/服务端/静态层
  • 添加注释解释关键操作
  • 使用
    == 章节名称 ==
    对相关步骤进行分组