Logo von Clean Architecture

Clean Architecture

Community
alpham8
clean-architecture

Structure software around the Dependency Rule: source code dependencies point inward from frameworks to use cases to entities. Use when the user mentions "architecture layers", "dependency rule", "ports and adapters", "hexagonal architecture", "use case boundary", "onion architecture", "screaming architecture", or "framework independence". Also trigger when decoupling business logic from databases or frameworks, defining module boundaries, or debating where to put business rules. Covers component principles, boundaries, and SOLID. For code quality, see clean-code. For domain modeling, see domain-driven-design.

Übersicht

Herausgeberalpham8
Repositoryagentic-webdev
Skill-Nameclean-architecture
Sterne
4
Forks
0
Mitgelieferte Dateien
6
LizenzMIT
Links
  • Anweisungen in Markdown

    Eine SKILL.md-Datei, die das Modell bei Bedarf lädt. So werden nur dann Token verbraucht, wenn eine Anfrage tatsächlich dazu passt.

  • Funktioniert mit jedem LLM

    KI-Skills bestehen aus reinem Markdown, nicht aus anbieterspezifischem Code. Daher funktionieren sie mit GPT, Claude, Gemini, Grok oder einem lokalen Modell.

  • 6 mitgelieferte Dateien

    Skripte, Vorlagen und Referenzmaterial, die das Modell bei der Arbeit lesen kann. Die Dateien sind schreibgeschützt und werden niemals ausgeführt.

  • Open Source

    Von alpham8 auf GitHub veröffentlicht. Prüfen Sie den Quellinhalt vor der Installation.

Installation

Installieren Sie den KI-Skill Clean Architecture in TypingMind, um ihn mit jedem LLM zu nutzen, oder fügen Sie ihn einem anderen Agenten hinzu, der SKILL.md lesen kann.

1

In TypingMind installieren

TypingMind installiert einen Skill direkt aus seinem GitHub-Ordner — liest SKILL.md, bündelt die Ressourcendateien und speichert das Ergebnis lokal.

  1. Öffnen Sie die App und gehen Sie zu Plugins → Skills.
  2. Wählen Sie „Von GitHub installieren“.
  3. Fügen Sie die unten angegebene URL des Skill-Ordners ein und bestätigen Sie.
    https://github.com/alpham8/agentic-webdev/tree/master/skills/wondelai/clean-architecture
  4. Aktivieren Sie den Skill in jedem Chat, in dem er verfügbar sein soll.
Plugins → Skills → Skill anlegen → Über GitHub-URL. Fügen Sie dann die Ordner-URL ein und klicken Sie auf „Weiter“.
2

In einem anderen Agenten installieren

Jeder Agent, der das Agent-Skills-Format lesen kann, kann diesen Skill nutzen — kopieren Sie den Ordner in das Skill-Verzeichnis des jeweiligen Agenten.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/alpham8/agentic-webdev.git /tmp/agentic-webdev
mkdir -p .claude/skills
cp -r /tmp/agentic-webdev/skills/wondelai/clean-architecture .claude/skills/clean-architecture
Starten Sie Claude Code nach dem Kopieren neu, damit der neue Skill erkannt wird.

In TypingMind verwenden

Aktivieren Sie Clean Architecture in einem beliebigen Chat in TypingMind. Den Rest übernimmt das Modell. Name und Beschreibung des Skills stehen im System-Prompt. Sobald eine Anfrage passt, lädt das Modell selbstständig die vollständigen Anweisungen — Sie müssen den Skill nie manuell aufrufen, und er verbraucht erst Token, wenn er tatsächlich genutzt wird.

Das Modell lädt Clean Architecture automatisch, sobald eine passende Anfrage gestellt wird.

Funktioniert mit jedem KI-Modell

