| name | ttb-skill-refactor |
| description | Refactor TTBaseUIKit code: migrate to TTViewCodable, replace raw UIKit with TTBaseUIKit, TTBaseSUI adoption, clean MVVM separation. |
| version | 2.3.0 |
| date_updated | 2026-05-30 |
| risk | safe |
| source | internal |
| loadLevel | domain |
| tags | ["refactor","migration","ttviewcodable","ttbasesui","cleanup","routing"] |
ttb-skill-refactor
Enterprise-grade refactoring workflow for TTBaseUIKit apps.
Zero Functional Change | TTViewCodable | TTBaseSUI | MVVM-C
Mandatory Preflight Execution Gate
Before this skill generates code, refactors, migrates, modifies files, creates architecture, updates UI/navigation, changes dependencies, updates workflows, or changes business logic, run the shared gate:
ttb-skill-shared/fragments/ttb-preflight-execution-gate.frag.md
ttb-skill-shared/fragments/ttb-cross-functional-analysis-gate.frag.md when refactor scope touches feature behavior, UX flow, architecture, or bug prevention
ttb-skill-shared/templates/ttb-clarification-survey.md when confidence is below threshold
Required phase order: Requirement Analysis -> Context Validation -> Ambiguity Detection -> Missing Information Detection -> Survey / Clarification -> Confidence Evaluation -> Execution Approval.
Execution thresholds:
| Confidence | Action |
|---|
90-100 | Execute directly and state key assumptions |
70-89 | Execute only with documented low-risk assumptions |
<70 | Do not execute; ask a concise survey first |
Cap confidence at 69 when target module, architecture direction, UIKit/SwiftUI choice, navigation behavior, API/business logic, localization format, state management, dependency info, or ownership is unclear. Parse English, Vietnamese, mixed-language, diacritic-free Vietnamese, and light typos before scoring.
When refactor scope is tied to feature updates, bug prevention, architecture changes, or user-visible flow changes, analyze as Product Owner, Business Analyst, UX/UI Designer, Solution Architect, Senior Developer, and QA. Compare options across business value, architecture, UI/UX, performance, scalability, maintainability, security, testing, and operations; ask at least 5 value-expansion questions after analysis. If requirements are ambiguous/incomplete, ask at least 6 clarification questions before design/development.
When to Use
- "refactor", "clean up code", "restructure"
- "migrate to TTViewCodable"
- "replace raw UIKit with TTBaseUIKit"
- "migrate native SwiftUI to TTBaseSUI"
Routing Contract
input:
required: [refactor_goal, affected_files_or_module, behavior_to_preserve]
optional: [target_pattern, migration_constraints, verification_command]
output:
artifacts: [migration_plan, changed_files, before_after_notes, verification_report]
completion_gate: "zero behavior change + build/compliance verification"
confidence:
auto_route: ">= 0.78 for refactor/cleanup/migration/raw UIKit replacement intents"
clarify: "0.55-0.77 when prompt mixes bugfix and cleanup"
fallback:
default: "If behavior is broken, run ttb-skill-bugfix first. If user only wants scoring, route to audit."
Multilingual aliases: refactor, clean up code, migrate to TTViewCodable, replace raw UIKit, dọn code, don code, tái cấu trúc, giam trung lap.
Anti-patterns: do not add new features during refactor; do not change behavior silently; do not migrate across unrelated modules in one step.
Scope
| Command | Scope |
|---|
/ttb-refactor-uikit | UIKit → TTViewCodable, TTBaseUIKit |
/ttb-refactor-swiftui | Native SwiftUI → TTBaseSUI |
Workflow Overview
UIKit Refactoring (5 Phases)
See ttb-skill-refactor.prompt.md for detailed steps:
| Phase | Focus |
|---|
| 1 | MVVM Separation — ViewModel purity |
| 2 | TTViewCodable Adoption |
| 3 | Component Replacement — TTBaseUIKit |
| 4 | Constraint Refactoring — token usage |
| 5 | Handler Refactoring — closures |
SwiftUI Refactoring (4 Phases)
See ttb-skill-refactor.prompt.md for detailed steps:
| Phase | Focus |
|---|
| 1 | Component Migration — TTBaseSUI wrappers |
| 2 | Modifier Migration — token-based styling |
| 3 | iOS 14+ Compliance — API compatibility |
| 4 | View Composition — extract subviews |
Rules
- ZERO behavioral change — refactoring must not alter functionality
- One change at a time — don't mix architecture with style changes
- Verify compilation — ensure xcodebuild succeeds after each phase
- No new features — refactoring does not add functionality
- Preserve git history — commit each phase separately if possible
Shared Resources
ttb-skill-shared/rules/ttb-rule-anti-patterns.md — Full anti-pattern reference
ttb-skill-shared/rules/ttb-rule-coding-standards.md — Coding conventions
ttb-skill-shared/rules/ttb-rule-memory-leaks.md — Memory leak detection
ttb-skill-shared/refs/ttb-ref-ttbaseuikit.md — TTBaseUIKit API reference
ttb-skill-shared/refs/ttb-ref-ttbasesui.md — TTBaseSUI component reference
ttb-skill-shared/refs/ttb-ref-ios14-compatibility.md — iOS 14 API guide
Output Format
See ttb-skill-refactor.prompt.md for the complete REFACTOR REPORT template.
Version: 2.3.0 | Date: 2026-05-30
Changelog: v2.3.0 — Added cross-functional product analysis gate, option exploration, 5 value-expansion questions, and 6-question ambiguity clarification gate. v2.2.0 — Added standardized routing contract, EN/VI refactor aliases, input/output schema, confidence guidance, and fallback strategy. v2.0.0 — Version bump, Iron Laws, critical token warnings, and shared resource alignment.