Book clean architecture full

From yanacuti1121/Yana-AI · View interactive version

Book clean architecture full is an AI agent skill from the GitHub repository yanacuti1121/Yana-AI. Clean Architecture (Robert C. Martin) — Full rules — comprehensive mandatory coding standards. Use when asked to apply Clean Architecture principles or review code against Clean Architecture standards.

How to use this skill

Skill file

OBEY Clean Architecture by Robert C. Martin

Purpose

This repository must follow Clean Architecture.

When writing, modifying, or reviewing code, prefer decisions that preserve:

Treat this file as a binding implementation policy: MUST is binding, SHOULD is a strong default, and MUST NOT is forbidden.


Non-Negotiable Rules

  1. Follow the Dependency Rule
  1. Keep Business Rules Pure
  1. Treat Frameworks as Details
  1. Treat the Database as a Detail
  1. Treat the Web as a Detail
  1. Use Explicit Boundaries
  1. Organize by Use Case
  1. Use Cases Must Orchestrate
  1. Entities Must Guard Invariants
  1. Outer Layers May Depend on Inner Layers, Never the Reverse

Required Layer Responsibilities

Domain Layer

Contains:

These may be implemented with plain objects, functions, modules, or other structures. Clean Architecture requires independent business rules; it does not require a specific domain modeling style.

Must:

Must not:

Application Layer

Contains:

Must:

Must not:

Interface Adapters Layer

Contains:

Must:

Must not:

Infrastructure Layer

Contains:

Must:

Must not:


Code Generation Rules

When generating code, always apply the following.

1. Define the Use Case First

For every non-trivial feature:

Prefer this order:

  1. domain rule or entity behavior
  2. use case
  3. boundary interfaces
  4. presenter contract
  5. gateway contract
  6. adapters
  7. framework wiring

2. Use Plain Models at Boundaries

3. Create Ports for Volatile Dependencies

Introduce interfaces for:

Do not call volatile details directly from core use cases.

4. Keep Wiring in the Main Component

5. Prefer Stable Dependencies

6. Keep Boundaries Visible


Architecture Heuristics

Dependency Direction

Always verify:

If yes, refactor.

Policy vs Detail

When placing code, ask:

Put the code in the highest-level place that matches its responsibility.

Stable Core, Replaceable Edge

Prefer designs where you can replace:

without rewriting business rules.

Feature First Structure

Prefer:

Over:

Technical subfolders are acceptable only when they do not obscure use-case ownership.


Architecture Economics and Priority

  1. Treat architecture as a way to keep future change cost proportional to the scope of change.
  2. Do not sacrifice important architectural work merely because urgent feature work is louder.
  3. Preserve options around frameworks, databases, delivery mechanisms, and deployment topology until evidence justifies commitment.
  4. Choose boundaries by volatility, policy importance, substitution value, testability, and cost.
  5. Do not overbuild boundaries whose cost exceeds the option value they preserve.
  6. Revisit architecture when change shape, team ownership, deployment needs, or operational constraints reveal rising cost.

Paradigm and Component Rules

  1. Use structured programming to make behavior decomposable and testable.
  2. Use polymorphism to invert dependencies when high-level policy must not know low-level details.
  3. Use immutability or controlled mutation when it protects policy from accidental state coupling.
  4. Apply SRP by separating code that changes for different actors or reasons.
  5. Apply the Open-Closed Principle by protecting stable policy from volatile extension details.
  6. Apply LSP by ensuring substitutable implementations preserve caller expectations.
  7. Apply ISP by keeping interfaces focused on what each client actually needs.
  8. Apply DIP by making source dependencies point toward stable policy and abstractions.
  9. Group components by cohesion and release pressure; do not group unrelated policy just because it shares a technical layer.
  10. Avoid component cycles; break cycles before they harden into deployment or test bottlenecks.
  11. Balance stability and abstraction: stable components should not depend on unstable details, and abstract components should have concrete reason to exist.

Boundary Cost, Deployment, and Operations

  1. A boundary may be a source boundary, deployment boundary, process boundary, service boundary, or partial boundary.
  2. Choose the lightest boundary that preserves the needed independence.
  3. Use partial boundaries when a full deployment/runtime split is too expensive but future separation is valuable.
  4. Keep development, deployment, operation, and maintenance concerns visible without letting them own business policy.
  5. Do not combine unrelated use cases just because operational wiring is easier.
  6. Do not eliminate duplication when the shared code would couple use cases that change for different actors.
  7. Make architectural boundaries enforceable through package structure, tests, dependency rules, or build constraints.

Services, Distribution, and Embedded Boundaries

  1. A service is not automatically an architectural boundary; source dependencies and data ownership still decide coupling.
  2. Remote calls must be treated as I/O boundaries, not as local method calls.
  3. Keep service listeners humble: translate external messages into use case calls and return through output boundaries.
  4. Keep embedded and hardware details behind interfaces so policy can be tested without the target device.
  5. Do not let real-time, firmware, database, web, or framework concerns pull policy outward.

Naming Rules


Testing Rules

Core Tests First

Prioritize tests for:

These tests must:

Adapter Tests

Test adapters separately for:

Do not use slow integration tests as a substitute for testing business rules.

Test Through Supported Boundaries


Forbidden Patterns

Do not generate or keep code that does any of the following unless explicitly required and justified.

Framework Leakage

Database Leakage

Controller-Centric Logic

God Services

Layer Bypass

Direction Violations

Utility Dumping Grounds


Refactoring Rules

When modifying existing code:

  1. Move business rules inward
  1. Introduce boundaries around details
  1. Replace concrete dependencies with ports
  1. Separate translation from policy
  1. Break up god services
  1. Eliminate framework coupling from tests
  1. Preserve behavior while improving direction

Output Expectations

When asked to implement a feature, default to producing:

When asked to modify existing code:

When asked to review code:


Review Checklist

Before finalizing any change, verify:

If any answer is no, revise the design before shipping.


Preferred Default Shapes

Preferred feature shape

Or, if feature-oriented:

Preferred use case shape

Preferred dependency pattern


When Tradeoffs Are Necessary

If constraints force a compromise:

Choose the design that minimizes long-term coupling, not the one that is only shortest today.


Final Instruction

When uncertain, choose the option that:

  1. keeps business rules independent
  2. points dependencies inward
  3. isolates details behind boundaries
  4. improves testability
  5. makes replacement of frameworks, databases, and delivery mechanisms easier

If a proposed change conflicts with these priorities, reject it and propose a cleaner architectural alternative.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.