- Version: 2.0
Analyzes codebase against project standards and creates a prioritized refactoring story with actionable requirements.
/plugin marketplace add ninthspace/claude-code-marketplace/plugin install sdd@ninthspace-marketplacePurpose: Analyze codebase against project standards and create a prioritized refactoring story with specific, actionable requirements.
Syntax: /sdd:story-refactor [objective]
| Parameter | Type | Required | Default | Description | Validation |
|---|---|---|---|---|---|
| objective | string | No | comprehensive | Refactoring focus area or general analysis | Any text phrase |
/docs/project-context/ directory/docs/stories/development//docs/project-context/ directory exists/sdd:project-init first/docs/project-context/coding-standards.md - Code quality rules and thresholds/docs/project-context/technical-stack.md - Framework patterns and best practices/docs/project-context/development-process.md - Quality requirementsANALYZE codebase using DISCOVERED standards from project context:
Structure Issues:
Naming Conventions:
Framework Patterns (from technical-stack.md):
Error Handling:
Performance:
Accessibility (if relevant):
PRIORITIZE findings:
IF comprehensive mode:
IF objective-focused mode:
STORY-YYYY-NNN:
ENSURE /docs/stories/backlog/ directory exists
CREATE story file at /docs/stories/backlog/[story-id].md
POPULATE refactoring story template with:
REFERENCE analysis findings:
DISPLAY refactoring summary:
✅ Refactoring Story Created
═══════════════════════════════════
Story ID: [STORY-YYYY-NNN]
Title: [Auto-generated Title]
Location: /docs/stories/backlog/[story-id].md
Status: backlog
Analysis Mode: [Comprehensive / Objective-focused: {objective}]
Findings:
- Priority 1 (Critical): [count] issues
- Priority 2 (Important): [count] issues
- Priority 3 (Nice to have): [count] improvements
Files Affected: [count] files
Estimated Complexity: [Low/Medium/High]
SUGGEST next steps:
💡 NEXT STEPS:
1. Review story in /docs/stories/backlog/[story-id].md
2. /sdd:story-start [story-id] # Move to development when ready
3. /sdd:project-status # View all stories
/docs/stories/backlog/[story-id].md - New refactoring story with comprehensive analysis# [STORY-ID]: [Refactoring Title]
## Status: backlog
**Started:** [Today's Date]
**Completed:**
**Branch:** (none - in backlog)
## Objective
[Clear statement of refactoring goal based on analysis]
## Background
[Why this refactoring is needed - analysis context, pain points, violations found]
## Analysis Findings
### Priority 1: Critical
- [ ] **[File:Line]**: [Issue description]
- Current: [Code example or pattern]
- Standard: [Expected pattern from coding-standards.md]
- Impact: [Why this matters]
### Priority 2: Important
- [ ] **[File:Line]**: [Issue description]
- Current: [Code example]
- Suggested: [Improved pattern]
- Benefit: [Improvement gained]
### Priority 3: Nice to Have
- [ ] **[File:Line]**: [Improvement opportunity]
- Enhancement: [What to improve]
- Justification: [Why it helps]
## Requirements
### R1: [Requirement Title]
**What**: [Specific change needed]
**Why**: [Business/technical justification]
**How**: [Suggested approach or pattern]
**Tests**: [Impact on existing tests]
**Dependencies**: [Related components]
### R2: [Requirement Title]
[Same structure as R1]
## Acceptance Criteria
- [ ] All Priority 1 issues resolved
- [ ] Code quality metrics maintained or improved
- [ ] All existing functionality works identically
- [ ] All tests pass (no failures introduced)
- [ ] Code follows [framework] patterns from technical-stack.md
- [ ] Performance metrics maintained or improved
- [ ] Documentation updated where necessary
## Implementation Notes
**Approach**: [Recommended refactoring strategy]
**Stack**: [Auto-populated from technical-stack.md]
**Patterns**: [Framework-specific patterns to apply]
**Tools**: [Linters, formatters, static analysis tools to use]
## Testing Requirements
### Existing Tests
- [ ] All unit tests pass
- [ ] All integration tests pass
- [ ] All E2E tests pass
- [ ] No regressions in test coverage
### New Tests
- [ ] [New test scenario 1]
- [ ] [New test scenario 2]
### Manual Testing
- [ ] [Manual verification step 1]
- [ ] [Manual verification step 2]
## Risk Assessment
### High Risk
- **[Risk description]**: [Mitigation strategy]
### Medium Risk
- **[Risk description]**: [Mitigation strategy]
### Low Risk
- **[Risk description]**: [Mitigation strategy]
## Impact Analysis
**Components Affected**: [List of components/modules]
**Tests Affected**: [List of test files]
**Dependencies**: [External dependencies or other stories]
**Breaking Changes**: [Yes/No - details if yes]
## Progress Log
- [Today]: Created refactoring story from code analysis
## Rollback Plan
[How to rollback if issues arise during refactoring]
## Lessons Learned
[To be filled when complete]
INPUT:
/sdd:story-refactor
OUTPUT:
→ Checking project context...
→ Loading coding standards and framework patterns...
→ Analyzing codebase comprehensively...
→ Found 23 issues across 8 files
✅ Refactoring Story Created
═══════════════════════════════════
Story ID: STORY-2025-012
Title: Comprehensive Code Quality Improvements
Location: /docs/stories/backlog/STORY-2025-012.md
Status: backlog
Analysis Mode: Comprehensive
Findings:
- Priority 1 (Critical): 3 issues
- Priority 2 (Important): 12 issues
- Priority 3 (Nice to have): 8 improvements
Files Affected: 8 files
Estimated Complexity: High
💡 NEXT STEPS:
1. Review story in /docs/stories/backlog/STORY-2025-012.md
2. /sdd:story-start STORY-2025-012 # Move to development when ready
3. /sdd:project-status # View all stories
INPUT:
/sdd:story-refactor improve performance
OUTPUT:
→ Checking project context...
→ Loading coding standards and framework patterns...
→ Analyzing for performance issues...
→ Scanning database queries, caching, assets...
→ Found 7 performance issues across 5 files
✅ Refactoring Story Created
═══════════════════════════════════
Story ID: STORY-2025-013
Title: Performance Optimization Refactoring
Location: /docs/stories/backlog/STORY-2025-013.md
Status: backlog
Analysis Mode: Objective-focused (improve performance)
Findings:
- Priority 1 (Performance): 7 issues
• 3 N+1 query problems
• 2 missing cache opportunities
• 2 unoptimized asset loads
- Priority 2 (Critical): 0 issues
- Priority 3 (Supporting): 2 improvements
Files Affected: 5 files
Estimated Complexity: Medium
💡 NEXT STEPS:
1. Review story in /docs/stories/backlog/STORY-2025-013.md
2. /sdd:story-start STORY-2025-013 # Move to development when ready
3. /sdd:project-status # View all stories
INPUT:
/sdd:story-refactor improve accessibility
OUTPUT:
→ Checking project context...
→ Analyzing ARIA, keyboard nav, screen reader support...
→ Found 15 accessibility issues across 6 components
✅ Refactoring Story Created
═══════════════════════════════════
Story ID: STORY-2025-014
Title: Accessibility Compliance Refactoring
Location: /docs/stories/backlog/STORY-2025-014.md
Status: backlog
Analysis Mode: Objective-focused (improve accessibility)
Findings:
- Priority 1 (Accessibility): 15 issues
• 8 missing ARIA attributes
• 4 keyboard navigation gaps
• 3 screen reader issues
- Priority 2 (Critical): 0 issues
- Priority 3 (Supporting): 5 improvements
Files Affected: 6 components
Estimated Complexity: Medium
💡 NEXT STEPS:
1. Review story in /docs/stories/backlog/STORY-2025-014.md
2. /sdd:story-start STORY-2025-014 # Move to development when ready
3. /sdd:project-status # View all stories
/docs/project-context/ directory/sdd:project-init/sdd:project-init/sdd:project-init - Initialize project structure with standards/sdd:project-brief - Define project goals and constraints/sdd:story-new - Create feature story/sdd:story-start [id] - Begin refactoring work/sdd:project-status - View all stories