c4-architecture-c4-architecture by sickn33/antigravity-awesome-skills
npx skills add https://github.com/sickn33/antigravity-awesome-skills --skill c4-architecture-c4-architecture使用自底向上的分析方法,为现有仓库/代码库生成全面的 C4 架构文档。
[扩展思考:此工作流遵循 C4 模型(Context, Container, Component, Code),实现了一个完整的 C4 架构文档流程。它采用自底向上的方法,从最深的代码目录开始向上处理,确保在合成为更高层抽象之前,每个代码元素都被记录下来。该工作流协调四个专门的 C4 代理(Code, Component, Container, Context)来创建一套完整的架构文档集,服务于技术和非技术相关方。]
resources/implementation-playbook.md。此工作流遵循 官方 C4 模型,通过以下步骤创建全面的 C4 架构文档:
注意:根据 C4 模型,您不需要使用所有 4 个层级的图表——对于大多数软件开发团队来说,系统上下文图和容器图就足够了。此工作流为了完整性而生成了所有层级,但团队可以选择使用哪些层级。
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
所有文档都将写入仓库根目录下新建的 C4-Documentation/ 目录中。
对于每个目录,从最深的开始:
按照以下结构创建全面的 C4 代码级文档:
1. **概述部分**:
* 名称:[此代码目录的描述性名称]
* 描述:[此代码功能的简短描述]
* 位置:[相对于仓库根目录的实际目录路径链接]
* 语言:[使用的主要编程语言]
* 用途:[此代码实现的功能]
2. **代码元素部分**:
* 记录所有函数/方法及其完整签名:
* 函数名、参数(含类型)、返回类型
* 每个函数功能的描述
* 位置(文件路径和行号)
* 依赖项(此函数依赖什么)
* 记录所有类/模块:
* 类名、描述、位置
* 方法及其签名
* 依赖项
3. **依赖项部分**:
* 内部依赖项(此仓库中的其他代码)
* 外部依赖项(库、框架、服务)
4. **关系部分**:
* 如果关系复杂,可选的 Mermaid 图
将输出保存为:C4-Documentation/c4-code-[directory-name].md 文件名使用经过处理的目录名(将 / 替换为 -,移除特殊字符)。
确保文档包含:
* 包含所有参数和类型的完整函数签名
* 指向实际源代码位置的链接
* 所有依赖项(内部和外部)
* 清晰、描述性的名称和描述
对每个子目录重复此过程,直到所有目录都有对应的 c4-code-*.md 文件。
对于每个识别出的组件:
要分析的代码文件:[c4-code-*.md 文件路径列表]
按照以下结构创建全面的 C4 组件级文档:
1. **概述部分**:
* 名称:[组件名称 - 描述性且有意义]
* 描述:[组件用途的简短描述]
* 类型:[应用程序、服务、库等]
* 技术:[使用的主要技术]
2. **用途部分**:
* 此组件功能的详细描述
* 它解决了什么问题
* 它在系统中的角色
3. **软件功能部分**:
* 列出此组件提供的所有软件功能
* 每个功能附带简要描述
4. **代码元素部分**:
* 列出此组件中包含的所有 c4-code-*.md 文件
* 链接到每个文件并附简要描述
5. **接口部分**:
* 记录所有组件接口:
* 接口名称
* 协议(REST、GraphQL、gRPC、事件等)
* 描述
* 操作(函数签名、端点等)
6. **依赖项部分**:
* 使用的组件(此组件依赖的其他组件)
* 外部系统(数据库、API、服务)
7. **组件图**:
* 显示此组件及其关系的 Mermaid 图
将输出保存为:C4-Documentation/c4-component-[component-name].md 文件名使用经过处理的组件名。
基于创建的所有 c4-component-*.md 文件,生成:
1. **系统组件部分**:
* 列出所有组件,包含:
* 组件名称
* 简短描述
* 指向组件文档的链接
2. **组件关系图**:
* 显示所有组件及其关系的 Mermaid 图
* 显示组件间的依赖关系
* 显示外部系统依赖关系
将输出保存为:C4-Documentation/c4-component.md
组件文档:[所有 c4-component-*.md 文件路径列表] 找到的部署定义:[部署配置文件列表:Dockerfiles、K8s 清单等]
按照以下结构创建全面的 C4 容器级文档:
1. **容器部分**(针对每个容器):
* 名称:[容器名称]
* 描述:[容器用途和部署的简短描述]
* 类型:[Web 应用程序、API、数据库、消息队列等]
* 技术:[主要技术:Node.js、Python、PostgreSQL 等]
* 部署方式:[Docker、Kubernetes、云服务等]
2. **用途部分**(针对每个容器):
* 此容器功能的详细描述
* 它如何部署
* 它在系统中的角色
3. **组件部分**(针对每个容器):
* 列出部署在此容器中的所有组件
* 链接到组件文档
4. **接口部分**(针对每个容器):
* 记录所有容器 API 和接口:
* API/接口名称
* 协议(REST、GraphQL、gRPC、事件等)
* 描述
* 指向 OpenAPI/Swagger/API 规范文件的链接
* 端点/操作列表
5. **API 规范**:
* 为每个容器 API 创建一个 OpenAPI 3.1+ 规范
* 保存为:C4-Documentation/apis/[container-name]-api.yaml
* 包含:
* 所有端点及其方法(GET、POST 等)
* 请求/响应模式
* 身份验证要求
* 错误响应
6. **依赖项部分**(针对每个容器):
* 使用的容器(此容器依赖的其他容器)
* 外部系统(数据库、第三方 API 等)
* 通信协议
7. **基础设施部分**(针对每个容器):
* 指向部署配置的链接(Dockerfile、K8s 清单等)
* 扩展策略
* 资源需求(CPU、内存、存储)
8. **容器图**:
* 显示所有容器及其关系的 Mermaid 图
* 显示通信协议
* 显示外部系统依赖关系
将输出保存为:C4-Documentation/c4-container.md
容器文档:C4-Documentation/c4-container.md 组件文档:C4-Documentation/c4-component.md 系统文档:[README、架构文档、需求文档等列表] 测试文件:[显示系统行为的测试文件列表]
按照以下结构创建全面的 C4 上下文级文档:
1. **系统概述部分**:
* 简短描述:[系统功能的一句话描述]
* 详细描述:[系统目的、能力、解决问题的详细描述]
2. **角色部分**:
* 针对每个角色(人类用户和程序化"用户"):
* 角色名称
* 类型(人类用户 / 程序化用户 / 外部系统)
* 描述(他们是谁,他们需要什么)
* 目标(他们想要实现什么)
* 使用的关键功能
3. **系统功能部分**:
* 针对每个高层次功能:
* 功能名称
* 描述(此功能的作用)
* 用户(哪些角色使用此功能)
* 指向用户旅程图的链接
4. **用户旅程部分**:
* 针对每个关键功能和角色:
* 旅程名称:[功能名称] - [角色名称] 旅程
* 逐步旅程:
1. 2. ...
* 包含所有系统接触点
* 针对程序化用户(外部系统、API):
* 包含逐步流程的集成旅程
5. **外部系统和依赖项部分**:
* 针对每个外部系统:
* 系统名称
* 类型(数据库、API、服务、消息队列等)
* 描述(它提供什么)
* 集成类型(API、事件、文件传输等)
* 目的(系统为何依赖于此)
6. **系统上下文图**:
* 使用 Mermaid C4Context 图显示:
* 系统(中心框)
* 所有角色(用户)环绕
* 所有外部系统环绕
* 关系和数据流
* 使用 C4Context 符号绘制正确的 C4 图
7. **相关文档部分**:
* 指向容器文档的链接
* 指向组件文档的链接
将输出保存为:C4-Documentation/c4-context.md
确保文档:
* 非技术相关方能够理解
* 关注系统目的、用户和外部关系
* 包含全面的用户旅程图
* 识别所有外部系统和依赖项
target_directory:要分析的根目录(默认:当前仓库根目录)exclude_patterns:要排除的模式(默认:node_modules, .git, build, dist 等)output_directory:写入 C4 文档的位置(默认:C4-Documentation/)include_tests:是否分析测试文件以获取上下文(默认:true)api_format:API 规范的格式(默认:openapi)C4-Documentation/
├── c4-code-*.md # 代码级文档(每个目录一个)
├── c4-component-*.md # 组件级文档(每个组件一个)
├── c4-component.md # 主组件索引
├── c4-container.md # 容器级文档
├── c4-context.md # 上下文级文档
└── apis/ # API 规范
├── [container]-api.yaml # 每个容器的 OpenAPI 规范
└── ...
/c4-architecture:c4-architecture
这将:
所有文档写入:C4-Documentation/
每周安装次数
130
仓库
GitHub 星标
27.4K
首次出现
2026年1月28日
安全审计
安装于
gemini-cli123
opencode123
codex120
github-copilot119
cursor115
claude-code109
Generate comprehensive C4 architecture documentation for an existing repository/codebase using a bottom-up analysis approach.
[Extended thinking: This workflow implements a complete C4 architecture documentation process following the C4 model (Context, Container, Component, Code). It uses a bottom-up approach, starting from the deepest code directories and working upward, ensuring every code element is documented before synthesizing into higher-level abstractions. The workflow coordinates four specialized C4 agents (Code, Component, Container, Context) to create a complete architectural documentation set that serves both technical and non-technical stakeholders.]
resources/implementation-playbook.md.This workflow creates comprehensive C4 architecture documentation following the official C4 model by:
Note : According to the C4 model, you don't need to use all 4 levels of diagram - the system context and container diagrams are sufficient for most software development teams. This workflow generates all levels for completeness, but teams can choose which levels to use.
All documentation is written to a new C4-Documentation/ directory in the repository root.
For each directory, starting from the deepest:
Use Task tool with subagent_type="c4-architecture::c4-code"
Prompt: | Analyze the code in directory: [directory_path]
Create comprehensive C4 Code-level documentation following this structure:
1. **Overview Section** :
* Name: [Descriptive name for this code directory]
* Description: [Short description of what this code does]
* Location: [Link to actual directory path relative to repo root]
* Language: [Primary programming language(s) used]
* Purpose: [What this code accomplishes]
2. **Code Elements Section** :
* Document all functions/methods with complete signatures:
* Function name, parameters (with types), return type
* Description of what each function does
* Location (file path and line numbers)
* Dependencies (what this function depends on)
* Document all classes/modules:
* Class name, description, location
* Methods and their signatures
* Dependencies
3. **Dependencies Section** :
* Internal dependencies (other code in this repo)
* External dependencies (libraries, frameworks, services)
4. **Relationships Section** :
* Optional Mermaid diagram if relationships are complex
Save the output as: C4-Documentation/c4-code-[directory-name].md Use a sanitized directory name (replace / with -, remove special chars) for the filename.
Ensure the documentation includes:
* Complete function signatures with all parameters and types
* Links to actual source code locations
* All dependencies (internal and external)
* Clear, descriptive names and descriptions
Expected output: c4-code-.md file in C4-Documentation/
Context: All files in the directory and its subdirectories
Repeat for every subdirectory until all directories have corresponding c4-code-*.md files.
For each identified component:
Use Task tool with subagent_type="c4-architecture::c4-component"
Prompt: | Synthesize the following C4 Code-level documentation files into a logical component:
Code files to analyze: [List of c4-code-*.md file paths]
Create comprehensive C4 Component-level documentation following this structure:
1. **Overview Section** :
* Name: [Component name - descriptive and meaningful]
* Description: [Short description of component purpose]
* Type: [Application, Service, Library, etc.]
* Technology: [Primary technologies used]
2. **Purpose Section** :
* Detailed description of what this component does
* What problems it solves
* Its role in the system
3. **Software Features Section** :
* List all software features provided by this component
* Each feature with a brief description
4. **Code Elements Section** :
* List all c4-code-*.md files contained in this component
* Link to each file with a brief description
5. **Interfaces Section** :
* Document all component interfaces:
* Interface name
* Protocol (REST, GraphQL, gRPC, Events, etc.)
* Description
* Operations (function signatures, endpoints, etc.)
6. **Dependencies Section** :
* Components used (other components this depends on)
* External systems (databases, APIs, services)
7. **Component Diagram** :
* Mermaid diagram showing this component and its relationships
Save the output as: C4-Documentation/c4-component-[component-name].md Use a sanitized component name for the filename.
Expected output: c4-component-.md file for each component
Context: All relevant c4-code-*.md files for this component
Use Task tool with subagent_type="c4-architecture::c4-component"
Prompt: | Create a master component index that lists all components in the system.
Based on all c4-component-*.md files created, generate:
1. **System Components Section** :
* List all components with:
* Component name
* Short description
* Link to component documentation
2. **Component Relationships Diagram** :
* Mermaid diagram showing all components and their relationships
* Show dependencies between components
* Show external system dependencies
Save the output as: C4-Documentation/c4-component.md
Expected output: Master c4-component.md file
Context: All c4-component-*.md files
Use Task tool with subagent_type="c4-architecture::c4-container"
Prompt: | Synthesize components into containers based on deployment definitions.
Component documentation: [List of all c4-component-*.md file paths]
Deployment definitions found: [List of deployment config files: Dockerfiles, K8s manifests, etc.]
Create comprehensive C4 Container-level documentation following this structure:
1. **Containers Section** (for each container):
* Name: [Container name]
* Description: [Short description of container purpose and deployment]
* Type: [Web Application, API, Database, Message Queue, etc.]
* Technology: [Primary technologies: Node.js, Python, PostgreSQL, etc.]
* Deployment: [Docker, Kubernetes, Cloud Service, etc.]
2. **Purpose Section** (for each container):
* Detailed description of what this container does
* How it's deployed
* Its role in the system
3. **Components Section** (for each container):
* List all components deployed in this container
* Link to component documentation
4. **Interfaces Section** (for each container):
* Document all container APIs and interfaces:
* API/Interface name
* Protocol (REST, GraphQL, gRPC, Events, etc.)
* Description
* Link to OpenAPI/Swagger/API Spec file
* List of endpoints/operations
5. **API Specifications** :
* For each container API, create an OpenAPI 3.1+ specification
* Save as: C4-Documentation/apis/[container-name]-api.yaml
* Include:
* All endpoints with methods (GET, POST, etc.)
* Request/response schemas
* Authentication requirements
* Error responses
6. **Dependencies Section** (for each container):
* Containers used (other containers this depends on)
* External systems (databases, third-party APIs, etc.)
* Communication protocols
7. **Infrastructure Section** (for each container):
* Link to deployment config (Dockerfile, K8s manifest, etc.)
* Scaling strategy
* Resource requirements (CPU, memory, storage)
8. **Container Diagram** :
* Mermaid diagram showing all containers and their relationships
* Show communication protocols
* Show external system dependencies
Save the output as: C4-Documentation/c4-container.md
Expected output: c4-container.md with all containers and API specifications
Context: All component documentation and deployment definitions
Use Task tool with subagent_type="c4-architecture::c4-context"
Prompt: | Create comprehensive C4 Context-level documentation for the system.
Container documentation: C4-Documentation/c4-container.md Component documentation: C4-Documentation/c4-component.md System documentation: [List of README, architecture docs, requirements, etc.] Test files: [List of test files that show system behavior]
Create comprehensive C4 Context-level documentation following this structure:
1. **System Overview Section** :
* Short Description: [One-sentence description of what the system does]
* Long Description: [Detailed description of system purpose, capabilities, problems solved]
2. **Personas Section** :
* For each persona (human users and programmatic "users"):
* Persona name
* Type (Human User / Programmatic User / External System)
* Description (who they are, what they need)
* Goals (what they want to achieve)
* Key features used
3. **System Features Section** :
* For each high-level feature:
* Feature name
* Description (what this feature does)
* Users (which personas use this feature)
* Link to user journey map
4. **User Journeys Section** :
* For each key feature and persona:
* Journey name: [Feature Name] - [Persona Name] Journey
* Step-by-step journey:
1. 2. ...
* Include all system touchpoints
* For programmatic users (external systems, APIs):
* Integration journey with step-by-step process
5. **External Systems and Dependencies Section** :
* For each external system:
* System name
* Type (Database, API, Service, Message Queue, etc.)
* Description (what it provides)
* Integration type (API, Events, File Transfer, etc.)
* Purpose (why the system depends on this)
6. **System Context Diagram** :
* Mermaid C4Context diagram showing:
* The system (as a box in the center)
* All personas (users) around it
* All external systems around it
* Relationships and data flows
* Use C4Context notation for proper C4 diagram
7. **Related Documentation Section** :
* Links to container documentation
* Links to component documentation
Save the output as: C4-Documentation/c4-context.md
Ensure the documentation is:
* Understandable by non-technical stakeholders
* Focuses on system purpose, users, and external relationships
* Includes comprehensive user journey maps
* Identifies all external systems and dependencies
Expected output: c4-context.md with complete system context
Context: All container, component, and system documentation
target_directory: Root directory to analyze (default: current repository root)exclude_patterns: Patterns to exclude (default: node_modules, .git, build, dist, etc.)output_directory: Where to write C4 documentation (default: C4-Documentation/)include_tests: Whether to analyze test files for context (default: true)api_format: Format for API specs (default: openapi)C4-Documentation/
├── c4-code-*.md # Code-level docs (one per directory)
├── c4-component-*.md # Component-level docs (one per component)
├── c4-component.md # Master component index
├── c4-container.md # Container-level docs
├── c4-context.md # Context-level docs
└── apis/ # API specifications
├── [container]-api.yaml # OpenAPI specs for each container
└── ...
/c4-architecture:c4-architecture
This will:
All documentation written to: C4-Documentation/
Weekly Installs
130
Repository
GitHub Stars
27.4K
First Seen
Jan 28, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
gemini-cli123
opencode123
codex120
github-copilot119
cursor115
claude-code109
Skills CLI 使用指南:AI Agent 技能包管理器安装与管理教程
36,300 周安装