AgentSkillsCN

clean-architecture

采用分层架构(领域层、应用层、基础架构层)践行清洁架构理念。在创建docs/architecture.md文档、设计新模块,或按照正确的依赖方向,将代码重构为多层结构时,可使用此功能。

SKILL.md
--- frontmatter
name: clean-architecture
description: Apply Clean Architecture with layered structure (Domain, Application, Infrastructure). Use when creating docs/architecture.md, designing new modules, or restructuring code into layers with proper dependency direction.

Applicability Rubric

ConditionPassFail
Architecture documentation missingdocs/architecture.md not foundFile exists
Significant structural changesFeature affects 2+ layersSingle-layer change
New module creationCreating new namespace/directoryModifying existing
Legacy restructuringReorganizing unstructured codeCode already layered

Apply when: Any condition passes

Core Principles

Layer Structure

code
┌─────────────────────────────────────┐
│           Infrastructure            │  ← Frameworks, DB, External APIs
├─────────────────────────────────────┤
│            Application              │  ← Use Cases, DTOs, Services
├─────────────────────────────────────┤
│              Domain                 │  ← Entities, Value Objects, Domain Services
└─────────────────────────────────────┘

Dependency Rule

Dependencies MUST point inward:

  • Infrastructure → Application → Domain
  • Domain has NO dependencies on outer layers
  • Use interfaces (ports) for dependency inversion

Layer Responsibilities

LayerContainsDepends On
DomainEntities, Value Objects, Domain Services, Repository InterfacesNothing
ApplicationUse Cases, Application Services, DTOsDomain
InfrastructureControllers, DB Adapters, External APIs, Framework CodeApplication, Domain

Completion Rubric

Before Implementation

CriterionPassFail
Layer identificationTarget layer explicitly statedNo layer consideration
Architecture docCreated/updated when neededNo documentation
Dependency verificationAll deps point inwardOutward deps exist

During Implementation

CriterionPassFail
Domain layer purityContains only business logicHas infrastructure concerns
Application orchestrationCoordinates use cases properlyMixed responsibilities
Infrastructure isolationExternal concerns separatedLeaked into inner layers
Interface definitionDefined for external depsDirect coupling

After Implementation

CriterionPassFail
No circular depsLayers have one-way depsCircular references exist
Domain testabilityTestable without infrastructureRequires external deps
Convention adherenceFollows project patternsInconsistent with codebase

Architecture Documentation

If docs/architecture.md doesn't exist, create it with:

markdown
# Architecture Overview

## Layer Structure
[Describe the layers used in this project]

## Directory Mapping
[Map directories to architectural layers]

## Dependency Guidelines
[Document dependency rules and conventions]