agentleFS
parvez3019parvez3019/ai-coding-microservices-skills/skills/clean-architecture/SKILL.md

clean-architecture

Skill1 starsChanged 13 days agoMITView on GitHub

Place code in the right layer and keep dependencies pointing inward, inside a single service. Covers ports and adapters (hexagonal) layering, the dependency rule, SOLID applied at class and service level, anti-corruption layers, framework isolation, and choosing a design pattern only when a named force demands it. Use when writing or reviewing any implementation code, deciding where a class belongs, wiring a dependency, adding a framework annotation to domain code, or when the user says 'architecture', 'layering', 'SOLID', 'coupling', 'hexagonal', 'design pattern', or 'where should this go'. This skill governs structure inside one service — not where services divide (see service-boundaries), not aggregate rules (see domain-modelling), not adapter craft (see infrastructure-adapters).

37 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use designing-data-intensive-applications, implementing-domain-driven-design and 10 more.

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.
  • ciemborSkill

    designing-data-intensive-applications

    Apply Martin Kleppmann-inspired data-system rules when designing reliability, scalability, consistency, replication, transactions, streams, or schema evolution.

    Also in 3 projects that use this

  • ciemborSkill

    implementing-domain-driven-design

    Apply Vaughn Vernon-inspired implementation DDD rules when building aggregates, domain events, repositories, application services, or context integrations.

    Also in 3 projects that use this

  • OleksandrKucherenkoSkill

    release-it

    Automate versioned releases of NPM packages to GitHub repositories. Use this skill when setting up or configuring release-it for version bumping, changelog generation, npm publishing, GitHub releases, and CI/CD integration. Triggers include requests to: (1) Set up automated releases for an npm package, (2) Configure release-it for a project, (3) Create GitHub Actions workflows for releases, (4) Set up conventional commits with changelog generation, (5) Configure pre-release versioning (alpha/beta/rc), (6) Troubleshoot release-it issues.

    Also in 3 projects that use this

  • 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 6 projects that use this

  • YepAPISkill

    background-jobs

    Queue workers with BullMQ/Inngest/Trigger.dev, job retries, dead letter queues, concurrency.

    Also in 3 projects that use this

  • yariv1025Skill

    python-engineering

    Production Python engineering patterns covering architecture, observability, testing, performance/concurrency, and core practices. Use when designing Python systems, implementing async/sync APIs, setting up monitoring, structuring tests, optimizing performance, or following Python best practices.

    Also in 3 projects that use this

  • +1 more from ciembor

The file

We split this skill into the rules it gives an agent

5 rules. 0 are common, 2 are distinctive, and 3 are very specific to this project.

  • 0

    Common

    Most of the 33 edited versions we read keep these.

  • 2

    Distinctive

    This author's own choices. Worth a look.

  • 3

    Very specific

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

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

    Read .msskills/config.yaml in the repo root.

    line 17
  2. Very specific:

    No config file or no paths.architecture key → use defaults.

    line 23
  3. Very specific:

    No project document and no stack profile → use the defaults, and say once that stack-profile would make the guidance concrete.

    line 26
  4. Distinctive:

    PATTERN JUSTIFIED: If a named design pattern appears, can you state the force that demands it in one sentence?

    line 59
  5. Distinctive:

    All checks pass → state "Passes clean-architecture.

    line 62

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

The point of layering is not tidiness. It is that business rules should be readable, testable, and changeable without starting a database, a broker, or a web server — and that swapping any of those should not touch a line of business logic.

One rule generates almost everything else: dependencies point inward, toward the domain.

Config Resolution

  1. Read .msskills/config.yaml in the repo root; look up paths.architecture.
  2. A custom document exists at that path → read its frontmatter mode:
    • override → use it alone; ignore the defaults below.
    • overlay (default, or no mode key) → read defaults first, then apply the custom document's sections on top, matched by exact heading; new sections append.
  3. A path is configured but no file exists there → say which path is missing, then use the defaults.
  4. No config file or no paths.architecture key → use defaults.
  5. .msskills/stack.md exists → express every rule in that stack's idiom: its module system, its dependency-injection style, its package conventions, its architecture-test tooling.
  6. No project document and no stack profile → use the defaults, and say once that stack-profile would make the guidance concrete.

Self-Validation Checklist

