agentleFS
kayamankayaman/skills/clean-architecture/SKILL.md

clean-architecture

Skill3 starsChanged 8 months agoCC0-1.0View on GitHub

Enforces Clean Architecture principles including the dependency rule, layer separation, and component design. Use when structuring application layers, defining boundaries between domain and infrastructure, reviewing code for dependency rule violations, applying Screaming Architecture, or evaluating component cohesion and coupling (REP, CCP, CRP, ADP, SDP, SAP).

28 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use convention-learner, opentelemetry and 7 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.
  • codewithmukeshSkill

    convention-learner

    Detects and enforces project-specific coding conventions by analyzing existing codebase patterns. Learns naming conventions, folder structure, test organization, and coding style from the existing code. Load when: "conventions", "coding standards", "project patterns", "enforce style", "detect patterns", "learn conventions", "code consistency".

    Also in 3 projects that use this

  • codewithmukeshSkill

    opentelemetry

    OpenTelemetry observability for .NET 10 applications. Covers traces, metrics, and logs using the OpenTelemetry SDK with OTLP export. Includes custom ActivitySource, IMeterFactory metrics, resource configuration, and Aspire Dashboard integration. Load this skill when setting up distributed tracing, custom metrics, OTLP export, or when the user mentions "OpenTelemetry", "OTLP", "traces", "spans", "Activity", "ActivitySource", "metrics", "IMeterFactory", "Meter", "Counter", "Histogram", "Gauge", "telemetry", "observability", "distributed tracing", "OTEL", or "Aspire Dashboard".

    Also in 3 projects that use this

  • MovGP0Skill

    modern-csharp

    Modern C# style guidance for Bendex and MicroSea code changes, including primary constructors, expression-bodied members, var usage, target-typed new, lambdas, and pattern matching.

    Also in 3 projects that use this

  • MicrosoftSkill

    resilience

    Apply resilience patterns (retry, backoff, circuit breaking) when writing or reviewing code that makes outbound HTTP/REST calls, database operations, or any I/O that can experience transient failures. Use this skill when: (1) writing new code that calls external services or APIs, (2) reviewing code that uses fetch, HTTP clients, or service-to-service calls, (3) adding queue consumers or workers that interact with remote systems, (4) debugging intermittent failures in production.

    Also in 3 projects that use this

  • hongyuancSkill

    vertical-slice

    Build and evaluate a production-quality vertical slice before advancing from Pre-Production to Production.

    Also in 3 projects that use this

  • wpankSkill

    caching

    Caching strategies, invalidation, eviction policies, HTTP caching, distributed caching, and anti-patterns. Use when designing cache layers, choosing eviction policies, debugging stale data, or optimizing read-heavy workloads.

    Also in 3 projects that use this

The file

Show its rules and text

We split this skill into the rules it gives an agent

19 rules. 0 are common, 18 are distinctive, and 1 is very specific to this project.

  • 0

    Common

    Most of the 26 edited versions we read keep these.

  • 18

    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:

    MUST NOT depend on any other layer

    line 37
  2. Distinctive:

    MUST NOT import framework classes, database libraries, or HTTP concepts

    line 38
  3. Distinctive:

    MUST depend only on Entities

    line 45
  4. Distinctive:

    MUST NOT know about delivery mechanism (HTTP, CLI, queue) or persistence technology

    line 46
  5. Very specific:

    SHOULD be named by business action: PlaceOrder, CancelSubscription, TransferFunds

    line 47
  6. Distinctive:

    MUST NOT contain business logic — only format conversion and delegation

    line 52
  7. Distinctive:

    All SQL, HTTP serialization, and framework annotations are restricted to this layer

    line 53
  8. Distinctive:

    SHOULD contain minimal code — mostly glue configuration wiring frameworks to adapters

    line 60
  9. Distinctive:

    MUST pass only simple data structures across boundaries: DTOs, primitives, or plain value objects

    line 67
  10. Distinctive:

    MUST NOT pass Entities outward — map to a response DTO at the adapter layer

    line 68
  11. Distinctive:

    MUST NOT pass database rows or ORM entities inward — map to domain objects at the adapter layer

    line 69
  12. Distinctive:

    SHOULD NOT create identical DTOs for every layer boundary — map only where formats genuinely differ

    line 70
  13. Distinctive:

    SHOULD organize top-level packages by business capability or use case

    line 102
  14. Distinctive:

    SHOULD push all logic out of hard-to-test components into their testable counterparts

    line 118
  15. Distinctive:

    SHOULD use the humble object boundary as a natural seam for unit vs integration testing

    line 119
  16. Distinctive:

    SHOULD balance these three forces: REP and CCP tend to make components larger.

    line 133
  17. Distinctive:

    MUST break dependency cycles using DIP (introduce an interface) or extract a new shared component

    line 143
  18. Distinctive:

    SHOULD measure instability (I = outgoing / (incoming + outgoing)) and abstractness (A = abstract classes / total classes)

    line 144
  19. Distinctive:

    When designing or reviewing architecture, verify:

    line 164

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

