agentleFS
milad-raeisimilad-raeisi/senior-skills/skills/deep-modules/SKILL.md

deep-modules

Skill4 starsChanged 15 days agoMITView on GitHub

Software design for codebases that stay easy to change, for humans and agents alike. Use when designing a new module, service, class, or API, refactoring a tangled area, deciding where logic belongs or where to split code, reviewing architecture, or when the user mentions maintainability, coupling, abstraction, layering, testability, or "this code is a mess". Applies deep modules (small interface, rich hidden behavior), information hiding, seams, and explicit states, and refactors in safe, behavior-preserving steps.

6 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

7 rules. 0 are common, 6 are distinctive, and 1 is very specific to this project.

  • 0

    Common

    Most of the 6 edited versions we read keep these.

  • 6

    Distinctive

    This author's own choices. Worth a look.

  • 1

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Make modules deep: Before adding a module, ask what complexity it hides.

    line 24
  2. Very specific:

    Make illegal states unrepresentable: Use types that only allow valid combinations (see state-machine-hunter).

    line 28
  3. Distinctive:

    Functional core, imperative shell: Keep decisions in pure functions that take data and return data.

    line 29
  4. Distinctive:

    One adapter is a hypothetical seam; two is a real one: Don't create an interface "in case we swap databases".

    line 31
  5. Distinctive:

    Different layer, different abstraction: If two adjacent layers have the same methods with the same parameters, one of them is probably a …

    line 32
  6. Distinctive:

    Keep refactors and behavior changes in separate commits, so a reviewer can verify each on its own.

    line 54
  7. Distinctive:

    Stop when the change you actually needed has become easy.

    line 55

“Common” is measured: kept by at least 6 in 10 of the 6 edited versions of this file we could read. “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

Deep Modules

Complexity is what makes software hard to change, and it accumulates in small increments: one more parameter, one more pass-through layer, one more place that knows a detail it shouldn't. Good design fights it by hiding complexity behind simple interfaces so that most of the code never has to think about it. Ideas here draw on John Ousterhout's A Philosophy of Software Design, Michael Feathers' work on seams, and the functional-core / imperative-shell pattern.

Vocabulary

  • Module: anything with an interface and an implementation: a function, class, package, or service.
  • Interface: everything a caller must know to use the module correctly. That covers signatures, but also ordering rules, error modes, invariants, and performance characteristics.
  • Deep module: lots of useful behavior behind a small interface. Unix file I/O (open, read, write, lseek, close) hides caching, devices, and permissions behind five calls.
  • Shallow module: an interface nearly as complex as its implementation. Pass-through wrappers, getter/setter classes, and "manager" classes that forward every call.
  • Seam: a place where behavior can be changed without editing the code there, such as a parameter, an interface, or a configuration point. This is where tests and alternate implementations plug in.

Principles

  1. Make modules deep. Before adding a module, ask what complexity it hides. If callers still need to understand everything inside, it isn't earning its keep.
  2. Hide information. Each design decision (a file format, a caching strategy, a vendor API) should live in one module. When a decision leaks into many places, changing it means changing all of them.
  3. Pull complexity downward. It's better for the module to handle a hard case once than for every caller to handle it. Sensible defaults beat required configuration.
  4. Define errors out of existence where you can. An API where "delete a missing key" is simply a no-op is easier to use correctly than one that throws.
  5. Make illegal states unrepresentable. Use types that only allow valid combinations (see state-machine-hunter).
  6. Functional core, imperative shell. Keep decisions in pure functions that take data and return data; keep I/O at the edges. The core becomes trivially testable and the shell stays thin.
  7. Accept dependencies, don't construct them. Pass the clock, the HTTP client, and the repository in. It's the cheapest seam there is.
  8. One adapter is a hypothetical seam; two is a real one. Don't create an interface "in case we swap databases". Create it when the second implementation (often the test fake) exists.
  9. Different layer, different abstraction. If two adjacent layers have the same methods with the same parameters, one of them is probably a pass-through that should go.
  10. Names are interface. A name that needs a comment to explain it is a design smell. If you can't name a module simply, its responsibility probably isn't simple.

Red flags

SmellWhat it suggests
A change requires edits in many unrelated filesInformation leakage; a decision isn't localized
A function needs 6+ parameters or boolean flagsSeveral responsibilities fused together, or complexity pushed up to callers
Classes named *Manager, *Helper, *Util, *Service with grab-bag methodsMissing domain concepts
Tests need heavy mocking of your own codeLogic tangled with I/O; missing seam
Same conditional repeated across the codebaseA missing abstraction or an implicit state machine
A comment repeats what the code saysThe code isn't expressing intent; rename or restructure

The deletion test

Imagine deleting a module and inlining it into its callers. If complexity vanishes, it was a pass-through; inline it as part of your refactor (or propose removing it, if it isn't code you're already changing). If complexity reappears in many places, it's earning its keep.

Refactoring safely

  1. Pin current behavior with tests at the module's public interface; add characterization tests if needed.
  2. Change structure in small, behavior-preserving steps (extract, inline, move, rename), running the tests after each.
  3. Keep refactors and behavior changes in separate commits, so a reviewer can verify each on its own.
  4. Stop when the change you actually needed has become easy. Refactoring is in service of a goal, not a goal in itself.

Designing for agents (AX)

Code that's easy for agents to change is code that's easy for anyone to change: one obvious place for each concept, greppable names that match the domain, explicit types and states, small modules with clear entry points, and fast tests at stable interfaces. When a design decision isn't obvious from the code, write it down next to the code (a short README in the module, or an ADR).

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.