mirror of
https://github.com/ruvnet/ruflo.git
synced 2026-11-25 06:36:49 +09:00
- Reorganize v3/ into implementation/ subfolders: - planning/, architecture/, migration/, integration/ - security/, adrs/, research/, swarm-plans/ - Add 15-agent concurrent swarm implementation plans: - SWARM-OVERVIEW.md: Hierarchical mesh topology, 4 phases - AGENT-SPECIFICATIONS.md: 15 agent configs with capabilities - TDD-LONDON-SCHOOL-PLAN.md: Mock-first TDD methodology - BENCHMARK-OPTIMIZATION.md: Performance targets (2.49x-7.47x) - DEPLOYMENT-PLAN.md: Release strategy, CI/CD, rollback - GITHUB-ISSUE-TRACKING.md: Issue workflow with agent replies - Update .claude/settings.json with proper hooks format - Add bash aliases for claude --dangerously-skip-permissions 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
5.6 KiB
5.6 KiB
SPARC Test-Driven Development Guide
Learn how to use SPARC methodology for systematic TDD with Claude Flow.
What is SPARC?
SPARC stands for:
- Specification: Define requirements clearly
- Pseudocode: Plan the logic
- Architecture: Design the structure
- Refinement: Implement with TDD
- Completion: Integrate and polish
Prerequisites
- Claude Flow with SPARC modes configured
- Understanding of TDD principles
- Basic programming knowledge
Tutorial: Building a User Authentication System
Step 1: Specification Phase
Define what we're building:
cd examples
../claude-flow sparc run spec-pseudocode \
"Design a user authentication system with:
- Email/password login
- JWT tokens
- Password reset
- Rate limiting
- Security best practices"
This creates:
- Detailed requirements document
- User stories
- Acceptance criteria
- Edge cases
Step 2: Pseudocode Phase
Plan the implementation logic:
../claude-flow sparc run spec-pseudocode \
"Create pseudocode for authentication flow:
- Login process
- Token generation
- Password hashing
- Session management"
Output includes:
- Algorithm descriptions
- Data flow diagrams
- State transitions
- Error handling logic
Step 3: Architecture Phase
Design the system structure:
../claude-flow sparc run architect \
"Design authentication service architecture:
- API endpoints
- Database schema
- Security layers
- Integration points"
Creates:
- System diagrams
- API specifications
- Database designs
- Security architecture
Step 4: TDD Implementation (Refinement)
Now we implement using Test-Driven Development:
../claude-flow sparc tdd \
"Implement user authentication system" \
--spec ./output/auth-spec.md \
--architecture ./output/auth-architecture.md
The TDD Cycle:
-
RED Phase - Write failing tests first:
// Generated test example describe('Authentication', () => { it('should hash passwords securely', async () => { const password = 'testPass123'; const hash = await authService.hashPassword(password); expect(hash).not.toBe(password); expect(hash.length).toBeGreaterThan(50); }); }); -
GREEN Phase - Implement minimal code to pass:
// Generated implementation async hashPassword(password) { const salt = await bcrypt.genSalt(10); return bcrypt.hash(password, salt); } -
REFACTOR Phase - Optimize and clean up:
// Refactored version async hashPassword(password, rounds = 10) { if (!password || password.length < 8) { throw new Error('Invalid password'); } const salt = await bcrypt.genSalt(rounds); return bcrypt.hash(password, salt); }
Step 5: Integration Testing
Test the complete system:
../claude-flow sparc run integration \
"Test authentication system integration:
- API endpoints
- Database operations
- Token validation
- Error handling"
Step 6: Security Review
Ensure security best practices:
../claude-flow sparc run security-review \
"Review authentication system for:
- OWASP compliance
- SQL injection
- XSS vulnerabilities
- Token security"
Advanced SPARC Features
Parallel Mode Execution
Run multiple SPARC modes simultaneously:
../claude-flow sparc run parallel \
--modes "spec-pseudocode,architect,code" \
"Create payment processing system"
Memory Integration
Store and retrieve SPARC artifacts:
# Store specifications
../claude-flow memory store auth_spec "$(cat ./output/auth-spec.md)"
# Retrieve for future work
../claude-flow memory query auth_spec > ./restored-spec.md
Custom Test Patterns
Define test templates:
../claude-flow sparc tdd \
"Create user service" \
--test-pattern "AAA" \ # Arrange-Act-Assert
--coverage-threshold 90
Best Practices
1. Specification Quality
- Be specific about requirements
- Include error scenarios
- Define performance criteria
- Document security needs
2. TDD Discipline
- Always write tests first
- One test at a time
- Keep tests simple
- Test behavior, not implementation
3. Architecture Decisions
- Document why, not just what
- Consider scalability early
- Plan for change
- Keep it simple
4. Integration Points
- Test boundaries thoroughly
- Mock external services
- Verify error propagation
- Check edge cases
Common Patterns
Authentication Flow
../claude-flow sparc tdd "implement login flow" \
--pattern "request-validate-authenticate-respond"
CRUD Operations
../claude-flow sparc tdd "implement user CRUD" \
--pattern "rest-api" \
--with-validation
Event-Driven Systems
../claude-flow sparc tdd "implement event handlers" \
--pattern "pub-sub" \
--async
Troubleshooting
Tests Not Running
- Check test file naming (*.test.js)
- Verify test runner configuration
- Ensure dependencies installed
Coverage Too Low
- Add edge case tests
- Test error conditions
- Cover all branches
Integration Failures
- Check service dependencies
- Verify environment variables
- Test in isolation first
Summary
You've learned:
- ✅ SPARC methodology phases
- ✅ TDD implementation cycle
- ✅ Integration and security testing
- ✅ Best practices and patterns
Next Steps
- Try building a complete feature with SPARC
- Explore other SPARC modes
- Create custom test patterns
- Integrate with CI/CD
Continue to Advanced SPARC Patterns