This guide demonstrates how to apply the Analyze → Plan → Execute → Iterate cycle to achieve optimal results in software development.
┌──────────────┐
│ ANALYZE │ ← Return here if not optimal
│ Understand │
│ Problem │
└──────┬───────┘
↓
┌──────────────┐
│ PLAN │
│ Design │
│ Solution │
└──────┬───────┘
↓
┌──────────────┐
│ EXECUTE │
│ Implement │
│ Step by Step │
└──────┬───────┘
↓
┌──────────────┐
│ ITERATE │
│ Measure & │
│ Review │
└──────┬───────┘
↓
Optimal? ─No─→ Back to ANALYZE
↓
Yes
↓
DONE
- Fully understand the problem or requirement
- Gather all necessary context
- Identify constraints and dependencies
- Assess current state
Questions to answer:
- What is the goal?
- What are the acceptance criteria?
- What are the constraints (time, resources, technical)?
- Who are the stakeholders?
- What is the expected timeline?# Explore repository structure
tree -L 3 -I 'node_modules|dist|build'
# Review recent changes
git log --oneline -20
# Check current status
git status
# Review existing tests
npm test --listTests # or equivalent
# Check dependencies
npm list --depth=0 # or pip list, etc.- Review existing architecture
- Identify design patterns in use
- Understand testing approach
- Check CI/CD setup
- Review documentation
Common risks to consider:
- Breaking existing functionality
- Performance degradation
- Security vulnerabilities
- Backwards compatibility issues
- Integration problems
- Technical debt increase
- Requirements clearly understood
- Codebase structure mapped out
- Existing patterns identified
- Dependencies documented
- Test coverage assessed
- Risks identified
- Constraints noted
- Success criteria defined
Document your findings:
## Analysis Summary
### Problem Statement
[Clear description of what needs to be done]
### Current State
[What exists now]
### Constraints
- [List any limitations]
### Dependencies
- [List dependencies and integrations]
### Risks
1. [Risk 1]: Mitigation: [how to address]
2. [Risk 2]: Mitigation: [how to address]
### Success Criteria
- [ ] [Criterion 1]
- [ ] [Criterion 2]- Design the solution
- Break work into manageable steps
- Prioritize tasks
- Define validation approach
Consider multiple approaches:
## Approach A: [Name]
Pros:
- [Advantage 1]
- [Advantage 2]
Cons:
- [Disadvantage 1]
- [Disadvantage 2]
## Approach B: [Name]
Pros:
- [Advantage 1]
Cons:
- [Disadvantage 1]
## Selected Approach: [A or B]
Rationale: [Why this approach is best]Break the work into small, testable units:
## Implementation Plan
### Phase 1: Foundation
- [ ] Task 1.1: [Small, specific task]
- Estimated time: [X minutes]
- Validation: [How to test]
- [ ] Task 1.2: [Small, specific task]
- Estimated time: [X minutes]
- Validation: [How to test]
### Phase 2: Core Implementation
- [ ] Task 2.1: [Small, specific task]
- [ ] Task 2.2: [Small, specific task]
### Phase 3: Integration & Testing
- [ ] Task 3.1: Integration tests
- [ ] Task 3.2: E2E tests
- [ ] Task 3.3: Performance testing
### Phase 4: Documentation
- [ ] Update README
- [ ] Update API docs
- [ ] Add code commentsDefine how each change will be validated:
## Testing Plan
### Unit Tests
- [ ] Test case 1: [Description]
- [ ] Test case 2: [Description]
### Integration Tests
- [ ] Test scenario 1: [Description]
- [ ] Test scenario 2: [Description]
### Manual Validation
- [ ] Step 1: [Action to take]
- Expected: [What should happen]
- [ ] Step 2: [Action to take]
- Expected: [What should happen]- Solution approach selected
- Work broken into small tasks
- Tasks ordered by dependency
- Each task has validation criteria
- Testing strategy defined
- Rollback plan considered
- Documentation needs identified
A detailed, actionable plan:
## Execution Plan
### Overview
[Brief description of solution]
### Steps (in order)
1. [Step 1]: [What to do]
- Files: [Files to modify]
- Tests: [Tests to add/update]
- Validation: [How to verify]
2. [Step 2]: [What to do]
- Files: [Files to modify]
- Tests: [Tests to add/update]
- Validation: [How to verify]
### Rollback Plan
If things go wrong:
1. [Rollback step 1]
2. [Rollback step 2]- Implement the plan step by step
- Validate each change immediately
- Adapt plan based on learnings
- Maintain quality throughout
# Ensure clean starting state
git status
# Create feature branch if needed
git checkout -b feature/descriptive-name
# Install/update dependencies
npm install # or pip install -r requirements.txtFor each task in the plan:
Step Template:
## Task: [Task Name]
### Implementation
1. [Action 1]
2. [Action 2]
3. [Action 3]
### Validation
```bash
# Run relevant tests
npm test path/to/test
# Manual verification
[Commands to verify change works]git add [files]
git commit -m "feat: [clear description]
[Body explaining why and how]
Relates to #[issue number]"- Does it work as expected?
- Are tests passing?
- Is code quality maintained?
- Any unexpected side effects?
#### 3. Continuous Validation
After EACH change:
```bash
# Run related tests
npm test -- path/to/changed/area
# Run linter
npm run lint
# Check for type errors (if applicable)
npm run type-check
# Manual smoke test
# [Run the application and verify]
Update documentation with each change:
- Add code comments for complex logic
- Update README if behavior changes
- Update API docs if interface changes
- Add inline examples where helpful
- Task implemented
- Tests added/updated
- Tests passing
- Linting passing
- Manual verification done
- Documentation updated
- Code reviewed (self-review)
- Committed with clear message
# ✅ GOOD: Small, focused commits
git commit -m "feat: add user validation"
git commit -m "test: add user validation tests"
git commit -m "docs: update user API docs"
# ❌ BAD: Giant, unfocused commit
git commit -m "implement entire feature with tests and docs"# After each file change
npm test -- path/to/test.js
# Before each commit
npm test && npm run lint && git commit# If something goes wrong
git diff # Review changes
git checkout -- file.js # Revert single file
git reset --hard # Revert all changes (last resort)- Measure results against success criteria
- Identify what worked well
- Identify what needs improvement
- Decide if another iteration is needed
# Run complete test suite
npm test
# Run E2E tests
npm run test:e2e
# Check code coverage
npm run test:coverage
# Performance tests (if applicable)
npm run test:performance# Code quality
npm run lint
npm run type-check
# Security scan
npm audit
# Bundle size (for web)
npm run build
ls -lh dist/Test the actual user experience:
## Manual Test Checklist
- [ ] Happy path works
- [ ] Error cases handled gracefully
- [ ] Edge cases covered
- [ ] Performance acceptable
- [ ] UI/UX smooth (if applicable)
- [ ] Backwards compatible
- [ ] No regressions in existing features## Success Criteria Review
Original criteria:
- [ ] Criterion 1: [Status and notes]
- [ ] Criterion 2: [Status and notes]
- [ ] Criterion 3: [Status and notes]
All criteria met? [Yes/No]
If No, what's missing? [Description]## What Worked Well
- [Thing 1]
- [Thing 2]
## What Could Be Better
- [Improvement 1]
- [Improvement 2]
## Should We Iterate?
- [ ] No - Solution is optimal for current needs
- [ ] Yes - [Specific improvements needed]- All tests passing
- Code quality checks passed
- Manual testing completed
- Success criteria reviewed
- Performance measured
- Security checked
- Documentation complete
- Improvement opportunities identified
If improvements are needed:
## Iteration N+1 Plan
### Issues Found
1. [Issue 1]: [Description]
2. [Issue 2]: [Description]
### Proposed Improvements
1. [Improvement 1]: [Expected benefit]
2. [Improvement 2]: [Expected benefit]
### Next Steps
Return to ANALYZE phase with new focus:
[What to analyze in next iteration]If solution is optimal:
## Completion Summary
### Achievements
- [Achievement 1]
- [Achievement 2]
### Metrics
- Test coverage: [X%]
- Performance: [metrics]
- Code quality: [metrics]
### Lessons Learned
- [Lesson 1]
- [Lesson 2]
### Future Considerations
- [Potential enhancement 1]
- [Potential enhancement 2]Add authentication to an existing API
- Current state: API has no authentication
- Goal: Add JWT-based authentication
- Constraints: Don't break existing clients initially
- Risk: Existing integrations might break
- Add authentication middleware (optional initially)
- Create login endpoint
- Add tests
- Update documentation
- Make authentication required (phase 2)
# Step 1: Install dependencies
npm install jsonwebtoken bcrypt
# Step 2: Create auth middleware
# [Implement auth.middleware.js]
npm test auth.middleware.test.js ✓
# Step 3: Create login endpoint
# [Implement auth.controller.js]
npm test auth.controller.test.js ✓
# Step 4: Add to existing routes (optional)
# [Update routes with optional auth]
npm test ✓
git commit -m "feat(auth): add JWT authentication"- ✓ Authentication works
- ✓ Tests pass
- ✓ Existing clients still work (auth optional)
⚠️ Performance concern: Token verification on every request- → Decision: Iterate to add caching
- Issue: Token verification is slow (100ms per request)
- Goal: Reduce to <10ms
- Approach: Add Redis caching for verified tokens
- Add Redis caching layer
- Cache verified tokens (5 min TTL)
- Benchmark performance
- Update documentation
npm install redis
# [Implement token caching]
npm test ✓
# Benchmark: Token verification now 5ms ✓
git commit -m "perf(auth): add Redis caching for token verification"- ✓ Performance target met
- ✓ All tests pass
- ✓ Documentation updated
- → Decision: Solution is optimal, complete
- Success criteria not fully met
- Performance issues discovered
- Edge cases found
- Better approach identified
- New requirements emerged
- All success criteria met
- Diminishing returns on improvements
- Time/resource constraints
- Good enough for current needs
- Each iteration adds value
- Changes are measurable
- Learning from previous iterations
- Clear progress toward goal
- Circular changes (undoing previous work)
- No measurable improvement
- Scope creep
- Changes based on assumptions, not data
- Iterate with purpose: Each iteration should have clear goals
- Measure progress: Use metrics to track improvement
- Know when to stop: Perfect is the enemy of done
- Document learnings: Help future iterations
The goal is not infinite iteration, but reaching an optimal solution efficiently.