software-patterns by bobmatnyc/claude-mpm-skills
npx skills add https://github.com/bobmatnyc/claude-mpm-skills --skill software-patterns架构模式解决特定的结构性问题。本技能提供了一个决策框架,用于判断何时应用每种模式,而不是一个需要死记硬背的模式目录。
核心理念: 模式解决问题。没有问题?则无需模式。
在以下情况下激活:
这些模式为可维护的系统提供了结构基础。除非有特定理由,否则都应应用。
| 模式 | 解决的问题 | 应用信号 |
|---|---|---|
| 依赖注入 | 紧耦合、不可测试的代码 | 类实例化自己的依赖项 |
| 面向服务的架构 | 单体纠缠、边界不清 | 业务逻辑分散,没有明确的归属 |
这些模式解决特定问题。不要预先应用。
| 模式 | 解决的问题 |
|---|
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
| 应用信号 |
|---|
| 仓储模式 | 数据访问耦合 | 服务了解数据库细节 |
| 领域事件 | 循环依赖、时间耦合 | 服务 A 调用 B 调用 C 调用 A |
| 防腐层 | 外部系统耦合 | 外部 API 变更破坏你的代码 |
| 断路器 | 级联故障 | 一个缓慢的服务拖垮整个系统 |
Is code hard to test?
├─ Yes → Apply Dependency Injection
└─ No → Continue
Is business logic scattered?
├─ Yes → Apply Service-Oriented Architecture
└─ No → Continue
Do services know database details?
├─ Yes → Apply Repository Pattern
└─ No → Continue
Do services call each other in cycles?
├─ Yes → Apply Domain Events
└─ No → Continue
Does external API change break your code?
├─ Yes → Apply Anti-Corruption Layer
└─ No → Continue
Does one slow service break everything?
├─ Yes → Apply Circuit Breaker
└─ No → Current patterns sufficient
→ 完整决策树
主要: 依赖注入 原因: 依赖项被传入 = 依赖项可模拟
主要: 面向服务的架构 次要: 仓储模式(如果数据访问是困惑点) 原因: 清晰的边界 = 明确的归属
主要: 防腐层 原因: 转换层吸收外部变化
主要: 领域事件 原因: 发布/订阅模式打破循环依赖
主要: 断路器 次要: 带退避的重试 原因: 快速失败防止级联
主要: 仓储模式 原因: 抽象层隔离数据访问
→ 实际示例
启动新系统时:
重构现有系统时:
最小充分模式 应用能解决问题的最简单模式。过度设计会带来自身的维护负担。
问题优先选择 永远不要问"我应该使用哪些模式?",而要问"我要解决什么问题?"
组合优于规定 模式可以组合。仓储 + 领域事件 + 断路器对于外部数据源是常见的组合。
显式优于隐式 依赖关系应该是可见的。服务定位器隐藏它们;DI 暴露它们。
当出现以下情况时,请停止:
所有这些都意味着:停止。首先识别具体问题。
常见有效的组合:
| 场景 | 模式 |
|---|---|
| 新微服务 | DI + SOA + Repository |
| 外部 API 集成 | DI + ACL + Circuit Breaker |
| 事件驱动系统 | DI + SOA + Domain Events |
| 数据密集型应用 | DI + SOA + Repository + Unit of Work |
记住: 模式的存在是为了解决问题。从问题开始,而不是从模式开始。
每周安装次数
81
代码仓库
GitHub 星标数
18
首次出现
Jan 23, 2026
安全审计
安装于
claude-code62
gemini-cli62
opencode61
codex60
github-copilot57
cursor56
Architectural patterns solve specific structural problems. This skill provides a decision framework for when to apply each pattern, not a catalog to memorize.
Core philosophy: Patterns solve problems. No problem? No pattern needed.
Activate when:
These patterns provide the structural foundation for maintainable systems. Apply unless you have specific reasons not to.
| Pattern | Problem Solved | Signal to Apply |
|---|---|---|
| Dependency Injection | Tight coupling, untestable code | Classes instantiate their own dependencies |
| Service-Oriented Architecture | Monolithic tangles, unclear boundaries | Business logic scattered, no clear ownership |
These patterns address specific problems. Don't apply preemptively.
| Pattern | Problem Solved | Signal to Apply |
|---|---|---|
| Repository | Data access coupling | Services know about database details |
| Domain Events | Circular dependencies, temporal coupling | Service A calls B calls C calls A |
| Anti-Corruption Layer | External system coupling | External API changes break your code |
| Circuit Breaker | Cascading failures | One slow service takes down everything |
→ Foundational Patterns Detail → Situational Patterns Detail
Is code hard to test?
├─ Yes → Apply Dependency Injection
└─ No → Continue
Is business logic scattered?
├─ Yes → Apply Service-Oriented Architecture
└─ No → Continue
Do services know database details?
├─ Yes → Apply Repository Pattern
└─ No → Continue
Do services call each other in cycles?
├─ Yes → Apply Domain Events
└─ No → Continue
Does external API change break your code?
├─ Yes → Apply Anti-Corruption Layer
└─ No → Continue
Does one slow service break everything?
├─ Yes → Apply Circuit Breaker
└─ No → Current patterns sufficient
Primary: Dependency Injection Why: Dependencies passed in = dependencies mockable
Primary: Service-Oriented Architecture Secondary: Repository (if data access is the confusion) Why: Clear boundaries = clear ownership
Primary: Anti-Corruption Layer Why: Translation layer absorbs external volatility
Primary: Domain Events Why: Publish/subscribe breaks circular dependencies
Primary: Circuit Breaker Secondary: Retry with Backoff Why: Fail fast prevents cascade
Primary: Repository Pattern Why: Abstraction layer isolates data access
When starting a new system:
When refactoring existing system:
Minimal Sufficient Pattern Apply the simplest pattern that solves the problem. Over-architecting creates its own maintenance burden.
Problem-First Selection Never ask "which patterns should I use?" Ask "what problem am I solving?"
Composition Over Prescription Patterns combine. Repository + Domain Events + Circuit Breaker is common for external data sources.
Explicit Over Implicit Dependencies should be visible. Service Locator hides them; DI exposes them.
STOP when:
ALL of these mean: STOP. Identify the specific problem first.
Common effective combinations:
| Scenario | Patterns |
|---|---|
| New microservice | DI + SOA + Repository |
| External API integration | DI + ACL + Circuit Breaker |
| Event-driven system | DI + SOA + Domain Events |
| Data-heavy application | DI + SOA + Repository + Unit of Work |
Remember: Patterns exist to solve problems. Start with the problem, not the pattern.
Weekly Installs
81
Repository
GitHub Stars
18
First Seen
Jan 23, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
claude-code62
gemini-cli62
opencode61
codex60
github-copilot57
cursor56
站立会议模板:敏捷开发每日站会指南与工具(含远程团队异步模板)
10,500 周安装