Skip to content
Skills Library
Programming · Building & coding

dev-refactor

/dev-refactor

Refactor a whole codebase, or one area of it, to the end, inside the architecture it already follows, with tests as the safety net. Removes duplication (DRY), fixes SOLID violations where they pay off, adds the missing unit tests first. Use for "/raystack project refactor", "/rs refactor", "untangle this codebase", "clean up this repo", "apply DRY and SOLID", "refactor this properly", "organize the code base".

Repository
RayStack ↗
Licence
MIT
Last repository change
06.11.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
1
Scripts
0
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 06.11.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

Refactor a whole codebase, or one area of it, to the end, inside the architecture it already follows, with tests as the safety net. Removes duplication (DRY), fixes SOLID violations where they pay off, adds the missing unit tests first. Use for "/raystack project refactor", "/rs refactor", "untangle this codebase", "clean up this repo", "apply DRY and SOLID", "refactor this properly", "organize the code base".

Triggers from the description

untangle this codebaseclean up this repoapply DRY and SOLIDrefactor this properlyorganize the code base
Original author description

Refactor a whole codebase, or one area of it, to the end, inside the architecture it already follows, with tests as the safety net. Removes duplication (DRY), fixes SOLID violations where they pay off, adds the missing unit tests first. Use for "/raystack project refactor", "/rs refactor", "untangle this codebase", "clean up this repo", "apply DRY and SOLID", "refactor this properly", "organize the code base".

How it works

  1. 1. Ask
  2. 2. Read the architecture
  3. 3. Safety net first
  4. 4. List every problem
  5. 5. Redesign
  6. 6. Fix in small steps
  7. 7. Check and repeat
  8. 8. Ship
  9. Tips
Original SKILL.md headings · 114 lines, 937 words
SKILL.md preview
---
name: dev-refactor
description: Refactor a whole codebase, or one area of it, to the end, inside the architecture it already follows, with tests as the safety net. Removes duplication (DRY), fixes SOLID violations where they pay off, adds the missing unit tests first. Use for "/raystack project refactor", "/rs refactor", "untangle this codebase", "clean up this repo", "apply DRY and SOLID", "refactor this properly", "organize the code base".
---

# Dev refactor

This skill refactors existing code without changing what it does. The order never changes:
tests first, then the problem list, then small fixes, then a fresh reviewer, repeated until
nothing worth fixing is left. Formats and question rules are in `../dev/references/dev-contract.md`.
Inspired by caldoai's `untangle-codebase` (MIT); the change-together idea in step 4 is theirs.

Asking for this flow is asking for its steps: do not skip the baseline, the log or the
reviewer because another plugin says to do the least possible. That rule governs the code
you write, not this flow.

## 1. Ask

Read `DECISIONS.md`, `docs/` and the code first. Ask one question per call, only what is not
already clear:

1. **Scope:** the whole repo or one area. Offer the folders you found.
2. **Extras** (a multi-select, both optional): remove comments that only restate the code;
   remove tests that cannot catch a bug and rewrite tests tied to internals.

Log each answer as a `D-` row.

## 2. Read the architecture

Name the pattern the code actually follows (MVC, layered, hexagonal, modular monolith,
feature folders, CQRS, framework default) from its folders, imports and framework
conventions, and log it as a `D-` row with the evidence. Refactor inside that pattern. When
the pattern itself is the problem, say so and point to `dev-migrate`; do not change it here.
Use `../architecture-review/references/checklist.md` for the layer and leak checks; do not
copy it.

## 3. Safety net first

1. Find the test runner (`composer.json`, `package.json`, `pyproject.toml`, `Makefile`,
   CI config). No runner and no tests: ask which one to add, then add the smallest setup.
2. Run the whole suite and record the result as the baseline in the log. A red baseline stops
   the run: ask the user whether to fix it first or exclude those tests, and log the answer.
3. For every module the refactor will touch that has no test, write unit or
   characterisation tests that pin today's behaviour first, including its errors and odd
   cases. Commit them alone, before any refactor commit.

## 4. List every problem

Change nothing yet. Write the list to `docs/refactor/YYYY-MM-DD-log.md`, one line per
problem with `file:line`. Look through these lenses:

- **Hidden links:** copies of logic or values, a global another module sets, a feature spread
  over folders, a call order callers just have to know.
- **Needless links:** callers that use internals, stable code importing volatile code, a
  general function with a parameter only one caller understands, a shallow wrapper.