KI-Skills bestehen aus reinen Markdown-Anweisungen statt aus anbieterspezifischem Code. Daher ist Clean Architecture nicht an das Modell gebunden, für das der Skill geschrieben wurde. Installieren Sie ihn einmal in TypingMind und nutzen Sie ihn mit GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama oder einem selbst betriebenen lokalen Modell — alles mit Ihren eigenen API-Keys.

  • Wird nur bei Bedarf geladen

    Der System-Prompt enthält nur den Namen und die Beschreibung. Die Anweisungen werden bei der ersten passenden Anfrage geladen. Ein ungenutzter Skill verursacht daher keine Kosten.

  • Modell im laufenden Chat wechseln

    Da der Skill aus Anweisungen statt aus Code besteht, funktioniert er auch nach einem Modellwechsel — das nächste Modell liest dieselbe SKILL.md-Datei.

Skill-Anweisungen

Dies ist der Inhalt von SKILL.md, den das Modell lädt. Lesen Sie ihn vor der Installation — ein Skill besteht aus Anweisungen, denen Ihr Modell folgt.

Clean Architecture Framework

A disciplined approach to structuring software so that business rules remain independent of frameworks, databases, and delivery mechanisms. Apply these principles when designing system architecture, reviewing module boundaries, or advising on dependency management.

Core Principle

Source code dependencies must point inward -- toward higher-level policies. Nothing in an inner circle can know anything about something in an outer circle. This single rule, applied consistently, produces systems that are testable, independent of frameworks, independent of the UI, independent of the database, and independent of any external agency.

The foundation: Software architecture is about drawing lines -- boundaries -- that separate things that matter from things that are details. Business rules are what matter. Databases, web frameworks, and delivery mechanisms are details. When details depend on policies (not the other way around), you can defer decisions, swap implementations, and test business logic in isolation.

Scoring

Goal: 10/10. When reviewing or creating software architecture, rate it 0-10 based on adherence to the principles below. A 10/10 means full alignment with all guidelines; lower scores indicate gaps to address. Always provide the current score and specific improvements needed to reach 10/10.

The Clean Architecture Framework

Six principles for building systems that survive the passage of time:

1. Dependency Rule and Concentric Circles

Core concept: The architecture is organized as concentric circles. The innermost circle contains Entities (enterprise business rules). The next circle contains Use Cases (application business rules). Then Interface Adapters. The outermost circle contains Frameworks and Drivers. Source code dependencies always point inward.

Why it works: When high-level policies don't depend on low-level details, you can change the database from MySQL to MongoDB, swap a web framework, or replace a REST API with GraphQL -- all without touching business logic. The system becomes resilient to the most volatile parts of the technology stack.

Key insights:

  • The Dependency Rule is the overriding rule: inner circles cannot mention outer circle names (classes, functions, variables, data formats)
  • Data that crosses boundaries must be in a form convenient for the inner circle, never in a form dictated by the outer circle
  • Dependency Inversion (interfaces defined inward, implemented outward) is the mechanism that enforces the rule
  • The number of circles is not fixed -- four is typical, but you may have more; the rule stays the same
  • Frameworks are details, not architecture -- they belong in the outermost circle

Code applications:

ContextPatternExample
Layer directionInner circles define interfaces; outer circles implement themUserRepository interface in Use Cases; PostgresUserRepository in Adapters
Data crossingDTOs or simple structs cross boundaries, not ORM entitiesUse Case returns UserResponse DTO, not an ActiveRecord model
Framework isolationWrap framework calls behind interfacesEmailSender interface hides whether you use SendGrid or SES
Database independenceRepository pattern abstracts persistenceBusiness logic calls repo.save(user), never raw SQL
Dependency directionImport arrows on a diagram always point inwardController imports Use Case; Use Case never imports Controller

See: references/dependency-rule.md

2. Entities and Use Cases

Core concept: Entities encapsulate enterprise-wide business rules -- the most general, highest-level rules that would exist even if no software system existed. Use Cases contain application-specific business rules that orchestrate the flow of data to and from Entities.

Why it works: By separating what the business does (Entities) from how the application orchestrates it (Use Cases), you can reuse Entities across multiple applications and change application behavior without altering core business rules.

