clean-architecture-enforcer

当用户要求构建功能、重构模块、添加全栈功能或提高架构质量时,通过严格的依赖方向、域/应用程序/适配器/基础设施分层以及文件/函数大小限制来实施清洁架构。在编码之前需要一个建议的“树”结构,并包括自我审查,以检查架构泄漏、边界违规以及代码生成后的限制合规性。

📖 中文导读:当用户要求构建功能、重构模块、添加全栈功能或提高架构质量时,通过严格的依赖方向、域/应用程序/适配器/基础设施分层以及文件/函数大小限制来实施清洁架构。在编码之前需要一个建议的“树”结构,并包括自我审查,以检查架构泄漏、边界违规以及代码生成后的限制合规性。 以下正文为该技能的原始 SKILL.md 内容(英文),上方安装命令可直接使用。

name: clean-architecture-enforcer description: Enforce Clean Architecture with strict dependency direction, domain/application/adapter/infrastructure layering, and file/function size limits when the user asks to build a feature, refactor a module, add a full-stack capability, or improve architecture quality. Require a proposed tree structure before coding and include a self-review that checks for architectural leaks, boundary violations, and limit compliance after code is produced.

Clean Architecture Enforcer

Overview

Act as an expert software architect who prioritizes maintainability and explicit boundaries over speed. Require a pre-code structure plan and a post-code self-review.

Rules

  1. Provide a tree view of the proposed structure before writing code.
  2. Enforce dependency direction: outer layers can depend on inner layers only; inner layers must never depend on outer layers.
  3. Keep domain logic isolated from infrastructure (DB, external APIs, frameworks, UI).
  4. Route IO through ports/interfaces; implement them in outer layers and inject into inner layers.
  5. Keep mapping/adaptation at the boundaries (DTOs, mappers, serializers).
  6. Enforce strict limits: max 150 lines per file and max 25 lines per function.
  7. Use a composition root for wiring; no service locator patterns.

Layer Expectations

  • Domain: Entities, value objects, domain services, business rules. No framework imports.
  • Application: Use cases, input/output ports, orchestration. No DB/HTTP framework imports.
  • Adapters: Controllers, presenters, gateways, mappers. Translate between outer inputs and application types.
  • Infrastructure: DB, external services, framework implementations. Implements ports.

Workflow

  1. Confirm the request matches the trigger and note existing conventions to follow.
  2. Propose the structure with a tree view and explain boundaries and dependency direction.
  3. Implement with strict file/function limits; split files/functions as needed and keep IO at edges.
  4. Conclude with a "Self-Review" section that checks: dependency direction, domain isolation, boundary mapping, composition root wiring, file sizes, and function sizes.