NestJS 모듈 안에 DDD 계층을 매핑한다

Nest 모듈 안에서 Controller, Application Service, Domain, Repository, Infrastructure 책임을 분리해 연결한다.

Controller

HTTP 입력

요청을 해석하고 DTO를 만든다.

Application Service

유스케이스 조정

흐름을 만들지만 규칙은 갖지 않는다.

Domain Model

비즈니스 규칙

불변식과 상태 변경을 책임진다.

Repository Port

저장 계약

도메인이 필요한 저장 기능만 약속한다.

Infrastructure

구현 세부

TypeORM, Prisma, 외부 API를 감싼다.

controllerapplicationdomainrepositoryinfrastructure

NestJS 모듈 안의 DDD 계층 매핑 기술 모듈 안에서도 도메인 모델을 안쪽에 두면 변경 이유가 더 명확해진다.