sparc-methodology

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

SPARC Methodology - Comprehensive Development Framework

SPARC方法论——综合性开发框架

Overview

概述

SPARC (Specification, Pseudocode, Architecture, Refinement, Completion) is a systematic development methodology integrated with Claude Flow's multi-agent orchestration capabilities. It provides 17 specialized modes for comprehensive software development, from initial research through deployment and monitoring.
SPARC(Specification、Pseudocode、Architecture、Refinement、Completion)是集成了Claude Flow多Agent编排能力的系统化开发方法论。它提供17种专业模式,支持从初始研究到部署监控的全流程软件开发。

Table of Contents

目录

Core Philosophy

核心理念

SPARC methodology emphasizes:
  • Systematic Approach: Structured phases from specification to completion
  • Test-Driven Development: Tests written before implementation
  • Parallel Execution: Concurrent agent coordination for 2.8-4.4x speed improvements
  • Memory Integration: Persistent knowledge sharing across agents and sessions
  • Quality First: Comprehensive reviews, testing, and validation
  • Modular Design: Clean separation of concerns with clear interfaces
SPARC方法论强调:
  • 系统化方法:从需求定义到完成的结构化阶段
  • 测试驱动开发:先编写测试再实现功能
  • 并行执行:多Agent协同,速度提升2.8-4.4倍
  • 内存集成:跨Agent和会话的持久化知识共享
  • 质量优先:全面的评审、测试与验证
  • 模块化设计:清晰的关注点分离与接口定义

Key Principles

关键原则

  1. Specification Before Code: Define requirements and constraints clearly
  2. Design Before Implementation: Plan architecture and components
  3. Tests Before Features: Write failing tests, then make them pass
  4. Review Everything: Code quality, security, and performance checks
  5. Document Continuously: Maintain current documentation throughout

  1. 先定义再编码:明确需求与约束
  2. 先设计再实现:规划架构与组件
  3. 先测试再功能:编写失败测试,再实现使其通过
  4. 全面评审:代码质量、安全与性能检查
  5. 持续文档:全程维护最新文档

Development Phases

开发阶段

Phase 1: Specification

阶段1:需求定义

Goal: Define requirements, constraints, and success criteria
  • Requirements analysis
  • User story mapping
  • Constraint identification
  • Success metrics definition
  • Pseudocode planning
Key Modes:
researcher
,
analyzer
,
memory-manager
目标:定义需求、约束与成功标准
  • 需求分析
  • 用户故事映射
  • 约束识别
  • 成功指标定义
  • 伪代码规划
关键模式
researcher
,
analyzer
,
memory-manager

Phase 2: Architecture

阶段2:架构设计

Goal: Design system structure and component interfaces
  • System architecture design
  • Component interface definition
  • Database schema planning
  • API contract specification
  • Infrastructure planning
Key Modes:
architect
,
designer
,
orchestrator
目标:设计系统结构与组件接口
  • 系统架构设计
  • 组件接口定义
  • 数据库 schema 规划
  • API 契约规范
  • 基础设施规划
关键模式
architect
,
designer
,
orchestrator

Phase 3: Refinement (TDD Implementation)

阶段3:迭代优化(TDD实现)

Goal: Implement features with test-first approach
  • Write failing tests
  • Implement minimum viable code
  • Make tests pass
  • Refactor for quality
  • Iterate until complete
Key Modes:
tdd
,
coder
,
tester
目标:以测试优先的方式实现功能
  • 编写失败测试
  • 实现最小可行代码
  • 使测试通过
  • 重构以提升质量
  • 迭代直至完成
关键模式
tdd
,
coder
,
tester

Phase 4: Review

阶段4:评审

Goal: Ensure code quality, security, and performance
  • Code quality assessment
  • Security vulnerability scanning
  • Performance profiling
  • Best practices validation
  • Documentation review
Key Modes:
reviewer
,
optimizer
,
debugger
目标:确保代码质量、安全与性能
  • 代码质量评估
  • 安全漏洞扫描
  • 性能分析
  • 最佳实践验证
  • 文档评审
关键模式
reviewer
,
optimizer
,
debugger

Phase 5: Completion

阶段5:完成

Goal: Integration, deployment, and monitoring
  • System integration
  • Deployment automation
  • Monitoring setup
  • Documentation finalization
  • Knowledge capture
Key Modes:
workflow-manager
,
documenter
,
memory-manager

目标:集成、部署与监控
  • 系统集成
  • 部署自动化
  • 监控设置
  • 文档定稿
  • 知识捕获
关键模式
workflow-manager
,
documenter
,
memory-manager

Available Modes

可用模式

Core Orchestration Modes

核心编排模式

orchestrator

orchestrator

Multi-agent task orchestration with TodoWrite/Task/Memory coordination.
Capabilities:
  • Task decomposition into manageable units
  • Agent coordination and resource allocation
  • Progress tracking and result synthesis
  • Adaptive strategy selection
  • Cross-agent communication
Usage:
javascript
mcp__claude-flow__sparc_mode {
  mode: "orchestrator",
  task_description: "coordinate feature development",
  options: { parallel: true, monitor: true }
}
结合TodoWrite/Task/Memory的多Agent任务编排。
能力:
  • 将任务分解为可管理单元
  • Agent协同与资源分配
  • 进度跟踪与结果合成
  • 自适应策略选择
  • 跨Agent通信
用法:
javascript
mcp__claude-flow__sparc_mode {
  mode: "orchestrator",
  task_description: "coordinate feature development",
  options: { parallel: true, monitor: true }
}

swarm-coordinator

swarm-coordinator

Specialized swarm management for complex multi-agent workflows.
Capabilities:
  • Topology optimization (mesh, hierarchical, ring, star)
  • Agent lifecycle management
  • Dynamic scaling based on workload
  • Fault tolerance and recovery
  • Performance monitoring
