软件架构设计指导
software-architecture
整洁架构(Clean Architecture)、SOLID 原则与架构决策指导。适用于评估分层边界、依赖流向、设计契约违规或 ADR 级别的决策。不适用于:开放式想法探索(使用 brainstorming)、UI 组件设计(使用 frontend-design)、编写测试(使用 test-driven-development),或协调并行实现通道(使用 parallel-execution)。
- License 许可
- MIT
- 最近更新
- 2026-08-16
- Stars
- ★ 3
- Forks
- 0
01 前言 Front Matter
- name
- software-architecture
- description
- Clean Architecture, SOLID principles, and architectural decision guidance. Use when evaluating layer boundaries, dependency flow, design contract violations, or ADR-level decisions. DO NOT USE FOR: open-ended idea exploration (use brainstorming), UI component design (use frontend-design), writing tests (use test-driven-development), or coordinating parallel implementation lanes (use parallel-execution).
03 SKILL.md 正文
Software Architecture Skill
High-level architectural patterns and decision-making frameworks.
When to Use
- Designing new systems or major features
- Evaluating existing architecture
- Making structural decisions (layer boundaries, dependencies)
- Reviewing code for architectural alignment
- Documenting architectural decisions (ADRs)
SOLID Principles Quick Reference
| Principle | Summary | Violation Smell |
|---|---|---|
| Single Responsibility | One reason to change | Class does too many things |
| Open/Closed | Extend, don't modify | Modifying existing code for new features |
| Liskov Substitution | Subtypes are substitutable | Overrides that break expectations |
| Interface Segregation | Small, focused interfaces | Implementing methods you don't need |
| Dependency Inversion | Depend on abstractions | High-level imports low-level directly |
Clean Architecture Layers
┌─────────────────────────────────────────┐
│ External Systems │ Frameworks, DB, UI
├─────────────────────────────────────────┤
│ Interface Adapters │ Controllers, Presenters, Gateways
├─────────────────────────────────────────┤
│ Application Layer │ Use Cases, Application Services
├─────────────────────────────────────────┤
│ Domain Layer │ Entities, Value Objects, Domain Services
└─────────────────────────────────────────┘
Dependencies point INWARD →
Layer Responsibilities
Domain Layer (innermost):
- Business entities and logic
- No dependencies on outer layers
- Framework-agnostic
Application Layer:
- Use case orchestration
- Application-specific business rules
- Coordinates domain objects
Interface Adapters:
- Convert data between layers
- Controllers, presenters, gateways
- Maps to/from domain models
External Systems (outermost):
- Frameworks, databases, UI
- All implementation details
- Easily replaceable
Dependency Rule
Source code dependencies must point only inward, toward higher-level policies.
Good: Controller → Use Case → Entity Bad: Entity → Database (domain knows about infrastructure)
Common Architectural Patterns
Hexagonal Architecture (Ports & Adapters)
┌──────────────┐
Driving │ │ Driven
Adapters│ Core │ Adapters
(Input) │ Domain │ (Output)
────>│ │────>
└──────────────┘
Ports (Interfaces)
CQRS (Command Query Responsibility Segregation)
- Separate read and write models
- Use when read/write patterns differ significantly
- Consider eventual consistency implications
Event-Driven Architecture
- Loose coupling through events
- Good for: cross-boundary communication, audit trails
- Consider: event ordering, idempotency, replay
Architectural Decision Framework
When making architectural decisions:
1. Identify the Decision
- What specific decision needs to be made?
- What are the constraints?
- Who are the stakeholders?
2. Gather Context
- What are the requirements (functional and non-functional)?
- What are the quality attributes (performance, scalability, etc.)?
- What are the constraints (time, budget, team skills)?
3. Evaluate Options
For each option, consider:
- Benefits: What problems does it solve?
- Costs: Implementation effort, maintenance, complexity
- Risks: What could go wrong?
- Trade-offs: What are we giving up?
4. Document Decision (ADR)
# ADR-XXX: [Title]
## Status
[Proposed | Accepted | Deprecated | Superseded]
## Context
[What is the issue that we're seeing that is motivating this decision?]
## Decision
[What is the change that we're proposing and/or doing?]
## Consequences
[What becomes easier or harder as a result of this change?]
Code-Level Architecture Patterns
Dependency Injection
[CUSTOMIZE] Add your DI framework examples:
// Framework: [Your framework]
// Pattern: [Constructor injection, etc.]
Repository Pattern
Interface: Repository<T>
- findById(id): T
- save(entity): void
- delete(id): void
Implementation in infrastructure layer
Domain layer depends only on interface
Service Layer
Thin controllers → Application Services → Domain
Controllers: HTTP handling only
Services: Use case orchestration
Domain: Business logic
Architectural Smells
| Smell | Symptom | Remedy |
|---|---|---|
| Big Ball of Mud | Everything depends on everything | Define boundaries |
| Distributed Monolith | Microservices with tight coupling | Find real boundaries |
| Anemic Domain Model | Logic in services, entities are data bags | Rich domain model |
| God Object | Class that knows/does too much | Split responsibilities |
| Circular Dependencies | A→B→C→A | Introduce abstractions |
Review Checklist
When reviewing architecture:
Boundaries
- [ ] Clear layer/module boundaries defined
- [ ] Dependencies flow in correct direction
- [ ] Boundaries match team structure (Conway's Law)
Coupling
- [ ] Low coupling between modules
- [ ] Changes are localized
- [ ] Can deploy independently (if relevant)
Cohesion
- [ ] Related things are together
- [ ] Modules have clear, single purpose
- [ ] Naming reflects responsibility
Testability
- [ ] Can test business logic without infrastructure
- [ ] Dependencies are injectable
- [ ] Seams exist for test doubles
Project-Specific Architecture
[CUSTOMIZE] Document your project's architecture:
## Architecture Overview
[Diagram or description of your architecture]
## Layer Structure
- Domain: [location]
- Application: [location]
- Infrastructure: [location]
- Presentation: [location]
## Key Patterns Used
- [Pattern 1]: [Where/why used]
- [Pattern 2]: [Where/why used]
## Architecture Decision Log
- [Link to ADRs or decision log]
Gotchas
| Trigger | Gotcha | Fix |
|---|---|---|
| Domain/entity class importing a database adapter or HTTP client directly | Domain layer gains transitive dependency on all infrastructure; DIP violation | Depend on interfaces; inject concrete adapters from outer layers |
| Adding a new case to an existing switch/if chain for new behavior | Breaks open-close: touching existing code increases regression risk → OCP violation | Extend via new class or strategy; existing code unchanged |
| Duplicating a formula or logic block in a new class instead of injecting it | Two sources of truth; diverge silently when one changes | Search for existing logic first; inject as dependency; delegate via composition |
| One class handles parsing, validation, and persistence | Multiple unrelated reasons to change; tests require the full class → SRP violation | Split into single-responsibility components with clear ownership |
| New implementation class imported only in test files | Component never reaches production call path; feature silently absent | Verify import + instantiation + callsite in production code, not just test imports |
| Cyclomatic complexity > 10 in a single method | Untestable paths; risky to change; each branch multiplies test surface | Extract helpers per SRP; enforce file size limits from project conventions |
04 同仓库更多 Skills
Playwright 端到端测试
webapp-testing
面向 Web 应用的 Playwright 端到端测试指南,包含实用模式和设置步骤。在创建或改进基于浏览器的 E2E 覆盖率、测试稳定性和 CI 执行时使用。不要用于:React 组件测试(使用 ui-testing)、Canvas 游戏交互(使用 browser-canvas-testing)、TDD 工作流(使用 test-driven-development)、失败调试(使用 systematic-debugging)或随机化属性测试(使用 property-based-testing)。
任务完成前验证
verification-before-completion
在将工作标记为完成前使用的基于证据的验证清单。适用于提交 PR、发布、将工单标记为完成,或任何「我已完成」的声明之前;也适用于为差异测试套件的主张指定基线提交、设计变异测试活动或红灯运行证据、做出「不存在」的主张、普遍性主张,或将一次性演示作为长期保证提供时、归因某项测量结果或声称某次扫描或验证循环已完成时,以及陈述某项检查或 CI 套件将如何处理某个变更时。不要用于:合并后清理或归档(使用 post-pr-review),或处理 GitHub 审查意见(使用 code-review-intake)。
验证与审查方法论
validation-methodology
用于分阶段验证、故障分诊和追查深度设置的可复用验证与审查方法论。在运行验证阶梯、对失败进行分诊或执行对抗性审查时使用。不要用于:CE Gate 编排、专家派发的职责归属或步骤执行流程(这些保留在 Code-Conductor 中)。
上游智能体接手协议
upstream-onboarding
供上游智能体(Experience-Owner、Solution-Designer、Issue-Planner)与 Code-Conductor 在针对现有 GitHub issue 被调用时使用的共享开场阶段协议。它会生成适配规模的上下文简报,并在每个阶段边界对承接的工作执行标准检查。当用户可调用的智能体收到引用现有 GitHub issue 的请求、且必须在开场阶段加载 solution-authoring 与 upstream-onboarding 时使用。不要用于:子智能体派发(其已在经评估的会话上下文中运行)、合并后审查(使用 post-pr-review)、研究类或非树形子智能体。
React 组件测试策略
ui-testing
以用户行为为核心的弹性 React 组件测试策略。适用于编写或审阅组件级 React 测试、修复不稳定的组件测试,或建立 React 测试模式。不适用于:Playwright E2E 测试(使用 webapp-testing)、canvas 游戏交互(使用 browser-canvas-testing)、TDD 工作流(使用 test-driven-development)、失败调试(使用 systematic-debugging)、UI 组件设计(使用 frontend-design),或随机属性测试(使用 property-based-testing)。
UI 界面视觉迭代优化
ui-iteration
可复用的截图驱动 UI 打磨工作流,用于迭代式视觉优化。适用于通过反复审阅与调整来改进布局、层级、间距、反馈或基于 Tailwind 的呈现效果。不适用于:功能性 Bug 修复、仅针对无障碍的审计,或重大重设计策略工作(使用 Code-Smith 或 frontend-design)。