Key insights:

  • Entities are not database rows -- they are objects (or pure functions) that encapsulate critical business rules and data
  • Use Cases describe application-specific automation rules; they orchestrate Entities but do not contain enterprise logic
  • Use Cases accept Request Models and return Response Models -- never framework objects
  • Each Use Case represents a single application operation (e.g., CreateOrder, ApproveExpense)
  • The Interactor pattern: a Use Case class implements an input boundary interface and calls an output boundary interface
  • Changes to a Use Case should never affect an Entity; changes to an Entity may require Use Case updates

Code applications:

ContextPatternExample
Entity designEncapsulate critical business rules with no framework dependenciesOrder.calculateTotal() applies tax rules; knows nothing about HTTP
Use Case boundaryDefine Input Port and Output Port interfacesCreateOrderInput interface; CreateOrderOutput interface
Request/ResponseSimple data structures cross the boundaryCreateOrderRequest { items, customerId } -- no ORM models
Single responsibilityOne Use Case per application operationPlaceOrder, CancelOrder, RefundOrder as separate classes
InteractorUse Case class implements Input Port, calls Output PortPlaceOrderInteractor implements PlaceOrderInput

See: references/entities-use-cases.md

3. Interface Adapters and Frameworks

Core concept: Interface Adapters convert data between the format most convenient for Use Cases and Entities and the format required by external agencies (database, web, devices). Frameworks and Drivers are the outermost layer -- glue code that connects to the outside world.

Why it works: When the web framework, ORM, or message queue is confined to the outermost circles, replacing any of them becomes a localized change. The database is a detail. The web is a detail. The framework is a detail. Details should be plugins to your business rules, not the skeleton of your application.

Key insights:

  • Controllers translate HTTP requests into Use Case input; Presenters translate Use Case output into view models
  • Gateways implement repository interfaces defined by Use Cases -- the Use Case defines the contract, the gateway fulfills it
  • The database is a detail: business rules don't need to know whether data is stored in SQL, NoSQL, or flat files
  • The web is a detail: business rules don't know they're being delivered over HTTP
  • Treat frameworks with suspicion -- they want you to couple to them; keep them at arm's length
  • Plugin architecture: the system should be structured so that frameworks plug into business rules, not the reverse

Code applications:

ContextPatternExample
ControllerTranslates delivery mechanism to Use Case inputOrderController.create(req) builds CreateOrderRequest and calls Interactor
PresenterTranslates Use Case output to view modelOrderPresenter.present(response) formats data for JSON/HTML
GatewayImplements repository interface using a specific DBSqlOrderRepository implements OrderRepository
Framework boundaryFramework code calls inward, never called by inner circlesExpress route handler calls Controller; Controller never imports Express
Plugin architectureMain component wires dependencies at startupmain() instantiates concrete classes and injects them

See: references/adapters-frameworks.md

4. Component Principles

Core concept: Components are the units of deployment. Three cohesion principles govern what goes inside a component; three coupling principles govern relationships between components. Together they determine a system's releasability, maintainability, and stability.

Why it works: Poorly composed components create ripple effects: one change forces redeployment of unrelated code. The cohesion and coupling principles provide a systematic way to group classes and manage inter-component dependencies so that changes remain localized.

Key insights:

  • REP (Reuse/Release Equivalence): classes in a component should be releasable together -- if you can't version and release them as a unit, they don't belong together
  • CCP (Common Closure): classes that change for the same reason at the same time belong in the same component (SRP for components)
  • CRP (Common Reuse): don't force users to depend on things they don't use -- if you must import a component, you should need most of its classes
  • ADP (Acyclic Dependencies): the dependency graph of components must have no cycles; break cycles with DIP or by extracting a new component
  • SDP (Stable Dependencies): depend in the direction of stability -- a component with many dependents should be hard to change
  • SAP (Stable Abstractions): stable components should be abstract; unstable components should be concrete

Code applications:

