Comprehensive guide to Clean Architecture principles for designing maintainable, testable software systems. Based on Robert C. Martin's "Clean Architecture: A Craftsman's Guide to Software Structure and Design." Contains 42 rules across 8 categories, prioritized by architectural impact.
When to Apply
Reference these guidelines when:
Designing new software systems or modules
Structuring dependencies between layers
Defining boundaries between business logic and infrastructure
Reviewing code for architectural violations
Refactoring coupled systems toward cleaner structure
Rule Categories by Priority
Priority
Category
Impact
Prefix
1
Dependency Direction
CRITICAL
dep-
2
Entity Design
CRITICAL
entity-
3
Use Case Isolation
HIGH
usecase-
4
Component Cohesion
HIGH
comp-
5
Boundary Definition
MEDIUM-HIGH
bound-
6
Interface Adapters
MEDIUM
adapt-
7
Framework Isolation
MEDIUM
frame-
8
Testing Architecture
LOW-MEDIUM
test-
Quick Reference
1. Dependency Direction (CRITICAL)
dep-inward-only - Source dependencies point inward only
dep-interface-ownership - Interfaces belong to clients not implementers
dep-no-framework-imports - Avoid framework imports in inner layers
dep-data-crossing-boundaries - Use simple data structures across boundaries
dep-acyclic-dependencies - Eliminate cyclic dependencies between components
dep-stable-abstractions - Depend on stable abstractions not volatile concretions
2. Entity Design (CRITICAL)
entity-pure-business-rules - Entities contain only enterprise business rules
entity-no-persistence-awareness - Entities must not know how they are persisted
entity-encapsulate-invariants - Encapsulate business invariants within entities
entity-value-objects - Use value objects for domain concepts
entity-rich-not-anemic - Build rich domain models not anemic data structures
3. Use Case Isolation (HIGH)
usecase-single-responsibility - Each use case has one reason to change
usecase-input-output-ports - Define input and output ports for use cases
usecase-orchestrates-not-implements - Use cases orchestrate entities not implement business rules
usecase-no-presentation-logic - Use cases must not contain presentation logic
usecase-explicit-dependencies - Declare all dependencies explicitly in constructor
usecase-transaction-boundary - Use case defines the transaction boundary
4. Component Cohesion (HIGH)
comp-screaming-architecture - Structure should scream the domain not the framework
comp-common-closure - Group classes that change together
comp-common-reuse - Avoid forcing clients to depend on unused code
comp-reuse-release-equivalence - Release components as cohesive units
comp-stable-dependencies - Depend in the direction of stability
5. Boundary Definition (MEDIUM-HIGH)
bound-humble-object - Use humble objects at architectural boundaries
bound-partial-boundaries - Use partial boundaries when full separation is premature
bound-boundary-cost-awareness - Weigh boundary cost against ignorance cost
bound-main-component - Treat main as a plugin to the application
bound-defer-decisions - Defer framework and database decisions
bound-service-internal-architecture - Services must have internal clean architecture
6. Interface Adapters (MEDIUM)
adapt-controller-thin - Keep controllers thin
adapt-presenter-formats - Presenters format data for the view
adapt-gateway-abstraction - Gateways hide external system details
adapt-mapper-translation - Use mappers to translate between layers
adapt-anti-corruption-layer - Build anti-corruption layers for external systems
7. Framework Isolation (MEDIUM)
frame-domain-purity - Domain layer has zero framework dependencies
frame-orm-in-infrastructure - Keep ORM usage in infrastructure layer
frame-web-in-infrastructure - Web framework concerns stay in interface layer
frame-di-container-edge - Dependency injection containers live at the edge
test-tests-are-architecture - Tests are part of the system architecture
test-testable-design - Design for testability from the start
test-layer-isolation - Test each layer in isolation
test-boundary-verification - Verify architectural boundaries with tests
How to Use
Read individual reference files for detailed explanations and code examples:
Section definitions - Category structure and impact levels
Rule template - Template for adding new rules
Reference Files
File
Description
references/_sections.md
Category definitions and ordering
assets/templates/_template.md
Template for new rules
metadata.json
Version and reference information
1---2name: clean-architecture3description: Clean Architecture Best Practices4---5# Clean Architecture Best Practices67Comprehensive guide to Clean Architecture principles for designing maintainable, testable software systems. Based on Robert C. Martin's "Clean Architecture: A Craftsman's Guide to Software Structure and Design." Contains 42 rules across 8 categories, prioritized by architectural impact.89## When to Apply1011Reference these guidelines when:12- Designing new software systems or modules13- Structuring dependencies between layers14- Defining boundaries between business logic and infrastructure15- Reviewing code for architectural violations16- Refactoring coupled systems toward cleaner structure1718## Rule Categories by Priority1920| Priority | Category | Impact | Prefix |21|----------|----------|--------|--------|22| 1 | Dependency Direction | CRITICAL | `dep-` |23| 2 | Entity Design | CRITICAL | `entity-` |24| 3 | Use Case Isolation | HIGH | `usecase-` |25| 4 | Component Cohesion | HIGH | `comp-` |26| 5 | Boundary Definition | MEDIUM-HIGH | `bound-` |27| 6 | Interface Adapters | MEDIUM | `adapt-` |28| 7 | Framework Isolation | MEDIUM | `frame-` |29| 8 | Testing Architecture | LOW-MEDIUM | `test-` |3031## Quick Reference3233### 1. Dependency Direction (CRITICAL)3435- [`dep-inward-only`](references/dep-inward-only.md) - Source dependencies point inward only36- [`dep-interface-ownership`](references/dep-interface-ownership.md) - Interfaces belong to clients not implementers37- [`dep-no-framework-imports`](references/dep-no-framework-imports.md) - Avoid framework imports in inner layers38- [`dep-data-crossing-boundaries`](references/dep-data-crossing-boundaries.md) - Use simple data structures across boundaries39- [`dep-acyclic-dependencies`](references/dep-acyclic-dependencies.md) - Eliminate cyclic dependencies between components40- [`dep-stable-abstractions`](references/dep-stable-abstractions.md) - Depend on stable abstractions not volatile concretions4142### 2. Entity Design (CRITICAL)4344- [`entity-pure-business-rules`](references/entity-pure-business-rules.md) - Entities contain only enterprise business rules45- [`entity-no-persistence-awareness`](references/entity-no-persistence-awareness.md) - Entities must not know how they are persisted46- [`entity-encapsulate-invariants`](references/entity-encapsulate-invariants.md) - Encapsulate business invariants within entities47- [`entity-value-objects`](references/entity-value-objects.md) - Use value objects for domain concepts48- [`entity-rich-not-anemic`](references/entity-rich-not-anemic.md) - Build rich domain models not anemic data structures4950### 3. Use Case Isolation (HIGH)5152- [`usecase-single-responsibility`](references/usecase-single-responsibility.md) - Each use case has one reason to change53- [`usecase-input-output-ports`](references/usecase-input-output-ports.md) - Define input and output ports for use cases54- [`usecase-orchestrates-not-implements`](references/usecase-orchestrates-not-implements.md) - Use cases orchestrate entities not implement business rules55- [`usecase-no-presentation-logic`](references/usecase-no-presentation-logic.md) - Use cases must not contain presentation logic56- [`usecase-explicit-dependencies`](references/usecase-explicit-dependencies.md) - Declare all dependencies explicitly in constructor57- [`usecase-transaction-boundary`](references/usecase-transaction-boundary.md) - Use case defines the transaction boundary5859### 4. Component Cohesion (HIGH)6061- [`comp-screaming-architecture`](references/comp-screaming-architecture.md) - Structure should scream the domain not the framework62- [`comp-common-closure`](references/comp-common-closure.md) - Group classes that change together63- [`comp-common-reuse`](references/comp-common-reuse.md) - Avoid forcing clients to depend on unused code64- [`comp-reuse-release-equivalence`](references/comp-reuse-release-equivalence.md) - Release components as cohesive units65- [`comp-stable-dependencies`](references/comp-stable-dependencies.md) - Depend in the direction of stability6667### 5. Boundary Definition (MEDIUM-HIGH)6869- [`bound-humble-object`](references/bound-humble-object.md) - Use humble objects at architectural boundaries70- [`bound-partial-boundaries`](references/bound-partial-boundaries.md) - Use partial boundaries when full separation is premature71- [`bound-boundary-cost-awareness`](references/bound-boundary-cost-awareness.md) - Weigh boundary cost against ignorance cost72- [`bound-main-component`](references/bound-main-component.md) - Treat main as a plugin to the application73- [`bound-defer-decisions`](references/bound-defer-decisions.md) - Defer framework and database decisions74- [`bound-service-internal-architecture`](references/bound-service-internal-architecture.md) - Services must have internal clean architecture7576### 6. Interface Adapters (MEDIUM)7778- [`adapt-controller-thin`](references/adapt-controller-thin.md) - Keep controllers thin79- [`adapt-presenter-formats`](references/adapt-presenter-formats.md) - Presenters format data for the view80- [`adapt-gateway-abstraction`](references/adapt-gateway-abstraction.md) - Gateways hide external system details81- [`adapt-mapper-translation`](references/adapt-mapper-translation.md) - Use mappers to translate between layers82- [`adapt-anti-corruption-layer`](references/adapt-anti-corruption-layer.md) - Build anti-corruption layers for external systems8384### 7. Framework Isolation (MEDIUM)8586- [`frame-domain-purity`](references/frame-domain-purity.md) - Domain layer has zero framework dependencies87- [`frame-orm-in-infrastructure`](references/frame-orm-in-infrastructure.md) - Keep ORM usage in infrastructure layer88- [`frame-web-in-infrastructure`](references/frame-web-in-infrastructure.md) - Web framework concerns stay in interface layer89- [`frame-di-container-edge`](references/frame-di-container-edge.md) - Dependency injection containers live at the edge90- [`frame-logging-abstraction`](references/frame-logging-abstraction.md) - Abstract logging behind domain interfaces9192### 8. Testing Architecture (LOW-MEDIUM)9394- [`test-tests-are-architecture`](references/test-tests-are-architecture.md) - Tests are part of the system architecture95- [`test-testable-design`](references/test-testable-design.md) - Design for testability from the start96- [`test-layer-isolation`](references/test-layer-isolation.md) - Test each layer in isolation97- [`test-boundary-verification`](references/test-boundary-verification.md) - Verify architectural boundaries with tests9899## How to Use100101Read individual reference files for detailed explanations and code examples:102103- [Section definitions](references/_sections.md) - Category structure and impact levels104- [Rule template](assets/templates/_template.md) - Template for adding new rules105106## Reference Files107108| File | Description |109|------|-------------|110| [references/_sections.md](references/_sections.md) | Category definitions and ordering |111| [assets/templates/_template.md](assets/templates/_template.md) | Template for new rules |112| [metadata.json](metadata.json) | Version and reference information |
Run npx skillmds@latest add comeonoliver/clean-architecture in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
Clean Architecture Best Practices It is listed under Coding & Dev Tools on SkillMD.
This skill has not completed SkillMD's automated safety review yet. Independent scanners report: SkillSpector: PASS, Skill Scanner: PASS. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
ComeOnOliver (@comeonoliver) published this skill. Their other Agent Skills are listed on their SkillMD profile.