agentleFS
timurgaleevtimurgaleev/vibestack/skills/improve-arch/SKILL.md

improve-arch

Skill8 starsChanged 6 months agoMITView on GitHub

Find shallow modules in a codebase and propose refactors that make them deep: small interface, deep implementation.

4 other projects use a version of this, 2 of them edited.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

11 rules. About 0 are common, 5 are distinctive, and 6 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈5

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 6

    Very specific

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

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

    If this session was compacted, the copy of this skill in context may be cut off.

    line 22
  2. Very specific:

    Read ${CLAUDE_SKILL_DIR}/SKILL.md from disk and resume at the step you are on.

    line 23
  3. Distinctive:

    Use when asked to "improve architecture", "find refactoring opportunities", "deepen modules", "consolidate tightly-coupled modules", or to …

    line 27
  4. Distinctive:

    Use these terms exactly in every suggestion.

    line 59
  5. Distinctive:

    ADR conflicts: if a candidate contradicts an existing ADR, only surface it when the friction is real enough to warrant revisiting the ADR.

    line 119
  6. Very specific:

    Do NOT propose interfaces yet.

    line 125
  7. Very specific:

    Keep a numbered frontier of open decisions and ask one at a time, each with a Recommended: answer worded so that a plain yes accepts it.

    line 131
  8. Very specific:

    Never ask what the code can answer.

    line 132
  9. Distinctive:

    Stop when no open decision remains, and confirm the resulting design with the user in one summary.

    line 135
  10. Very specific:

    Naming a deepened module after a concept not yet documented?: Add the term to the glossary (GLOSSARY.md, else CONTEXT.md).

    line 139
  11. Distinctive:

    Sharpening a fuzzy term during the conversation?: Update the glossary right there.

    line 140

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 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

If this session was compacted, the copy of this skill in context may be cut off. Read ${CLAUDE_SKILL_DIR}/SKILL.md from disk and resume at the step you are on.

When to invoke

Use when asked to "improve architecture", "find refactoring opportunities", "deepen modules", "consolidate tightly-coupled modules", or to make a codebase more testable and AI-navigable.

Preamble

eval "$("${VIBESTACK_HOME:-$HOME/.vibestack}/bin/vibe-slug" 2>/dev/null)" 2>/dev/null || SLUG="unknown"
_LEARN_FILE="${VIBESTACK_HOME:-$HOME/.vibestack}/projects/${SLUG:-unknown}/learnings.jsonl"
if [ -f "$_LEARN_FILE" ]; then
  _LEARN_COUNT=$(wc -l < "$_LEARN_FILE" 2>/dev/null | tr -d ' ')
  echo "LEARNINGS: $_LEARN_COUNT entries loaded"
  if [ "$_LEARN_COUNT" -gt 5 ] 2>/dev/null; then
    "${VIBESTACK_HOME:-$HOME/.vibestack}/bin/vibe-learnings-search" --limit 5 2>/dev/null || true
  fi
else
  echo "LEARNINGS: none yet"
fi

{{include lib/snippets/session-host.md}}

{{include lib/snippets/decision-brief.md}}

{{include lib/snippets/working-protocols.md}}

{{include lib/snippets/state-protocols.md}}

Improve Codebase Architecture

Surface architectural friction and propose deepening opportunities — refactors that turn shallow modules into deep ones. The aim is testability and AI-navigability.

Glossary

Use these terms exactly in every suggestion. Consistent language is the point — don't drift into "component," "service," "API," or "boundary." Full definitions in LANGUAGE.md.

  • Module — anything with an interface and an implementation (function, class, package, slice).
  • Interface — everything a caller must know to use the module: types, invariants, error modes, ordering, config. Not just the type signature.
  • Implementation — the code inside.
  • Depth — leverage at the interface: a lot of behaviour behind a small interface. Deep = high leverage. Shallow = interface nearly as complex as the implementation.
  • Seam — where an interface lives; a place behaviour can be altered without editing in place. (Use this, not "boundary.")
  • Adapter — a concrete thing satisfying an interface at a seam.
  • Leverage — what callers get from depth.
  • Locality — what maintainers get from depth: change, bugs, knowledge concentrated in one place.

Key principles (see LANGUAGE.md for the full list):

  • Deletion test: imagine deleting the module. If complexity vanishes, it was a pass-through. If complexity reappears across N callers, it was earning its keep.
  • The interface is the test surface.
  • One adapter = hypothetical seam. Two adapters = real seam.

