sparc-implement
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSPARC Architecture + Implementation
SPARC架构与实现
Run Phases 2 and 3 of the SPARC methodology: design algorithms with pseudocode, then establish architecture with module boundaries and API contracts.
执行SPARC方法论的第2和第3阶段:用伪代码设计算法,然后确定架构的模块边界和API契约。
When to use
使用时机
After the Specification phase is complete and its gate has been passed. This skill covers both the Pseudocode and Architecture phases as they are tightly coupled — algorithm design informs module boundaries and vice versa.
在规格说明阶段完成并通过检查门之后使用。本技能涵盖伪代码和架构两个阶段,因为它们紧密关联——算法设计影响模块边界,反之亦然。
Steps
步骤
-
Retrieve specification — callwith namespace
mcp__claude-flow__memory_searchand query for the feature's spec. Extract requirements, acceptance criteria, constraints, and edge cases.sparc-phases -
Retrieve phase state — callwith namespace
mcp__claude-flow__memory_searchand query for the feature to confirm we are in Phase 2 or 3.sparc-state -
Search for architectural patterns — callwith the feature description to find relevant architectural decisions from past projects
mcp__claude-flow__neural_predict -
Phase 2 — Pseudocode Design: a. For each acceptance criterion, write language-agnostic pseudocode that satisfies it b. Define core data structures with type annotations c. Map control flow including:
- Happy path
- Error/exception paths for each edge case
- Concurrent access handling if applicable d. Annotate algorithmic complexity (time and space) for critical paths e. Store pseudocode artifact:
- Call with namespace
mcp__claude-flow__memory_store, keysparc-phasespseudo-{feature-slug} - Value:
{ status: "complete", algorithms: [...], dataStructures: [...], controlFlow: [...], complexity: {...} }
-
Phase 3 — Architecture Design: a. Define bounded contexts and aggregate roots following DDD patterns:
- Identify entity boundaries and value objects
- Define aggregate invariants
- Map domain events b. Design API contracts:
- Request/response schemas with TypeScript interfaces
- Error response codes and formats
- Versioning strategy if applicable c. Plan module boundaries:
- Directory structure
- Dependency direction rules (no circular dependencies)
- Public vs internal interfaces d. Specify infrastructure concerns:
- Persistence strategy (database, cache, file)
- Messaging patterns (sync, async, event-driven)
- Configuration and environment requirements e. Store architecture artifact:
- Call with namespace
mcp__claude-flow__memory_store, keysparc-phasesarch-{feature-slug} - Value:
{ status: "complete", boundedContexts: [...], apiContracts: [...], moduleBoundaries: {...}, infrastructure: {...} }
-
Update phase state — callwith namespace
mcp__claude-flow__memory_store, updating current phase to 3 (Architecture) with both artifacts recordedsparc-state -
Record trajectory step — callwith architecture summary
mcp__claude-flow__hooks_intelligence_trajectory-step -
Begin implementation — if the user confirms, proceed to write production code: a. Create files following the defined module boundaries b. Implement interfaces and types first c. Implement core logic following the pseudocode d. Write unit tests alongside implementation (TDD when possible) e. Run tests to verify acceptance criteria
-
Present architecture — display the architecture decision record and suggest runningto pass the Phase 3 gate
/sparc advance
-
获取规格说明 —— 调用,命名空间为
mcp__claude-flow__memory_search,查询功能的规格说明。提取需求、验收标准、约束条件和边缘情况。sparc-phases -
获取阶段状态 —— 调用,命名空间为
mcp__claude-flow__memory_search,查询功能以确认我们处于第2或第3阶段。sparc-state -
搜索架构模式 —— 调用,传入功能描述,从过往项目中查找相关的架构决策。
mcp__claude-flow__neural_predict -
第2阶段——伪代码设计: a. 针对每个验收标准,编写满足要求的与语言无关的伪代码 b. 定义带有类型注解的核心数据结构 c. 映射控制流,包括:
- 正常流程
- 针对每种边缘情况的错误/异常处理流程
- 适用时的并发访问处理 d. 标注关键路径的算法复杂度(时间和空间) e. 存储伪代码工件:
- 调用,命名空间为
mcp__claude-flow__memory_store,键为sparc-phasespseudo-{feature-slug} - 值:
{ status: "complete", algorithms: [...], dataStructures: [...], controlFlow: [...], complexity: {...} }
-
第3阶段——架构设计: a. 遵循DDD模式定义限界上下文和聚合根:
- 识别实体边界和值对象
- 定义聚合不变量
- 映射领域事件 b. 设计API契约:
- 带有TypeScript接口的请求/响应 schema
- 错误响应代码和格式
- 适用时的版本控制策略 c. 规划模块边界:
- 目录结构
- 依赖方向规则(无循环依赖)
- 公开接口与内部接口 d. 指定基础设施相关事项:
- 持久化策略(数据库、缓存、文件)
- 消息传递模式(同步、异步、事件驱动)
- 配置和环境要求 e. 存储架构工件:
- 调用,命名空间为
mcp__claude-flow__memory_store,键为sparc-phasesarch-{feature-slug} - 值:
{ status: "complete", boundedContexts: [...], apiContracts: [...], moduleBoundaries: {...}, infrastructure: {...} }
-
更新阶段状态 —— 调用,命名空间为
mcp__claude-flow__memory_store,将当前阶段更新为第3阶段(架构),并记录两个工件。sparc-state -
记录轨迹步骤 —— 调用,传入架构摘要。
mcp__claude-flow__hooks_intelligence_trajectory-step -
开始实现 —— 如果用户确认,继续编写生产代码: a. 按照定义的模块边界创建文件 b. 先实现接口和类型 c. 遵循伪代码实现核心逻辑 d. 边实现边编写单元测试(尽可能采用TDD) e. 运行测试以验证验收标准
-
展示架构 —— 显示架构决策记录,并建议运行以通过第3阶段的检查门。
/sparc advance
Output format
输出格式
undefinedundefinedPseudocode: {Feature Name}
伪代码:{功能名称}
Core Algorithms
核心算法
Algorithm 1: {name}
算法1:{名称}
pseudocode
FUNCTION processRequest(input):
VALIDATE input against schema
IF invalid THEN THROW ValidationError
result <- TRANSFORM input
STORE result
RETURN resultComplexity: O(n) time, O(1) space
pseudocode
FUNCTION processRequest(input):
VALIDATE input against schema
IF invalid THEN THROW ValidationError
result <- TRANSFORM input
STORE result
RETURN result复杂度:O(n) 时间,O(1) 空间
Data Structures
数据结构
- {StructName}: { field1: type, field2: type }
- {结构名称}: { field1: type, field2: type }
Architecture: {Feature Name}
架构:{功能名称}
Bounded Contexts
限界上下文
- {ContextName}: {description}
- Aggregates: {list}
- Events: {list}
- {上下文名称}: {描述}
- 聚合:{列表}
- 事件:{列表}
API Contracts
API契约
POST /api/{resource}
POST /api/{资源}
- Request: { field1: string, field2: number }
- Response: { id: string, ...fields }
- Errors: 400 (validation), 409 (conflict), 500 (internal)
- 请求:{ field1: string, field2: number }
- 响应:{ id: string, ...fields }
- 错误:400(验证失败)、409(冲突)、500(内部错误)
Module Structure
模块结构
src/{feature}/
{feature}.types.ts # Interfaces and types
{feature}.service.ts # Business logic
{feature}.controller.ts # HTTP handling
{feature}.repository.ts # Data access
{feature}.test.ts # Testssrc/{feature}/
{feature}.types.ts # 接口和类型
{feature}.service.ts # 业务逻辑
{feature}.controller.ts # HTTP处理
{feature}.repository.ts # 数据访问
{feature}.test.ts # 测试Infrastructure
基础设施
- Persistence: {strategy}
- Caching: {strategy}
- Events: {strategy}
Phases 2-3 complete. Run to pass the gate check.
/sparc advanceundefined- 持久化:{策略}
- 缓存:{策略}
- 事件:{策略}
第2-3阶段完成。运行以通过检查门。
/sparc advanceundefined