针对复杂多Agent工作流的专用集群管理。
能力:
  • 拓扑优化(网状、分层、环状、星状)
  • Agent生命周期管理
  • 基于负载的动态扩容
  • 容错与恢复
  • 性能监控

workflow-manager

workflow-manager

Process automation and workflow orchestration.
Capabilities:
  • Workflow definition and execution
  • Event-driven triggers
  • Sequential and parallel pipelines
  • State management
  • Error handling and retry logic
流程自动化与工作流编排。
能力:
  • 工作流定义与执行
  • 事件驱动触发器
  • 串行与并行流水线
  • 状态管理
  • 错误处理与重试逻辑

batch-executor

batch-executor

Parallel task execution for high-throughput operations.
Capabilities:
  • Concurrent file operations
  • Batch processing optimization
  • Resource pooling
  • Load balancing
  • Progress aggregation

针对高吞吐量操作的并行任务执行。
能力:
  • 并发文件操作
  • 批处理优化
  • 资源池化
  • 负载均衡
  • 进度聚合

Development Modes

开发模式

coder

coder

Autonomous code generation with batch file operations.
Capabilities:
  • Feature implementation
  • Code refactoring
  • Bug fixes and patches
  • API development
  • Algorithm implementation
Quality Standards:
  • ES2022+ standards
  • TypeScript type safety
  • Comprehensive error handling
  • Performance optimization
  • Security best practices
Usage:
javascript
mcp__claude-flow__sparc_mode {
  mode: "coder",
  task_description: "implement user authentication with JWT",
  options: {
    test_driven: true,
    parallel_edits: true,
    typescript: true
  }
}
支持批量文件操作的自主代码生成。
能力:
  • 功能实现
  • 代码重构
  • 漏洞修复与补丁
  • API开发
  • 算法实现
质量标准:
  • ES2022+ 标准
  • TypeScript 类型安全
  • 全面的错误处理
  • 性能优化
  • 安全最佳实践
用法:
javascript
mcp__claude-flow__sparc_mode {
  mode: "coder",
  task_description: "implement user authentication with JWT",
  options: {
    test_driven: true,
    parallel_edits: true,
    typescript: true
  }
}

architect

architect

System design with Memory-based coordination.
Capabilities:
  • Microservices architecture
  • Event-driven design
  • Domain-driven design (DDD)
  • Hexagonal architecture
  • CQRS and Event Sourcing
Memory Integration:
  • Store architectural decisions
  • Share component specifications
  • Maintain design consistency
  • Track architectural evolution
Design Patterns:
  • Layered architecture
  • Microservices patterns
  • Event-driven patterns
  • Domain modeling
  • Infrastructure as Code
Usage:
javascript
mcp__claude-flow__sparc_mode {
  mode: "architect",
  task_description: "design scalable e-commerce platform",
  options: {
    detailed: true,
    memory_enabled: true,
    patterns: ["microservices", "event-driven"]
  }
}
基于Memory协同的系统设计。
能力:
  • 微服务架构
  • 事件驱动设计
  • 领域驱动设计(DDD)
  • 六边形架构
  • CQRS与事件溯源
内存集成:
  • 存储架构决策
  • 共享组件规范
  • 维护设计一致性
  • 跟踪架构演进
设计模式:
  • 分层架构
  • 微服务模式
  • 事件驱动模式
  • 领域建模
  • 基础设施即代码
用法:
javascript
mcp__claude-flow__sparc_mode {
  mode: "architect",
  task_description: "design scalable e-commerce platform",
  options: {
    detailed: true,
    memory_enabled: true,
    patterns: ["microservices", "event-driven"]
  }
}

tdd

tdd

Test-driven development with comprehensive testing.
Capabilities:
  • Test-first development
  • Red-green-refactor cycle
  • Test suite design
  • Coverage optimization (target: 90%+)
  • Continuous testing
TDD Workflow:
  1. Write failing test (RED)
  2. Implement minimum code
  3. Make test pass (GREEN)
  4. Refactor for quality (REFACTOR)
  5. Repeat cycle
Testing Strategies:
  • Unit testing (Jest, Mocha, Vitest)
  • Integration testing
  • End-to-end testing (Playwright, Cypress)
  • Performance testing
  • Security testing
Usage:
javascript
mcp__claude-flow__sparc_mode {
  mode: "tdd",
  task_description: "shopping cart feature with payment integration",
  options: {
    coverage_target: 90,
    test_framework: "jest",
    e2e_framework: "playwright"
  }
}
支持全面测试的测试驱动开发。
能力:
  • 测试优先开发
  • 红-绿-重构循环
  • 测试套件设计
  • 覆盖率优化(目标:90%+)
  • 持续测试
TDD工作流:
  1. 编写失败测试(RED)
  2. 实现最小代码
  3. 使测试通过(GREEN)
  4. 重构提升质量(REFACTOR)
  5. 重复循环
测试策略:
  • 单元测试(Jest、Mocha、Vitest)
  • 集成测试
  • 端到端测试(Playwright、Cypress)
  • 性能测试
  • 安全测试
用法:
javascript
mcp__claude-flow__sparc_mode {
  mode: "tdd",
  task_description: "shopping cart feature with payment integration",
  options: {
    coverage_target: 90,
    test_framework: "jest",
    e2e_framework: "playwright"
  }
}

reviewer

reviewer

Code review using batch file analysis.
Capabilities:
  • Code quality assessment
  • Security vulnerability detection
  • Performance analysis
  • Best practices validation
  • Documentation review
Review Criteria:
  • Code correctness and logic
  • Design pattern adherence
  • Comprehensive error handling
  • Test coverage adequacy
  • Maintainability and readability
  • Security vulnerabilities
  • Performance bottlenecks
Batch Analysis:
  • Parallel file review
  • Pattern detection
  • Dependency checking
  • Consistency validation
  • Automated reporting
