hexagonal-architecture
하는 일
이 스킬은 프로그램 코드를 정리해 핵심 업무 로직을 데이터베이스나 사용자 화면 같은 기술적 세부 사항과 분리하도록 돕습니다. 이렇게 하면 코드를 이해하고, 테스트하고, 수정하기가 더 쉬워집니다.
사용하는 경우
- ✓유지보수가 쉬워야 하는 새 프로젝트를 시작할 때.
- ✓현재 코드가 업무 규칙과 기술을 뒤섞어 복잡할 때.
- ✓데이터베이스나 API 같은 여러 시스템에 핵심 로직을 바꾸지 않고 프로그램을 연결해야 하는 경우.
스킬 링크
https://github.com/affaan-m/ECC/blob/main/pi/core/skills/hexagonal-architecture/SKILL.md복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.
사용 방법
가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.
바로 붙여넣을 수 있는 메시지
Claude Code, Codex, Cursor용입니다. 프로젝트 폴더에서 실행하면 스킬이 설치됩니다.
SKILL.md를 다운로드해 에이전트의 스킬 폴더에 넣으세요.
AI에게 요청하는 예시
“데이터베이스를 바꿔도 업무 로직이 영향을 받지 않도록 코드를 어떻게 정리할 수 있을까요?”
매주 새 스킬 5개. 읽는 데 1분.
작동 방식
외부와의 상호작용을 위한 ‘포트(계약)’를 정의하고, 이 포트를 구현하는 ‘어댑터’를 만듭니다. 핵심 프로그램 로직은 포트를 사용하고, 어댑터가 기술적인 세부 사항을 처리합니다.
기술 내용 (원본 SKILL.md)
작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.
Hexagonal Architecture
Hexagonal architecture (Ports and Adapters) keeps business logic independent from frameworks, transport, and persistence details. The core app depends on abstract ports, and adapters implement those ports at the edges.
When to Use
- Building new features where long-term maintainability and testability matter.
- Refactoring layered or framework-heavy code where domain logic is mixed with I/O concerns.
- Supporting multiple interfaces for the same use case (HTTP, CLI, queue workers, cron jobs).
- Replacing infrastructure (database, external APIs, message bus) without rewriting business rules.
Use this skill when the request involves boundaries, domain-centric design, refactoring tightly coupled services, or decoupling application logic from specific libraries.
Core Concepts
- Domain model: Business rules and entities/value objects. No framework imports.
- Use cases (application layer): Orchestrate domain behavior and workflow steps.
- Inbound ports: Contracts describing what the application can do (commands/queries/use-case interfaces).
- Outbound ports: Contracts for dependencies the application needs (repositories, gateways, event publishers, clock, UUID, etc.).
- Adapters: Infrastructure and delivery implementations of ports (HTTP controllers, DB repositories, queue consumers, SDK wrappers).
- Composition root: Single wiring location where concrete adapters are bound to use cases.
Outbound port interfaces usually live in the application layer (or in domain only when the abstraction is truly domain-level), while infrastructure adapters implement them.
Dependency direction is always inward:
- Adapters -> application/domain
- Application -> port interfaces (inbound/outbound contracts)
- Domain -> domain-only abstractions (no framework or infrastructure dependencies)
- Domain -> nothing external
How It Works
Step 1: Model a use case boundary
Define a single use case with a clear input and output DTO. Keep transport details (Express req, GraphQL context, job payload wrappers) outside this boundary.
Step 2: Define outbound ports first
Identify every side effect as a port:
- persistence (
UserRepositoryPort) - external calls (
BillingGatewayPort) - cross-cutting (
LoggerPort,ClockPort)
Ports should model capabilities, not technologies.
Step 3: Implement the use case with pure orchestration
Use case class/function receives ports via constructor/arguments. It validates application-level invariants, coordinates domain rules, and returns plain data structures.
Step 4: Build adapters at the edge
- Inbound adapter converts protocol input to use-case input.
- Outbound adapter maps app contracts to concrete APIs/ORM/query builders.
- Mapping stays in adapters, not inside use cases.
Step 5: Wire everything in a composition root
Instantiate adapters, then inject them into use cases. Keep this wiring centralized to avoid hidden service-locator behavior.
Step 6: Test per boundary
- Unit test use cases with fake ports.
- Integration test adapters with real infra dependencies.
- E2E test user-facing flows through inbound adapters.
Architecture Diagram
flowchart LR
Client["Client (HTTP/CLI/Worker)"] --> InboundAdapter["Inbound Adapter"]
InboundAdapter -->|"calls"| UseCase["UseCase (Application Layer)"]
UseCase -->|"uses"| OutboundPort["OutboundPort (Interface)"]
OutboundAdapter["Outbound Adapter"] -->|"implements"| OutboundPort
OutboundAdapter --> ExternalSystem["DB/API/Queue"]
UseCase --> DomainModel["DomainModel"]
Suggested Module Layout
Use feature-first organization with explicit boundaries:
src/
features/
orders/
domain/
Order.ts
OrderPolicy.ts
application/
ports/
inbound/
CreateOrder.ts
outbound/
OrderRepositoryPort.ts
PaymentGatewayPort.ts
use-cases/
CreateOrderUseCase.ts
adapters/
inbound/
http/
createOrderRoute.ts
outbound/
postgres/
PostgresOrderRepository.ts
stripe/
StripePaymentGateway.ts
composition/
ordersContainer.ts
TypeScript Example
Port definitions
export interface OrderRepositoryPort {
save(order: Order): Promise<void>;
findById(orderId: string): Promise<Order | null>;
}
export interface PaymentGatewayPort {
…
자주 묻는 질문
‘포트’와 ‘어댑터’란 무엇인가요?
포트는 프로그램이 해야 할 일이나 사용할 외부 서비스를 정의하는 계약과 같습니다. 어댑터는 이 계약을 실제로 구현한 것으로, 데이터베이스나 API 등과의 통신을 담당합니다.
왜 ‘헥사고날 아키텍처’라고 부르나요?
핵심 업무 로직을 육각형으로 보고, 각 면에 포트를 두어 여러 어댑터와 연결할 수 있다는 개념에서 나온 이름입니다. 컴퓨터에 키보드와 모니터를 연결하는 것과 비슷합니다.
구현하기가 더 복잡한가요?
처음에는 조금 복잡해 보일 수 있습니다. 하지만 장기적으로는 특히 큰 프로젝트에서 개발과 유지보수를 훨씬 쉽고 안전하게 만들어 줍니다.
상세 정보
작성자의 원본 설명
Design, implement, and refactor Ports & Adapters systems with clear domain boundaries, dependency inversion, and testable use-case orchestration across TypeScript, Java, Kotlin, and Go services. Use when introducing or refactoring toward Ports and Adapters, or when domain logic has become entangled with I/O.
repo: affaan-m/ECC
인기도
- GitHub 스타
- 280k
- 순위
- #188
- 라이선스
- MIT
- 업데이트
- 2026. 10. 15.
댓글
- …
이 저장소의 다른 스킬
accessibility
280k에이전트가 모든 사람이 쓸 수 있는 인터페이스를 만들도록 돕습니다. 시각 장애나 운동 장애가 있는 사람도 쓸 수 있게 합니다.
agent-architecture-audit
280k에이전트가 모든 것이 올바르게 작동하는지 점검하도록 돕습니다. AI 시스템의 문제를 찾아 고쳐서 기대대로 작동하게 합니다.
agent-eval
280k에이전트가 서로 다른 AI 코딩 도구를 비교하도록 돕습니다. 특정 작업에서 어느 도구가 더 빠르고, 저렴하고, 믿을 만한지 측정합니다.
agent-harness-construction
280k에이전트가 작업을 더 잘 이해하도록 돕습니다. 에이전트가 쓰는 도구와 지시문을 최적화해 성공 가능성을 높입니다.