Reference: Clean Architecture (Martin), Get Your Hands Dirty on Clean Architecture (Hombergs), Fundamentals of Software Architecture (Richards & Ford)

When to Apply

  • Structuring a new application's package/module layout
  • Defining boundaries between domain logic and infrastructure
  • Reviewing imports for dependency rule violations
  • Deciding how data should cross layer boundaries
  • Evaluating whether the architecture "screams" business purpose or framework choice
  • Assessing component cohesion and coupling in a modular system

The Dependency Rule

The overriding rule: Source code dependencies MUST only point inward — from outer layers toward inner layers. Nothing in an inner circle can know anything about an outer circle: no names, no data formats, no function calls.

Dynamic polymorphism (DIP) creates source code dependencies that oppose the flow of control, allowing inner layers to define interfaces that outer layers implement.


The Four Layers

From innermost (most stable) to outermost (most volatile):

1. Entities (Enterprise Business Rules)

  • Domain objects encapsulating business rules independent of any application
  • Least likely to change when externalities change
  • MUST NOT depend on any other layer
  • MUST NOT import framework classes, database libraries, or HTTP concepts
  • Examples: Order, Money, ShippingPolicy

2. Use Cases (Application Business Rules)

  • Application-specific orchestration — direct entities to use their business rules
  • Each use case represents one user goal or system operation
  • MUST depend only on Entities
  • MUST NOT know about delivery mechanism (HTTP, CLI, queue) or persistence technology
  • SHOULD be named by business action: PlaceOrder, CancelSubscription, TransferFunds

3. Interface Adapters

  • Controllers, presenters, gateways — convert data between use case format and external format
  • MUST NOT contain business logic — only format conversion and delegation
  • All SQL, HTTP serialization, and framework annotations are restricted to this layer
  • Examples: REST controllers, repository implementations, view models, DTO mappers

4. Frameworks & Drivers

  • Outermost layer: web frameworks, databases, UI, external services
  • "The web is a detail. The database is a detail."
  • SHOULD contain minimal code — mostly glue configuration wiring frameworks to adapters
  • Changes here MUST NOT propagate inward

Data Crossing Boundaries

  • MUST pass only simple data structures across boundaries: DTOs, primitives, or plain value objects
  • MUST NOT pass Entities outward — map to a response DTO at the adapter layer
  • MUST NOT pass database rows or ORM entities inward — map to domain objects at the adapter layer
  • SHOULD NOT create identical DTOs for every layer boundary — map only where formats genuinely differ
DirectionWhat CrossesExample
Inward (request)Input DTO or command objectPlaceOrderCommand { customerId, items[] }
Outward (response)Output DTO or result objectOrderConfirmation { orderId, estimatedDelivery }
NeverEntity, DB row, ORM model, framework objectOrder entity, Hibernate proxy, Express Request

Screaming Architecture

The top-level directory structure SHOULD reveal the system's business purpose, not its framework.

Good — screams "health clinic":

src/
  appointments/
  patients/
  billing/
  prescriptions/

Bad — screams "Spring Boot":