Usage:
javascript
mcp__claude-flow__sparc_mode {
  mode: "reviewer",
  task_description: "review authentication module PR #123",
  options: {
    security_check: true,
    performance_check: true,
    test_coverage_check: true
  }
}

基于批量文件分析的代码评审。
能力:
  • 代码质量评估
  • 安全漏洞检测
  • 性能分析
  • 最佳实践验证
  • 文档评审
评审标准:
  • 代码正确性与逻辑
  • 设计模式遵循度
  • 全面的错误处理
  • 测试覆盖率充足性
  • 可维护性与可读性
  • 安全漏洞
  • 性能瓶颈
批量分析:
  • 并行文件评审
  • 模式检测
  • 依赖检查
  • 一致性验证
  • 自动化报告
用法:
javascript
mcp__claude-flow__sparc_mode {
  mode: "reviewer",
  task_description: "review authentication module PR #123",
  options: {
    security_check: true,
    performance_check: true,
    test_coverage_check: true
  }
}

Analysis and Research Modes

分析与研究模式

researcher

researcher

Deep research with parallel WebSearch/WebFetch and Memory coordination.
Capabilities:
  • Comprehensive information gathering
  • Source credibility evaluation
  • Trend analysis and forecasting
  • Competitive research
  • Technology assessment
Research Methods:
  • Parallel web searches
  • Academic paper analysis
  • Industry report synthesis
  • Expert opinion gathering
  • Statistical data compilation
Memory Integration:
  • Store research findings with citations
  • Build knowledge graphs
  • Track information sources
  • Cross-reference insights
  • Maintain research history
Usage:
javascript
mcp__claude-flow__sparc_mode {
  mode: "researcher",
  task_description: "research microservices best practices 2024",
  options: {
    depth: "comprehensive",
    sources: ["academic", "industry", "news"],
    citations: true
  }
}
结合并行WebSearch/WebFetch与Memory协同的深度研究。
能力:
  • 全面信息收集
  • 来源可信度评估
  • 趋势分析与预测
  • 竞品研究
  • 技术评估
研究方法:
  • 并行网页搜索
  • 学术论文分析
  • 行业报告综合
  • 专家意见收集
  • 统计数据整理
内存集成:
  • 存储带引用的研究成果
  • 构建知识图谱
  • 跟踪信息来源
  • 交叉引用洞察
  • 维护研究历史
用法:
javascript
mcp__claude-flow__sparc_mode {
  mode: "researcher",
  task_description: "research microservices best practices 2024",
  options: {
    depth: "comprehensive",
    sources: ["academic", "industry", "news"],
    citations: true
  }
}

analyzer

analyzer

Code and data analysis with pattern recognition.
Capabilities:
  • Static code analysis
  • Dependency analysis
  • Performance profiling
  • Security scanning
  • Data pattern recognition
支持模式识别的代码与数据分析。
能力:
  • 静态代码分析
  • 依赖分析
  • 性能分析
  • 安全扫描
  • 数据模式识别

optimizer

optimizer

Performance optimization and bottleneck resolution.
Capabilities:
  • Algorithm optimization
  • Database query tuning
  • Caching strategy design
  • Bundle size reduction
  • Memory leak detection

性能优化与瓶颈解决。
能力:
  • 算法优化
  • 数据库查询调优
  • 缓存策略设计
  • 包体积缩减
  • 内存泄漏检测

Creative and Support Modes

创意与支持模式

designer

designer

UI/UX design with accessibility focus.
Capabilities:
  • Interface design
  • User experience optimization
  • Accessibility compliance (WCAG 2.1)
  • Design system creation
  • Responsive layout design
聚焦可访问性的UI/UX设计。
能力:
  • 界面设计
  • 用户体验优化
  • 可访问性合规(WCAG 2.1)
  • 设计系统创建
  • 响应式布局设计

innovator

innovator

Creative problem-solving and novel solutions.
Capabilities:
  • Brainstorming and ideation
  • Alternative approach generation
  • Technology evaluation
  • Proof of concept development
  • Innovation feasibility analysis
创造性问题解决与创新方案生成。
能力:
  • 头脑风暴与创意生成
  • 替代方案提出
  • 技术评估
  • 概念验证开发
  • 创新可行性分析

documenter

documenter

Comprehensive documentation generation.
Capabilities:
  • API documentation (OpenAPI/Swagger)
  • Architecture diagrams
  • User guides and tutorials
  • Code comments and JSDoc
  • README and changelog maintenance
全面文档生成。
能力:
  • API文档(OpenAPI/Swagger)
  • 架构图
  • 用户指南与教程
  • 代码注释与JSDoc
  • README与变更日志维护

debugger

debugger

Systematic debugging and issue resolution.
Capabilities:
  • Bug reproduction
  • Root cause analysis
  • Fix implementation
  • Regression prevention
  • Debug logging optimization
系统化调试与问题解决。
能力:
  • 漏洞复现
  • 根因分析
  • 修复实现
  • 回归预防
  • 调试日志优化

tester

tester

Comprehensive testing beyond TDD.
Capabilities:
  • Test suite expansion
  • Edge case identification
  • Performance testing
  • Load testing
  • Chaos engineering
超越TDD的全面测试。
能力:
  • 测试套件扩展
  • 边缘场景识别
  • 性能测试
  • 负载测试
  • 混沌工程

memory-manager

memory-manager

Knowledge management and context preservation.
Capabilities:
  • Cross-session memory persistence
  • Knowledge graph construction
  • Context restoration
  • Learning pattern extraction
  • Decision tracking

知识管理与上下文保存。
能力:
  • 跨会话内存持久化
  • 知识图谱构建
  • 上下文恢复
  • 学习模式提取
  • 决策跟踪

Activation Methods

激活方式

Method 1: MCP Tools (Preferred in Claude Code)

方法1:MCP工具(Claude Code中首选)

