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-development3description: Use when building a production-ready REST API from requirements through deployment. Orchestrates 8-12 specialist agents across 5 phases using Test-Driven Development methodology. Covers planning, architecture, TDD implementation, comprehensive testing, documentation, and blue-green deployment over a 2-week timeline with emphasis on quality and reliability.4---56# API Development Orchestration Workflow78Complete 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.910## Overview1112This 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.1314The 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.1516## Trigger Conditions1718Use this workflow when:19- Building a new REST API or microservice from scratch20- Migrating existing API to modern architecture with comprehensive testing21- Need systematic TDD approach with documented test coverage22- Require production-ready API with security, performance, and scalability validation23- Timeline is 2-4 weeks with clear milestones and deliverables24- Quality gates (testing, security, performance) are non-negotiable25- Need comprehensive API documentation and operational runbooks2627## Orchestrated Agents (12 Total)2829### Planning & Architecture Agents30- **`product-manager`** - Requirements gathering, endpoint definition, API contracts, success criteria31- **`system-architect`** - API architecture design, RESTful patterns, versioning, error handling strategy32- **`database-architect`** - Schema design, query optimization, indexing, migration planning33- **`qa-engineer`** - Test planning, TDD strategy, coverage targets, performance benchmarks3435### Development Agents (TDD Cycle)36- **`tester`** - Write tests first (red phase), integration tests, E2E scenarios37- **`backend-developer`** - Implement to pass tests (green phase), refactor for quality38- **`code-reviewer`** - Code quality review, refactoring suggestions, best practices validation3940### Quality & Validation Agents41- **`security-specialist`** - Security architecture, OWASP validation, penetration testing42- **`performance-analyst`** - Load testing, stress testing, bottleneck identification, optimization43- **`api-documentation-specialist`** - OpenAPI specs, developer guides, code examples4445### Deployment & Operations Agents46- **`devops-engineer`** - CI/CD pipeline, Docker/K8s deployment, infrastructure as code47- **`production-validator`** - Pre-production validation, go/no-go decision, smoke testing48- **`performance-monitor`** - Production monitoring, logging, alerting, SLO tracking4950## Workflow Phases5152### Phase 1: Planning & Design (Days 1-2, Sequential)5354**Duration**: 2 days55**Execution Mode**: Sequential analysis and design56**Agents**: `product-manager`, `system-architect`, `database-architect`, `qa-engineer`5758**Process**:59601. **Gather API Requirements** (Day 1 Morning)61 ```bash62 npx claude-flow hooks pre-task --description "API Development: ${API_NAME}"63 npx claude-flow swarm init --topology hierarchical --max-agents 12 --strategy specialized64 npx claude-flow agent spawn --type planner65 ```6667 **Product Manager** defines:68 - Complete endpoint list with HTTP methods (GET, POST, PUT, DELETE, PATCH)69 - Data models and relationships (entities, attributes, cardinality)70 - Authentication and authorization requirements (OAuth, JWT, RBAC)71 - Rate limiting and quota specifications72 - Third-party integrations and external dependencies73 - API versioning strategy (URL path, header, content negotiation)74 - Success metrics and SLAs (response time, uptime, throughput)7576 **Memory Storage**:77 ```bash78 npx claude-flow memory store --key "api-development/${API_ID}/phase-1/product-manager/requirements" \79 --value "${REQUIREMENTS_JSON}"80 ```81822. **Design API Architecture** (Day 1 Afternoon)83 ```bash84 npx claude-flow memory retrieve --key "api-development/${API_ID}/phase-1/product-manager/requirements"85 npx claude-flow agent spawn --type system-architect86 ```8788 **System Architect** designs:89 - RESTful API structure following Richardson Maturity Model90 - URL patterns and resource naming conventions91 - Request/response formats with JSON schemas92 - Error handling patterns (error codes, messages, stack traces)93 - Pagination, filtering, sorting, and search strategies94 - Caching strategy (ETags, cache-control headers)95 - API security architecture (authentication flow, token management)96 - Versioning and backward compatibility approach9798 Generate OpenAPI 3.0 specification:99 ```bash100 npx claude-flow memory store --key "api-development/${API_ID}/phase-1/system-architect/openapi-spec" \101 --value "${OPENAPI_YAML}"102 ```1031043. **Design Database Schema** (Day 2 Morning)105 ```bash106 npx claude-flow memory retrieve --key "api-development/${API_ID}/phase-1/system-architect/openapi-spec"107 npx claude-flow agent spawn --type code-analyzer108 ```109110 **Database Architect** creates:111 - Normalized schema design (3NF) with entity-relationship diagram112 - Table definitions (columns, data types, constraints, defaults)113 - Relationships and foreign key constraints114 - Indexes for query performance (primary, secondary, composite)115 - Migration scripts (up and down migrations)116 - Backup and recovery strategy117 - Scaling strategy (sharding, replication, read replicas)118119 Generate SQL schema and migrations:120 ```bash121 npx claude-flow memory store --key "api-development/${API_ID}/phase-1/database-architect/schema" \122 --value "${SCHEMA_SQL}"123 npx claude-flow memory store --key "api-development/${API_ID}/phase-1/database-architect/migrations"124 ```1251264. **Create Test Strategy** (Day 2 Afternoon)127 ```bash128 npx claude-flow memory retrieve --pattern "api-development/${API_ID}/phase-1/*"129 npx claude-flow agent spawn --type tester130 ```131132 **QA Engineer** plans:133 - Unit test strategy (per endpoint, per function)134 - Integration test scenarios (database, external APIs)135 - End-to-end test workflows (complete user journeys)136 - Performance test targets (load, stress, endurance)137 - Security test cases (OWASP API Security Top 10)138 - Test data management (fixtures, factories, mocks)139 - Coverage targets (>90% for new code)140 - CI/CD test automation strategy141142 **Memory Storage**:143 ```bash144 npx claude-flow memory store --key "api-development/${API_ID}/phase-1/qa-engineer/test-plan"145 npx claude-flow hooks post-task --task-id "phase-1-planning"146 ```147148**Outputs**:149- API requirements document with complete endpoint specifications150- OpenAPI 3.0 specification (machine-readable contract)151- Database schema with ER diagram and migrations152- Comprehensive test plan with coverage targets153- DevOps plan with infrastructure requirements154155**Success Criteria**:156- [ ] All API endpoints documented in OpenAPI spec157- [ ] Database schema normalized and indexed for performance158- [ ] Test strategy covers all quality dimensions159- [ ] Architecture approved by technical stakeholders160- [ ] Phase 1 deliverables stored in memory161162---163164### Phase 2: Foundation Setup (Days 3-4, Parallel)165166**Duration**: 2 days167**Execution Mode**: Parallel infrastructure setup168**Agents**: `backend-developer`, `database-architect`, `devops-engineer`169170**Process**:1711721. **Initialize Development Environment**173 ```bash174 npx claude-flow swarm init --topology mesh --max-agents 3 --strategy adaptive175 npx claude-flow task orchestrate --strategy parallel176 ```1771782. **Parallel Setup Execution**179180 Spawn all setup agents concurrently:181 ```bash182 # Backend project setup183 npx claude-flow agent spawn --type backend-dev --capabilities "nodejs,typescript,express"184185 # Database setup186 npx claude-flow agent spawn --type code-analyzer --capabilities "postgresql,prisma,migrations"187188 # CI/CD setup189 npx claude-flow agent spawn --type cicd-engineer --capabilities "github-actions,docker,testing"190 ```191192 **Backend Developer** initializes:193 - Node.js/Express (or FastAPI/Flask/Spring Boot) project194 - TypeScript configuration (strict mode, path aliases)195 - ESLint + Prettier (code quality and formatting)196 - Environment variable management (dotenv, validation)197 - Dependency installation (express, prisma, jest, supertest, etc.)198 - Project structure (controllers, services, models, middleware)199 - Logging framework (Winston, Pino) with structured logging200 - Error handling middleware (global error handler)201202 **Memory Pattern**: `api-development/${API_ID}/phase-2/backend-developer/project-setup`203204 **Database Architect** sets up:205 - PostgreSQL database (or MySQL/MongoDB)206 - Connection pooling configuration (pg-pool, connection limits)207 - Initial migration execution (create tables, indexes)208 - Seed data for development and testing209 - Database backup scripts (pg_dump automation)210 - Performance monitoring queries (slow query log)211212 **Memory Pattern**: `api-development/${API_ID}/phase-2/database-architect/db-config`213214 **DevOps Engineer** configures:215 - GitHub Actions workflow (or GitLab CI/Jenkins)216 - Docker containers (multi-stage builds for optimization)217 - Docker Compose for local development218 - Environment secrets management (GitHub Secrets, Vault)219 - Automated testing pipeline (run tests on PR)220 - Code quality checks (linting, type checking)221 - Build artifact generation and storage222223 **Memory Pattern**: `api-development/${API_ID}/phase-2/devops-engineer/ci-config`224225 **Coordination Script**:226 ```bash227 npx claude-flow hooks post-edit --file "package.json" \228 --memory-key "api-development/${API_ID}/phase-2/setup-complete"229 npx claude-flow hooks notify --message "Development environment ready"230 ```231232**Outputs**:233- Initialized project with all dependencies234- Database with schema and seed data235- CI/CD pipeline operational236- Development environment fully functional237238**Success Criteria**:239- [ ] Project builds without errors240- [ ] Database connections established and tested241- [ ] CI/CD pipeline runs successfully242- [ ] Local development environment documented243244---245246### Phase 3: TDD Implementation (Days 5-10, Red-Green-Refactor Cycle)247248**Duration**: 6 days249**Execution Mode**: Iterative TDD cycles per endpoint250**Agents**: `tester`, `backend-developer`, `code-reviewer`251252**Process**:253254This phase follows strict Test-Driven Development:2551. **RED**: Write failing tests (tester agent)2562. **GREEN**: Implement code to pass tests (backend-developer agent)2573. **REFACTOR**: Improve code quality (code-reviewer agent)258259**TDD Cycle Example** (POST /api/auth/register endpoint):2602611. **RED Phase: Write Failing Tests** (30-60 min per endpoint)262 ```bash263 npx claude-flow agent spawn --type tester264 ```265266 **Tester Agent** writes:267 ```javascript268 // Unit tests269 describe('POST /api/auth/register', () => {270 test('should register user with valid email and password', async () => {271 const response = await request(app)272 .post('/api/auth/register')273 .send({ email: 'user@example.com', password: 'SecurePass123!' });274275 expect(response.status).toBe(201);276 expect(response.body).toHaveProperty('token');277 expect(response.body.user.email).toBe('user@example.com');278 });279280 test('should reject duplicate email registration', async () => {281 // Create user first282 await createUser({ email: 'existing@example.com' });283284 const response = await request(app)285 .post('/api/auth/register')286 .send({ email: 'existing@example.com', password: 'Pass123!' });287288 expect(response.status).toBe(409);289 expect(response.body.error).toContain('Email already exists');290 });291292 test('should validate password strength', async () => {293 const response = await request(app)294 .post('/api/auth/register')295 .send({ email: 'user@example.com', password: 'weak' });296297 expect(response.status).toBe(400);298 expect(response.body.error).toContain('Password must be at least 8 characters');299 });300301 test('should validate email format', async () => {302 const response = await request(app)303 .post('/api/auth/register')304 .send({ email: 'invalid-email', password: 'SecurePass123!' });305306 expect(response.status).toBe(400);307 expect(response.body.error).toContain('Invalid email format');308 });309 });310311 // Integration tests312 describe('User Registration Integration', () => {313 test('should create user in database', async () => {314 const response = await request(app)315 .post('/api/auth/register')316 .send({ email: 'dbtest@example.com', password: 'Pass123!' });317318 const userInDb = await db.user.findUnique({ where: { email: 'dbtest@example.com' } });319 expect(userInDb).toBeDefined();320 expect(userInDb.passwordHash).not.toBe('Pass123!'); // Password should be hashed321 });322 });323 ```324325 **Memory Storage**:326 ```bash327 npx claude-flow memory store --key "api-development/${API_ID}/phase-3/tester/auth/register-tests" \328 --value "${TEST_FILE_CONTENT}"329 ```3303312. **GREEN Phase: Implement to Pass Tests** (1-2 hours per endpoint)332 ```bash333 npx claude-flow memory retrieve --key "api-development/${API_ID}/phase-3/tester/auth/register-tests"334 npx claude-flow agent spawn --type backend-dev335 ```336337 **Backend Developer** implements:338 ```javascript339 // POST /api/auth/register implementation340 router.post('/register', async (req, res, next) => {341 try {342 // Validate input343 const { email, password } = req.body;344345 if (!isValidEmail(email)) {346 return res.status(400).json({ error: 'Invalid email format' });347 }348349 if (password.length < 8) {350 return res.status(400).json({ error: 'Password must be at least 8 characters' });351 }352353 // Check for duplicate email354 const existingUser = await db.user.findUnique({ where: { email } });355 if (existingUser) {356 return res.status(409).json({ error: 'Email already exists' });357 }358359 // Hash password360 const passwordHash = await bcrypt.hash(password, 10);361362 // Create user363 const user = await db.user.create({364 data: { email, passwordHash }365 });366367 // Generate JWT token368 const token = jwt.sign({ userId: user.id }, process.env.JWT_SECRET, { expiresIn: '7d' });369370 res.status(201).json({371 token,372 user: { id: user.id, email: user.email }373 });374 } catch (error) {375 next(error);376 }377 });378 ```379380 Run tests and verify all pass:381 ```bash382 npm test -- auth/register.test.js383 # All tests should pass (GREEN)384 ```385386 **Memory Storage**:387 ```bash388 npx claude-flow memory store --key "api-development/${API_ID}/phase-3/backend-developer/auth/register-impl"389 ```3903913. **REFACTOR Phase: Improve Code Quality** (30 min per endpoint)392 ```bash393 npx claude-flow memory retrieve --pattern "api-development/${API_ID}/phase-3/*/auth/register-*"394 npx claude-flow agent spawn --type reviewer395 ```396397 **Code Reviewer** evaluates:398 - Code readability and clarity399 - Duplication (extract validation to middleware)400 - Security best practices (password hashing, JWT signing)401 - Error handling completeness402 - Performance optimizations403404 Suggests refactoring:405 ```javascript406 // Extracted validation middleware407 const validateRegistration = (req, res, next) => {408 const { email, password } = req.body;409410 if (!isValidEmail(email)) {411 return res.status(400).json({ error: 'Invalid email format' });412 }413414 if (password.length < 8) {415 return res.status(400).json({ error: 'Password must be at least 8 characters' });416 }417418 next();419 };420421 // Cleaner route handler422 router.post('/register', validateRegistration, async (req, res, next) => {423 try {424 const user = await authService.registerUser(req.body);425 const token = authService.generateToken(user.id);426427 res.status(201).json({ token, user });428 } catch (error) {429 if (error.code === 'DUPLICATE_EMAIL') {430 return res.status(409).json({ error: 'Email already exists' });431 }432 next(error);433 }434 });435 ```436437 **Memory Storage**:438 ```bash439 npx claude-flow memory store --key "api-development/${API_ID}/phase-3/code-reviewer/auth/register-review"440 npx claude-flow hooks post-edit --file "src/routes/auth.ts"441 ```4424434. **Repeat TDD Cycle for All Endpoints** (Days 5-10)444445 Apply RED-GREEN-REFACTOR to all endpoints:446 - Authentication (register, login, logout, refresh, reset-password)447 - CRUD operations (create, read, update, delete for all resources)448 - Search and filtering449 - Pagination and sorting450 - File uploads (if applicable)451 - Webhooks (if applicable)452453 **Progress Tracking**:454 ```bash455 npx claude-flow memory store --key "api-development/${API_ID}/phase-3/progress" \456 --value '{"completed_endpoints": 12, "total_endpoints": 20, "coverage": 93.5}'457 ```458459**Outputs**:460- All API endpoints implemented461- Comprehensive test suite with >90% coverage462- Refactored, clean, maintainable code463- All tests passing (green)464465**Success Criteria**:466- [ ] All endpoints functional and tested467- [ ] Test coverage exceeds 90%468- [ ] No code quality violations (ESLint passing)469- [ ] Code review approved for all endpoints470- [ ] TDD cycle completed for entire API surface471472---473474### Phase 4: Testing & Documentation (Days 11-12, Parallel)475476**Duration**: 2 days477**Execution Mode**: Parallel validation across multiple dimensions478**Agents**: `qa-engineer`, `security-specialist`, `performance-analyst`, `api-documentation-specialist`479480**Process**:4814821. **Initialize Testing Swarm**483 ```bash484 npx claude-flow swarm init --topology star --max-agents 4 --strategy specialized485 npx claude-flow task orchestrate --strategy parallel --priority high486 ```4874882. **Parallel Testing Execution**489490 Spawn all testing agents concurrently:491 ```bash492 # E2E testing493 npx claude-flow agent spawn --type tester --focus "end-to-end"494495 # Performance testing496 npx claude-flow agent spawn --type perf-analyzer --focus "load-stress-endurance"497498 # Security testing499 npx claude-flow agent spawn --type security-manager --focus "owasp-penetration"500501 # Documentation502 npx claude-flow agent spawn --type api-docs --focus "openapi-developer-guide"503 ```504505 **QA Engineer** conducts:506 - **End-to-End Testing**: Complete user workflows (register → login → CRUD → logout)507 - **Error Scenario Testing**: Invalid inputs, unauthorized access, rate limiting508 - **Edge Case Testing**: Boundary conditions, null values, concurrent requests509 - **Smoke Testing**: Basic functionality across all endpoints510511 **Memory Pattern**: `api-development/${API_ID}/phase-4/qa-engineer/e2e-results`512513 **Performance Analyst** tests:514 - **Load Testing**: 1000 req/sec sustained for 10 minutes (target)515 - **Stress Testing**: Find breaking point (max throughput)516 - **Endurance Testing**: 24-hour sustained load for memory leaks517 - **Spike Testing**: Sudden traffic spikes (10x normal load)518 - **Bottleneck Identification**: Database queries, API calls, CPU/memory usage519520 Tools: k6, Apache JMeter, Gatling521522 **Memory Pattern**: `api-development/${API_ID}/phase-4/performance-analyst/benchmarks`523524 **Security Specialist** validates:525 - **OWASP API Security Top 10**:526 1. Broken Object Level Authorization (BOLA)527 2. Broken Authentication528 3. Broken Object Property Level Authorization529 4. Unrestricted Resource Consumption530 5. Broken Function Level Authorization (BFLA)531 6. Unrestricted Access to Sensitive Business Flows532 7. Server Side Request Forgery (SSRF)533 8. Security Misconfiguration534 9. Improper Inventory Management535 10. Unsafe Consumption of APIs536 - SQL injection testing (automated + manual)537 - XSS vulnerability scanning538 - Authentication bypass attempts539 - Rate limiting validation540 - Secrets scanning (no hardcoded credentials)541542 Tools: OWASP ZAP, Burp Suite, Snyk543544 **Memory Pattern**: `api-development/${API_ID}/phase-4/security-specialist/audit-report`545546 **API Documentation Specialist** creates:547 - **OpenAPI/Swagger UI**: Interactive API documentation548 - **Authentication Guide**: How to obtain and use tokens549 - **Endpoint Reference**: All endpoints with parameters, responses, errors550 - **Code Examples**: cURL, JavaScript, Python, Java SDK examples551 - **Rate Limiting Guide**: Quota limits and header interpretations552 - **Error Handling Guide**: Error codes, messages, troubleshooting553 - **Developer Getting Started**: Quick start tutorial554 - **Changelog**: Versioning and breaking changes555556 **Memory Pattern**: `api-development/${API_ID}/phase-4/api-documentation-specialist/docs`5575583. **DevOps Runbook** (Parallel with documentation)559 ```bash560 npx claude-flow agent spawn --type cicd-engineer --focus "operations"561 ```562563 **DevOps Engineer** documents:564 - Deployment procedures (step-by-step)565 - Monitoring and alerting setup (Grafana, Prometheus)566 - Troubleshooting guide (common issues, solutions)567 - Performance tuning (database, caching, scaling)568 - Backup and recovery procedures569 - Incident response plan (runbook)570 - Rollback procedures571572 **Memory Pattern**: `api-development/${API_ID}/phase-4/devops-engineer/runbook`573574**Outputs**:575- E2E test results (all passing)576- Performance benchmark report (meets targets)577- Security audit report (no critical issues)578- Complete API documentation (developer-ready)579- Operations runbook (deployment-ready)580581**Success Criteria**:582- [ ] All E2E tests passing583- [ ] Performance targets met (API < 200ms, throughput > 1000 req/sec)584- [ ] Security audit passed (zero critical, zero high issues)585- [ ] Documentation complete and published586- [ ] Operations runbook approved587588---589590### Phase 5: Deployment & Monitoring (Days 13-14, Sequential → Continuous)591592**Duration**: 2 days + ongoing monitoring593**Execution Mode**: Sequential deployment with validation gates594**Agents**: `production-validator`, `devops-engineer`, `performance-monitor`595596**Process**:5975981. **Pre-Production Validation** (Day 13 Morning)599 ```bash600 npx claude-flow hooks pre-task --description "Final production validation"601 npx claude-flow agent spawn --type production-validator602 ```603604 **Production Validator** checks:605 - **All Tests Passing**: 100% of test suite (unit + integration + E2E)606 - **Code Coverage**: >90% verified607 - **Security Audit**: Passed with zero critical/high issues608 - **Performance Benchmarks**: All targets met or exceeded609 - **Documentation**: Complete and published610 - **Monitoring Setup**: Dashboards and alerts configured611 - **Rollback Plan**: Documented and rehearsed612613 Generate go/no-go report:614 ```bash615 npx claude-flow memory store --key "api-development/${API_ID}/phase-5/production-validator/go-no-go" \616 --value '{"decision": "GO", "readiness_score": 98, "blockers": []}'617 ```618619 If any validation fails:620 ```bash621 # Return to appropriate phase to fix issues622 npx claude-flow hooks notify --message "Production validation FAILED: ${BLOCKER_ISSUES}"623 # Halt deployment until issues resolved624 ```6256262. **Staging Deployment** (Day 13 Afternoon)627 ```bash628 npx claude-flow agent spawn --type cicd-engineer629 ```630631 **DevOps Engineer** deploys to staging:632 ```bash633 # Deploy API to staging environment634 kubectl apply -f k8s/staging/635636 # Run smoke tests637 npm run test:smoke -- --env=staging638639 # Validate monitoring640 curl https://api-staging.example.com/health641 ```642643 **Staging Validation**:644 - Full test suite execution against staging645 - Data persistence verification646 - Error handling validation647 - Monitoring dashboard validation648 - Load balancer health checks649650 **Memory Storage**:651 ```bash652 npx claude-flow memory store --key "api-development/${API_ID}/phase-5/devops-engineer/staging-deploy"653 ```6546553. **Production Deployment** (Day 14 Morning - Blue-Green Strategy)656 ```bash657 npx claude-flow workflow create --name "production-deployment" \658 --steps '["blue-green-deploy","canary-rollout","full-rollout","monitor"]'659 ```660661 **DevOps Engineer** executes:662 ```bash663 # Step 1: Deploy to green environment (alongside blue)664 kubectl apply -f k8s/production/green/665666 # Step 2: Run smoke tests on green667 npm run test:smoke -- --env=production-green668669 # Step 3: Gradual traffic shift (canary rollout)670 # 10% traffic to green671 kubectl patch service api-service -p '{"spec":{"selector":{"version":"green","weight":"10"}}}'672 sleep 300 # Monitor for 5 minutes673674 # 50% traffic to green675 kubectl patch service api-service -p '{"spec":{"selector":{"version":"green","weight":"50"}}}'676 sleep 600 # Monitor for 10 minutes677678 # 100% traffic to green679 kubectl patch service api-service -p '{"spec":{"selector":{"version":"green","weight":"100"}}}'680681 # Step 4: Keep blue environment ready for rollback (for 24 hours)682 ```683684 **Rollback Procedure** (if issues detected):685 ```bash686 # Instant rollback to blue687 kubectl patch service api-service -p '{"spec":{"selector":{"version":"blue","weight":"100"}}}'688 ```689690 **Memory Storage**:691 ```bash692 npx claude-flow memory store --key "api-development/${API_ID}/phase-5/devops-engineer/production-deploy" \693 --value '{"status": "SUCCESS", "deployment_time": "2025-01-15T10:00:00Z", "version": "v1.0.0"}'694 ```6956964. **Post-Deployment Monitoring** (Day 14 Afternoon + Ongoing)697 ```bash698 npx claude-flow agent spawn --type performance-monitor699 ```700701 **Performance Monitor** tracks:702 - **Application Metrics**:703 - API response time (p50, p95, p99)704 - Throughput (requests per second)705 - Error rate (4xx, 5xx errors)706 - Uptime and availability707 - **Infrastructure Metrics**:708 - CPU and memory utilization709 - Database connection pool usage710 - Cache hit ratio711 - Network throughput712 - **Business Metrics**:713 - API usage by endpoint714 - User activity patterns715 - Rate limit violations716 - Authentication success/failure rates717718 Generate hourly reports for first 24 hours:719 ```bash720 npx claude-flow hooks post-task --task-id "production-monitoring" --export-metrics true721 npx claude-flow memory store --key "api-development/${API_ID}/phase-5/performance-monitor/metrics/hour-${HOUR}"722 ```723724 **Alert Configuration**:725 - Response time > 500ms (p95): WARNING726 - Response time > 1000ms (p95): CRITICAL727 - Error rate > 1%: WARNING728 - Error rate > 5%: CRITICAL729 - Uptime < 99.9%: CRITICAL730 - Database connection pool > 80%: WARNING7317325. **Documentation Publication** (Day 14)733 ```bash734 npx claude-flow agent spawn --type api-docs735 ```736737 **Update Final Documentation**:738 - Production API URLs and endpoints739 - Authentication endpoints (production)740 - Monitoring dashboards (link to Grafana)741 - Support contact information742 - SLA and uptime guarantees743744 Publish to developer portal:745 ```bash746 npm run docs:publish -- --env=production747 ```7487496. **Knowledge Transfer** (End of Phase 5)750 ```bash751 npx claude-flow hooks session-end --export-workflow "/tmp/${API_ID}-workflow.json"752 ```753754 Create handoff materials:755 - Developer onboarding guide756 - Support team training materials757 - Common issues and troubleshooting758 - Escalation procedures759760 **Memory Storage**:761 ```bash762 npx claude-flow memory store --key "api-development/${API_ID}/phase-5/knowledge-transfer/complete"763 ```764765**Outputs**:766- Production API (live and stable)767- Complete documentation (published to developer portal)768- Monitoring dashboards (real-time metrics)769- Trained support team (ready for inquiries)770- Workflow documentation (for future reference)771772**Success Criteria**:773- [ ] Production deployment successful with zero downtime774- [ ] All monitoring metrics within acceptable ranges775- [ ] Documentation published and accessible776- [ ] Support team trained and ready777- [ ] Post-deployment validation complete778779---780781## Memory Coordination782783### Namespace Convention784785All workflow data follows this hierarchical pattern:786787```788api-development/{api-id}/phase-{N}/{agent-type}/{deliverable-type}789```790791**Examples**:792- `api-development/user-api-v1/phase-1/product-manager/requirements`793- `api-development/user-api-v1/phase-1/system-architect/openapi-spec`794- `api-development/user-api-v1/phase-2/backend-developer/project-setup`795- `api-development/user-api-v1/phase-3/tester/auth/register-tests`796- `api-development/user-api-v1/phase-4/security-specialist/audit-report`797- `api-development/user-api-v1/phase-5/devops-engineer/production-deploy`798799### Cross-Phase Data Flow800801**Phase 1 → Phase 2**:802```bash803# Phase 2 retrieves design specifications804npx claude-flow memory retrieve --key "api-development/${API_ID}/phase-1/system-architect/openapi-spec"805npx claude-flow memory retrieve --key "api-development/${API_ID}/phase-1/database-architect/schema"806```807808**Phase 2 → Phase 3**:809```bash810# Phase 3 retrieves project structure and test plan811npx claude-flow memory retrieve --key "api-development/${API_ID}/phase-2/backend-developer/project-setup"812npx claude-flow memory retrieve --key "api-development/${API_ID}/phase-1/qa-engineer/test-plan"813```814815**Phase 3 → Phase 4**:816```bash817# Phase 4 retrieves implementation for testing818npx claude-flow memory retrieve --pattern "api-development/${API_ID}/phase-3/backend-developer/*"819```820821**Phase 4 → Phase 5**:822```bash823# Phase 5 retrieves test results and documentation824npx claude-flow memory retrieve --pattern "api-development/${API_ID}/phase-4/*/results"825```826827---828829## Scripts & Automation830831### Pre-Workflow Initialization832833```bash834#!/bin/bash835# Initialize API development workflow836837API_NAME="$1"838API_ID="${API_NAME}-api-$(date +%Y%m%d)"839840# Setup coordination841npx claude-flow hooks pre-task --description "API Development: ${API_NAME}"842843# Initialize hierarchical swarm (12 agents max)844npx claude-flow swarm init --topology hierarchical --max-agents 12 --strategy specialized845846# Store API metadata847npx claude-flow memory store --key "api-development/${API_ID}/metadata" --value '{848 "api_name": "'"${API_NAME}"'",849 "api_id": "'"${API_ID}"'",850 "start_date": "'"$(date -I)"'",851 "timeline_days": 14,852 "phases": 5,853 "tdd_approach": true854}'855856echo "✅ API development initialized: ${API_ID}"857```858859### TDD Cycle Script860861```bash862#!/bin/bash863# Execute TDD cycle for single endpoint864865API_ID="$1"866ENDPOINT_PATH="$2" # e.g., "POST /api/auth/register"867868echo "🔴 RED Phase: Writing tests for ${ENDPOINT_PATH}"869npx claude-flow agent spawn --type tester --task "write-tests:${ENDPOINT_PATH}"870871# Wait for tests to be written872npx claude-flow memory retrieve --key "api-development/${API_ID}/phase-3/tester/${ENDPOINT_PATH}/tests"873874echo "🟢 GREEN Phase: Implementing ${ENDPOINT_PATH}"875npx claude-flow agent spawn --type backend-dev --task "implement:${ENDPOINT_PATH}"876877# Run tests to verify implementation878npm test -- "${ENDPOINT_PATH}.test.js"879880echo "🔵 REFACTOR Phase: Code review for ${ENDPOINT_PATH}"881npx claude-flow agent spawn --type reviewer --task "review:${ENDPOINT_PATH}"882883# Store completion884npx claude-flow hooks post-edit --file "src/routes/${ENDPOINT_PATH}.ts" \885 --memory-key "api-development/${API_ID}/phase-3/completed/${ENDPOINT_PATH}"886```887888### Deployment Script889890```bash891#!/bin/bash892# Blue-green deployment to production893894API_ID="$1"895VERSION="$2"896897echo "🚀 Starting blue-green deployment: ${VERSION}"898899# Pre-deployment validation900npx claude-flow agent spawn --type production-validator901VALIDATION=$(npx claude-flow memory retrieve --key "api-development/${API_ID}/phase-5/production-validator/go-no-go")902903if [ "$(echo $VALIDATION | jq -r '.decision')" != "GO" ]; then904 echo "❌ Production validation FAILED. Aborting deployment."905 exit 1906fi907908# Deploy to green environment909kubectl apply -f k8s/production/green/910911# Smoke tests912npm run test:smoke -- --env=production-green913914# Gradual traffic shift (canary)915for WEIGHT in 10 50 100; do916 echo "Shifting ${WEIGHT}% traffic to green..."917 kubectl patch service api-service -p "{\"spec\":{\"selector\":{\"version\":\"green\",\"weight\":\"${WEIGHT}\"}}}"918919 # Monitor for issues (5-10 minutes per step)920 DURATION=$((WEIGHT == 100 ? 10 : 5))921 sleep $((DURATION * 60))922923 # Check error rate924 ERROR_RATE=$(curl -s https://monitoring.example.com/api/error-rate | jq -r '.rate')925 if (( $(echo "$ERROR_RATE > 1.0" | bc -l) )); then926 echo "❌ High error rate detected: ${ERROR_RATE}%. Rolling back."927 kubectl patch service api-service -p '{"spec":{"selector":{"version":"blue","weight":"100"}}}'928 exit 1929 fi930done931932echo "✅ Deployment complete: ${VERSION}"933npx claude-flow hooks post-task --task-id "production-deployment" --export-metrics true934```935936---937938## Success Metrics939940### Technical Metrics941- **Test Coverage**: > 90% (code coverage report)942- **API Response Time**: < 200ms (p95)943- **Uptime**: 99.9%+ (production SLA)944- **Error Rate**: < 0.1% (4xx + 5xx errors)945- **Code Quality Score**: A rating (SonarQube/CodeClimate)946- **Security Audit**: Zero critical, zero high issues947948### Performance Metrics949- **Throughput**: > 1000 req/sec sustained950- **Database Query Time**: < 50ms (p95)951- **Memory Usage**: < 512MB per instance952- **CPU Usage**: < 70% under normal load953954### Quality Metrics955- **TDD Adherence**: 100% (all endpoints test-first)956- **Documentation Coverage**: 100% of endpoints documented957- **API Compliance**: OpenAPI 3.0 valid (no errors)958- **Code Review Approval**: 100% (all code reviewed)959960---961962## Usage Examples963964### Example 1: User Management API965966```bash967# Initialize workflow968API_ID="user-management-api-20250115"969npx claude-flow hooks pre-task --description "User Management API Development"970971# Phase 1: Planning (Day 1-2)972npx claude-flow agent spawn --type planner973# Output: 15 endpoints defined, authentication strategy established974975# Phase 3: TDD Implementation (Day 5-10)976for endpoint in "POST /api/users/register" "POST /api/users/login" "GET /api/users/:id"; do977 ./tdd-cycle.sh "${API_ID}" "${endpoint}"978done979# Output: All endpoints implemented with 94% test coverage980981# Phase 5: Production Deployment (Day 14)982./deploy-production.sh "${API_ID}" "v1.0.0"983# Output: Deployed successfully, handling 1500 req/sec with 99.95% uptime984```985986### Example 2: Payment Gateway API987988```bash989# High-security API with PCI compliance990API_ID="payment-gateway-api-20250120"991992# Phase 1: Enhanced security planning993npx claude-flow agent spawn --type system-architect --focus "pci-compliance"994npx claude-flow agent spawn --type security-specialist --focus "payment-security"995# Output: PCI DSS compliant architecture designed996997# Phase 4: Enhanced security testing998npx claude-flow agent spawn --type security-manager --focus "penetration-testing-comprehensive"999# Output: Zero vulnerabilities, PCI DSS validation passed1000```10011002### Example 3: Microservice API (Event-Driven)10031004```bash1005# Microservice with message queue integration1006API_ID="order-service-api-20250125"10071008# Phase 2: Message queue setup1009npx claude-flow agent spawn --type backend-dev --capabilities "rabbitmq,events"1010# Output: Event-driven architecture with pub/sub patterns10111012# Phase 3: Event handler TDD1013./tdd-cycle.sh "${API_ID}" "POST /api/orders/create"1014./tdd-cycle.sh "${API_ID}" "EVENT order.created"1015# Output: Synchronous API + asynchronous event processing1016```10171018---10191020## GraphViz Process Diagram10211022See `when-building-backend-api-orchestrate-api-development-process.dot` for visual workflow representation showing:1023- 5 phases with TDD cycle details1024- 12 agent interactions and coordination1025- Memory flow between phases1026- Blue-green deployment strategy1027- Validation gates and decision points10281029---10301031## Quality Checklist10321033Before considering API development complete, verify:10341035- [ ] **Phase 1**: Requirements documented, OpenAPI spec complete, database schema designed1036- [ ] **Phase 2**: Development environment operational, CI/CD pipeline functional1037- [ ] **Phase 3**: All endpoints implemented following TDD, test coverage > 90%1038- [ ] **Phase 4**: E2E tests passing, security audit passed, performance benchmarks met1039- [ ] **Phase 5**: Production deployment successful, monitoring active, documentation published10401041**Memory Verification**:1042- [ ] `api-development/${API_ID}/phase-1/*` - Planning artifacts1043- [ ] `api-development/${API_ID}/phase-2/*` - Setup configurations1044- [ ] `api-development/${API_ID}/phase-3/*` - TDD implementation + tests1045- [ ] `api-development/${API_ID}/phase-4/*` - Test results + documentation1046- [ ] `api-development/${API_ID}/phase-5/*` - Deployment logs + metrics10471048---10491050**Workflow Complexity**: Medium (12 agents, 14 days, 5 phases)1051**Coordination Pattern**: Hierarchical with TDD cycle iteration1052**Memory Footprint**: ~30-50 memory entries per API1053**Typical Use Case**: Production-ready REST API with comprehensive testing and quality gates