c4-code
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseC4 Code Level: [Directory Name]
C4代码级:[目录名称]
Use this skill when
使用场景
- Working on c4 code level: [directory name] tasks or workflows
- Needing guidance, best practices, or checklists for c4 code level: [directory name]
- 处理C4代码级:[目录名称]相关任务或工作流时
- 需要C4代码级:[目录名称]的指导、最佳实践或检查清单时
Do not use this skill when
禁用场景
- The task is unrelated to c4 code level: [directory name]
- You need a different domain or tool outside this scope
- 任务与C4代码级:[目录名称]无关时
- 需要超出此范围的其他领域或工具时
Instructions
操作指南
- Clarify goals, constraints, and required inputs.
- Apply relevant best practices and validate outcomes.
- Provide actionable steps and verification.
- If detailed examples are required, open .
resources/implementation-playbook.md
- 明确目标、约束条件和所需输入。
- 应用相关最佳实践并验证结果。
- 提供可执行的步骤和验证方法。
- 如果需要详细示例,请打开。
resources/implementation-playbook.md
Overview
概述
- Name: [Descriptive name for this code directory]
- Description: [Short description of what this code does]
- Location: [Link to actual directory path]
- Language: [Primary programming language(s)]
- Purpose: [What this code accomplishes]
- 名称:[此代码目录的描述性名称]
- 说明:[此代码的功能简述]
- 位置:[实际目录路径链接]
- 语言:[主要编程语言]
- 用途:[此代码实现的目标]
Code Elements
代码元素
Functions/Methods
函数/方法
functionName(param1: Type, param2: Type): ReturnType- Description: [What this function does]
- Location: [file path:line number]
- Dependencies: [what this function depends on]
functionName(param1: Type, param2: Type): ReturnType- 说明:[此函数的功能]
- 位置:[文件路径:行号]
- 依赖项:[此函数依赖的内容]
Classes/Modules
类/模块
ClassName- Description: [What this class does]
- Location: [file path]
- Methods: [list of methods]
- Dependencies: [what this class depends on]
ClassName- 说明:[此类的功能]
- 位置:[文件路径]
- 方法:[方法列表]
- 依赖项:[此类依赖的内容]
Dependencies
依赖关系
Internal Dependencies
内部依赖
- [List of internal code dependencies]
- [内部代码依赖列表]
External Dependencies
外部依赖
- [List of external libraries, frameworks, services]
- [外部库、框架、服务列表]
Relationships
关系图
Optional Mermaid diagrams for complex code structures. Choose the diagram type based on the programming paradigm. Code diagrams show the internal structure of a single component.
对于复杂的代码结构,可选择添加Mermaid图。根据编程范式选择图表类型。代码图用于展示单个组件的内部结构。
Object-Oriented Code (Classes, Interfaces)
面向对象代码(类、接口)
Use for OOP code with classes, interfaces, and inheritance:
classDiagrammermaid
---
title: Code Diagram for [Component Name]
---
classDiagram
namespace ComponentName {
class Class1 {
+attribute1 Type
+method1() ReturnType
}
class Class2 {
-privateAttr Type
+publicMethod() void
}
class Interface1 {
<<interface>>
+requiredMethod() ReturnType
}
}
Class1 ..|> Interface1 : implements
Class1 --> Class2 : usesundefined对于包含类、接口和继承的OOP代码,使用:
classDiagrammermaid
---
title: Code Diagram for [Component Name]
---
classDiagram
namespace ComponentName {
class Class1 {
+attribute1 Type
+method1() ReturnType
}
class Class2 {
-privateAttr Type
+publicMethod() void
}
class Interface1 {
<<interface>>
+requiredMethod() ReturnType
}
}
Class1 ..|> Interface1 : implements
Class1 --> Class2 : usesFunctional/Procedural Code (Modules, Functions)
函数式/过程式代码(模块、函数)
For functional or procedural code, you have two options:
Option A: Module Structure Diagram - Use to show modules and their exported functions:
classDiagrammermaid
---
title: Module Structure for [Component Name]
---
classDiagram
namespace DataProcessing {
class validators {
<<module>>
+validateInput(data) Result~Data, Error~
+validateSchema(schema, data) bool
+sanitize(input) string
}
class transformers {
<<module>>
+parseJSON(raw) Record
+normalize(data) NormalizedData
+aggregate(items) Summary
}
class io {
<<module>>
+readFile(path) string
+writeFile(path, content) void
}
}
transformers --> validators : uses
transformers --> io : reads fromOption B: Data Flow Diagram - Use to show function pipelines and data transformations:
flowchartmermaid
---
title: Data Pipeline for [Component Name]
---
flowchart LR
subgraph Input
A[readFile]
end
subgraph Transform
B[parseJSON]
C[validateInput]
D[normalize]
E[aggregate]
end
subgraph Output
F[writeFile]
end
A -->|raw string| B
B -->|parsed data| C
C -->|valid data| D
D -->|normalized| E
E -->|summary| FOption C: Function Dependency Graph - Use to show which functions call which:
flowchartmermaid
---
title: Function Dependencies for [Component Name]
---
flowchart TB
subgraph Public API
processData[processData]
exportReport[exportReport]
end
subgraph Internal Functions
validate[validate]
transform[transform]
format[format]
cache[memoize]
end
subgraph Pure Utilities
compose[compose]
pipe[pipe]
curry[curry]
end
processData --> validate
processData --> transform
processData --> cache
transform --> compose
transform --> pipe
exportReport --> format
exportReport --> processData对于函数式或过程式代码,有以下三种选择:
选项A:模块结构图 - 使用展示模块及其导出函数:
classDiagrammermaid
---
title: Module Structure for [Component Name]
---
classDiagram
namespace DataProcessing {
class validators {
<<module>>
+validateInput(data) Result~Data, Error~
+validateSchema(schema, data) bool
+sanitize(input) string
}
class transformers {
<<module>>
+parseJSON(raw) Record
+normalize(data) NormalizedData
+aggregate(items) Summary
}
class io {
<<module>>
+readFile(path) string
+writeFile(path, content) void
}
}
transformers --> validators : uses
transformers --> io : reads from选项B:数据流图 - 使用展示函数流水线和数据转换:
flowchartmermaid
---
title: Data Pipeline for [Component Name]
---
flowchart LR
subgraph Input
A[readFile]
end
subgraph Transform
B[parseJSON]
C[validateInput]
D[normalize]
E[aggregate]
end
subgraph Output
F[writeFile]
end
A -->|raw string| B
B -->|parsed data| C
C -->|valid data| D
D -->|normalized| E
E -->|summary| F选项C:函数依赖图 - 使用展示函数调用关系:
flowchartmermaid
---
title: Function Dependencies for [Component Name]
---
flowchart TB
subgraph Public API
processData[processData]
exportReport[exportReport]
end
subgraph Internal Functions
validate[validate]
transform[transform]
format[format]
cache[memoize]
end
subgraph Pure Utilities
compose[compose]
pipe[pipe]
curry[curry]
end
processData --> validate
processData --> transform
processData --> cache
transform --> compose
transform --> pipe
exportReport --> format
exportReport --> processDataChoosing the Right Diagram
选择合适的图表
| Code Style | Primary Diagram | When to Use |
|---|---|---|
| OOP (classes, interfaces) | | Show inheritance, composition, interface implementation |
| FP (pure functions, pipelines) | | Show data transformations and function composition |
| FP (modules with exports) | | Show module structure and dependencies |
| Procedural (structs + functions) | | Show data structures and associated functions |
| Mixed | Combination | Use multiple diagrams if needed |
Note: According to the C4 model, code diagrams are typically only created when needed for complex components. Most teams find system context and container diagrams sufficient. Choose the diagram type that best communicates the code structure regardless of paradigm.
| 代码风格 | 首选图表类型 | 使用场景 |
|---|---|---|
| 面向对象(类、接口) | | 展示继承、组合、接口实现关系 |
| 函数式(纯函数、流水线) | | 展示数据转换和函数组合关系 |
| 函数式(带导出的模块) | 标记 | 展示模块结构和依赖关系 |
| 过程式(结构体+函数) | | 展示数据结构和关联函数 |
| 混合风格 | 组合使用多种图表 | 必要时使用多个图表展示 |
注意:根据C4模型,代码图通常仅在处理复杂组件时才需要创建。大多数团队认为系统上下文图和容器图已足够。无论编程范式如何,选择最能清晰传达代码结构的图表类型即可。
Notes
注意事项
[Any additional context or important information]
undefined[任何额外的上下文或重要信息]
Example Interactions
交互示例
Object-Oriented Codebases
面向对象代码库
- "Analyze the src/api directory and create C4 Code-level documentation"
- "Document the service layer code with complete class hierarchies and dependencies"
- "Create C4 Code documentation showing interface implementations in the repository layer"
- “分析src/api目录并创建C4代码级文档”
- “记录服务层代码,包含完整的类层次结构和依赖关系”
- “创建展示仓储层接口实现的C4代码文档”
Functional/Procedural Codebases
函数式/过程式代码库
- "Document all functions in the authentication module with their signatures and data flow"
- "Create a data pipeline diagram for the ETL transformers in src/pipeline"
- "Analyze the utils directory and document all pure functions and their composition patterns"
- "Document the Rust modules in src/handlers showing function dependencies"
- "Create C4 Code documentation for the Elixir GenServer modules"
- “记录认证模块中的所有函数及其签名和数据流”
- “为src/pipeline中的ETL转换器创建数据流图”
- “分析utils目录并记录所有纯函数及其组合模式”
- “记录src/handlers中的Rust模块,展示函数依赖关系”
- “为Elixir GenServer模块创建C4代码文档”
Mixed Paradigm
混合范式
- "Document the Go handlers package showing structs and their associated functions"
- "Analyze the TypeScript codebase that mixes classes with functional utilities"
- “记录Go handlers包,展示结构体及其关联函数”
- “分析混合了类和函数式工具的TypeScript代码库”
Key Distinctions
核心区别
- vs C4-Component agent: Focuses on individual code elements; Component agent synthesizes multiple code files into components
- vs C4-Container agent: Documents code structure; Container agent maps components to deployment units
- vs C4-Context agent: Provides code-level detail; Context agent creates high-level system diagrams
- 与C4-Component agent对比:聚焦于单个代码元素;Component agent将多个代码文件整合为组件
- 与C4-Container agent对比:记录代码结构;Container agent将组件映射到部署单元
- 与C4-Context agent对比:提供代码级细节;Context agent创建高层系统图
Output Examples
输出示例
When analyzing code, provide:
- Complete function/method signatures with all parameters and return types
- Clear descriptions of what each code element does
- Links to actual source code locations
- Complete dependency lists (internal and external)
- Structured documentation following C4 Code-level template
- Mermaid diagrams for complex code relationships when needed
- Consistent naming and formatting across all code documentation
undefined分析代码时,需提供:
- 包含所有参数和返回类型的完整函数/方法签名
- 每个代码元素的清晰功能说明
- 指向实际源代码位置的链接
- 完整的依赖列表(内部和外部)
- 遵循C4代码级模板的结构化文档
- 必要时为复杂代码关系添加Mermaid图
- 所有代码文档保持一致的命名和格式