Best for: Integrated Claude Code workflows with full orchestration capabilities
javascript
// Basic mode execution
mcp__claude-flow__sparc_mode {
  mode: "<mode-name>",
  task_description: "<task description>",
  options: {
    // mode-specific options
  }
}

// Initialize swarm for complex tasks
mcp__claude-flow__swarm_init {
  topology: "hierarchical",  // or "mesh", "ring", "star"
  strategy: "auto",           // or "balanced", "specialized", "adaptive"
  maxAgents: 8
}

// Spawn specialized agents
mcp__claude-flow__agent_spawn {
  type: "<agent-type>",
  capabilities: ["<capability1>", "<capability2>"]
}

// Monitor execution
mcp__claude-flow__swarm_monitor {
  swarmId: "current",
  interval: 5000
}
最佳场景:集成Claude Code工作流,支持完整编排能力
javascript
// 基础模式执行
mcp__claude-flow__sparc_mode {
  mode: "<mode-name>",
  task_description: "<task description>",
  options: {
    // 模式专属选项
  }
}

// 初始化集群以处理复杂任务
mcp__claude-flow__swarm_init {
  topology: "hierarchical",  // 或 "mesh", "ring", "star"
  strategy: "auto",           // 或 "balanced", "specialized", "adaptive"
  maxAgents: 8
}

// 生成专用Agent
mcp__claude-flow__agent_spawn {
  type: "<agent-type>",
  capabilities: ["<capability1>", "<capability2>"]
}

// 监控执行
mcp__claude-flow__swarm_monitor {
  swarmId: "current",
  interval: 5000
}

Method 2: NPX CLI (Fallback)

方法2:NPX CLI(备选)

Best for: Terminal usage or when MCP tools unavailable
bash
undefined
最佳场景:终端使用或MCP工具不可用时
bash
undefined

Execute specific mode

执行特定模式

npx claude-flow sparc run <mode> "task description"
npx claude-flow sparc run <mode> "task description"

Use alpha features

使用Alpha特性

npx claude-flow@alpha sparc run <mode> "task description"
npx claude-flow@alpha sparc run <mode> "task description"

List all available modes

列出所有可用模式

npx claude-flow sparc modes
npx claude-flow sparc modes

Get help for specific mode

获取特定模式帮助

npx claude-flow sparc help <mode>
npx claude-flow sparc help <mode>

Run with options

带选项执行

npx claude-flow sparc run <mode> "task" --parallel --monitor
npx claude-flow sparc run <mode> "task" --parallel --monitor

Execute TDD workflow

执行TDD工作流

npx claude-flow sparc tdd "feature description"
npx claude-flow sparc tdd "feature description"

Batch execution

批量执行

npx claude-flow sparc batch <mode1,mode2,mode3> "task"
npx claude-flow sparc batch <mode1,mode2,mode3> "task"

Pipeline execution

流水线执行

npx claude-flow sparc pipeline "task description"
undefined
npx claude-flow sparc pipeline "task description"
undefined

Method 3: Local Installation

方法3:本地安装

Best for: Projects with local claude-flow installation
bash
undefined
最佳场景:已本地安装claude-flow的项目
bash
undefined

If claude-flow is installed locally

若已本地安装claude-flow

./claude-flow sparc run <mode> "task description"

---
./claude-flow sparc run <mode> "task description"

---

Orchestration Patterns

编排模式

Pattern 1: Hierarchical Coordination

模式1:分层协同

Best for: Complex projects with clear delegation hierarchy
javascript
// Initialize hierarchical swarm
mcp__claude-flow__swarm_init {
  topology: "hierarchical",
  maxAgents: 12
}

// Spawn coordinator
mcp__claude-flow__agent_spawn {
  type: "coordinator",
  capabilities: ["planning", "delegation", "monitoring"]
}

// Spawn specialized workers
mcp__claude-flow__agent_spawn { type: "architect" }
mcp__claude-flow__agent_spawn { type: "coder" }
mcp__claude-flow__agent_spawn { type: "tester" }
mcp__claude-flow__agent_spawn { type: "reviewer" }
最佳场景:具有清晰委托层级的复杂项目
javascript
// 初始化分层集群
mcp__claude-flow__swarm_init {
  topology: "hierarchical",
  maxAgents: 12
}

// 生成协调器
mcp__claude-flow__agent_spawn {
  type: "coordinator",
  capabilities: ["planning", "delegation", "monitoring"]
}

// 生成专用工作Agent
mcp__claude-flow__agent_spawn { type: "architect" }
mcp__claude-flow__agent_spawn { type: "coder" }
mcp__claude-flow__agent_spawn { type: "tester" }
mcp__claude-flow__agent_spawn { type: "reviewer" }

Pattern 2: Mesh Coordination

模式2:网状协同

Best for: Collaborative tasks requiring peer-to-peer communication
javascript
mcp__claude-flow__swarm_init {
  topology: "mesh",
  strategy: "balanced",
  maxAgents: 6
}
最佳场景:需要点对点通信的协作任务
javascript
mcp__claude-flow__swarm_init {
  topology: "mesh",
  strategy: "balanced",
  maxAgents: 6
}

Pattern 3: Sequential Pipeline

模式3:串行流水线

Best for: Ordered workflow execution (spec → design → code → test → review)
javascript
mcp__claude-flow__workflow_create {
  name: "development-pipeline",
  steps: [
    { mode: "researcher", task: "gather requirements" },
    { mode: "architect", task: "design system" },
    { mode: "coder", task: "implement features" },
    { mode: "tdd", task: "create tests" },
    { mode: "reviewer", task: "review code" }
  ],
  triggers: ["on_step_complete"]
}
最佳场景:有序工作流执行(需求定义→设计→编码→测试→评审)
javascript
mcp__claude-flow__workflow_create {
  name: "development-pipeline",
  steps: [
    { mode: "researcher", task: "gather requirements" },
    { mode: "architect", task: "design system" },
    { mode: "coder", task: "implement features" },
    { mode: "tdd", task: "create tests" },
    { mode: "reviewer", task: "review code" }
  ],
  triggers: ["on_step_complete"]
}

