用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/mikailustuner/OmniRule --skill hexagonal-architecture命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
正在显示 SKILL.md
基于 SOC 职业分类
| name | hexagonal-architecture |
| description | Hexagonal Architecture: Ports and adapters, domain-driven design, external dependencies isolation. |
| triggers | {"keywords":["hexagonal","ports","adapters","domain isolation","infrastructure","application service"]} |
| auto_load_when | Designing hexagonal/ports-adapters architecture |
| agent | architect |
| tools | ["Read","Write","Bash"] |
Focus: Port/adapter separation, dependency inversion, domain isolation
Hexagon (ports on outside, domain inside):
┌─────────────┐
│ Driving │ ← API/Controllers
│ Adapters │
└──────┬──────┘
│
┌──────▼──────┐
│ Ports │ ← Interfaces
│ (Input/Out) │
├─────────────┤
│ Domain │ ← Core business logic
│ (Core) │ ← No external deps
├─────────────┤
│ Ports │ ← Interfaces
│(Secondary) │
└──────┬──────┘
│
┌──────▼──────┐
│ Driven │ ← DB, External APIs
│ Adapters │
└─────────────┘
Driving Ports (Primary):
├── Input interfaces for use cases
├── Called by adapters (API, CLI)
└── Define what the app can do
Driven Ports (Secondary):
├── Output interfaces for external deps
├── Implemented by adapters (DB, cache)
└── Define what the app needs
Use hexagonal when:
├── Multiple external dependencies
├── Need to mock external services
├── Domain logic needs to be reusable
├── Different delivery mechanisms (API, CLI, queue)
└── Complex integration scenarios
Not for:
├── Simple apps with one UI
├── Tightly coupled legacy systems
└── Rapid prototyping
Driving Adapter:
├── REST Controller → calls Use Case (port)
├── GraphQL Resolver → calls Use Case
└── CLI Command → calls Use Case
Driven Adapter:
├── RepositoryImpl → implements IRepository
├── CacheAdapter → implements ICachePort
└── ExternalApiClient → implements IApiPort
Domain must have:
├── No imports from adapters
├── No framework annotations
├── Pure business logic
├── Explicit dependencies (via ports)
Domain should contain:
├── Entities
├── Value Objects
├── Domain Services
├── Domain Events
└── Port Interfaces
Testing pyramid for hexagonal:
├── Unit: Domain logic (no mocks)
├── Integration: Use case + port (mock adapter)
├── E2E: Full adapter (real deps)
Mocking pattern:
├── Mock driven adapters for unit tests
├── Use test doubles for ports
└── Never mock the domain itself
(End of file - 80 lines)
❌ Port (interface) defined in infrastructure layer
✅ Ports belong to the application/domain core
❌ Adapter directly instantiated inside business logic
✅ Inject adapters via constructor/DI container
❌ HTTP concerns (status codes, headers) leaking into use cases
✅ HTTP is an adapter detail — use cases return plain results
❌ Testing with real DB instead of fake adapter
✅ Swap adapters with in-memory fakes in tests
❌ One giant port that does everything
✅ Small, focused ports per capability
| Concept | Hexagonal term | Lives where |
|---|---|---|
| Business logic | Application core | Center |
| Interface definition | Port | Core (defines shape) |
| Framework integration | Adapter | Outside |
| DB implementation | Driven adapter | Outside |
| HTTP handler | Driving adapter | Outside |
| DI wiring | Composition root | App startup |