계좌에서 다른 계좌로 돈을 송금하는 유스케이스를 예제로 육각형 아키텍처를 직접적으로 반영하는 표현력 있는 패키지를 소개하겠다.
buckpal
|---- domain
|---- Acount
|---- Activity
|---- AccountRepository
|---- AccountService
|---- persistence
|---- AccountRepositoryImpl
|---- web
|---- AccountController
buckpal
|---- account
|---- Acount
|---- AcountController
|---- AccountRepository
|---- AccountRepositoryImpl
|---- SendMoneyService
account
패키지에 구성AccountService
의 책임을 좁히기 위해 SendMoneyService
로 클래스명 변경
buckpal
|---- account
|---- adapter
|---- in
|---- web
|---- AccountController
|---- out
|---- persistence
|---- AccountPersistenceAdapter
|---- SpringDataAccountRepository
|---- domain
|---- Account
|---- Activity
|---- application
|---- SendMoneyService
|---- port
|---- in
|---- SendMoneyUseCase
|---- out
|---- LoadAccountPort
|---- UpdateAccountStatePort
account
패키지가 존재domain
패키지가 있으며 application
패키지는 도메인 모델을 둘러싼 서비스 계층
SendMoneyService
는 인커밍 포트 인터페이스인 SendMoneyUseCase
를 구현SendMoneyService
는 아웃고잉 인터페이스이자 영속성 어댑터에 의해 구현된 LoadAccountPort
와 UpdateAccountStatePort
를 사용한다.adapter
패키지는 애플리케이션 계층 내의 포트를 사용하는 어댑터를 포함한다
web
어댑터와 persistence
어댑터로 구성된다.web
어댑터에선 애플리케이션 계층의 인커밍 포트를 호출persistence
어댑터는 애플리케이션 계층의 아웃고잉 포트 인터페이스를 구현public
으로 열지 않아도 된다.
adapter
패키지의 모든 클래스들은 application
패키지 내 포트 인터페이스를 통하지 않고는 호출되지 않기에 package-private
으로 충분하다.application
과 domain
패키지 내 일부 어댑터에서 접근 가능해야 하는 포트들은 public
으로 지정해야 한다application
패키지 내 서비스는 인커밍 포트 뒤에 숨을 수 있기에 public
일 필요가 없다.account
같은 상위 레벨 패키지는 다른 바운디드 컨텍스트와 통신할 전용 진입점 출구(포트)를 포함하는 바운디드 컨텍스트에 해당한다.