Pattern 4: Parallel Execution

模式4:并行执行

Best for: Independent tasks that can run concurrently
javascript
mcp__claude-flow__task_orchestrate {
  task: "build full-stack application",
  strategy: "parallel",
  dependencies: {
    backend: [],
    frontend: [],
    database: [],
    tests: ["backend", "frontend"]
  }
}
最佳场景:可独立并发运行的任务
javascript
mcp__claude-flow__task_orchestrate {
  task: "build full-stack application",
  strategy: "parallel",
  dependencies: {
    backend: [],
    frontend: [],
    database: [],
    tests: ["backend", "frontend"]
  }
}

Pattern 5: Adaptive Strategy

模式5:自适应策略

Best for: Dynamic workloads with changing requirements
javascript
mcp__claude-flow__swarm_init {
  topology: "hierarchical",
  strategy: "adaptive",  // Auto-adjusts based on workload
  maxAgents: 20
}

最佳场景:需求变化的动态负载
javascript
mcp__claude-flow__swarm_init {
  topology: "hierarchical",
  strategy: "adaptive",  // 基于负载自动调整
  maxAgents: 20
}

TDD Workflows

TDD工作流

Complete TDD Workflow

完整TDD工作流

javascript
// Step 1: Initialize TDD swarm
mcp__claude-flow__swarm_init {
  topology: "hierarchical",
  maxAgents: 8
}

// Step 2: Research and planning
mcp__claude-flow__sparc_mode {
  mode: "researcher",
  task_description: "research testing best practices for feature X"
}

// Step 3: Architecture design
mcp__claude-flow__sparc_mode {
  mode: "architect",
  task_description: "design testable architecture for feature X"
}

// Step 4: TDD implementation
mcp__claude-flow__sparc_mode {
  mode: "tdd",
  task_description: "implement feature X with 90% coverage",
  options: {
    coverage_target: 90,
    test_framework: "jest",
    parallel_tests: true
  }
}

// Step 5: Code review
mcp__claude-flow__sparc_mode {
  mode: "reviewer",
  task_description: "review feature X implementation",
  options: {
    test_coverage_check: true,
    security_check: true
  }
}

// Step 6: Optimization
mcp__claude-flow__sparc_mode {
  mode: "optimizer",
  task_description: "optimize feature X performance"
}
javascript
// 步骤1:初始化TDD集群
mcp__claude-flow__swarm_init {
  topology: "hierarchical",
  maxAgents: 8
}

// 步骤2:研究与规划
mcp__claude-flow__sparc_mode {
  mode: "researcher",
  task_description: "research testing best practices for feature X"
}

// 步骤3:架构设计
mcp__claude-flow__sparc_mode {
  mode: "architect",
  task_description: "design testable architecture for feature X"
}

// 步骤4:TDD实现
mcp__claude-flow__sparc_mode {
  mode: "tdd",
  task_description: "implement feature X with 90% coverage",
  options: {
    coverage_target: 90,
    test_framework: "jest",
    parallel_tests: true
  }
}

// 步骤5:代码评审
mcp__claude-flow__sparc_mode {
  mode: "reviewer",
  task_description: "review feature X implementation",
  options: {
    test_coverage_check: true,
    security_check: true
  }
}

// 步骤6:优化
mcp__claude-flow__sparc_mode {
  mode: "optimizer",
  task_description: "optimize feature X performance"
}

Red-Green-Refactor Cycle

红-绿-重构循环

javascript
// RED: Write failing test
mcp__claude-flow__sparc_mode {
  mode: "tester",
  task_description: "create failing test for shopping cart add item",
  options: { expect_failure: true }
}

// GREEN: Minimal implementation
mcp__claude-flow__sparc_mode {
  mode: "coder",
  task_description: "implement minimal code to pass test",
  options: { minimal: true }
}

// REFACTOR: Improve code quality
mcp__claude-flow__sparc_mode {
  mode: "coder",
  task_description: "refactor shopping cart implementation",
  options: { maintain_tests: true }
}

javascript
// RED:编写失败测试
mcp__claude-flow__sparc_mode {
  mode: "tester",
  task_description: "create failing test for shopping cart add item",
  options: { expect_failure: true }
}

// GREEN:最小实现
mcp__claude-flow__sparc_mode {
  mode: "coder",
  task_description: "implement minimal code to pass test",
  options: { minimal: true }
}

// REFACTOR:提升代码质量
mcp__claude-flow__sparc_mode {
  mode: "coder",
  task_description: "refactor shopping cart implementation",
  options: { maintain_tests: true }
}

Best Practices

最佳实践

1. Memory Integration

1. 内存集成

Always use Memory for cross-agent coordination:
javascript
// Store architectural decisions
mcp__claude-flow__memory_usage {
  action: "store",
  namespace: "architecture",
  key: "api-design-v1",
  value: JSON.stringify(apiDesign),
  ttl: 86400000  // 24 hours
}

// Retrieve in subsequent agents
mcp__claude-flow__memory_usage {
  action: "retrieve",
  namespace: "architecture",
  key: "api-design-v1"
}
始终使用Memory进行跨Agent协同:
javascript
// 存储架构决策
mcp__claude-flow__memory_usage {
  action: "store",
  namespace: "architecture",
  key: "api-design-v1",
  value: JSON.stringify(apiDesign),
  ttl: 86400000  // 24小时
}

// 在后续Agent中检索
mcp__claude-flow__memory_usage {
  action: "retrieve",
  namespace: "architecture",
  key: "api-design-v1"
}

2. Parallel Operations

2. 并行操作