src/
  controllers/
  services/
  repositories/
  models/
  • SHOULD organize top-level packages by business capability or use case
  • MAY use technical sub-packages within a business package (e.g., appointments/adapter/, appointments/domain/)

Humble Object Pattern

Split behavior into two parts: a testable component with all the logic, and a humble component that is hard to test but contains minimal logic.

ComponentTestable?Contains
PresenterYesFormats data, applies display logic, builds view model
ViewHumble (hard to test)Renders the view model to screen — minimal logic
GatewayYes (interface)Defines data access contract
Repository ImplHumbleExecutes SQL, calls ORM — tested via integration tests
  • SHOULD push all logic out of hard-to-test components into their testable counterparts
  • SHOULD use the humble object boundary as a natural seam for unit vs integration testing

Component Design Principles

Cohesion Principles (what goes inside a component)

PrincipleRuleTension
REP (Reuse/Release Equivalence)The granule of reuse is the granule of release — group things released togetherToo broad: components become bloated
CCP (Common Closure)Classes that change together belong together — SRP at component levelToo narrow: too many components
CRP (Common Reuse)Don't force users to depend on things they don't need — ISP at component levelToo strict: components fragment

SHOULD balance these three forces: REP and CCP tend to make components larger; CRP makes them smaller. Early in development, favor CCP (group by change). As the system matures, shift toward CRP (minimize unnecessary dependencies).

Coupling Principles (relationships between components)

PrincipleRule
ADP (Acyclic Dependencies)The component dependency graph MUST have no cycles
SDP (Stable Dependencies)Depend in the direction of stability — volatile components depend on stable ones
SAP (Stable Abstractions)Stable components SHOULD be abstract; unstable components SHOULD be concrete
  • MUST break dependency cycles using DIP (introduce an interface) or extract a new shared component
  • SHOULD measure instability (I = outgoing / (incoming + outgoing)) and abstractness (A = abstract classes / total classes)
  • Components in the "zone of pain" (stable + concrete) are rigid; components in the "zone of uselessness" (unstable + abstract) are irrelevant

Common Pitfalls

PitfallWhy It HappensRemedy
Over-layering CRUD appsApplying 4 layers to simple data entrySkip use case layer for trivial operations; use adapters directly
Use cases as repository proxiesUse case does nothing but call repository.save()If there's no business logic, the use case adds no value — simplify
Mapping everythingIdentical DTOs at every boundaryMap only where formats genuinely differ; don't cargo-cult mapping
"Easy database swap" mythJustifying layers by hypothetical DB migrationLayers exist for testability and independence, not DB swaps
Framework in the domainAnnotations, framework types leak into entitiesEntities MUST be plain objects with zero framework dependencies
Designing components top-downTrying to define all components before writing codeComponent structure evolves as the codebase grows — don't over-plan

Checklist

When designing or reviewing architecture, verify:

  • Source code dependencies point inward — no inner layer imports from an outer layer
  • Entities contain business rules and have zero framework dependencies
  • Use cases orchestrate entities without knowing about HTTP, SQL, or UI
  • Interface adapters convert between use case format and external format only
  • Data crosses boundaries as DTOs or simple structures, never as entities or DB rows
  • Top-level directory structure reveals business purpose (Screaming Architecture)
  • Hard-to-test code is isolated in humble objects with minimal logic
  • Component dependency graph has no cycles (ADP)
  • Stable components are abstract; volatile components are concrete (SAP)
  • Architecture complexity matches the problem — no over-layering for simple operations

Key References

BookAuthor(s)PublisherYear
Clean ArchitectureRobert C. MartinPearson2017
Get Your Hands Dirty on Clean Architecture (2nd ed.)Tom HombergsPackt2023
Fundamentals of Software ArchitectureMark Richards, Neal FordO'Reilly2020
Software Architecture: The Hard PartsFord, Richards, Sadalage, DehghaniO'Reilly2021
Software Architecture in Practice (4th ed.)Bass, Clements, KazmanAddison-Wesley2024
A Philosophy of Software Design (2nd ed.)John OusterhoutStanford2021

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.