API Development Orchestration Workflow
Complete REST API development workflow using Test-Driven Development and multi-agent coordination. Orchestrates 8-12 specialist agents across planning, architecture design, TDD implementation, testing, documentation, and production deployment in a systematic 2-week process.
Overview
This SOP implements a comprehensive API development workflow emphasizing quality through Test-Driven Development (TDD). The workflow balances speed with thoroughness, using hierarchical coordination for planning phases and parallel execution for development and testing. Each phase produces validated deliverables that subsequent phases consume, ensuring continuity and traceability.
The TDD approach ensures high test coverage (>90%), reduces bugs, and produces well-designed, maintainable code. Parallel execution of specialized reviews accelerates quality validation while maintaining comprehensive coverage of security, performance, and architectural concerns.
Trigger Conditions
Use this workflow when:
- Building a new REST API or microservice from scratch
- Migrating existing API to modern architecture with comprehensive testing
- Need systematic TDD approach with documented test coverage
- Require production-ready API with security, performance, and scalability validation
- Timeline is 2-4 weeks with clear milestones and deliverables
- Quality gates (testing, security, performance) are non-negotiable
- Need comprehensive API documentation and operational runbooks
Orchestrated Agents (12 Total)
Planning & Architecture Agents
product-manager - Requirements gathering, endpoint definition, API contracts, success criteria
system-architect - API architecture design, RESTful patterns, versioning, error handling strategy
database-architect - Schema design, query optimization, indexing, migration planning
qa-engineer - Test planning, TDD strategy, coverage targets, performance benchmarks
Development Agents (TDD Cycle)
tester - Write tests first (red phase), integration tests, E2E scenarios
backend-developer - Implement to pass tests (green phase), refactor for quality
code-reviewer - Code quality review, refactoring suggestions, best practices validation
Quality & Validation Agents
security-specialist - Security architecture, OWASP validation, penetration testing
performance-analyst - Load testing, stress testing, bottleneck identification, optimization
api-documentation-specialist - OpenAPI specs, developer guides, code examples
Deployment & Operations Agents
devops-engineer - CI/CD pipeline, Docker/K8s deployment, infrastructure as code
production-validator - Pre-production validation, go/no-go decision, smoke testing
performance-monitor - Production monitoring, logging, alerting, SLO tracking
Workflow Phases
Phase 1: Planning & Design (Days 1-2, Sequential)
Duration: 2 days
Execution Mode: Sequential analysis and design
Agents: product-manager, system-architect, database-architect, qa-engineer
Process:
Gather API Requirements (Day 1 Morning)
npx claude-flow hooks pre-task --description "API Development: ${API_NAME}"
npx claude-flow swarm init --topology hierarchical --max-agents 12 --strategy specialized
npx claude-flow agent spawn --type planner
Product Manager defines:
- Complete endpoint list with HTTP methods (GET, POST, PUT, DELETE, PATCH)
- Data models and relationships (entities, attributes, cardinality)
- Authentication and authorization requirements (OAuth, JWT, RBAC)
- Rate limiting and quota specifications
- Third-party integrations and external dependencies
- API versioning strategy (URL path, header, content negotiation)
- Success metrics and SLAs (response time, uptime, throughput)
Memory Storage:
npx claude-flow memory store --key "api-development/${API_ID}/phase-1/product-manager/requirements" \
--value "${REQUIREMENTS_JSON}"
Design API Architecture (Day 1 Afternoon)
npx claude-flow memory retrieve --key "api-development/${API_ID}/phase-1/product-manager/requirements"
npx claude-flow agent spawn --type system-architect
System Architect designs:
- RESTful API structure following Richardson Maturity Model
- URL patterns and resource naming conventions
- Request/response formats with JSON schemas
- Error handling patterns (error codes, messages, stack traces)
- Pagination, filtering, sorting, and search strategies
- Caching strategy (ETags, cache-control headers)
- API security architecture (authentication flow, token management)
- Versioning and backward compatibility approach
Generate OpenAPI 3.0 specification:
npx claude-flow memory store --key "api-development/${API_ID}/phase-1/system-architect/openapi-spec" \
--value "${OPENAPI_YAML}"
Design Database Schema (Day 2 Morning)
npx claude-flow memory retrieve --key "api-development/${API_ID}/phase-1/system-architect/openapi-spec"
npx claude-flow agent spawn --type code-analyzer
Database Architect creates:
- Normalized schema design (3NF) with entity-relationship diagram
- Table definitions (columns, data types, constraints, defaults)
- Relationships and foreign key constraints
- Indexes for query performance (primary, secondary, composite)
- Migration scripts (up and down migrations)
- Backup and recovery strategy
- Scaling strategy (sharding, replication, read replicas)
Generate SQL schema and migrations:
npx claude-flow memory store --key "api-development/${API_ID}/phase-1/database-architect/schema" \
--value "${SCHEMA_SQL}"
npx claude-flow memory store --key "api-development/${API_ID}/phase-1/database-architect/migrations"
Create Test Strategy (Day 2 Afternoon)
npx claude-flow memory retrieve --pattern "api-development/${API_ID}/phase-1/*"
npx claude-flow agent spawn --type tester
QA Engineer plans:
- Unit test strategy (per endpoint, per function)
- Integration test scenarios (database, external APIs)
- End-to-end test workflows (complete user journeys)
- Performance test targets (load, stress, endurance)
- Security test cases (OWASP API Security Top 10)
- Test data management (fixtures, factories, mocks)
- Coverage targets (>90% for new code)
- CI/CD test automation strategy
Memory Storage:
npx claude-flow memory store --key "api-development/${API_ID}/phase-1/qa-engineer/test-plan"
npx claude-flow hooks post-task --task-id "phase-1-planning"
Outputs:
- API requirements document with complete endpoint specifications
- OpenAPI 3.0 specification (machine-readable contract)
- Database schema with ER diagram and migrations
- Comprehensive test plan with coverage targets
- DevOps plan with infrastructure requirements
Success Criteria:
Phase 2: Foundation Setup (Days 3-4, Parallel)
Duration: 2 days
Execution Mode: Parallel infrastructure setup
Agents: backend-developer, database-architect, devops-engineer
Process:
Initialize Development Environment
npx claude-flow swarm init --topology mesh --max-agents 3 --strategy adaptive
npx claude-flow task orchestrate --strategy parallel
Parallel Setup Execution
Spawn all setup agents concurrently:
# Backend project setup
npx claude-flow agent spawn --type backend-dev --capabilities "nodejs,typescript,express"
# Database setup
npx claude-flow agent spawn --type code-analyzer --capabilities "postgresql,prisma,migrations"
# CI/CD setup
npx claude-flow agent spawn --type cicd-engineer --capabilities "github-actions,docker,testing"
Backend Developer initializes:
- Node.js/Express (or FastAPI/Flask/Spring Boot) project
- TypeScript configuration (strict mode, path aliases)
- ESLint + Prettier (code quality and formatting)
- Environment variable management (dotenv, validation)
- Dependency installation (express, prisma, jest, supertest, etc.)
- Project structure (controllers, services, models, middleware)
- Logging framework (Winston, Pino) with structured logging
- Error handling middleware (global error handler)
Memory Pattern: api-development/${API_ID}/phase-2/backend-developer/project-setup
Database Architect sets up:
- PostgreSQL database (or MySQL/MongoDB)
- Connection pooling configuration (pg-pool, connection limits)
- Initial migration execution (create tables, indexes)
- Seed data for development and testing
- Database backup scripts (pg_dump automation)
- Performance monitoring queries (slow query log)
Memory Pattern: api-development/${API_ID}/phase-2/database-architect/db-config
DevOps Engineer configures:
- GitHub Actions workflow (or GitLab CI/Jenkins)
- Docker containers (multi-stage builds for optimization)
- Docker Compose for local development
- Environment secrets management (GitHub Secrets, Vault)
- Automated testing pipeline (run tests on PR)
- Code quality checks (linting, type checking)
- Build artifact generation and storage
Memory Pattern: api-development/${API_ID}/phase-2/devops-engineer/ci-config
Coordination Script:
npx claude-flow hooks post-edit --file "package.json" \
--memory-key "api-development/${API_ID}/phase-2/setup-complete"
npx claude-flow hooks notify --message "Development environment ready"
Outputs:
- Initialized project with all dependencies
- Database with schema and seed data
- CI/CD pipeline operational
- Development environment fully functional
Success Criteria:
Phase 3: TDD Implementation (Days 5-10, Red-Green-Refactor Cycle)
Duration: 6 days
Execution Mode: Iterative TDD cycles per endpoint
Agents: tester, backend-developer, code-reviewer
Process:
This phase follows strict Test-Driven Development:
- RED: Write failing tests (tester agent)
- GREEN: Implement code to pass tests (backend-developer agent)
- REFACTOR: Improve code quality (code-reviewer agent)
TDD Cycle Example (POST /api/auth/register endpoint):
RED Phase: Write Failing Tests (30-60 min per endpoint)
npx claude-flow agent spawn --type tester
Tester Agent writes:
// Unit tests
describe('POST /api/auth/register', () => {
test('should register user with valid email and password', async () => {
const response = await request(app)
.post('/api/auth/register')
.send({ email: 'user@example.com', password: 'SecurePass123!' });
expect(response.status).toBe(201);
expect(response.body).toHaveProperty('token');
expect(response.body.user.email).toBe('user@example.com');
});
test('should reject duplicate email registration', async () => {
// Create user first
await createUser({ email: 'existing@example.com' });
const response = await request(app)
.post('/api/auth/register')
.send({ email: 'existing@example.com', password: 'Pass123!' });
expect(response.status).toBe(409);
expect(response.body.error).toContain('Email already exists');
});
test('should validate password strength', async () => {
const response = await request(app)
.post('/api/auth/register')
.send({ email: 'user@example.com', password: 'weak' });
expect(response.status).toBe(400);
expect(response.body.error).toContain('Password must be at least 8 characters');
});
test('should validate email format', async () => {
const response = await request(app)
.post('/api/auth/register')
.send({ email: 'invalid-email', password: 'SecurePass123!' });
expect(response.status).toBe(400);
expect(response.body.error).toContain('Invalid email format');
});
});
// Integration tests
describe('User Registration Integration', () => {
test('should create user in database', async () => {
const response = await request(app)
.post('/api/auth/register')
.send({ email: 'dbtest@example.com', password: 'Pass123!' });
const userInDb = await db.user.findUnique({ where: { email: 'dbtest@example.com' } });
expect(userInDb).toBeDefined();
expect(userInDb.passwordHash).not.toBe('Pass123!'); // Password should be hashed
});
});
Memory Storage:
npx claude-flow memory store --key "api-development/${API_ID}/phase-3/tester/auth/register-tests" \
--value "${TEST_FILE_CONTENT}"
GREEN Phase: Implement to Pass Tests (1-2 hours per endpoint)
npx claude-flow memory retrieve --key "api-development/${API_ID}/phase-3/tester/auth/register-tests"
npx claude-flow agent spawn --type backend-dev
Backend Developer implements:
// POST /api/auth/register implementation
router.post('/register', async (req, res, next) => {
try {
// Validate input
const { email, password } = req.body;
if (!isValidEmail(email)) {
return res.status(400).json({ error: 'Invalid email format' });
}
if (password.length < 8) {
return res.status(400).json({ error: 'Password must be at least 8 characters' });
}
// Check for duplicate email
const existingUser = await db.user.findUnique({ where: { email } });
if (existingUser) {
return res.status(409).json({ error: 'Email already exists' });
}
// Hash password
const passwordHash = await bcrypt.hash(password, 10);
// Create user
const user = await db.user.create({
data: { email, passwordHash }
});
// Generate JWT token
const token = jwt.sign({ userId: user.id }, process.env.JWT_SECRET, { expiresIn: '7d' });
res.status(201).json({
token,
user: { id: user.id, email: user.email }
});
} catch (error) {
next(error);
}
});
Run tests and verify all pass:
npm test -- auth/register.test.js
# All tests should pass (GREEN)
Memory Storage:
npx claude-flow memory store --key "api-development/${API_ID}/phase-3/backend-developer/auth/register-impl"
REFACTOR Phase: Improve Code Quality (30 min per endpoint)
npx claude-flow memory retrieve --pattern "api-development/${API_ID}/phase-3/*/auth/register-*"
npx claude-flow agent spawn --type reviewer
Code Reviewer evaluates:
- Code readability and clarity
- Duplication (extract validation to middleware)
- Security best practices (password hashing, JWT signing)
- Error handling completeness
- Performance optimizations
Suggests refactoring:
// Extracted validation middleware
const validateRegistration = (req, res, next) => {
const { email, password } = req.body;
if (!isValidEmail(email)) {
return res.status(400).json({ error: 'Invalid email format' });
}
if (password.length < 8) {
return res.status(400).json({ error: 'Password must be at least 8 characters' });
}
next();
};
// Cleaner route handler
router.post('/register', validateRegistration, async (req, res, next) => {
try {
const user = await authService.registerUser(req.body);
const token = authService.generateToken(user.id);
res.status(201).json({ token, user });
} catch (error) {
if (error.code === 'DUPLICATE_EMAIL') {
return res.status(409).json({ error: 'Email already exists' });
}
next(error);
}
});
Memory Storage:
npx claude-flow memory store --key "api-development/${API_ID}/phase-3/code-reviewer/auth/register-review"
npx claude-flow hooks post-edit --file "src/routes/auth.ts"
Repeat TDD Cycle for All Endpoints (Days 5-10)
Apply RED-GREEN-REFACTOR to all endpoints:
- Authentication (register, login, logout, refresh, reset-password)
- CRUD operations (create, read, update, delete for all resources)
- Search and filtering
- Pagination and sorting
- File uploads (if applicable)
- Webhooks (if applicable)
Progress Tracking:
npx claude-flow memory store --key "api-development/${API_ID}/phase-3/progress" \
--value '{"completed_endpoints": 12, "total_endpoints": 20, "coverage": 93.5}'
Outputs:
- All API endpoints implemented
- Comprehensive test suite with >90% coverage
- Refactored, clean, maintainable code
- All tests passing (green)
Success Criteria:
Phase 4: Testing & Documentation (Days 11-12, Parallel)
Duration: 2 days
Execution Mode: Parallel validation across multiple dimensions
Agents: qa-engineer, security-specialist, performance-analyst, api-documentation-specialist
Process:
Initialize Testing Swarm
npx claude-flow swarm init --topology star --max-agents 4 --strategy specialized
npx claude-flow task orchestrate --strategy parallel --priority high
Parallel Testing Execution
Spawn all testing agents concurrently:
# E2E testing
npx claude-flow agent spawn --type tester --focus "end-to-end"
# Performance testing
npx claude-flow agent spawn --type perf-analyzer --focus "load-stress-endurance"
# Security testing
npx claude-flow agent spawn --type security-manager --focus "owasp-penetration"
# Documentation
npx claude-flow agent spawn --type api-docs --focus "openapi-developer-guide"
QA Engineer conducts:
- End-to-End Testing: Complete user workflows (register → login → CRUD → logout)
- Error Scenario Testing: Invalid inputs, unauthorized access, rate limiting
- Edge Case Testing: Boundary conditions, null values, concurrent requests
- Smoke Testing: Basic functionality across all endpoints
Memory Pattern: api-development/${API_ID}/phase-4/qa-engineer/e2e-results
Performance Analyst tests:
- Load Testing: 1000 req/sec sustained for 10 minutes (target)
- Stress Testing: Find breaking point (max throughput)
- Endurance Testing: 24-hour sustained load for memory leaks
- Spike Testing: Sudden traffic spikes (10x normal load)
- Bottleneck Identification: Database queries, API calls, CPU/memory usage
Tools: k6, Apache JMeter, Gatling
Memory Pattern: api-development/${API_ID}/phase-4/performance-analyst/benchmarks
Security Specialist validates:
- OWASP API Security Top 10:
- Broken Object Level Authorization (BOLA)
- Broken Authentication
- Broken Object Property Level Authorization
- Unrestricted Resource Consumption
- Broken Function Level Authorization (BFLA)
- Unrestricted Access to Sensitive Business Flows
- Server Side Request Forgery (SSRF)
- Security Misconfiguration
- Improper Inventory Management
- Unsafe Consumption of APIs
- SQL injection testing (automated + manual)
- XSS vulnerability scanning
- Authentication bypass attempts
- Rate limiting validation
- Secrets scanning (no hardcoded credentials)
Tools: OWASP ZAP, Burp Suite, Snyk
Memory Pattern: api-development/${API_ID}/phase-4/security-specialist/audit-report
API Documentation Specialist creates:
- OpenAPI/Swagger UI: Interactive API documentation
- Authentication Guide: How to obtain and use tokens
- Endpoint Reference: All endpoints with parameters, responses, errors
- Code Examples: cURL, JavaScript, Python, Java SDK examples
- Rate Limiting Guide: Quota limits and header interpretations
- Error Handling Guide: Error codes, messages, troubleshooting
- Developer Getting Started: Quick start tutorial
- Changelog: Versioning and breaking changes
Memory Pattern: api-development/${API_ID}/phase-4/api-documentation-specialist/docs
DevOps Runbook (Parallel with documentation)
npx claude-flow agent spawn --type cicd-engineer --focus "operations"
DevOps Engineer documents:
- Deployment procedures (step-by-step)
- Monitoring and alerting setup (Grafana, Prometheus)
- Troubleshooting guide (common issues, solutions)
- Performance tuning (database, caching, scaling)
- Backup and recovery procedures
- Incident response plan (runbook)
- Rollback procedures
Memory Pattern: api-development/${API_ID}/phase-4/devops-engineer/runbook
Outputs:
- E2E test results (all passing)
- Performance benchmark report (meets targets)
- Security audit report (no critical issues)
- Complete API documentation (developer-ready)
- Operations runbook (deployment-ready)
Success Criteria:
Phase 5: Deployment & Monitoring (Days 13-14, Sequential → Continuous)
Duration: 2 days + ongoing monitoring
Execution Mode: Sequential deployment with validation gates
Agents: production-validator, devops-engineer, performance-monitor
Process:
Pre-Production Validation (Day 13 Morning)
npx claude-flow hooks pre-task --description "Final production validation"
npx claude-flow agent spawn --type production-validator
Production Validator checks:
- All Tests Passing: 100% of test suite (unit + integration + E2E)
- Code Coverage: >90% verified
- Security Audit: Passed with zero critical/high issues
- Performance Benchmarks: All targets met or exceeded
- Documentation: Complete and published
- Monitoring Setup: Dashboards and alerts configured
- Rollback Plan: Documented and rehearsed
Generate go/no-go report:
npx claude-flow memory store --key "api-development/${API_ID}/phase-5/production-validator/go-no-go" \
--value '{"decision": "GO", "readiness_score": 98, "blockers": []}'
If any validation fails:
# Return to appropriate phase to fix issues
npx claude-flow hooks notify --message "Production validation FAILED: ${BLOCKER_ISSUES}"
# Halt deployment until issues resolved
Staging Deployment (Day 13 Afternoon)
npx claude-flow agent spawn --type cicd-engineer
DevOps Engineer deploys to staging:
# Deploy API to staging environment
kubectl apply -f k8s/staging/
# Run smoke tests
npm run test:smoke -- --env=staging
# Validate monitoring
curl https://api-staging.example.com/health
Staging Validation:
- Full test suite execution against staging
- Data persistence verification
- Error handling validation
- Monitoring dashboard validation
- Load balancer health checks
Memory Storage:
npx claude-flow memory store --key "api-development/${API_ID}/phase-5/devops-engineer/staging-deploy"
Production Deployment (Day 14 Morning - Blue-Green Strategy)
npx claude-flow workflow create --name "production-deployment" \
--steps '["blue-green-deploy","canary-rollout","full-rollout","monitor"]'
DevOps Engineer executes:
# Step 1: Deploy to green environment (alongside blue)
kubectl apply -f k8s/production/green/
# Step 2: Run smoke tests on green
npm run test:smoke -- --env=production-green
# Step 3: Gradual traffic shift (canary rollout)
# 10% traffic to green
kubectl patch service api-service -p '{"spec":{"selector":{"version":"green","weight":"10"}}}'
sleep 300 # Monitor for 5 minutes
# 50% traffic to green
kubectl patch service api-service -p '{"spec":{"selector":{"version":"green","weight":"50"}}}'
sleep 600 # Monitor for 10 minutes
# 100% traffic to green
kubectl patch service api-service -p '{"spec":{"selector":{"version":"green","weight":"100"}}}'
# Step 4: Keep blue environment ready for rollback (for 24 hours)
Rollback Procedure (if issues detected):
# Instant rollback to blue
kubectl patch service api-service -p '{"spec":{"selector":{"version":"blue","weight":"100"}}}'
Memory Storage:
npx claude-flow memory store --key "api-development/${API_ID}/phase-5/devops-engineer/production-deploy" \
--value '{"status": "SUCCESS", "deployment_time": "2025-01-15T10:00:00Z", "version": "v1.0.0"}'
Post-Deployment Monitoring (Day 14 Afternoon + Ongoing)
npx claude-flow agent spawn --type performance-monitor
Performance Monitor tracks:
- Application Metrics:
- API response time (p50, p95, p99)
- Throughput (requests per second)
- Error rate (4xx, 5xx errors)
- Uptime and availability
- Infrastructure Metrics:
- CPU and memory utilization
- Database connection pool usage
- Cache hit ratio
- Network throughput
- Business Metrics:
- API usage by endpoint
- User activity patterns
- Rate limit violations
- Authentication success/failure rates
Generate hourly reports for first 24 hours:
npx claude-flow hooks post-task --task-id "production-monitoring" --export-metrics true
npx claude-flow memory store --key "api-development/${API_ID}/phase-5/performance-monitor/metrics/hour-${HOUR}"
Alert Configuration:
- Response time > 500ms (p95): WARNING
- Response time > 1000ms (p95): CRITICAL
- Error rate > 1%: WARNING
- Error rate > 5%: CRITICAL
- Uptime < 99.9%: CRITICAL
- Database connection pool > 80%: WARNING
Documentation Publication (Day 14)
npx claude-flow agent spawn --type api-docs
Update Final Documentation:
- Production API URLs and endpoints
- Authentication endpoints (production)
- Monitoring dashboards (link to Grafana)
- Support contact information
- SLA and uptime guarantees
Publish to developer portal:
npm run docs:publish -- --env=production
Knowledge Transfer (End of Phase 5)
npx claude-flow hooks session-end --export-workflow "/tmp/${API_ID}-workflow.json"
Create handoff materials:
- Developer onboarding guide
- Support team training materials
- Common issues and troubleshooting
- Escalation procedures
Memory Storage:
npx claude-flow memory store --key "api-development/${API_ID}/phase-5/knowledge-transfer/complete"
Outputs:
- Production API (live and stable)
- Complete documentation (published to developer portal)
- Monitoring dashboards (real-time metrics)
- Trained support team (ready for inquiries)
- Workflow documentation (for future reference)
Success Criteria:
Memory Coordination
Namespace Convention
All workflow data follows this hierarchical pattern:
api-development/{api-id}/phase-{N}/{agent-type}/{deliverable-type}
Examples:
api-development/user-api-v1/phase-1/product-manager/requirements
api-development/user-api-v1/phase-1/system-architect/openapi-spec
api-development/user-api-v1/phase-2/backend-developer/project-setup
api-development/user-api-v1/phase-3/tester/auth/register-tests
api-development/user-api-v1/phase-4/security-specialist/audit-report
api-development/user-api-v1/phase-5/devops-engineer/production-deploy
Cross-Phase Data Flow
Phase 1 → Phase 2:
# Phase 2 retrieves design specifications
npx claude-flow memory retrieve --key "api-development/${API_ID}/phase-1/system-architect/openapi-spec"
npx claude-flow memory retrieve --key "api-development/${API_ID}/phase-1/database-architect/schema"
Phase 2 → Phase 3:
# Phase 3 retrieves project structure and test plan
npx claude-flow memory retrieve --key "api-development/${API_ID}/phase-2/backend-developer/project-setup"
npx claude-flow memory retrieve --key "api-development/${API_ID}/phase-1/qa-engineer/test-plan"
Phase 3 → Phase 4:
# Phase 4 retrieves implementation for testing
npx claude-flow memory retrieve --pattern "api-development/${API_ID}/phase-3/backend-developer/*"
Phase 4 → Phase 5:
# Phase 5 retrieves test results and documentation
npx claude-flow memory retrieve --pattern "api-development/${API_ID}/phase-4/*/results"
Scripts & Automation
Pre-Workflow Initialization
#!/bin/bash
# Initialize API development workflow
API_NAME="$1"
API_ID="${API_NAME}-api-$(date +%Y%m%d)"
# Setup coordination
npx claude-flow hooks pre-task --description "API Development: ${API_NAME}"
# Initialize hierarchical swarm (12 agents max)
npx claude-flow swarm init --topology hierarchical --max-agents 12 --strategy specialized
# Store API metadata
npx claude-flow memory store --key "api-development/${API_ID}/metadata" --value '{
"api_name": "'"${API_NAME}"'",
"api_id": "'"${API_ID}"'",
"start_date": "'"$(date -I)"'",
"timeline_days": 14,
"phases": 5,
"tdd_approach": true
}'
echo "✅ API development initialized: ${API_ID}"
TDD Cycle Script
#!/bin/bash
# Execute TDD cycle for single endpoint
API_ID="$1"
ENDPOINT_PATH="$2" # e.g., "POST /api/auth/register"
echo "🔴 RED Phase: Writing tests for ${ENDPOINT_PATH}"
npx claude-flow agent spawn --type tester --task "write-tests:${ENDPOINT_PATH}"
# Wait for tests to be written
npx claude-flow memory retrieve --key "api-development/${API_ID}/phase-3/tester/${ENDPOINT_PATH}/tests"
echo "🟢 GREEN Phase: Implementing ${ENDPOINT_PATH}"
npx claude-flow agent spawn --type backend-dev --task "implement:${ENDPOINT_PATH}"
# Run tests to verify implementation
npm test -- "${ENDPOINT_PATH}.test.js"
echo "🔵 REFACTOR Phase: Code review for ${ENDPOINT_PATH}"
npx claude-flow agent spawn --type reviewer --task "review:${ENDPOINT_PATH}"
# Store completion
npx claude-flow hooks post-edit --file "src/routes/${ENDPOINT_PATH}.ts" \
--memory-key "api-development/${API_ID}/phase-3/completed/${ENDPOINT_PATH}"
Deployment Script
#!/bin/bash
# Blue-green deployment to production
API_ID="$1"
VERSION="$2"
echo "🚀 Starting blue-green deployment: ${VERSION}"
# Pre-deployment validation
npx claude-flow agent spawn --type production-validator
VALIDATION=$(npx claude-flow memory retrieve --key "api-development/${API_ID}/phase-5/production-validator/go-no-go")
if [ "$(echo $VALIDATION | jq -r '.decision')" != "GO" ]; then
echo "❌ Production validation FAILED. Aborting deployment."
exit 1
fi
# Deploy to green environment
kubectl apply -f k8s/production/green/
# Smoke tests
npm run test:smoke -- --env=production-green
# Gradual traffic shift (canary)
for WEIGHT in 10 50 100; do
echo "Shifting ${WEIGHT}% traffic to green..."
kubectl patch service api-service -p "{\"spec\":{\"selector\":{\"version\":\"green\",\"weight\":\"${WEIGHT}\"}}}"
# Monitor for issues (5-10 minutes per step)
DURATION=$((WEIGHT == 100 ? 10 : 5))
sleep $((DURATION * 60))
# Check error rate
ERROR_RATE=$(curl -s https://monitoring.example.com/api/error-rate | jq -r '.rate')
if (( $(echo "$ERROR_RATE > 1.0" | bc -l) )); then
echo "❌ High error rate detected: ${ERROR_RATE}%. Rolling back."
kubectl patch service api-service -p '{"spec":{"selector":{"version":"blue","weight":"100"}}}'
exit 1
fi
done
echo "✅ Deployment complete: ${VERSION}"
npx claude-flow hooks post-task --task-id "production-deployment" --export-metrics true
Success Metrics
Technical Metrics
- Test Coverage: > 90% (code coverage report)
- API Response Time: < 200ms (p95)
- Uptime: 99.9%+ (production SLA)
- Error Rate: < 0.1% (4xx + 5xx errors)
- Code Quality Score: A rating (SonarQube/CodeClimate)
- Security Audit: Zero critical, zero high issues
Performance Metrics
- Throughput: > 1000 req/sec sustained
- Database Query Time: < 50ms (p95)
- Memory Usage: < 512MB per instance
- CPU Usage: < 70% under normal load
Quality Metrics
- TDD Adherence: 100% (all endpoints test-first)
- Documentation Coverage: 100% of endpoints documented
- API Compliance: OpenAPI 3.0 valid (no errors)
- Code Review Approval: 100% (all code reviewed)
Usage Examples
Example 1: User Management API
# Initialize workflow
API_ID="user-management-api-20250115"
npx claude-flow hooks pre-task --description "User Management API Development"
# Phase 1: Planning (Day 1-2)
npx claude-flow agent spawn --type planner
# Output: 15 endpoints defined, authentication strategy established
# Phase 3: TDD Implementation (Day 5-10)
for endpoint in "POST /api/users/register" "POST /api/users/login" "GET /api/users/:id"; do
./tdd-cycle.sh "${API_ID}" "${endpoint}"
done
# Output: All endpoints implemented with 94% test coverage
# Phase 5: Production Deployment (Day 14)
./deploy-production.sh "${API_ID}" "v1.0.0"
# Output: Deployed successfully, handling 1500 req/sec with 99.95% uptime
Example 2: Payment Gateway API
# High-security API with PCI compliance
API_ID="payment-gateway-api-20250120"
# Phase 1: Enhanced security planning
npx claude-flow agent spawn --type system-architect --focus "pci-compliance"
npx claude-flow agent spawn --type security-specialist --focus "payment-security"
# Output: PCI DSS compliant architecture designed
# Phase 4: Enhanced security testing
npx claude-flow agent spawn --type security-manager --focus "penetration-testing-comprehensive"
# Output: Zero vulnerabilities, PCI DSS validation passed
Example 3: Microservice API (Event-Driven)
# Microservice with message queue integration
API_ID="order-service-api-20250125"
# Phase 2: Message queue setup
npx claude-flow agent spawn --type backend-dev --capabilities "rabbitmq,events"
# Output: Event-driven architecture with pub/sub patterns
# Phase 3: Event handler TDD
./tdd-cycle.sh "${API_ID}" "POST /api/orders/create"
./tdd-cycle.sh "${API_ID}" "EVENT order.created"
# Output: Synchronous API + asynchronous event processing
GraphViz Process Diagram
See when-building-backend-api-orchestrate-api-development-process.dot for visual workflow representation showing:
- 5 phases with TDD cycle details
- 12 agent interactions and coordination
- Memory flow between phases
- Blue-green deployment strategy
- Validation gates and decision points
Quality Checklist
Before considering API development complete, verify:
Memory Verification:
Workflow Complexity: Medium (12 agents, 14 days, 5 phases)
Coordination Pattern: Hierarchical with TDD cycle iteration
Memory Footprint: ~30-50 memory entries per API
Typical Use Case: Production-ready REST API with comprehensive testing and quality gates
1---2name: when-building-backend-api-orchestrate-api-development3type: sop-workflow4description: |5 Use when building a production-ready REST API from requirements through deployment.6 Orchestrates 8-12 specialist agents across 5 phases using Test-Driven Development methodology.7 Covers planning, architecture, TDD implementation, comprehensive testing, documentation, and8 blue-green deployment over a 2-week timeline with emphasis on quality and reliability.9agents:10 - product-manager11 - system-architect12 - database-architect13 - qa-engineer14 - backend-developer15 - security-specialist16 - performance-analyst17 - api-documentation-specialist18 - devops-engineer19 - production-validator20 - performance-monitor21 - code-reviewer22phases: 523memory_pattern: "api-development/{api-id}/phase-{N}/{agent}/{deliverable}"24---2526# API Development Orchestration Workflow2728Complete REST API development workflow using Test-Driven Development and multi-agent coordination. Orchestrates 8-12 specialist agents across planning, architecture design, TDD implementation, testing, documentation, and production deployment in a systematic 2-week process.2930## Overview3132This SOP implements a comprehensive API development workflow emphasizing quality through Test-Driven Development (TDD). The workflow balances speed with thoroughness, using hierarchical coordination for planning phases and parallel execution for development and testing. Each phase produces validated deliverables that subsequent phases consume, ensuring continuity and traceability.3334The TDD approach ensures high test coverage (>90%), reduces bugs, and produces well-designed, maintainable code. Parallel execution of specialized reviews accelerates quality validation while maintaining comprehensive coverage of security, performance, and architectural concerns.3536## Trigger Conditions3738Use this workflow when:39- Building a new REST API or microservice from scratch40- Migrating existing API to modern architecture with comprehensive testing41- Need systematic TDD approach with documented test coverage42- Require production-ready API with security, performance, and scalability validation43- Timeline is 2-4 weeks with clear milestones and deliverables44- Quality gates (testing, security, performance) are non-negotiable45- Need comprehensive API documentation and operational runbooks4647## Orchestrated Agents (12 Total)4849### Planning & Architecture Agents50- **`product-manager`** - Requirements gathering, endpoint definition, API contracts, success criteria51- **`system-architect`** - API architecture design, RESTful patterns, versioning, error handling strategy52- **`database-architect`** - Schema design, query optimization, indexing, migration planning53- **`qa-engineer`** - Test planning, TDD strategy, coverage targets, performance benchmarks5455### Development Agents (TDD Cycle)56- **`tester`** - Write tests first (red phase), integration tests, E2E scenarios57- **`backend-developer`** - Implement to pass tests (green phase), refactor for quality58- **`code-reviewer`** - Code quality review, refactoring suggestions, best practices validation5960### Quality & Validation Agents61- **`security-specialist`** - Security architecture, OWASP validation, penetration testing62- **`performance-analyst`** - Load testing, stress testing, bottleneck identification, optimization63- **`api-documentation-specialist`** - OpenAPI specs, developer guides, code examples6465### Deployment & Operations Agents66- **`devops-engineer`** - CI/CD pipeline, Docker/K8s deployment, infrastructure as code67- **`production-validator`** - Pre-production validation, go/no-go decision, smoke testing68- **`performance-monitor`** - Production monitoring, logging, alerting, SLO tracking6970## Workflow Phases7172### Phase 1: Planning & Design (Days 1-2, Sequential)7374**Duration**: 2 days75**Execution Mode**: Sequential analysis and design76**Agents**: `product-manager`, `system-architect`, `database-architect`, `qa-engineer`7778**Process**:79801. **Gather API Requirements** (Day 1 Morning)81 ```bash82 npx claude-flow hooks pre-task --description "API Development: ${API_NAME}"83 npx claude-flow swarm init --topology hierarchical --max-agents 12 --strategy specialized84 npx claude-flow agent spawn --type planner85 ```8687 **Product Manager** defines:88 - Complete endpoint list with HTTP methods (GET, POST, PUT, DELETE, PATCH)89 - Data models and relationships (entities, attributes, cardinality)90 - Authentication and authorization requirements (OAuth, JWT, RBAC)91 - Rate limiting and quota specifications92 - Third-party integrations and external dependencies93 - API versioning strategy (URL path, header, content negotiation)94 - Success metrics and SLAs (response time, uptime, throughput)9596 **Memory Storage**:97 ```bash98 npx claude-flow memory store --key "api-development/${API_ID}/phase-1/product-manager/requirements" \99 --value "${REQUIREMENTS_JSON}"100 ```1011022. **Design API Architecture** (Day 1 Afternoon)103 ```bash104 npx claude-flow memory retrieve --key "api-development/${API_ID}/phase-1/product-manager/requirements"105 npx claude-flow agent spawn --type system-architect106 ```107108 **System Architect** designs:109 - RESTful API structure following Richardson Maturity Model110 - URL patterns and resource naming conventions111 - Request/response formats with JSON schemas112 - Error handling patterns (error codes, messages, stack traces)113 - Pagination, filtering, sorting, and search strategies114 - Caching strategy (ETags, cache-control headers)115 - API security architecture (authentication flow, token management)116 - Versioning and backward compatibility approach117118 Generate OpenAPI 3.0 specification:119 ```bash120 npx claude-flow memory store --key "api-development/${API_ID}/phase-1/system-architect/openapi-spec" \121 --value "${OPENAPI_YAML}"122 ```1231243. **Design Database Schema** (Day 2 Morning)125 ```bash126 npx claude-flow memory retrieve --key "api-development/${API_ID}/phase-1/system-architect/openapi-spec"127 npx claude-flow agent spawn --type code-analyzer128 ```129130 **Database Architect** creates:131 - Normalized schema design (3NF) with entity-relationship diagram132 - Table definitions (columns, data types, constraints, defaults)133 - Relationships and foreign key constraints134 - Indexes for query performance (primary, secondary, composite)135 - Migration scripts (up and down migrations)136 - Backup and recovery strategy137 - Scaling strategy (sharding, replication, read replicas)138139 Generate SQL schema and migrations:140 ```bash141 npx claude-flow memory store --key "api-development/${API_ID}/phase-1/database-architect/schema" \142 --value "${SCHEMA_SQL}"143 npx claude-flow memory store --key "api-development/${API_ID}/phase-1/database-architect/migrations"144 ```1451464. **Create Test Strategy** (Day 2 Afternoon)147 ```bash148 npx claude-flow memory retrieve --pattern "api-development/${API_ID}/phase-1/*"149 npx claude-flow agent spawn --type tester150 ```151152 **QA Engineer** plans:153 - Unit test strategy (per endpoint, per function)154 - Integration test scenarios (database, external APIs)155 - End-to-end test workflows (complete user journeys)156 - Performance test targets (load, stress, endurance)157 - Security test cases (OWASP API Security Top 10)158 - Test data management (fixtures, factories, mocks)159 - Coverage targets (>90% for new code)160 - CI/CD test automation strategy161162 **Memory Storage**:163 ```bash164 npx claude-flow memory store --key "api-development/${API_ID}/phase-1/qa-engineer/test-plan"165 npx claude-flow hooks post-task --task-id "phase-1-planning"166 ```167168**Outputs**:169- API requirements document with complete endpoint specifications170- OpenAPI 3.0 specification (machine-readable contract)171- Database schema with ER diagram and migrations172- Comprehensive test plan with coverage targets173- DevOps plan with infrastructure requirements174175**Success Criteria**:176- [ ] All API endpoints documented in OpenAPI spec177- [ ] Database schema normalized and indexed for performance178- [ ] Test strategy covers all quality dimensions179- [ ] Architecture approved by technical stakeholders180- [ ] Phase 1 deliverables stored in memory181182---183184### Phase 2: Foundation Setup (Days 3-4, Parallel)185186**Duration**: 2 days187**Execution Mode**: Parallel infrastructure setup188**Agents**: `backend-developer`, `database-architect`, `devops-engineer`189190**Process**:1911921. **Initialize Development Environment**193 ```bash194 npx claude-flow swarm init --topology mesh --max-agents 3 --strategy adaptive195 npx claude-flow task orchestrate --strategy parallel196 ```1971982. **Parallel Setup Execution**199200 Spawn all setup agents concurrently:201 ```bash202 # Backend project setup203 npx claude-flow agent spawn --type backend-dev --capabilities "nodejs,typescript,express"204205 # Database setup206 npx claude-flow agent spawn --type code-analyzer --capabilities "postgresql,prisma,migrations"207208 # CI/CD setup209 npx claude-flow agent spawn --type cicd-engineer --capabilities "github-actions,docker,testing"210 ```211212 **Backend Developer** initializes:213 - Node.js/Express (or FastAPI/Flask/Spring Boot) project214 - TypeScript configuration (strict mode, path aliases)215 - ESLint + Prettier (code quality and formatting)216 - Environment variable management (dotenv, validation)217 - Dependency installation (express, prisma, jest, supertest, etc.)218 - Project structure (controllers, services, models, middleware)219 - Logging framework (Winston, Pino) with structured logging220 - Error handling middleware (global error handler)221222 **Memory Pattern**: `api-development/${API_ID}/phase-2/backend-developer/project-setup`223224 **Database Architect** sets up:225 - PostgreSQL database (or MySQL/MongoDB)226 - Connection pooling configuration (pg-pool, connection limits)227 - Initial migration execution (create tables, indexes)228 - Seed data for development and testing229 - Database backup scripts (pg_dump automation)230 - Performance monitoring queries (slow query log)231232 **Memory Pattern**: `api-development/${API_ID}/phase-2/database-architect/db-config`233234 **DevOps Engineer** configures:235 - GitHub Actions workflow (or GitLab CI/Jenkins)236 - Docker containers (multi-stage builds for optimization)237 - Docker Compose for local development238 - Environment secrets management (GitHub Secrets, Vault)239 - Automated testing pipeline (run tests on PR)240 - Code quality checks (linting, type checking)241 - Build artifact generation and storage242243 **Memory Pattern**: `api-development/${API_ID}/phase-2/devops-engineer/ci-config`244245 **Coordination Script**:246 ```bash247 npx claude-flow hooks post-edit --file "package.json" \248 --memory-key "api-development/${API_ID}/phase-2/setup-complete"249 npx claude-flow hooks notify --message "Development environment ready"250 ```251252**Outputs**:253- Initialized project with all dependencies254- Database with schema and seed data255- CI/CD pipeline operational256- Development environment fully functional257258**Success Criteria**:259- [ ] Project builds without errors260- [ ] Database connections established and tested261- [ ] CI/CD pipeline runs successfully262- [ ] Local development environment documented263264---265266### Phase 3: TDD Implementation (Days 5-10, Red-Green-Refactor Cycle)267268**Duration**: 6 days269**Execution Mode**: Iterative TDD cycles per endpoint270**Agents**: `tester`, `backend-developer`, `code-reviewer`271272**Process**:273274This phase follows strict Test-Driven Development:2751. **RED**: Write failing tests (tester agent)2762. **GREEN**: Implement code to pass tests (backend-developer agent)2773. **REFACTOR**: Improve code quality (code-reviewer agent)278279**TDD Cycle Example** (POST /api/auth/register endpoint):2802811. **RED Phase: Write Failing Tests** (30-60 min per endpoint)282 ```bash283 npx claude-flow agent spawn --type tester284 ```285286 **Tester Agent** writes:287 ```javascript288 // Unit tests289 describe('POST /api/auth/register', () => {290 test('should register user with valid email and password', async () => {291 const response = await request(app)292 .post('/api/auth/register')293 .send({ email: 'user@example.com', password: 'SecurePass123!' });294295 expect(response.status).toBe(201);296 expect(response.body).toHaveProperty('token');297 expect(response.body.user.email).toBe('user@example.com');298 });299300 test('should reject duplicate email registration', async () => {301 // Create user first302 await createUser({ email: 'existing@example.com' });303304 const response = await request(app)305 .post('/api/auth/register')306 .send({ email: 'existing@example.com', password: 'Pass123!' });307308 expect(response.status).toBe(409);309 expect(response.body.error).toContain('Email already exists');310 });311312 test('should validate password strength', async () => {313 const response = await request(app)314 .post('/api/auth/register')315 .send({ email: 'user@example.com', password: 'weak' });316317 expect(response.status).toBe(400);318 expect(response.body.error).toContain('Password must be at least 8 characters');319 });320321 test('should validate email format', async () => {322 const response = await request(app)323 .post('/api/auth/register')324 .send({ email: 'invalid-email', password: 'SecurePass123!' });325326 expect(response.status).toBe(400);327 expect(response.body.error).toContain('Invalid email format');328 });329 });330331 // Integration tests332 describe('User Registration Integration', () => {333 test('should create user in database', async () => {334 const response = await request(app)335 .post('/api/auth/register')336 .send({ email: 'dbtest@example.com', password: 'Pass123!' });337338 const userInDb = await db.user.findUnique({ where: { email: 'dbtest@example.com' } });339 expect(userInDb).toBeDefined();340 expect(userInDb.passwordHash).not.toBe('Pass123!'); // Password should be hashed341 });342 });343 ```344345 **Memory Storage**:346 ```bash347 npx claude-flow memory store --key "api-development/${API_ID}/phase-3/tester/auth/register-tests" \348 --value "${TEST_FILE_CONTENT}"349 ```3503512. **GREEN Phase: Implement to Pass Tests** (1-2 hours per endpoint)352 ```bash353 npx claude-flow memory retrieve --key "api-development/${API_ID}/phase-3/tester/auth/register-tests"354 npx claude-flow agent spawn --type backend-dev355 ```356357 **Backend Developer** implements:358 ```javascript359 // POST /api/auth/register implementation360 router.post('/register', async (req, res, next) => {361 try {362 // Validate input363 const { email, password } = req.body;364365 if (!isValidEmail(email)) {366 return res.status(400).json({ error: 'Invalid email format' });367 }368369 if (password.length < 8) {370 return res.status(400).json({ error: 'Password must be at least 8 characters' });371 }372373 // Check for duplicate email374 const existingUser = await db.user.findUnique({ where: { email } });375 if (existingUser) {376 return res.status(409).json({ error: 'Email already exists' });377 }378379 // Hash password380 const passwordHash = await bcrypt.hash(password, 10);381382 // Create user383 const user = await db.user.create({384 data: { email, passwordHash }385 });386387 // Generate JWT token388 const token = jwt.sign({ userId: user.id }, process.env.JWT_SECRET, { expiresIn: '7d' });389390 res.status(201).json({391 token,392 user: { id: user.id, email: user.email }393 });394 } catch (error) {395 next(error);396 }397 });398 ```399400 Run tests and verify all pass:401 ```bash402 npm test -- auth/register.test.js403 # All tests should pass (GREEN)404 ```405406 **Memory Storage**:407 ```bash408 npx claude-flow memory store --key "api-development/${API_ID}/phase-3/backend-developer/auth/register-impl"409 ```4104113. **REFACTOR Phase: Improve Code Quality** (30 min per endpoint)412 ```bash413 npx claude-flow memory retrieve --pattern "api-development/${API_ID}/phase-3/*/auth/register-*"414 npx claude-flow agent spawn --type reviewer415 ```416417 **Code Reviewer** evaluates:418 - Code readability and clarity419 - Duplication (extract validation to middleware)420 - Security best practices (password hashing, JWT signing)421 - Error handling completeness422 - Performance optimizations423424 Suggests refactoring:425 ```javascript426 // Extracted validation middleware427 const validateRegistration = (req, res, next) => {428 const { email, password } = req.body;429430 if (!isValidEmail(email)) {431 return res.status(400).json({ error: 'Invalid email format' });432 }433434 if (password.length < 8) {435 return res.status(400).json({ error: 'Password must be at least 8 characters' });436 }437438 next();439 };440441 // Cleaner route handler442 router.post('/register', validateRegistration, async (req, res, next) => {443 try {444 const user = await authService.registerUser(req.body);445 const token = authService.generateToken(user.id);446447 res.status(201).json({ token, user });448 } catch (error) {449 if (error.code === 'DUPLICATE_EMAIL') {450 return res.status(409).json({ error: 'Email already exists' });451 }452 next(error);453 }454 });455 ```456457 **Memory Storage**:458 ```bash459 npx claude-flow memory store --key "api-development/${API_ID}/phase-3/code-reviewer/auth/register-review"460 npx claude-flow hooks post-edit --file "src/routes/auth.ts"461 ```4624634. **Repeat TDD Cycle for All Endpoints** (Days 5-10)464465 Apply RED-GREEN-REFACTOR to all endpoints:466 - Authentication (register, login, logout, refresh, reset-password)467 - CRUD operations (create, read, update, delete for all resources)468 - Search and filtering469 - Pagination and sorting470 - File uploads (if applicable)471 - Webhooks (if applicable)472473 **Progress Tracking**:474 ```bash475 npx claude-flow memory store --key "api-development/${API_ID}/phase-3/progress" \476 --value '{"completed_endpoints": 12, "total_endpoints": 20, "coverage": 93.5}'477 ```478479**Outputs**:480- All API endpoints implemented481- Comprehensive test suite with >90% coverage482- Refactored, clean, maintainable code483- All tests passing (green)484485**Success Criteria**:486- [ ] All endpoints functional and tested487- [ ] Test coverage exceeds 90%488- [ ] No code quality violations (ESLint passing)489- [ ] Code review approved for all endpoints490- [ ] TDD cycle completed for entire API surface491492---493494### Phase 4: Testing & Documentation (Days 11-12, Parallel)495496**Duration**: 2 days497**Execution Mode**: Parallel validation across multiple dimensions498**Agents**: `qa-engineer`, `security-specialist`, `performance-analyst`, `api-documentation-specialist`499500**Process**:5015021. **Initialize Testing Swarm**503 ```bash504 npx claude-flow swarm init --topology star --max-agents 4 --strategy specialized505 npx claude-flow task orchestrate --strategy parallel --priority high506 ```5075082. **Parallel Testing Execution**509510 Spawn all testing agents concurrently:511 ```bash512 # E2E testing513 npx claude-flow agent spawn --type tester --focus "end-to-end"514515 # Performance testing516 npx claude-flow agent spawn --type perf-analyzer --focus "load-stress-endurance"517518 # Security testing519 npx claude-flow agent spawn --type security-manager --focus "owasp-penetration"520521 # Documentation522 npx claude-flow agent spawn --type api-docs --focus "openapi-developer-guide"523 ```524525 **QA Engineer** conducts:526 - **End-to-End Testing**: Complete user workflows (register → login → CRUD → logout)527 - **Error Scenario Testing**: Invalid inputs, unauthorized access, rate limiting528 - **Edge Case Testing**: Boundary conditions, null values, concurrent requests529 - **Smoke Testing**: Basic functionality across all endpoints530531 **Memory Pattern**: `api-development/${API_ID}/phase-4/qa-engineer/e2e-results`532533 **Performance Analyst** tests:534 - **Load Testing**: 1000 req/sec sustained for 10 minutes (target)535 - **Stress Testing**: Find breaking point (max throughput)536 - **Endurance Testing**: 24-hour sustained load for memory leaks537 - **Spike Testing**: Sudden traffic spikes (10x normal load)538 - **Bottleneck Identification**: Database queries, API calls, CPU/memory usage539540 Tools: k6, Apache JMeter, Gatling541542 **Memory Pattern**: `api-development/${API_ID}/phase-4/performance-analyst/benchmarks`543544 **Security Specialist** validates:545 - **OWASP API Security Top 10**:546 1. Broken Object Level Authorization (BOLA)547 2. Broken Authentication548 3. Broken Object Property Level Authorization549 4. Unrestricted Resource Consumption550 5. Broken Function Level Authorization (BFLA)551 6. Unrestricted Access to Sensitive Business Flows552 7. Server Side Request Forgery (SSRF)553 8. Security Misconfiguration554 9. Improper Inventory Management555 10. Unsafe Consumption of APIs556 - SQL injection testing (automated + manual)557 - XSS vulnerability scanning558 - Authentication bypass attempts559 - Rate limiting validation560 - Secrets scanning (no hardcoded credentials)561562 Tools: OWASP ZAP, Burp Suite, Snyk563564 **Memory Pattern**: `api-development/${API_ID}/phase-4/security-specialist/audit-report`565566 **API Documentation Specialist** creates:567 - **OpenAPI/Swagger UI**: Interactive API documentation568 - **Authentication Guide**: How to obtain and use tokens569 - **Endpoint Reference**: All endpoints with parameters, responses, errors570 - **Code Examples**: cURL, JavaScript, Python, Java SDK examples571 - **Rate Limiting Guide**: Quota limits and header interpretations572 - **Error Handling Guide**: Error codes, messages, troubleshooting573 - **Developer Getting Started**: Quick start tutorial574 - **Changelog**: Versioning and breaking changes575576 **Memory Pattern**: `api-development/${API_ID}/phase-4/api-documentation-specialist/docs`5775783. **DevOps Runbook** (Parallel with documentation)579 ```bash580 npx claude-flow agent spawn --type cicd-engineer --focus "operations"581 ```582583 **DevOps Engineer** documents:584 - Deployment procedures (step-by-step)585 - Monitoring and alerting setup (Grafana, Prometheus)586 - Troubleshooting guide (common issues, solutions)587 - Performance tuning (database, caching, scaling)588 - Backup and recovery procedures589 - Incident response plan (runbook)590 - Rollback procedures591592 **Memory Pattern**: `api-development/${API_ID}/phase-4/devops-engineer/runbook`593594**Outputs**:595- E2E test results (all passing)596- Performance benchmark report (meets targets)597- Security audit report (no critical issues)598- Complete API documentation (developer-ready)599- Operations runbook (deployment-ready)600601**Success Criteria**:602- [ ] All E2E tests passing603- [ ] Performance targets met (API < 200ms, throughput > 1000 req/sec)604- [ ] Security audit passed (zero critical, zero high issues)605- [ ] Documentation complete and published606- [ ] Operations runbook approved607608---609610### Phase 5: Deployment & Monitoring (Days 13-14, Sequential → Continuous)611612**Duration**: 2 days + ongoing monitoring613**Execution Mode**: Sequential deployment with validation gates614**Agents**: `production-validator`, `devops-engineer`, `performance-monitor`615616**Process**:6176181. **Pre-Production Validation** (Day 13 Morning)619 ```bash620 npx claude-flow hooks pre-task --description "Final production validation"621 npx claude-flow agent spawn --type production-validator622 ```623624 **Production Validator** checks:625 - **All Tests Passing**: 100% of test suite (unit + integration + E2E)626 - **Code Coverage**: >90% verified627 - **Security Audit**: Passed with zero critical/high issues628 - **Performance Benchmarks**: All targets met or exceeded629 - **Documentation**: Complete and published630 - **Monitoring Setup**: Dashboards and alerts configured631 - **Rollback Plan**: Documented and rehearsed632633 Generate go/no-go report:634 ```bash635 npx claude-flow memory store --key "api-development/${API_ID}/phase-5/production-validator/go-no-go" \636 --value '{"decision": "GO", "readiness_score": 98, "blockers": []}'637 ```638639 If any validation fails:640 ```bash641 # Return to appropriate phase to fix issues642 npx claude-flow hooks notify --message "Production validation FAILED: ${BLOCKER_ISSUES}"643 # Halt deployment until issues resolved644 ```6456462. **Staging Deployment** (Day 13 Afternoon)647 ```bash648 npx claude-flow agent spawn --type cicd-engineer649 ```650651 **DevOps Engineer** deploys to staging:652 ```bash653 # Deploy API to staging environment654 kubectl apply -f k8s/staging/655656 # Run smoke tests657 npm run test:smoke -- --env=staging658659 # Validate monitoring660 curl https://api-staging.example.com/health661 ```662663 **Staging Validation**:664 - Full test suite execution against staging665 - Data persistence verification666 - Error handling validation667 - Monitoring dashboard validation668 - Load balancer health checks669670 **Memory Storage**:671 ```bash672 npx claude-flow memory store --key "api-development/${API_ID}/phase-5/devops-engineer/staging-deploy"673 ```6746753. **Production Deployment** (Day 14 Morning - Blue-Green Strategy)676 ```bash677 npx claude-flow workflow create --name "production-deployment" \678 --steps '["blue-green-deploy","canary-rollout","full-rollout","monitor"]'679 ```680681 **DevOps Engineer** executes:682 ```bash683 # Step 1: Deploy to green environment (alongside blue)684 kubectl apply -f k8s/production/green/685686 # Step 2: Run smoke tests on green687 npm run test:smoke -- --env=production-green688689 # Step 3: Gradual traffic shift (canary rollout)690 # 10% traffic to green691 kubectl patch service api-service -p '{"spec":{"selector":{"version":"green","weight":"10"}}}'692 sleep 300 # Monitor for 5 minutes693694 # 50% traffic to green695 kubectl patch service api-service -p '{"spec":{"selector":{"version":"green","weight":"50"}}}'696 sleep 600 # Monitor for 10 minutes697698 # 100% traffic to green699 kubectl patch service api-service -p '{"spec":{"selector":{"version":"green","weight":"100"}}}'700701 # Step 4: Keep blue environment ready for rollback (for 24 hours)702 ```703704 **Rollback Procedure** (if issues detected):705 ```bash706 # Instant rollback to blue707 kubectl patch service api-service -p '{"spec":{"selector":{"version":"blue","weight":"100"}}}'708 ```709710 **Memory Storage**:711 ```bash712 npx claude-flow memory store --key "api-development/${API_ID}/phase-5/devops-engineer/production-deploy" \713 --value '{"status": "SUCCESS", "deployment_time": "2025-01-15T10:00:00Z", "version": "v1.0.0"}'714 ```7157164. **Post-Deployment Monitoring** (Day 14 Afternoon + Ongoing)717 ```bash718 npx claude-flow agent spawn --type performance-monitor719 ```720721 **Performance Monitor** tracks:722 - **Application Metrics**:723 - API response time (p50, p95, p99)724 - Throughput (requests per second)725 - Error rate (4xx, 5xx errors)726 - Uptime and availability727 - **Infrastructure Metrics**:728 - CPU and memory utilization729 - Database connection pool usage730 - Cache hit ratio731 - Network throughput732 - **Business Metrics**:733 - API usage by endpoint734 - User activity patterns735 - Rate limit violations736 - Authentication success/failure rates737738 Generate hourly reports for first 24 hours:739 ```bash740 npx claude-flow hooks post-task --task-id "production-monitoring" --export-metrics true741 npx claude-flow memory store --key "api-development/${API_ID}/phase-5/performance-monitor/metrics/hour-${HOUR}"742 ```743744 **Alert Configuration**:745 - Response time > 500ms (p95): WARNING746 - Response time > 1000ms (p95): CRITICAL747 - Error rate > 1%: WARNING748 - Error rate > 5%: CRITICAL749 - Uptime < 99.9%: CRITICAL750 - Database connection pool > 80%: WARNING7517525. **Documentation Publication** (Day 14)753 ```bash754 npx claude-flow agent spawn --type api-docs755 ```756757 **Update Final Documentation**:758 - Production API URLs and endpoints759 - Authentication endpoints (production)760 - Monitoring dashboards (link to Grafana)761 - Support contact information762 - SLA and uptime guarantees763764 Publish to developer portal:765 ```bash766 npm run docs:publish -- --env=production767 ```7687696. **Knowledge Transfer** (End of Phase 5)770 ```bash771 npx claude-flow hooks session-end --export-workflow "/tmp/${API_ID}-workflow.json"772 ```773774 Create handoff materials:775 - Developer onboarding guide776 - Support team training materials777 - Common issues and troubleshooting778 - Escalation procedures779780 **Memory Storage**:781 ```bash782 npx claude-flow memory store --key "api-development/${API_ID}/phase-5/knowledge-transfer/complete"783 ```784785**Outputs**:786- Production API (live and stable)787- Complete documentation (published to developer portal)788- Monitoring dashboards (real-time metrics)789- Trained support team (ready for inquiries)790- Workflow documentation (for future reference)791792**Success Criteria**:793- [ ] Production deployment successful with zero downtime794- [ ] All monitoring metrics within acceptable ranges795- [ ] Documentation published and accessible796- [ ] Support team trained and ready797- [ ] Post-deployment validation complete798799---800801## Memory Coordination802803### Namespace Convention804805All workflow data follows this hierarchical pattern:806807```808api-development/{api-id}/phase-{N}/{agent-type}/{deliverable-type}809```810811**Examples**:812- `api-development/user-api-v1/phase-1/product-manager/requirements`813- `api-development/user-api-v1/phase-1/system-architect/openapi-spec`814- `api-development/user-api-v1/phase-2/backend-developer/project-setup`815- `api-development/user-api-v1/phase-3/tester/auth/register-tests`816- `api-development/user-api-v1/phase-4/security-specialist/audit-report`817- `api-development/user-api-v1/phase-5/devops-engineer/production-deploy`818819### Cross-Phase Data Flow820821**Phase 1 → Phase 2**:822```bash823# Phase 2 retrieves design specifications824npx claude-flow memory retrieve --key "api-development/${API_ID}/phase-1/system-architect/openapi-spec"825npx claude-flow memory retrieve --key "api-development/${API_ID}/phase-1/database-architect/schema"826```827828**Phase 2 → Phase 3**:829```bash830# Phase 3 retrieves project structure and test plan831npx claude-flow memory retrieve --key "api-development/${API_ID}/phase-2/backend-developer/project-setup"832npx claude-flow memory retrieve --key "api-development/${API_ID}/phase-1/qa-engineer/test-plan"833```834835**Phase 3 → Phase 4**:836```bash837# Phase 4 retrieves implementation for testing838npx claude-flow memory retrieve --pattern "api-development/${API_ID}/phase-3/backend-developer/*"839```840841**Phase 4 → Phase 5**:842```bash843# Phase 5 retrieves test results and documentation844npx claude-flow memory retrieve --pattern "api-development/${API_ID}/phase-4/*/results"845```846847---848849## Scripts & Automation850851### Pre-Workflow Initialization852853```bash854#!/bin/bash855# Initialize API development workflow856857API_NAME="$1"858API_ID="${API_NAME}-api-$(date +%Y%m%d)"859860# Setup coordination861npx claude-flow hooks pre-task --description "API Development: ${API_NAME}"862863# Initialize hierarchical swarm (12 agents max)864npx claude-flow swarm init --topology hierarchical --max-agents 12 --strategy specialized865866# Store API metadata867npx claude-flow memory store --key "api-development/${API_ID}/metadata" --value '{868 "api_name": "'"${API_NAME}"'",869 "api_id": "'"${API_ID}"'",870 "start_date": "'"$(date -I)"'",871 "timeline_days": 14,872 "phases": 5,873 "tdd_approach": true874}'875876echo "✅ API development initialized: ${API_ID}"877```878879### TDD Cycle Script880881```bash882#!/bin/bash883# Execute TDD cycle for single endpoint884885API_ID="$1"886ENDPOINT_PATH="$2" # e.g., "POST /api/auth/register"887888echo "🔴 RED Phase: Writing tests for ${ENDPOINT_PATH}"889npx claude-flow agent spawn --type tester --task "write-tests:${ENDPOINT_PATH}"890891# Wait for tests to be written892npx claude-flow memory retrieve --key "api-development/${API_ID}/phase-3/tester/${ENDPOINT_PATH}/tests"893894echo "🟢 GREEN Phase: Implementing ${ENDPOINT_PATH}"895npx claude-flow agent spawn --type backend-dev --task "implement:${ENDPOINT_PATH}"896897# Run tests to verify implementation898npm test -- "${ENDPOINT_PATH}.test.js"899900echo "🔵 REFACTOR Phase: Code review for ${ENDPOINT_PATH}"901npx claude-flow agent spawn --type reviewer --task "review:${ENDPOINT_PATH}"902903# Store completion904npx claude-flow hooks post-edit --file "src/routes/${ENDPOINT_PATH}.ts" \905 --memory-key "api-development/${API_ID}/phase-3/completed/${ENDPOINT_PATH}"906```907908### Deployment Script909910```bash911#!/bin/bash912# Blue-green deployment to production913914API_ID="$1"915VERSION="$2"916917echo "🚀 Starting blue-green deployment: ${VERSION}"918919# Pre-deployment validation920npx claude-flow agent spawn --type production-validator921VALIDATION=$(npx claude-flow memory retrieve --key "api-development/${API_ID}/phase-5/production-validator/go-no-go")922923if [ "$(echo $VALIDATION | jq -r '.decision')" != "GO" ]; then924 echo "❌ Production validation FAILED. Aborting deployment."925 exit 1926fi927928# Deploy to green environment929kubectl apply -f k8s/production/green/930931# Smoke tests932npm run test:smoke -- --env=production-green933934# Gradual traffic shift (canary)935for WEIGHT in 10 50 100; do936 echo "Shifting ${WEIGHT}% traffic to green..."937 kubectl patch service api-service -p "{\"spec\":{\"selector\":{\"version\":\"green\",\"weight\":\"${WEIGHT}\"}}}"938939 # Monitor for issues (5-10 minutes per step)940 DURATION=$((WEIGHT == 100 ? 10 : 5))941 sleep $((DURATION * 60))942943 # Check error rate944 ERROR_RATE=$(curl -s https://monitoring.example.com/api/error-rate | jq -r '.rate')945 if (( $(echo "$ERROR_RATE > 1.0" | bc -l) )); then946 echo "❌ High error rate detected: ${ERROR_RATE}%. Rolling back."947 kubectl patch service api-service -p '{"spec":{"selector":{"version":"blue","weight":"100"}}}'948 exit 1949 fi950done951952echo "✅ Deployment complete: ${VERSION}"953npx claude-flow hooks post-task --task-id "production-deployment" --export-metrics true954```955956---957958## Success Metrics959960### Technical Metrics961- **Test Coverage**: > 90% (code coverage report)962- **API Response Time**: < 200ms (p95)963- **Uptime**: 99.9%+ (production SLA)964- **Error Rate**: < 0.1% (4xx + 5xx errors)965- **Code Quality Score**: A rating (SonarQube/CodeClimate)966- **Security Audit**: Zero critical, zero high issues967968### Performance Metrics969- **Throughput**: > 1000 req/sec sustained970- **Database Query Time**: < 50ms (p95)971- **Memory Usage**: < 512MB per instance972- **CPU Usage**: < 70% under normal load973974### Quality Metrics975- **TDD Adherence**: 100% (all endpoints test-first)976- **Documentation Coverage**: 100% of endpoints documented977- **API Compliance**: OpenAPI 3.0 valid (no errors)978- **Code Review Approval**: 100% (all code reviewed)979980---981982## Usage Examples983984### Example 1: User Management API985986```bash987# Initialize workflow988API_ID="user-management-api-20250115"989npx claude-flow hooks pre-task --description "User Management API Development"990991# Phase 1: Planning (Day 1-2)992npx claude-flow agent spawn --type planner993# Output: 15 endpoints defined, authentication strategy established994995# Phase 3: TDD Implementation (Day 5-10)996for endpoint in "POST /api/users/register" "POST /api/users/login" "GET /api/users/:id"; do997 ./tdd-cycle.sh "${API_ID}" "${endpoint}"998done999# Output: All endpoints implemented with 94% test coverage10001001# Phase 5: Production Deployment (Day 14)1002./deploy-production.sh "${API_ID}" "v1.0.0"1003# Output: Deployed successfully, handling 1500 req/sec with 99.95% uptime1004```10051006### Example 2: Payment Gateway API10071008```bash1009# High-security API with PCI compliance1010API_ID="payment-gateway-api-20250120"10111012# Phase 1: Enhanced security planning1013npx claude-flow agent spawn --type system-architect --focus "pci-compliance"1014npx claude-flow agent spawn --type security-specialist --focus "payment-security"1015# Output: PCI DSS compliant architecture designed10161017# Phase 4: Enhanced security testing1018npx claude-flow agent spawn --type security-manager --focus "penetration-testing-comprehensive"1019# Output: Zero vulnerabilities, PCI DSS validation passed1020```10211022### Example 3: Microservice API (Event-Driven)10231024```bash1025# Microservice with message queue integration1026API_ID="order-service-api-20250125"10271028# Phase 2: Message queue setup1029npx claude-flow agent spawn --type backend-dev --capabilities "rabbitmq,events"1030# Output: Event-driven architecture with pub/sub patterns10311032# Phase 3: Event handler TDD1033./tdd-cycle.sh "${API_ID}" "POST /api/orders/create"1034./tdd-cycle.sh "${API_ID}" "EVENT order.created"1035# Output: Synchronous API + asynchronous event processing1036```10371038---10391040## GraphViz Process Diagram10411042See `when-building-backend-api-orchestrate-api-development-process.dot` for visual workflow representation showing:1043- 5 phases with TDD cycle details1044- 12 agent interactions and coordination1045- Memory flow between phases1046- Blue-green deployment strategy1047- Validation gates and decision points10481049---10501051## Quality Checklist10521053Before considering API development complete, verify:10541055- [ ] **Phase 1**: Requirements documented, OpenAPI spec complete, database schema designed1056- [ ] **Phase 2**: Development environment operational, CI/CD pipeline functional1057- [ ] **Phase 3**: All endpoints implemented following TDD, test coverage > 90%1058- [ ] **Phase 4**: E2E tests passing, security audit passed, performance benchmarks met1059- [ ] **Phase 5**: Production deployment successful, monitoring active, documentation published10601061**Memory Verification**:1062- [ ] `api-development/${API_ID}/phase-1/*` - Planning artifacts1063- [ ] `api-development/${API_ID}/phase-2/*` - Setup configurations1064- [ ] `api-development/${API_ID}/phase-3/*` - TDD implementation + tests1065- [ ] `api-development/${API_ID}/phase-4/*` - Test results + documentation1066- [ ] `api-development/${API_ID}/phase-5/*` - Deployment logs + metrics10671068---10691070**Workflow Complexity**: Medium (12 agents, 14 days, 5 phases)1071**Coordination Pattern**: Hierarchical with TDD cycle iteration1072**Memory Footprint**: ~30-50 memory entries per API1073**Typical Use Case**: Production-ready REST API with comprehensive testing and quality gates