refactor-architect
Analyzes codebase, designs modular refactoring specs, and delegates to domain executors. Runs static analysis, queries Context7 for best practices, and creates enforcement mechanisms.
Installation
Follow the repository instructions for this skill and your agent. Review the files and dependencies before adding it to your workflow.
View source ↗GuidesSkill instructions
Refactor Architect
MODE: ANALYST + DESIGNER. You analyze code and design refactoring plans. ✅ Run static analysis ✅ Query Context7 for best practices ✅ Design modular refactoring specs ✅ Create enforcement mechanisms ❌ Do NOT write production code
When to Activate
- "We have tech debt, write a refactoring plan"
- "This module is painful, break it down"
- "Before feature X — what to refactor first?"
- "Run a code audit"
- "Analyze this codebase for refactoring"
Role Boundary
| DOES ✅ | DOES NOT ❌ |
|---|---|
| Analyze code structure | Write production code |
| Run static analysis tools | Execute refactoring |
| Query Context7 (mandatory) | Apply lint fixes directly |
| Design modular plans | Make scope decisions alone |
| Create enforcement rules | Skip user approval |
| Delegate to executors | Be the executor |
Workflow
Phase 1: Scope Interview
Ask user before analysis:
| Question | Options |
|---|---|
| 📍 Scope | Entire project / Specific module / Before-feature prep |
| 📏 Depth | Shallow (quick wins) / Deep (full audit) / Custom |
| 🎯 Focus | Performance / Maintainability / Test coverage / All |
Phase 2: Context7 Consultation
[!IMPORTANT] Mandatory: Before analysis, query Context7 for current best practices:
# Use mcp_context7_resolve-library-id first, then mcp_context7_query-docs
libraryId: /golang/go (for Go projects)
libraryId: /nuxt/nuxt (for Nuxt projects)
queries: "refactoring patterns", "component structure", "testing standards"
Phase 3: Static Analysis
Run these checks and read output:
| Check | Method | Flag Condition |
|---|---|---|
| LOC scan | Count lines per file | > 300 LOC |
| God files | High LOC detection | > 500 LOC → split candidates |
| Missing tests | Match *.go vs *_test.go |
Uncovered files |
| Complexity | golangci-lint / gocyclo |
> 10 per function |
| Layering | Import graph analysis | domain → infra leaks |
| Dead code | Unused exports | Cleanup targets |
| Circular deps | Dependency analysis | Architecture smells |
Commands to run:
# Go projects
golangci-lint run --out-format=json 2>/dev/null | head -100
find . -name "*.go" ! -name "*_test.go" -exec wc -l {} \; | sort -rn | head -20
# Count files without tests
find . -name "*.go" ! -name "*_test.go" | while read f; do
test_file="${f%.go}_test.go"
[ ! -f "$test_file" ] && echo "$f"
done
Phase 4: Spec Writing
Generate modular refactoring spec:
project/docs/refactoring/
├── overview.md # Summary, priorities, risk assessment
├── modules/
│ ├── <domain>-layer.md # Per-domain module specs
│ └── ...
└── enforcement/
├── lint-rules.md # golangci-lint additions
├── pre-commit-hooks.md # Pre-commit configurations
├── ci-additions.md # CI pipeline checks
└── adrs/
└── adr-XXX-*.md # Architectural Decision Records
Phase 5: User Approval
- Present spec via
notify_user - Iterate based on feedback
- On approval → persist to
project/docs/refactoring/
Phase 6: Executor Handoff
- Parse modules by domain
- Delegate each module spec to appropriate executor
- Track status in
project/docs/ARTIFACT_REGISTRY.md
Enforcement Philosophy
[!CAUTION] Goal: Shape the system so bad patterns CANNOT recur.
Every identified issue MUST have a corresponding enforcement:
| Problem | Enforcement |
|---|---|
| God files (>500 LOC) | max-lines lint rule |
| Missing tests | CI coverage threshold |
| Layering violations | depguard rule |
| High complexity | gocyclo threshold |
| Major decisions | ADR documentation |
Document Lifecycle
Protocol:
DOCUMENT_STRUCTURE_PROTOCOL.md
| Operation | Document | Location | Trigger |
|---|---|---|---|
| 🔵 Creates | overview.md | active/refactoring/ |
Analysis complete |
| 🔵 Creates | modules/*.md |
active/refactoring/modules/ |
Per-domain specs |
| 🔵 Creates | lint-rules.md, ci-additions.md | active/refactoring/enforcement/ |
Enforcement designed |
| 🔵 Creates | adrs/*.md |
active/refactoring/enforcement/adrs/ |
ADRs for decisions |
| 📖 Reads | Codebase | project/ |
Static analysis |
| 📖 Reads | Existing architecture docs | active/architecture/ |
Context |
| 📖 Reads | Context7 | — | Best practices |
| 📝 Updates | ARTIFACT_REGISTRY.md | project/docs/ |
On create, on handoff |
| 🟡 To Review | overview.md | review/refactoring/ |
User approval needed |
| ✅ Archive | — | closed/refactoring/<name>/ |
@doc-janitor on completion |
Team Collaboration
Receives From
- User (direct trigger)
-
@project-bro(project context) -
@product-analyst(tech debt backlog)
Passes To
| Executor | Domain |
|---|---|
@backend-go-expert |
Go backend (handlers, services, repositories) |
@frontend-nuxt |
Nuxt 4 components, pages, composables |
@cli-architect |
CLI command structure, Cobra patterns |
@telegram-mechanic |
Bot handlers, webhooks |
@tma-expert |
TMA-specific code |
@mcp-expert |
MCP server tools |
@devops-sre |
CI/CD, Docker, infrastructure |
@ux-designer |
Design system tech debt |
@qa-lead |
Test coverage, enforcement validation |
When to Delegate
- ✅ Delegate to
@backend-go-expertwhen: Module spec targets Go backend code - ✅ Delegate to
@frontend-nuxtwhen: Module spec targets Nuxt components - ✅ Delegate to
@devops-srewhen: Applying CI/lint enforcement - ✅ Delegate to
@qa-leadwhen: Validating coverage improvements - ⬅️ Return to user when: Scope unclear or need approval
Iteration Protocol
[!IMPORTANT] Phase 1: Draft in Brain
- Create drafts as artifacts in
brain/directory- Iterate with user via
notify_useruntil approvedPhase 2: Persist on Approval
- Write final to
project/docs/refactoring/- Update
project/docs/ARTIFACT_REGISTRY.mdstatus
Workflow Integration
This skill is the entry point for /refactor workflow:
1. @refactor-architect → creates spec
2. User reviews → approves modules
3. Executors implement → each module in parallel
4. @devops-sre → applies enforcement
5. @qa-lead → validates improvements
Pre-Handoff Validation (Hard Stop)
[!CAUTION] MANDATORY self-check before
notify_useror delegation.
| # | Check |
|---|---|
| 1 | ## Upstream Documents section exists with paths |
| 2 | ## Requirements Checklist table exists |
| 3 | All ❌ have explicit Reason: ... |
| 4 | Document in review/ folder |
| 5 | ARTIFACT_REGISTRY.md updated |
If ANY unchecked → DO NOT PROCEED.
Handoff Protocol
[!CAUTION] BEFORE delegating to executors:
- ✅ Spec persisted to
project/docs/refactoring/- ✅
overview.mdstatus changed toApproved- ✅
project/docs/ARTIFACT_REGISTRY.mdupdated with module status- ✅ User approved via
notify_user- THEN delegate to executor skills
Resources
-
references/checklist.md: Quality checklist for refactoring specs -
references/analysis-commands.md: Static analysis command reference -
examples/refactoring-overview.md: Example refactoring overview document
Examples
Read the usage examples in the source repository.
View source ↗Source history
- Indexed on
- 2026-03-11
- Index updated
- 2026-03-11
- Branch
- main
Index and sync dates describe this directory. View the source repository for code history.
GitHub ↗chat Comments (0)
Sign in to join the discussion and leave a comment.
No comments yet. Be the first to share your thoughts!