This skill is informed by the project's domain model. The domain language gives names to good seams; ADRs record decisions the skill should not re-litigate.

Process

1. Scope first

Decide where to look before looking. A refactor in code nobody touches rarely pays for itself, so the scope is either a named direction — the module, feature or pain the user pointed at — or, when the user named none, the files that change most:

git log --since="6 months ago" --name-only --pretty=format: | grep -v '^$' | sort | uniq -c | sort -rn | head -20

Widen the window for a quiet repo, narrow it for a busy one. Use the direction, or these hotspots, to seed the Explore brief in step 2. Say which scope you used in one line before exploring.

2. Explore

Read the project's domain glossary first: GLOSSARY.md if it exists, else CONTEXT.md. A repo with several bounded contexts may keep a CONTEXT-MAP.md listing them — pick the context the scope lives in and read that context's glossary, not every one. Read the ADRs (docs/adr/) too.

Then use the Agent tool with subagent_type=Explore to walk the scoped part of the codebase. Don't follow rigid heuristics — explore organically and note where you experience friction:

{{include lib/snippets/foreground-dispatch.md}}

  • Where does understanding one concept require bouncing between many small modules?
  • Where are modules shallow — interface nearly as complex as the implementation?
  • Where have pure functions been extracted just for testability, but the real bugs hide in how they're called (no locality)?
  • Where do tightly-coupled modules leak across their seams?
  • Which parts of the codebase are untested, or hard to test through their current interface?

Apply the deletion test to anything you suspect is shallow: would deleting it concentrate complexity, or just move it? A "yes, concentrates" is the signal you want.

3. Present candidates

Present a numbered list of deepening opportunities. For each candidate:

  • Files — which files/modules are involved
  • Problem — why the current architecture is causing friction
  • Solution — plain English description of what would change
  • Benefits — explained in terms of locality and leverage, and also in how tests would improve
  • Strength — Strong (the deletion test and the hotspot data both point here), Worth exploring (real friction, unclear payoff) or Speculative (a hunch the exploration did not confirm)
  • Dependencies — the dependency category from DEEPENING.md (in-process, local-substitutable, remote but owned, true external), which decides how the deepened module gets tested

Use the project's domain vocabulary (from the glossary, if one exists) for domain concepts, and LANGUAGE.md vocabulary for the architecture. If the domain says "Order," talk about "the Order intake module" — not "the FooBarHandler," and not "the Order service."

ADR conflicts: if a candidate contradicts an existing ADR, only surface it when the friction is real enough to warrant revisiting the ADR. Mark it clearly (e.g. "contradicts ADR-0007 — but worth reopening because…"). Don't list every theoretical refactor an ADR forbids.

End the list with one line:

Top recommendation: <candidate> because <one line>

Do NOT propose interfaces yet. Ask which candidate to explore as a decision brief, one option per candidate, with the top recommendation marked (recommended).

4. Grilling loop

Once the user picks a candidate, walk the design tree with them — constraints, dependencies, the shape of the deepened module, what sits behind the seam, what tests survive. Run it the same way every time:

  1. Keep a numbered frontier of open decisions and ask one at a time, each with a Recommended: answer worded so that a plain yes accepts it.
  2. Never ask what the code can answer. Look facts up yourself, or dispatch an Explore subagent with run_in_background: false and wait for it.
  3. Cross-check what the user says the code does against the code; when they differ, show the difference before deciding.
  4. For each term the design introduces, walk one edge-case scenario through it to prove the name holds.
  5. Stop when no open decision remains, and confirm the resulting design with the user in one summary.

Side effects happen inline as decisions crystallize:

  • Naming a deepened module after a concept not yet documented? Add the term to the glossary (GLOSSARY.md, else CONTEXT.md). Create GLOSSARY.md lazily if neither exists.
  • Sharpening a fuzzy term during the conversation? Update the glossary right there.
  • Two rules for every glossary entry. Domain words only — a term goes in only if it is a word a domain expert would say, never a class name or implementation detail. One word per concept — when two words name the same thing, keep one and list the other under Avoid.
  • User rejects the candidate, or settles a decision, with a load-bearing reason? Offer an ADR only when the decision is hard to reverse, would be surprising without context, and came from a real trade-off; skip ephemeral reasons ("not worth it right now") and self-evident ones. On yes, hand off to /document-generate --adr with the decision and its reason — this skill never writes the ADR itself.
  • Want to explore alternative interfaces for the deepened module? See INTERFACE-DESIGN.md.

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.