Batch all related operations in single message:
javascript
// ✅ CORRECT: All operations together
[Single Message]:
  mcp__claude-flow__agent_spawn { type: "researcher" }
  mcp__claude-flow__agent_spawn { type: "coder" }
  mcp__claude-flow__agent_spawn { type: "tester" }
  TodoWrite { todos: [8-10 todos] }

// ❌ WRONG: Multiple messages
Message 1: mcp__claude-flow__agent_spawn { type: "researcher" }
Message 2: mcp__claude-flow__agent_spawn { type: "coder" }
Message 3: TodoWrite { todos: [...] }
将所有相关操作批量放在单条消息中:
javascript
// ✅ 正确:所有操作放在一起
[Single Message]:
  mcp__claude-flow__agent_spawn { type: "researcher" }
  mcp__claude-flow__agent_spawn { type: "coder" }
  mcp__claude-flow__agent_spawn { type: "tester" }
  TodoWrite { todos: [8-10 todos] }

// ❌ 错误:多条消息
Message 1: mcp__claude-flow__agent_spawn { type: "researcher" }
Message 2: mcp__claude-flow__agent_spawn { type: "coder" }
Message 3: TodoWrite { todos: [...] }

3. Hook Integration

3. Hook集成

Every SPARC mode should use hooks:
bash
undefined
每个SPARC模式都应使用hooks:
bash
undefined

Before work

工作前

npx claude-flow@alpha hooks pre-task --description "implement auth"
npx claude-flow@alpha hooks pre-task --description "implement auth"

During work

工作中

npx claude-flow@alpha hooks post-edit --file "auth.js"
npx claude-flow@alpha hooks post-edit --file "auth.js"

After work

工作后

npx claude-flow@alpha hooks post-task --task-id "task-123"
undefined
npx claude-flow@alpha hooks post-task --task-id "task-123"
undefined

4. Test Coverage

4. 测试覆盖率

Maintain minimum 90% coverage:
  • Unit tests for all functions
  • Integration tests for APIs
  • E2E tests for critical flows
  • Edge case coverage
  • Error path testing
保持至少90%的覆盖率:
  • 所有函数的单元测试
  • API的集成测试
  • 关键流程的端到端测试
  • 边缘场景覆盖
  • 错误路径测试

5. Documentation

5. 文档

Document as you build:
  • API documentation (OpenAPI)
  • Architecture decision records (ADR)
  • Code comments for complex logic
  • README with setup instructions
  • Changelog for version tracking
边构建边文档:
  • API文档(OpenAPI)
  • 架构决策记录(ADR)
  • 复杂逻辑的代码注释
  • 包含设置说明的README
  • 版本跟踪的变更日志

6. File Organization

6. 文件组织

Never save to root folder:
project/
├── src/           # Source code
├── tests/         # Test files
├── docs/          # Documentation
├── config/        # Configuration
├── scripts/       # Utility scripts
└── examples/      # Example code

切勿保存到根目录:
project/
├── src/           # 源代码
├── tests/         # 测试文件
├── docs/          # 文档
├── config/        # 配置
├── scripts/       # 工具脚本
└── examples/      # 示例代码

Integration Examples

集成示例

Example 1: Full-Stack Development

示例1:全栈开发

javascript
[Single Message - Parallel Agent Execution]:

// Initialize swarm
mcp__claude-flow__swarm_init {
  topology: "hierarchical",
  maxAgents: 10
}

// Architecture phase
mcp__claude-flow__sparc_mode {
  mode: "architect",
  task_description: "design REST API with authentication",
  options: { memory_enabled: true }
}

// Research phase
mcp__claude-flow__sparc_mode {
  mode: "researcher",
  task_description: "research authentication best practices"
}

// Implementation phase
mcp__claude-flow__sparc_mode {
  mode: "coder",
  task_description: "implement Express API with JWT auth",
  options: { test_driven: true }
}

// Testing phase
mcp__claude-flow__sparc_mode {
  mode: "tdd",
  task_description: "comprehensive API tests",
  options: { coverage_target: 90 }
}

// Review phase
mcp__claude-flow__sparc_mode {
  mode: "reviewer",
  task_description: "security and performance review",
  options: { security_check: true }
}

// Batch todos
TodoWrite {
  todos: [
    {content: "Design API schema", status: "completed"},
    {content: "Research JWT implementation", status: "completed"},
    {content: "Implement authentication", status: "in_progress"},
    {content: "Write API tests", status: "pending"},
    {content: "Security review", status: "pending"},
    {content: "Performance optimization", status: "pending"},
    {content: "API documentation", status: "pending"},
    {content: "Deployment setup", status: "pending"}
  ]
}
javascript
[Single Message - Parallel Agent Execution]:

// 初始化集群
mcp__claude-flow__swarm_init {
  topology: "hierarchical",
  maxAgents: 10
}

// 架构阶段
mcp__claude-flow__sparc_mode {
  mode: "architect",
  task_description: "design REST API with authentication",
  options: { memory_enabled: true }
}

// 研究阶段
mcp__claude-flow__sparc_mode {
  mode: "researcher",
  task_description: "research authentication best practices"
}

// 实现阶段
mcp__claude-flow__sparc_mode {
  mode: "coder",
  task_description: "implement Express API with JWT auth",
  options: { test_driven: true }
}

// 测试阶段
mcp__claude-flow__sparc_mode {
  mode: "tdd",
  task_description: "comprehensive API tests",
  options: { coverage_target: 90 }
}

// 评审阶段
mcp__claude-flow__sparc_mode {
  mode: "reviewer",
  task_description: "security and performance review",
  options: { security_check: true }
}

// 批量待办事项
TodoWrite {
  todos: [
    {content: "Design API schema", status: "completed"},
    {content: "Research JWT implementation", status: "completed"},
    {content: "Implement authentication", status: "in_progress"},
    {content: "Write API tests", status: "pending"},
    {content: "Security review", status: "pending"},
    {content: "Performance optimization", status: "pending"},
    {content: "API documentation", status: "pending"},
    {content: "Deployment setup", status: "pending"}
  ]
}

