modular-design-principles
它能做什么
这个技能为 AI 提供十条设计和审查模块结构的原则,例如清晰的公共接口、独立性以及故障隔离。适合希望在任何技术栈中都建立合理边界的架构师和开发者。
适用场景
- ✓当你在设计系统应如何拆分为模块或服务时。
- ✓当你审查代码库中导致麻烦的共享依赖时。
- ✓当你需要判断一个模块应该拆分还是合并时。
技能链接
https://github.com/tech-leads-club/agent-skills/blob/main/packages/skills-catalog/skills/(architecture)/modular-design-principles/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请审查我们的项目结构,告诉我模块边界哪里薄弱,并说明如何修正。”
每周 5 个新技能,1 分钟读完。
工作原理
AI 会运用一套简短的原则,涵盖边界、可组合性、状态隔离和契约,并据此检查设计。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Modular Design Principles
Use this skill when reasoning about structure and boundaries in any codebase. It intentionally avoids framework names, folder conventions, and tooling — map principles to your stack locally.
What to load
| Task | Where |
|---|---|
| Principles table + violations + workflows (this file) | SKILL.md |
| Per-principle definition, agent rules, abstract examples | references/principles.md |
Layered mental model
- Composition roots (applications, hosts, runners): wire modules together; keep orchestration thin.
- Modules / bounded contexts: cohesive units of behavior and data ownership; each should be understandable and testable on its own.
- Shared kernels (use sparingly): only stable, truly cross-cutting concepts; resist turning them into a grab-bag of “everything everyone needs.”
How you physically lay this out (mono repo, multi repo, packages, libraries) is a delivery choice, not the definition of modularity. The principles below still apply.
The ten principles
| # | Principle | Intent |
|---|---|---|
| 1 | Well-defined boundaries | A small, stable public surface; everything else is internal. Consumers depend on contracts, not internals. |
| 2 | Composability | Modules can be used alone or combined without special knowledge of each other’s internals. |
| 3 | Independence | No hidden shared mutable state across boundaries; each module should be testable in isolation (with fakes or test doubles at the edges). |
| 4 | Individual scale | Resources (compute, storage, rate limits, batch size) can be tuned per module where it matters, without rewriting others. |
| 5 | Explicit communication | Cross-module interaction uses documented contracts (APIs, events, messages, shared types) — not incidental coupling. |
| 6 | Replaceability | Dependencies on other modules are expressed through interfaces or protocols so implementations can change. |
| 7 | Deployment independence | Modules do not assume they share a process, host, or release cadence unless that is an explicit architectural decision. |
| 8 | State isolation | Each module owns its persistent state and naming; no silent sharing of the same logical data store or ambiguous global names across boundaries. |
| 9 | Observability | Each module can be diagnosed on its own: logs, metrics, traces, health — attributable to the unit that emitted them. |
| 10 | Fail independence | Failures are contained (timeouts, bulkheads, circuit breaking, idempotency) so one module’s outage does not blindly cascade. |
Principle 8 is often the hardest: ambiguous ownership of data or names is a frequent source of “works until it doesn’t” integration bugs.
For depth (rules for agents + abstract examples per principle), load references/principles.md.
Typical violations (stated abstractly)
- Colliding concepts — the same name or schema for different things in different modules, or duplicate “global” definitions that diverge over time.
- Reach-through persistence — one module reading or writing another module’s tables, buckets, or documents without going through an agreed contract.
- Centralized data ownership — a single persistence layer that registers and exposes all stores for all modules, encouraging hidden coupling.
- Logic at the edge — business rules in transport adapters (HTTP handlers, UI, CLI) instead of domain/application code.
- Edge talking to storage directly — adapters depending on low-level persistence APIs instead of use cases or application services.
- Unscoped transactions — writes that span boundaries without clear transaction ownership and failure semantics.
- Leaky exports — repositories, internal services, or implementation types exposed as the module’s public API.
- Facades that aren’t thin — “public” entry points that embed querying, mapping, or policy instead of delegating to the right layer inside the module.
Creating a bounded context (workflow)
Use when introducing a new cohesive area of the system (greenfield module or extracted domain).
- Scope and language — Name the context; list core nouns/verbs (ubiquitous language). Reject vague names that collide with other contexts.
- Responsibilities — What decisions happen only here? What is explicitly out of scope?
- State ownership — Which facts are **authori
常见问题
它依赖于某个特定框架吗?
不依赖。这些原则适用于任何技术栈。
它会描述文件夹布局吗?
不会。物理布局由你的团队决定,而这些原则依然适用。
它是一套编码风格规则吗?
不是。它关注的是结构和边界,而不是代码风格。
详情
作者的原始描述
Technology-agnostic guidance for modular systems: bounded contexts, clear boundaries, composability, state isolation, explicit contracts, failure containment, scaffolding workflows, split/merge criteria, sub-units inside a context, and compliance review signals. Use when designing or reviewing module structure, service boundaries, package layout, cross-cutting dependencies, "how should we split this?", modularity assessments, coupling between domains, greenfield context design, or architecture discussions without assuming a specific framework, language, or repository layout. Do NOT use for exe
热度
- GitHub 星标
- 7.1k
- 排名
- #13510
- 许可证
- —
- 更新时间
- 2026/11/2
评论
- …
同一仓库的更多技能
component-common-domain-detection
7.1k帮你的智能体找出代码库中多个部分重复的业务逻辑,并建议如何合并。
component-flattening-analysis
7.1k帮你的智能体找出位置不当的代码,并整理杂乱的组件文件夹结构,让每个部分都放在应在的位置。
component-identification-sizing
7.1k帮你的智能体梳理代码库的各个组成部分并测量其规模,以找出应首先拆分的模块。
coupling-analysis
7.1k帮你的智能体检查代码库各部分之间的依赖有多紧密,并找出应优先放松的连接。