ContextPatternExample
Component groupingGroup classes that change together (CCP)All order-related Use Cases in one component
Breaking cyclesApply DIP to invert a dependency edgeExtract an interface into a new component to break a circular dependency
Stability metricsMeasure instability: I = Ce / (Ca + Ce)A component with many incoming and no outgoing deps has I near 0 (stable)
Abstractness balanceStable components should contain mostly interfacesCore domain component is abstract; adapter component is concrete
Release granularityVersion and release components independentlyorder-domain v2.1.0 released without touching payment-adapter

See: references/component-principles.md

5. SOLID Principles

Core concept: Five principles for managing dependencies at the class and module level: Single Responsibility (SRP), Open-Closed (OCP), Liskov Substitution (LSP), Interface Segregation (ISP), and Dependency Inversion (DIP). They are the mid-level building blocks that make the Dependency Rule possible.

Why it works: SOLID principles keep source code flexible, understandable, and amenable to change. They prevent the rigidity, fragility, and immobility that turn codebases into legacy nightmares. Each principle addresses a specific way that dependencies can go wrong.

Key insights:

  • SRP: a module should have one, and only one, reason to change -- it serves one actor (not "does one thing")
  • OCP: extend behavior by adding new code, not by modifying existing code; strategy and plugin patterns are the mechanism
  • LSP: subtypes must be usable through the base type interface without the client knowing the difference; violated when subclass throws unexpected exceptions or ignores methods
  • ISP: clients should not be forced to depend on methods they do not use; fat interfaces create unnecessary coupling
  • DIP: high-level modules should not depend on low-level modules; both should depend on abstractions defined by the high-level module

Code applications:

ContextPatternExample
SRP violationClass serves multiple actorsEmployee handles pay calculation (CFO), reporting (COO), and persistence (CTO)
OCP via strategyNew behavior through new classes, not editsAdd ExpressShipping class implementing ShippingStrategy, no changes to Order
LSP violationSubtype changes expected behaviorSquare extends Rectangle breaks setWidth()/setHeight() contract
ISP applicationSplit fat interfaces into role interfacesPrinter, Scanner, Fax instead of one MultiFunctionDevice
DIP wiringHigh-level defines interface; low-level implementsOrderService depends on PaymentGateway interface, not StripeClient

See: references/solid-principles.md

6. Boundaries and Boundary Anatomy

Core concept: A boundary is a line drawn between things that matter and things that are details. Boundaries are implemented through polymorphism: source code dependencies cross the boundary pointing inward, while the flow of control may cross in either direction. The Humble Object pattern makes code at boundaries testable.

Why it works: Every boundary you draw gives you the option to defer a decision or swap an implementation. Boundaries separate the volatile from the stable, the concrete from the abstract. Early and strategic boundary placement determines whether a system is a joy or a pain to maintain over years.

Key insights:

  • Full boundaries use reciprocal interfaces on both sides; partial boundaries use a simpler strategy pattern or facade
  • The Humble Object pattern: split behavior at a boundary into two classes -- one hard to test (close to the boundary) and one easy to test (contains the logic)
  • Services are not inherently architectural boundaries -- a microservice with a fat shared data model is just a monolith with network calls
  • The Main component is a plugin: it creates all factories, strategies, and dependencies, then hands control to the high-level policy
  • Test boundaries: tests are the most isolated component; they always depend inward and nothing depends on them
  • Premature boundaries are expensive, but so are missing boundaries -- draw them when the cost of crossing is less than the cost of not having them

Code applications:

ContextPatternExample
Full boundaryInput/Output port interfaces on both sidesUse Case defines both PlaceOrderInput and PlaceOrderOutput
Partial boundaryStrategy or Facade without full reciprocal interfacesShippingCalculator accepts a ShippingStrategy -- simpler than full ports
Humble ObjectSeparate testable logic from hard-to-test infrastructurePresenterLogic (testable) produces ViewModel; View (humble) renders it
Main as pluginComposition root assembles the systemmain() wires all concrete implementations and starts the app
Test boundaryTests depend on source; source never depends on testsTest imports PlaceOrderInteractor; production code never imports test code