Example 2: Research-Driven Innovation

示例2:研究驱动的创新

javascript
// Research phase
mcp__claude-flow__sparc_mode {
  mode: "researcher",
  task_description: "research AI-powered search implementations",
  options: {
    depth: "comprehensive",
    sources: ["academic", "industry"]
  }
}

// Innovation phase
mcp__claude-flow__sparc_mode {
  mode: "innovator",
  task_description: "propose novel search algorithm",
  options: { memory_enabled: true }
}

// Architecture phase
mcp__claude-flow__sparc_mode {
  mode: "architect",
  task_description: "design scalable search system"
}

// Implementation phase
mcp__claude-flow__sparc_mode {
  mode: "coder",
  task_description: "implement search algorithm",
  options: { test_driven: true }
}

// Documentation phase
mcp__claude-flow__sparc_mode {
  mode: "documenter",
  task_description: "document search system architecture and API"
}
javascript
// 研究阶段
mcp__claude-flow__sparc_mode {
  mode: "researcher",
  task_description: "research AI-powered search implementations",
  options: {
    depth: "comprehensive",
    sources: ["academic", "industry"]
  }
}

// 创新阶段
mcp__claude-flow__sparc_mode {
  mode: "innovator",
  task_description: "propose novel search algorithm",
  options: { memory_enabled: true }
}

// 架构阶段
mcp__claude-flow__sparc_mode {
  mode: "architect",
  task_description: "design scalable search system"
}

// 实现阶段
mcp__claude-flow__sparc_mode {
  mode: "coder",
  task_description: "implement search algorithm",
  options: { test_driven: true }
}

// 文档阶段
mcp__claude-flow__sparc_mode {
  mode: "documenter",
  task_description: "document search system architecture and API"
}

Example 3: Legacy Code Refactoring

示例3:遗留代码重构

javascript
// Analysis phase
mcp__claude-flow__sparc_mode {
  mode: "analyzer",
  task_description: "analyze legacy codebase dependencies"
}

// Planning phase
mcp__claude-flow__sparc_mode {
  mode: "orchestrator",
  task_description: "plan incremental refactoring strategy"
}

// Testing phase (create safety net)
mcp__claude-flow__sparc_mode {
  mode: "tester",
  task_description: "create comprehensive test suite for legacy code",
  options: { coverage_target: 80 }
}

// Refactoring phase
mcp__claude-flow__sparc_mode {
  mode: "coder",
  task_description: "refactor module X with modern patterns",
  options: { maintain_tests: true }
}

// Review phase
mcp__claude-flow__sparc_mode {
  mode: "reviewer",
  task_description: "validate refactoring maintains functionality"
}

javascript
// 分析阶段
mcp__claude-flow__sparc_mode {
  mode: "analyzer",
  task_description: "analyze legacy codebase dependencies"
}

// 规划阶段
mcp__claude-flow__sparc_mode {
  mode: "orchestrator",
  task_description: "plan incremental refactoring strategy"
}

// 测试阶段(创建安全网)
mcp__claude-flow__sparc_mode {
  mode: "tester",
  task_description: "create comprehensive test suite for legacy code",
  options: { coverage_target: 80 }
}

// 重构阶段
mcp__claude-flow__sparc_mode {
  mode: "coder",
  task_description: "refactor module X with modern patterns",
  options: { maintain_tests: true }
}

// 评审阶段
mcp__claude-flow__sparc_mode {
  mode: "reviewer",
  task_description: "validate refactoring maintains functionality"
}

Common Workflows

常见工作流

Workflow 1: Feature Development

工作流1:功能开发

bash
undefined
bash
undefined

Step 1: Research and planning

步骤1:研究与规划

npx claude-flow sparc run researcher "authentication patterns"
npx claude-flow sparc run researcher "authentication patterns"

Step 2: Architecture design

步骤2:架构设计

npx claude-flow sparc run architect "design auth system"
npx claude-flow sparc run architect "design auth system"

Step 3: TDD implementation

步骤3:TDD实现

npx claude-flow sparc tdd "user authentication feature"
npx claude-flow sparc tdd "user authentication feature"

Step 4: Code review

步骤4:代码评审

npx claude-flow sparc run reviewer "review auth implementation"
npx claude-flow sparc run reviewer "review auth implementation"

Step 5: Documentation

步骤5:文档

npx claude-flow sparc run documenter "document auth API"
undefined
npx claude-flow sparc run documenter "document auth API"
undefined

Workflow 2: Bug Investigation

工作流2:漏洞排查

bash
undefined
bash
undefined

Step 1: Analyze issue

步骤1:分析问题

npx claude-flow sparc run analyzer "investigate bug #456"
npx claude-flow sparc run analyzer "investigate bug #456"

Step 2: Debug systematically

步骤2:系统化调试

npx claude-flow sparc run debugger "fix memory leak in service X"
npx claude-flow sparc run debugger "fix memory leak in service X"

Step 3: Create tests

步骤3:创建测试

npx claude-flow sparc run tester "regression tests for bug #456"
npx claude-flow sparc run tester "regression tests for bug #456"

Step 4: Review fix

步骤4:评审修复

npx claude-flow sparc run reviewer "validate bug fix"
undefined
npx claude-flow sparc run reviewer "validate bug fix"
undefined

Workflow 3: Performance Optimization

工作流3:性能优化

bash
undefined
bash
undefined

Step 1: Profile performance

步骤1:性能分析

npx claude-flow sparc run analyzer "profile API response times"
npx claude-flow sparc run analyzer "profile API response times"

Step 2: Identify bottlenecks

步骤2:识别瓶颈

npx claude-flow sparc run optimizer "optimize database queries"
npx claude-flow sparc run optimizer "optimize database queries"

Step 3: Implement improvements

