refactoring-patterns
Apply named refactoring transformations to improve code structure without changing behavior. Use when the user mentions "refactor this", "code smells", "extract method", "replace conditional", "technical debt", "move method", "inline variable", or "decompose conditional". Also trigger when cleaning up legacy code, preparing code for new features by restructuring, or identifying which transformation to apply to a specific code smell. Covers smell-driven refactoring, safe transformation sequences, and testing guards. For code quality foundations, see clean-code. For managing complexity, see software-design-philosophy.
What this skill does
# Refactoring Patterns Framework A disciplined approach to improving the internal structure of existing code without changing its observable behavior. Apply these named transformations when reviewing code, reducing technical debt, or preparing code for new features. Every refactoring follows the same loop: verify tests pass, apply one small structural change, verify tests still pass. ## Core Principle **Refactoring is not rewriting. It is a sequence of small, behavior-preserving transformations, each backed by tests.** You never change what the code does -- you change how the code is organized. The discipline of taking tiny verified steps is what makes refactoring safe. Big-bang rewrites fail because they combine structural change with behavioral change, making it impossible to know which broke things. **The foundation:** Bad code is not a character flaw -- it is a natural consequence of delivering features under time pressure. Code smells are objective signals that structure has degraded. Named refactorings are the proven mechanical recipes for fixing each smell. The catalog of smells tells you *where* to look; the catalog of refactorings tells you *what to do*. ## Scoring **Goal: 10/10.** When reviewing or refactoring code, rate the structural quality 0-10 based on adherence to the principles below. A 10/10 means: no obvious smells remain, each function does one thing, names reveal intent, duplication is eliminated, and the test suite covers the refactored paths. Always provide the current score and specific refactorings needed to reach 10/10. ## The Refactoring Patterns Framework Six areas of focus for systematically improving code structure: ### 1. Code Smells as Triggers **Core concept:** Code smells are surface indicators of deeper structural problems. They are not bugs -- the code works -- but they signal that the design is making the code harder to understand, extend, or maintain. Each smell maps to one or more named refactorings that fix it. **Why it works:** Without a shared vocabulary of smells, code review devolves into subjective "I don't like this." Named smells give teams objective criteria: "This is Feature Envy -- the method uses six fields from another class and only one of its own." The name points directly to the fix. **Key insights:** - Smells cluster into five families: Bloaters, Object-Orientation Abusers, Change Preventers, Dispensables, and Couplers - Long Method is the most common smell and the gateway to most other refactorings - Duplicate Code is the single biggest driver of maintenance cost - A method that needs a comment to explain *what* it does is a smell -- extract and name the block instead - Shotgun Surgery (one change requires edits in many classes) and Divergent Change (one class changes for many reasons) are opposites that both signal misplaced responsibilities - Primitive Obsession -- using raw strings, ints, or arrays instead of small domain objects -- causes errors and duplication throughout the codebase **Code applications:** | Context | Pattern | Example | |---------|---------|---------| | **Method > 10 lines** | Extract Method | Pull the loop body into `calculateLineTotal()` | | **Class > 200 lines** | Extract Class | Move shipping logic into a `ShippingCalculator` | | **Switch on type code** | Replace Conditional with Polymorphism | Create subclasses for each order type | | **Multiple methods use same params** | Introduce Parameter Object | Group `startDate, endDate` into `DateRange` | | **Method uses another object's data** | Move Method | Move `calculateDiscount()` to the `Customer` class | | **Copy-pasted logic** | Extract Method + Pull Up Method | Share via a common method or base class | See: [references/smell-catalog.md](references/smell-catalog.md) ### 2. Composing Methods **Core concept:** Most refactoring starts here. Long methods are broken into smaller, well-named pieces. Each extracted piece should do one thing and its name should say what that thing is. The goal is methods you can read like prose -- a sequence of high-level steps, each delegating to a clearly named helper. **Why it works:** Short methods with intention-revealing names eliminate the need for comments, make bugs obvious (each method is small enough to verify at a glance), and enable reuse. The cognitive cost of a method call is near zero when the name tells you everything. **Key insights:** - Extract Method is the single most important refactoring -- master it first - If you feel the urge to write a comment, extract the code block and use the comment as the method name - Inline Method when a method body is as clear as the name -- indirection without value is noise - Replace Temp with Query when a temporary variable holds a computed value that is used in multiple places - Split Temporary Variable when one variable is reused for two different purposes - Replace Method with Method Object when a method is too tangled to extract from (many local variables referencing each other) **Code applications:** | Context | Pattern | Example | |---------|---------|---------| | **Block with a comment** | Extract Method | `// check eligibility` becomes `isEligible()` | | **Temp used once** | Inline Variable | Remove `const price = order.getPrice()` if used once | | **Temp used in multiple places** | Replace Temp with Query | Replace `let discount = getDiscount()` with method calls | | **Temp assigned twice for different reasons** | Split Temporary Variable | Introduce `perimeterWidth` and `perimeterHeight` | | **Trivial delegating method** | Inline Method | Inline `moreThanFiveDeliveries()` if it's `return deliveries > 5` and only used once | | **Complex method with many locals** | Replace Method with Method Object | Move the method into its own class where locals become fields | See: [references/composing-methods.md](references/composing-methods.md) ### 3. Moving Features Between Objects **Core concept:** The key decision in object-oriented design is where to put responsibilities. When a method or field is in the wrong class -- evidenced by Feature Envy, excessive coupling, or unbalanced class sizes -- move it to where it belongs. **Why it works:** Well-placed responsibilities reduce coupling and increase cohesion. When a method lives in the class whose data it uses, changes to that data affect only one class. Misplaced methods create invisible dependencies that cause Shotgun Surgery. **Key insights:** - Move Method when a method uses more features of another class than its own - Move Field when a field is used more by another class than the class it lives in - Extract Class when one class does two things -- split along the axis of change - Inline Class when a class does too little to justify its existence - Hide Delegate to enforce the Law of Demeter -- a client shouldn't navigate a chain of objects - Remove Middle Man when a class does nothing but forward calls - The tension between Hide Delegate and Remove Middle Man is resolved case by case: hide the delegate when the chain is unstable; remove the middle man when forwarding becomes the entire class **Code applications:** | Context | Pattern | Example | |---------|---------|---------| | **Method envies another class** | Move Method | Move `calculateShipping()` from `Order` to `ShippingPolicy` | | **Field used by another class constantly** | Move Field | Move `discountRate` from `Order` to `Customer` | | **God class with 500+ lines** | Extract Class | Pull `Address` fields and methods into their own class | | **Tiny class with one field** | Inline Class | Merge `PhoneNumber` back into `Contact` if no behavior | | **Client calls a.getB().getC()** | Hide Delegate | Add `a.getCThroughB()` so client doesn't know about C | | **Class only forwards calls** | Remove Middle Man | Let client call the delegate directly | See: [references/moving-features.md](references/moving-features.md) ### 4. Organizing Data **Core concept:** Raw data -- magic numbers, exposed fields,
Related in Design
contribute
IncludedLocal-only OSS contribution command center. Auto-refreshes the user's in-flight PR and issue state on invoke so conversations start with full context — no need to brief Claude on what's in flight. Helps the user find issues to contribute to on GitHub, builds per-repo dossiers of what each upstream expects (CLA, DCO, branch convention, AI policy, draft-first, review bots, issue templates), runs deterministic gates before any external action so AI-assisted contributions don't reach maintainers as slop. State is markdown-only: candidate files at ~/.contribute-system/candidates/, repo dossiers at ~/.contribute-system/research/, append-only event log at ~/.contribute-system/log.jsonl. No database, no cloud calls. Use when the user asks about their PRs / issues / contributions, wants to find new work to take on, claim an issue, build/refresh a repo's dossier, or draft a Design Issue or PR. Trigger with "/contribute", "what's my PR status", "find a contribution", "claim issue X", "draft a Design Issue for Y", "refresh dossier for Z".
architectural-analysis
IncludedUser-triggered deep architectural analysis of a codebase or scoped subtree across eight modes — information architecture, data flow, integration points, UI surfaces, interaction patterns, data model, control flow, and failure modes. This skill should be used when the user asks to "diagram this codebase," "map the architecture," "show the data flow," "give me an ERD," "trace control flow," "find the integration points," "verify the layout pattern," "audit the UX architecture," or any similar request whose primary deliverable is mermaid diagrams plus cited reports under docs/architecture/. Dispatches haiku/sonnet sub-agents in parallel for per-mode exploration, then verifies every citation mechanically before any node lands in a diagram. Not for one-off prose explanations of code (use code-explanation) or for high-level system design from scratch (use system-design).
mcp
IncludedModel Context Protocol (MCP) server development and tool management. Languages: Python, TypeScript. Capabilities: build MCP servers, integrate external APIs, discover/execute MCP tools, manage multi-server configs, design agent-centric tools. Actions: create, build, integrate, discover, execute, configure MCP servers/tools. Keywords: MCP, Model Context Protocol, MCP server, MCP tool, stdio transport, SSE transport, tool discovery, resource provider, prompt template, external API integration, Gemini CLI MCP, Claude MCP, agent tools, tool execution, server config. Use when: building MCP servers, integrating external APIs as MCP tools, discovering available MCP tools, executing MCP capabilities, configuring multi-server setups, designing tools for AI agents.
react-native-skia
IncludedDesign, build, debug, and optimise high-polish animated graphics in React Native or Expo using @shopify/react-native-skia, Reanimated, and Gesture Handler. Use when the user wants canvas-driven UI, shaders, paths, rich text, image filters, sprite fields, Skottie, video frames, snapshots, web CanvasKit setup, or performance tuning for custom motion-heavy elements such as loaders, hero art, cards, charts, progress indicators, particle systems, or gesture-driven surfaces. Also use when the user asks for fluid, glow, glass, blob, parallax, 60fps/120fps, or GPU-friendly animated effects in React Native, even if they do not explicitly say "Skia". Do not use for ordinary form/layout work with standard views.
plaid
IncludedProduct Led AI Development — guides founders from idea to launched product. Six capabilities: Idea (discover a product idea), Validate (pressure-test the idea against fatal flaws, problem reality, competition, and 2-week MVP feasibility), Plan (vision intake + document generation), Design (translate image references into a design.md spec), Launch (go-to-market strategy), and Build (roadmap execution). Use when someone says "PLAID", "plaid idea", "help me find an idea", "product idea", "idea from my business", "idea from my expertise", "plaid validate", "validate my idea", "pressure-test", "is this idea good", "find fatal flaws", "validate the problem", "plan a product", "define my vision", "generate a PRD", "product strategy", "plaid design", "design from image", "translate image to design", "create design.md", "extract design tokens", "plaid launch", "go-to-market", "launch plan", "GTM strategy", "launch playbook", "plaid build", "build the app", "start building", or "execute the roadmap".
nextjs-framer-motion-animations
IncludedAdds production-safe Motion for React or Framer Motion animations to Next.js apps, including reveal, hover and tap micro-interactions, whileInView, stagger, AnimatePresence, layout and layoutId transitions, reorder, scroll-linked UI, and lightweight route-content transitions. Use when the user asks to add, refactor, or debug Motion or Framer Motion in App Router or Pages Router codebases, especially around server/client boundaries, reduced motion, LazyMotion, bundle size, hydration, or route transitions. Avoid for GSAP-style timelines, WebGL or 3D scenes, heavy scroll storytelling, or CSS-only effects unless Motion is explicitly requested.