See: references/boundaries.md

Common Mistakes

MistakeWhy It FailsFix
Letting the ORM leak into business logicEntities become coupled to the database schema; changing the DB means rewriting business rulesSeparate domain entities from persistence models; map between them at the adapter layer
Putting business rules in controllersLogic becomes untestable without spinning up HTTP; duplication across endpointsMove all business logic into Use Case Interactors; controllers only translate and delegate
Framework-first architectureThe framework dictates folder structure and dependency flow; swapping frameworks means a rewriteTreat the framework as a plugin in the outermost circle; structure code by business capability
Circular dependencies between componentsChanges ripple unpredictably; impossible to release independentlyApply DIP to break cycles or extract a shared abstraction component
One giant Use Case per featureUse Cases become bloated orchestrators with thousands of linesSplit into focused Use Cases with single application operations
Skipping boundaries "because it's simple"Coupling accumulates silently; by the time you need a boundary, the cost is enormousDraw boundaries proactively at points of likely volatility
Treating microservices as automatic good architectureA distributed monolith with shared databases and tight coupling is worse than a well-structured monolithApply the Dependency Rule within and across services; services are deployment boundaries, not architectural ones

Quick Diagnostic

QuestionIf NoAction
Can you test business rules without a database, web server, or framework?Business rules are coupled to infrastructureExtract entities and use cases behind interfaces; mock the outer layers
Do source code dependencies point inward on every import?The Dependency Rule is violatedIntroduce interfaces at the boundary; invert the offending dependency
Can you swap the database without changing business logic?Persistence is leaking inwardImplement the Repository pattern; isolate persistence in adapters
Are Use Cases independent of the delivery mechanism?Use Cases know about HTTP, CLI, or message queuesRemove delivery-specific types from Use Case signatures; use plain DTOs
Is the framework confined to the outermost circle?The framework is your architecture instead of a detailWrap framework calls behind interfaces; push framework code to the edges
Can you identify the component dependency graph and confirm it has no cycles?Circular dependencies existApply ADP: use DIP or extract new components to break every cycle
Does Main (or the composition root) wire all dependencies?Concrete classes are instantiated in inner circlesMove all construction logic to Main; use dependency injection or factories

Reference Files

  • dependency-rule.md: The Dependency Rule explained, concentric circles, data crossing boundaries, keeping the inner circle pure
  • entities-use-cases.md: Enterprise Business Rules, Application Business Rules, the Interactor pattern, request/response models
  • adapters-frameworks.md: Interface adapters, frameworks as details, database as a detail, plugin architecture
  • component-principles.md: REP, CCP, CRP, ADP, SDP, SAP -- component cohesion and coupling
  • solid-principles.md: SRP, OCP, LSP, ISP, DIP with code examples and common violations
  • boundaries.md: Boundary anatomy, Humble Object pattern, partial boundaries, Main as a plugin, test boundaries

Further Reading

This skill is based on Robert C. Martin's definitive guide to software architecture. For the complete methodology with detailed examples and case studies:

About the Author

Robert C. Martin ("Uncle Bob") is a software engineer, author, and one of the founding signatories of the Agile Manifesto. He has been programming since 1970 and has consulted for and trained development teams worldwide. Martin is the author of Clean Code, The Clean Coder, Clean Architecture, and Clean Agile, among other books. He is the founder of Uncle Bob Consulting LLC and cleancoder.com. His SOLID principles have become foundational vocabulary in object-oriented design, and his advocacy for craftsmanship and discipline in software development has influenced generations of programmers. Martin's work consistently argues that software architecture is about managing dependencies, drawing boundaries, and keeping business rules independent of delivery mechanisms and infrastructure details.

Mitgelieferte Dateien

Das Modell liest diese Dateien bei Bedarf, während der Skill geladen ist. Sie werden als lesbare Dateien bereitgestellt und niemals ausgeführt.

Häufig gestellte Fragen

