用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/G1Joshi/Agent-Skills --skill clean-architecture命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
基于 SOC 职业分类
正在显示 SKILL.md
| name | clean-architecture |
| description | Clean Architecture layered design. Use for maintainable code. |
Clean Architecture, popularized by Robert C. Martin (Uncle Bob), separates software into layers to ensure independence from frameworks, databases, and UIs. The core principle is the Dependency Rule: source code dependencies can only point inwards.
// 1. Entity (Enterprise Logic) - Inner Layer
class User {
constructor(
public id: string,
public name: string,
) {
if (name.length < 2) throw new Error("Name too short");
}
}
// 2. Use Case (Application Logic)
class CreateUserUseCase {
constructor(private userRepository: UserRepository) {} // Depends on interface
async execute(name: string): Promise<User> {
const user = new User(crypto.randomUUID(), name);
await this.userRepository.save(user);
return user;
}
}
// 3. Interface Adapter (Repository Interface)
interface UserRepository {
save(user: User): Promise<void>;
}
// 4. Frameworks & Drivers (Implementation) - Outer Layer
class SqlUserRepository implements UserRepository {
async save(user: User): Promise<void> {
await db.query("INSERT INTO users ...", [user.id, user.name]);
}
}
Inner layers (Entities) know nothing about outer layers (Controllers, Presenters). Outer layers depend on inner layers.
Enterprise-wide business rules. These are the least likely to change when something external changes (e.g., page navigation security).
Orchestrate the flow of data to and from the entities. They contain the specific business rules of the application (e.g., "Create Order").
The glue that makes Clean Architecture possible. Outer layers inject concrete implementations (e.g., SqlUserRepository) into inner layers (which expect UserRepository interface).
Use simple objects (DTOs) to cross boundaries. Do not pass Entities to the UI or Database rows to the Use Case.
Do:
Don't:
| Error | Cause | Solution |
|---|---|---|
Circular Dependency | Violating the dependency rule. | Use Dependency Inversion (Interfaces) to break the cycle. |
Boilerplate Overload | Creating strict layers for simple CRUD. | Consider "Vertical Slice Architecture" or Modular Monolith for simpler domains. |