agentleFS
dagarre00dagarre00/claude-code-template/.agents/skills/clean-architecture/SKILL.md

clean-architecture

Skill1 starsChanged 3 months agoMITView on GitHub

How to place and wire code under this project's clean-architecture layers — which layer a file belongs to, reaching the outside through a port, wiring adapters, and what to do when the architecture check fails. Use for any change that adds a file, an import between modules, or a dependency on a framework, database or external service. Trigger on "layers", "clean architecture", "hexagonal", "ports and adapters", "dependency rule", "use case", "repository", "architecture check failed", "where does this go".

16 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use domain-driven-design and tdd.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • jarrodmedranoSkill

    domain-driven-design

    This skill should be used whenever domain modeling is taking place. It provides specialized guidance for type-driven and data-driven design based on Rich Hickey and Scott Wlaschin's principles. The skill helps contextualize current modeling within the existing domain model, identifies inconsistencies, builds ubiquitous language, and creates visualizations (Mermaid, Graphviz/DOT, ASCII diagrams) to communicate domain concepts clearly. Use this skill when designing types, modeling business domains, refactoring domain logic, or ensuring domain consistency across a codebase.

    Also in 4 projects that use this

  • AWSSkill

    tdd

    Test-driven development. Use when the user wants to build features or fix bugs test-first, mentions "red-green-refactor", or wants integration tests.

    Also in 3 projects that use this

The file

We split this skill into the rules it gives an agent

5 rules. 0 are common, 4 are distinctive, and 1 is very specific to this project.

  • 0

    Common

    Most of the 15 edited versions we read keep these.

  • 4

    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:

    Put it in the directory the layer table names.

    line 25
  2. Distinctive:

    When application or domain code needs the outside world (persistence, time, randomness, email, another service):

    line 29
  3. Distinctive:

    Wire it in the composition root: only. Nothing else constructs a concrete adapter — a use case receives its ports.

    line 34
  4. Very specific:

    Never import a framework type, ORM model, HTTP request/response or SDK object into domain or application, not even "just the type".

    line 36
  5. Distinctive:

    Mocking what you own in domain tests: instead of writing a fake of the port — the test then asserts calls, not behavior.

    line 53

“Common” is measured: kept by at least 6 in 10 of the 15 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

Clean Architecture — placing and wiring code

Read first

  • docs/wiki/architecture.md § Layers — the layer table, the composition root, the exceptions. It is the contract; this skill is how to work inside it.
  • docs/wiki/commands.md § Architecture — the check that enforces it.

Place every new file

Decide the layer before writing the file, by what the code knows about:

If the code…Layer
states a business rule and would be true with no database, UI or networkdomain
orchestrates one user-meaningful operation (a use case) and needs something from outsideapplication — and it declares that need as a port
converts between the outside world's shapes and the application's (HTTP ↔ use-case input, rows ↔ entities, SDK ↔ port)adapters
configures or wraps a framework, driver, client or runtimeinfrastructure

Put it in the directory the layer table names. A file that seems to belong to two layers is two files.

Reach the outside through a port

When application or domain code needs the outside world (persistence, time, randomness, email, another service):

  1. Declare the port in the application layer, named for what the use case needs (OrderRepository.save(order), Clock.now()), in domain types — never the driver's types.
  2. Test the use case against a fake of the port that you write in the test. Red and Green for the use case need no database.
  3. Implement the port in adapters (or infrastructure for a thin wrapper), as its own Behavior case with an integration test against the real boundary where the project's testing strategy asks for one.
  4. Wire it in the composition root only. Nothing else constructs a concrete adapter — a use case receives its ports.

Never import a framework type, ORM model, HTTP request/response or SDK object into domain or application, not even "just the type".

When the architecture check fails

The failure names the importing file and the forbidden target.

  • Your change introduced it → move the code to the right layer, or invert the dependency with a port. Re-run the check and the tests.
  • The fix is more than a small port → stop and report: which case, which import, and the port you would add.
  • The rule itself looks wrong → stop and report. The rule file is protected; loosening it is a human decision recorded as an ADR.
  • Never silence it: no ignore comment, no moving the import behind a dynamic load, no widening a layer's allowed list.

Anti-patterns

  • Anemic use case: a use case that only forwards to a repository while the rule lives in a controller. Rules go to domain or application.
  • Leaky port: a port returning ORM rows, HTTP responses or SDK objects.
  • Service locator: reaching for a global container inside a use case instead of receiving the port.
  • Shared "utils" imported by every layer that quietly imports a framework. Utilities belong to a layer too.
  • Mocking what you own in domain tests instead of writing a fake of the port — the test then asserts calls, not behavior.

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.