# 后端架构模式 (architecture-patterns)

> 运用整洁架构、六边形架构和领域驱动设计，为服务建立分层结构、依赖规则、接口定义和测试边界。

- 分类: [架构设计](https://www.myskills.tools/zh/categories/architecture/)
- 来源: 社区 · Seth Hobson
- 代码仓库: https://github.com/wshobson/agents/tree/main/plugins/backend-development/skills/architecture-patterns (commit 0f73766)
- SKILL.md: https://github.com/wshobson/agents/blob/main/plugins/backend-development/skills/architecture-patterns/SKILL.md
- 安装命令: `npx skills add wshobson/agents --skill architecture-patterns`
- 许可证: MIT
- 兼容工具: Claude Code, Codex, Cursor, Copilot, OpenCode
- 权限: read-repo ✓, write-files ✓, shell ✗, network ✗
- 状态: 扫描通过
- 规则扫描无法覆盖所有风险，安装前请阅读此技能的 SKILL.md，确认权限后再使用。

## 核心规则

依赖只能向内指向，内层对外层一无所知。

## 执行阶段

1. **选择模式与边界** — 根据场景选用整洁架构、六边形架构或 DDD，划定限界上下文并统一领域语言。
2. **分层并定义接口** — 把实体、用例、接口适配器和框架驱动分层，每个层边界都通过抽象接口跨越。
3. **实现战术模式** — 使用聚合、值对象、仓储和领域事件；值对象在构造时校验不变量。
4. **内存适配器测试** — 每个用例都应能在不依赖真实数据库、Docker 或网络的普通单元测试中运行。
5. **排查常见问题** — 处理层间循环导入、领域实体带框架注解、控制器臃肿和跨上下文渗透，必要时引入防腐层。

## 权限说明（据 SKILL.md 整理）

| 能力 | 是否需要 | 说明 |
|---|---|---|
| 文件写入 | 需要 | 创建或重构分层代码结构、接口定义和单元测试。 |
| 命令执行 | 不需要 | 技能未要求运行命令。 |
| 网络外发 | 不需要 | 不访问网络。 |

## SKILL.md 头部信息（YAML）

```yaml
---
name: architecture-patterns
description: Implement proven backend architecture patterns including Clean Architecture, Hexagonal Architecture, and Domain-Driven Design. Use this skill when designing clean architecture for a new microservice, when refactoring a monolith to use bounded contexts, when implementing hexagonal or onion architecture patterns, or when debugging dependency cycles between application layers.
---
```

首页: https://www.myskills.tools/zh/ · URL: https://www.myskills.tools/zh/skills/architecture-patterns/