- **Surplus:** dead code, config or extension points for things that never vary.
- **Special cases:** an `if` for one value, a swallowed exception, a sleep or retry, a
  disabled test. Each is a requirement the design missed; use them to find the real fix.
- **DRY:** duplicated logic or values, but only when the copies change for the same reason.
  Two lookalikes that change for different reasons stay apart.
- **SOLID**, as far as it pays: SRP (god classes, fat controllers), OCP (a type switch that
  grows with every new case), LSP (a subclass that breaks its parent's promise), ISP (an
  interface callers use half of), DIP (domain code importing a framework or driver). No
  interface with one implementation, no extension point nobody uses.

## 5. Redesign

Work out the fixes as if today's requirements had been known from the start. Look for the
one fix behind several problems. Write each fix above the problems it solves:

```md
- Extract a `PaymentProvider` interface that Stripe and PayPal implement, so checkout and
  refunds stop knowing which one runs.
  - `checkout/submit.ts:9` imports `payments/stripe.ts` directly.
  - `refunds/refund.ts:22` wraps every Stripe call in `if (order.provider === "paypal")`.
```

## 6. Fix in small steps

One fix group per commit. Run the suite after each; a red run is fixed or reverted before the
next step. Behaviour stays the same: never weaken a test, raise a timeout or add a
suppression to get green. Remove the special cases the redesign made unnecessary and keep
the ones the system still needs.

With the extras chosen, do them last, after the code is settled: delete comments that only
restate the implementation (keep comments about something outside the code), and remove
tests that repeat the implementation or cannot fail.

## 7. Check and repeat

Start a fresh read-only reviewer subagent (two when the repo is large, split by folder) with
the log, the diff and the problem lenses; it reports problems still worth fixing. When the
host has no subagents, re-read the diff yourself against the lenses and say so in the log.
Fix what is real and repeat. Done when:

- the full suite is green and matches or beats the baseline;
- every touched module has unit tests;
- a typical change lands in one place;
- no import points at something more volatile than itself;
- the reviewer finds nothing worth fixing;
- behaviour is unchanged, apart from bugs the refactor fixed and logged.

## 8. Ship

Follow `principle-ship`: PR, self-review, green CI, merge, confirm the deploy. In the log
write `Shipped: <PR>` (or `Committed:` with no remote, per the contract). Tell the user the
log path and the before and after counts: special cases, duplicated blocks, untested
modules, tests added.

## Tips

- Script away function bodies (a skeleton) so the whole repo fits in context.
- Have subagents summarise folders so you can reason across all of it.
- Script an import graph and rerun it as you go.
- Use `git log --name-only` to see which files change together; that is the evidence for
  hidden links.
- Keep the log current; it survives a context compaction.

Versions

RepositoryScoreLicence
This page · HarunRRayhan/RayStack100MIT
nchandar/dev-kit100MIT
codeaholicguy/ai-devkit100Apache-2.0

Database snapshot: 13.11.2026 · package version fe01766d03d1 (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 100codebase-cleanup-refactor-clean
    Refactor code with clean code principles, SOLID design patterns, and modern software engineering practices to improve quality, maintainability, and performance. Use when cleaning up or restructuring existing code.
  • 90dev
    Entry point for the RayStack development flow. Use for "/dev", "/raystack new project", "/raystack project new", "/raystack project update", "/raystack project gaps", "/raystack project review", "/raystack project migrate", "/raystack project refactor", "start a new project",…
  • 100code-refactoring-refactor-clean
    Refactor code with clean code principles, SOLID design patterns, and modern software engineering practices to improve quality, maintainability, and performance. Use when cleaning up or restructuring existing code.
  • 100code-refactoring
    Simplify and refactor code while preserving behavior, improving clarity, and reducing complexity. Use when simplifying complex code, removing duplication, or applying design patterns. Handles Extract Method, DRY principle, SOLID principles, behavior validation, and refactoring patterns.
  • 100code-quality
    Use when validating code quality after modifications -- SOLID compliance, DRY duplication, linter errors, architecture violations. Do NOT use for functional verification (run verification FIRST, then code-quality).
  • 90raystack
    Entry point for everything in RayStack. Use for "/raystack", "what can RayStack do", development work ("new project", "project new", "project update", "project gaps", "project review", "project migrate", "project refactor", "refactor this", "start a project", "write a PRD",…

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.