agentleFS
augments-labsaugments-labs/sdlc-skills/skills/maintenance/refactor-architecture/SKILL.md

refactor-architecture

Skill1 starsChanged 4 months agoMITView on GitHub

Redesigns the structure of existing code when that structure makes change expensive: tangled boundaries, logic in the wrong layer, one small change touching many files. Use when the structure of existing code is what makes change expensive and needs redesigning, or when the user says this codebase is a mess, everything imports everything, or every feature makes the next one slower. Skip designing a new system, quick local cleanups, and read-only audits.

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

3 rules. About 0 are common, 1 is distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Ask through the harness's user-input action when one exists, else print this block.

    line 64
  2. Very specific:

    Only after exact scope and decision authority: REQUIRED SUB-SKILLS: invoke test-driven-development and yagni.

    line 70
  3. Distinctive:

    Before removing a surface, inventory every path that could still reach it: static calls, dynamic registration, reflection, configuration, …

    line 77

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Refactor Architecture

Improve the structure of code that already exists. The goal is deep modules — a lot of behaviour behind a small interface — and locality, so a change lives in one place. The vocabulary these steps lean on — module, interface, depth, seam, adapter, leverage, and the deletion test — is defined in references/vocabulary.md; open it when a term below reads unfamiliar.

When to use

  • An existing codebase has friction: a change bounces you across many files, modules are thin wrappers, tests couple to internals, seams leak.
  • Skip for greenfield design (system-architecture) or a one-off local fix.

Step 1: Classify and measure

  1. Fill the classification block. All four answers on the ordinary route → stay here. Any not → wait for an approved, current migration and assurance contract and passed entry gates. An authorized prerequisite consumes only its exact proposed contract; it cannot edit the target, approve the contract, or satisfy entry.
  2. Pin the exact source revision, the contracts it must honour, the external inputs it consumes.
  3. Inventory the surface and the friction with stable IDs. Trace callers, behavior, performance and resource profile, compatibility surface. Unmeasured friction is a preference.
  4. REQUIRED SUB-SKILLS: invoke using-git-worktrees, then test-driven-development for the preservation cycle in that workspace: baseline green, deliberate divergence red, exact restoration green. Compile-only or target-derived oracle → insufficient.

Step 2: Decide the structure

  1. Deletion test per suspect module: removal spreads complexity to callers → keep; complexity merely relocates → collapse.
  2. Seam only for repeated behavior with a stable owner and measured change friction, or one real volatile or external boundary with measured impedance, failure policy, or test isolation. Never for count or hypothetical variation.
  3. Fill assets/structural-proposal.md before presenting it: distinct structures compared, removals and where their invariants now live, slice table, approver rule. Decision outcome and slice progress stay outside it.
  4. Hard-to-reverse choice → invoke architecture-decisions.
  5. Present. Never pick the structure yourself:

    Structural proposal {{identity (per template)}}
    Friction: {{measured, one line}}  Target: {{one line}}
    Alternatives: {{list}}  Slices: {{n}}  Rollback: {{one line}}
    
    1. Approve under the preservation gate
    2. Request changes
    3. Reject and retain the current structure
    4. Cancel
    
    Recommendation: {{option the friction and recovery evidence support}} — {{one sentence}}.

    Ask through the harness's user-input action when one exists, else print this block; end the turn; clarifying-intent owns what closes it.

  6. Input drift, or a change to what was approved → an approved successor; affected slices invalid.

Step 3: Transform under preservation

  1. Only after exact scope and decision authority: REQUIRED SUB-SKILLS: invoke test-driven-development and yagni. Multi-step slices → invoke writing-plans; its mode answer names the executor.
  2. Per slice: migrate its callers, run the bound and project gates, compare accepted floors, retain the known-green state. Checkpoint under using-git-worktrees.
  3. Behavior delta → stop. Return to its requirement or new-behavior cycle.
  4. Before removing a surface, inventory every path that could still reach it: static calls, dynamic registration, reflection, configuration, generated inputs, tests, external consumers. Unsure → it stays, or waits for a completed deprecation and migration.
  5. Map every invariant the surface carried to surviving coverage. Falsify that surviving gate. Keep the rollback recoverable until integration.

Gotchas

  • A surface with zero static callers can still be reached through dynamic registration, reflection, or a generated config — a plain call-site search finds none of those and reads as proof the surface is dead when it is only unproven.
  • The deletion test's "removal spreads complexity to callers" branch is only as good as the caller trace behind it: run it against a guessed caller set and a genuinely load-bearing module reads as a thin wrapper worth collapsing.

Common mistakes

  • Refactoring for tidiness, not leverage — change structure only where it cuts real friction.
  • Combining so many structural moves that behavior, performance, compatibility, or rollback can no longer be attributed to one slice.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.