본문으로 건너뛰기
Skillpedia
일반 코딩280k · #188

hexagonal-architecture

하는 일

이 스킬은 프로그램 코드를 정리해 핵심 업무 로직을 데이터베이스나 사용자 화면 같은 기술적 세부 사항과 분리하도록 돕습니다. 이렇게 하면 코드를 이해하고, 테스트하고, 수정하기가 더 쉬워집니다.

사용하는 경우

  • ✓유지보수가 쉬워야 하는 새 프로젝트를 시작할 때.
  • ✓현재 코드가 업무 규칙과 기술을 뒤섞어 복잡할 때.
  • ✓데이터베이스나 API 같은 여러 시스템에 핵심 로직을 바꾸지 않고 프로그램을 연결해야 하는 경우.

스킬 링크

https://github.com/affaan-m/ECC/blob/main/pi/core/skills/hexagonal-architecture/SKILL.md

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/affaan-m/ECC/blob/main/pi/core/skills/hexagonal-architecture/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

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.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