STOP after generating or reviewing each class, module, or file. Verify every check. Fix failures before presenting.

  1. LAYER PLACEMENT: Can you name this file's layer — domain, application, adapter, infrastructure — and does its responsibility match? If it does two layers' jobs (a handler that contains a business rule, an entity that writes SQL) → split it.
  2. DEPENDENCY DIRECTION: Does every import point inward or sideways within the layer? An inner layer importing an outer one → invert it with an interface owned by the inner layer.
  3. FRAMEWORK ISOLATION: Is the domain free of framework and library types — annotations, ORM base classes, HTTP types, broker clients, serialisation attributes? If not → move them to the adapter and map at the edge.
  4. PORTS OWNED INWARD: Is each outbound interface declared in the layer that uses it, not the layer that implements it? A repository interface next to its database implementation is not a port; it is a package split.
  5. SINGLE RESPONSIBILITY: Can you describe this class in one sentence without "and"? If not → extract. Watch for the common pair: business logic and persistence.
  6. OPEN/CLOSED: Would a new variant of an existing concept require editing a switch in several files? If yes → introduce polymorphism, but only for a variation that has actually happened twice.
  7. LISKOV: Does every implementation of an interface honour its contract, or do some throw UnsupportedOperation, tighten preconditions, or return null where others cannot? If so → the abstraction is wrong; split it.
  8. INTERFACE SEGREGATION: Does any caller depend on an interface where it uses one of eight methods? Split by consumer need, not by implementation convenience.
  9. DEPENDENCY INVERSION: Does business logic depend on an abstraction it owns, or on a concrete client? Constructor-injected, never resolved from a static locator or newed inline.
  10. TESTABLE WITHOUT I/O: Can this class's behaviour be tested without a database, network, or clock? If not → push the side effect outward and inject time, IDs, and randomness.
  11. PATTERN JUSTIFIED: If a named design pattern appears, can you state the force that demands it in one sentence? "It is more extensible" is not a force → remove the indirection.

All checks pass → state "Passes clean-architecture. [next step]."

Active Anti-Pattern Scan

Any box you can check is a defect. Fix it before presenting.

  • Anaemic Domain: entities are field bags and all rules live in services → move the invariants onto the type that owns them.
  • Framework in the Domain: ORM, HTTP, or serialisation annotations on domain types → map at the adapter boundary instead.
  • Leaky Repository: a port that returns the ORM's query builder, a DataSet, or a framework page type → return domain types.
  • Fat Controller: business rules, orchestration, and validation in a handler → the handler parses input, calls one application service, and renders output.
  • Service Locator: dependencies fetched from a static container or singleton inside a method → constructor injection.
  • Circular Dependency: two modules importing each other → extract the shared concept, or invert one direction with an interface.
  • Utility Dumping Ground: a utils, helpers, or common package with unrelated statics → move each function next to the concept it belongs to.
  • Speculative Abstraction: an interface with exactly one implementation and no second one in sight, or a plugin system nobody plugs into → inline it until a real second case appears.
  • Pattern Theatre: factories producing factories, a strategy with one strategy, an observer with one observer → delete the indirection.
  • Leaked External Model: a third-party or upstream DTO used directly as a domain type → add an anti-corruption layer and translate at the edge.
  • Hidden Global State: static mutable state, ambient singletons, DateTime.now() buried in logic → inject it.
  • Transaction in the Domain: commit or session handling inside domain code → own the transaction in the application layer.

Ambiguity Signals

Route these through collaborative-judgment. Each has two defensible answers.

  • How many layers. Full four-layer separation is right for a service with real domain complexity and ceremony for a CRUD adapter over one table. Propose the lighter shape and let the user ask for more.
  • Port granularity. One repository per aggregate is conventional; one narrow port per use case is more honest about what each caller needs and produces more interfaces. Both defensible.
  • Mapping cost. Separate domain, persistence, and API models are the clean answer and triple the type count. Sharing one model is pragmatic until the first field that only one of them needs.
  • When an abstraction has earned its place. The rule of three is a guideline, not a law; a second case with the same reason to change can justify it, and three coincidentally similar cases do not.
  • Where a rule lives when two aggregates share it. A domain service, a policy object, or duplication in both — the right answer depends on which one owns the invariant.

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.