Was macht der KI-Skill Clean Architecture?

Structure software around the Dependency Rule: source code dependencies point inward from frameworks to use cases to entities. Use when the user mentions "architecture layers", "dependency rule", "ports and adapters", "hexagonal architecture", "use case boundary", "onion architecture", "screaming architecture", or "framework independence". Also trigger when decoupling business logic from databases or frameworks, defining module boundaries, or debating where to put business rules. Covers component principles, boundaries, and SOLID. For code quality, see clean-code. For domain modeling, see d...

Warum Clean Architecture in TypingMind nutzen?

Weil Sie den Skill einmal installieren und mit jedem Modell verwenden können. Clean Architecture besteht aus reinem Markdown statt aus anbieterspezifischem Code. So funktioniert derselbe Skill mit GPT-5, Claude, Gemini, Grok oder einem lokalen Modell – und Sie können das Modell mitten im Chat wechseln, ohne dass der Skill seine Funktion verliert. TypingMind verwendet Ihre eigenen API-Schlüssel. Sie bezahlen die Anbieter daher direkt statt über ein Abonnement pro Nutzerplatz, und Ihre Skills und Chats bleiben in Ihrem eigenen Speicher.

Wie installiere ich Clean Architecture in TypingMind?

Öffnen Sie in TypingMind Plugins → Skills → Von GitHub installieren und fügen Sie https://github.com/alpham8/agentic-webdev/tree/master/skills/wondelai/clean-architecture ein. TypingMind liest die Datei SKILL.md, bündelt die zugehörigen Dateien und installiert alles als Skill, den Sie für jeden Chat einzeln aktivieren können.

Welche KI-Modelle können Clean Architecture nutzen?

Jedes Modell, das Sie in TypingMind verbinden. KI-Skills bestehen aus reinen Markdown-Anweisungen statt aus anbieterspezifischem Code. Daher können GPT, Claude, Gemini, Grok und lokale Modelle diesen Skill laden, wenn eine Anfrage dazu passt.

Wie viele KI-Modelle kann ich mit Clean Architecture verwenden?

So viele Sie möchten. Solange ein Modell Skills unterstützt, können Sie Clean Architecture damit verwenden – GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama und weitere – alles in TypingMind mit Ihren eigenen API-Schlüsseln.

Ist der KI-Skill Clean Architecture kostenlos?

Ja. Der Skill wird von alpham8 auf GitHub unter der Lizenz MIT veröffentlicht. Sie bezahlen nur Ihren eigenen KI-Anbieter für die verwendeten Token.

Was sind KI-Skills?

Ein KI-Skill ist ein wiederverwendbares Anweisungspaket, das einem KI-Modell vermittelt, wie es eine bestimmte Aufgabe erledigt. Es folgt dem offenen Format Agent Skills: eine Datei namens SKILL.md mit einem Namen und einer Beschreibung sowie allen Skripten, Vorlagen oder Referenzdateien, die das Modell möglicherweise benötigt. Das Modell liest die Anweisungen nur, wenn Ihre Anfrage zum Skill passt. Ein installierter Skill verursacht daher erst Kosten, wenn er verwendet wird.

Wie unterscheiden sich KI-Skills von Plugins oder MCP-Servern?

Ein Plugin oder MCP-Server stellt einem Modell neue aufrufbare Tools bereit – Code, der auf einem System ausgeführt wird und ein Ergebnis zurückgibt. Ein KI-Skill vermittelt dem Modell stattdessen Wissen und Vorgehensweisen: wie es eine Aufgabe angeht, welche Schritte es befolgt und wie eine gute Ausgabe aussieht. Skills bestehen aus reinem Markdown und benötigen daher weder Server noch API-Schlüssel oder Laufzeitumgebung. Sie funktionieren mit jedem Modell.

Alle

Jetzt eigenen KI-Arbeitsbereich einrichten

Abonnieren Sie unseren Newsletter und erfahren Sie mehr über neue Funktionen und kommende Gewinnspiele 👇