← ClaudeAtlas

refactor_to_patternlisted

Use this skill when the user wants to restructure existing code to follow a specific architectural or design pattern — such as Repository, Use Case / Interactor, Service Layer, Factory, Strategy, Observer, CQRS, DDD aggregates, or Clean Architecture. Triggers on: "apply the repository pattern", "refactor to use cases", "extract this into a service", "separate concerns", "make this follow DDD", "restructure this to be cleaner", "I want to apply X pattern". Also use when the user says something is "too tangled" or "hard to test" and needs a structural solution.
feralbureau/luminy · ★ 0 · Code & Development · score 68
Install: claude install-skill feralbureau/luminy
# refactor_to_pattern Refactoring to a pattern is about improving structure without changing behavior. The external behavior must be identical before and after. The benefit is improved testability, separation of concerns, and long-term maintainability. ## Guiding Principle A pattern is a solution to a recurring problem. Before applying one, confirm the problem exists in the code you're working on. Don't apply patterns speculatively — they add complexity. Apply them because the current structure is causing concrete pain (hard to test, duplicate logic, unclear responsibilities). ## Step 0: Confirm the Pattern Fits Ask (or assess) these questions before starting: 1. What specific pain is this refactor solving? (hard to test? too much coupling? business logic leaking into the wrong layer?) 2. Is the team familiar with this pattern? A pattern nobody understands creates more problems than it solves. 3. How large is the blast radius? Patterns often require changing multiple files. 4. Are there existing tests that will serve as a safety net during the refactor? ## The Safe Refactor Loop Use this loop for every refactor, regardless of pattern: ``` Read → Understand → Write tests (if missing) → Refactor step → Verify → Repeat ``` Never refactor without a safety net. If tests don't exist, write characterization tests first: ```python # Characterization test — captures current behavior, even if imperfect def test_current_behavior(): result = legacy_function(known_input)