步骤3:实现改进

npx claude-flow sparc run coder "implement caching layer"
npx claude-flow sparc run coder "implement caching layer"

Step 4: Benchmark results

步骤4:基准测试

npx claude-flow sparc run tester "performance benchmarks"
undefined
npx claude-flow sparc run tester "performance benchmarks"
undefined

Workflow 4: Complete Pipeline

工作流4:完整流水线

bash
undefined
bash
undefined

Execute full development pipeline

执行完整开发流水线

npx claude-flow sparc pipeline "e-commerce checkout feature"
npx claude-flow sparc pipeline "e-commerce checkout feature"

This automatically runs:

自动执行以下步骤:

1. researcher - Gather requirements

1. researcher - 收集需求

2. architect - Design system

2. architect - 设计系统

3. coder - Implement features

3. coder - 实现功能

4. tdd - Create comprehensive tests

4. tdd - 创建全面测试

5. reviewer - Code quality review

5. reviewer - 代码质量评审

6. optimizer - Performance tuning

6. optimizer - 性能调优

7. documenter - Documentation

7. documenter - 文档生成


---

---

Advanced Features

高级特性

Neural Pattern Training

神经模式训练

javascript
// Train patterns from successful workflows
mcp__claude-flow__neural_train {
  pattern_type: "coordination",
  training_data: "successful_tdd_workflow.json",
  epochs: 50
}
javascript
// 从成功工作流中训练模式
mcp__claude-flow__neural_train {
  pattern_type: "coordination",
  training_data: "successful_tdd_workflow.json",
  epochs: 50
}

Cross-Session Memory

跨会话内存

javascript
// Save session state
mcp__claude-flow__memory_persist {
  sessionId: "feature-auth-v1"
}

// Restore in new session
mcp__claude-flow__context_restore {
  snapshotId: "feature-auth-v1"
}
javascript
undefined

GitHub Integration

保存会话状态

javascript
// Analyze repository
mcp__claude-flow__github_repo_analyze {
  repo: "owner/repo",
  analysis_type: "code_quality"
}

// Manage pull requests
mcp__claude-flow__github_pr_manage {
  repo: "owner/repo",
  pr_number: 123,
  action: "review"
}
mcp__claude-flow__memory_persist { sessionId: "feature-auth-v1" }

Performance Monitoring

在新会话中恢复

javascript
// Real-time swarm monitoring
mcp__claude-flow__swarm_monitor {
  swarmId: "current",
  interval: 5000
}

// Bottleneck analysis
mcp__claude-flow__bottleneck_analyze {
  component: "api-layer",
  metrics: ["latency", "throughput", "errors"]
}

// Token usage tracking
mcp__claude-flow__token_usage {
  operation: "feature-development",
  timeframe: "24h"
}

mcp__claude-flow__context_restore { snapshotId: "feature-auth-v1" }
undefined

Performance Benefits

GitHub集成

Proven Results:
  • 84.8% SWE-Bench solve rate
  • 32.3% token reduction through optimizations
  • 2.8-4.4x speed improvement with parallel execution
  • 27+ neural models for pattern learning
  • 90%+ test coverage standard

javascript
undefined

Support and Resources

分析仓库


mcp__claude-flow__github_repo_analyze { repo: "owner/repo", analysis_type: "code_quality" }

Quick Reference

管理拉取请求

Most Common Commands

bash
undefined
mcp__claude-flow__github_pr_manage { repo: "owner/repo", pr_number: 123, action: "review" }
undefined

List modes

性能监控

npx claude-flow sparc modes
javascript
undefined

Run specific mode

实时集群监控

npx claude-flow sparc run <mode> "task"
mcp__claude-flow__swarm_monitor { swarmId: "current", interval: 5000 }

TDD workflow

瓶颈分析

npx claude-flow sparc tdd "feature"
mcp__claude-flow__bottleneck_analyze { component: "api-layer", metrics: ["latency", "throughput", "errors"] }

Full pipeline

Token使用跟踪

npx claude-flow sparc pipeline "task"
mcp__claude-flow__token_usage { operation: "feature-development", timeframe: "24h" }

---

Batch execution

性能收益

npx claude-flow sparc batch <modes> "task"
undefined
已验证结果:
  • 84.8% 的SWE-Bench解决率
  • 32.3% 的Token使用优化缩减
  • 2.8-4.4倍 的并行执行速度提升
  • 27+ 个用于模式学习的神经模型
  • 90%+ 的测试覆盖率标准

Most Common MCP Calls

支持与资源

javascript
// Initialize swarm
mcp__claude-flow__swarm_init { topology: "hierarchical" }

// Execute mode
mcp__claude-flow__sparc_mode { mode: "coder", task_description: "..." }

// Monitor progress
mcp__claude-flow__swarm_monitor { interval: 5000 }

// Store in memory
mcp__claude-flow__memory_usage { action: "store", key: "...", value: "..." }

Remember: SPARC = Systematic, Parallel, Agile, Refined, Complete

快速参考

最常用命令

bash
undefined

列出模式

npx claude-flow sparc modes

运行特定模式

npx claude-flow sparc run <mode> "task"

TDD工作流

npx claude-flow sparc tdd "feature"

完整流水线

npx claude-flow sparc pipeline "task"

批量执行

npx claude-flow sparc batch <modes> "task"
undefined

最常用MCP调用

javascript
undefined

初始化集群

mcp__claude-flow__swarm_init { topology: "hierarchical" }

执行模式

mcp__claude-flow__sparc_mode { mode: "coder", task_description: "..." }

监控进度

mcp__claude-flow__swarm_monitor { interval: 5000 }

存储到内存

mcp__claude-flow__memory_usage { action: "store", key: "...", value: "..." }

---

记住:**SPARC = Systematic(系统化)、Parallel(并行化)、Agile(敏捷)、Refined(精细化)、Complete(全流程)**