Skip to content

[3주차] 도메인 주도 설계 구현 - 안성훈#117

Open
shAn-kor wants to merge 21 commits intoLoopers-dev-lab:shAn-korfrom
shAn-kor:shAn-kor
Open

[3주차] 도메인 주도 설계 구현 - 안성훈#117
shAn-kor wants to merge 21 commits intoLoopers-dev-lab:shAn-korfrom
shAn-kor:shAn-kor

Conversation

@shAn-kor
Copy link

📌 Summary

  • 배경: 이커머스 핵심 기능(상품, 브랜드, 좋아요, 주문, 카테고리)에 대한 도메인 모델과 API가 부재한 상태였습니다.
  • 목표: Controller, Facade/Application Service, Domain, Repository 경계를 명확히 정렬하고 Admin 인증(ldap header) 적용 지점을 통일하며 도메인별 테스트 가능성을 높입니다.
  • 결과: Facade/Application 중심 요청 흐름으로 재구성했고(BrandAdminFacade, OrderFacade, LikeFacade, ProductQueryFacade), AdminLdapInterceptorWebConfig에 연결해 /api-admin/v1/** 보호를 일원화했습니다.

🧭 Context & Decision

문제 정의

  • 현재 동작/제약:
    • 기능 추가는 진행됐지만 일부 유스케이스에서 컨트롤러/서비스 책임 경계가 흐려질 여지가 있었습니다.
    • Admin 인증 정책(X-Loopers-Ldap)을 모든 Admin API에 일관되게 걸어야 했습니다.
  • 문제(또는 리스크):
    • 계층 침범 시 변경 영향도가 커지고, 유지보수/검증 비용이 증가합니다.
    • 인증 누락 시 Admin API 보안 리스크가 발생합니다.
  • 성공 기준(완료 정의):
    • 도메인 기준 계층 재정렬(Interfaces -> Facade/Application -> Domain <- Infrastructure).
    • Admin 인증 체인 공통화.
    • 도메인/응용/인터페이스 테스트 보강으로 회귀 안정성 확보.

선택지와 결정

  • 고려한 대안:
    • A: 도메인 서비스에서 트랜잭션, 영속화 진행, Facade 는 여러 도메인 서비스 오케스트레이션만 진행
    • B: 트랜잭션 관리, 영속화는 어플리케이션 서비스에서 진행, 도메인서비스는 특정 도메인 혼자 할수 없는 도메인 로직 담당, 퍼사드는 필요시 어플리케이션 서비스 오케스트레이션 (트랜잭션 금지)
  • 최종 결정:
    • B
  • 트레이드오프:
    • 장점: 컨트롤러에서 도메인 계층 직접 참조 없음,
    • 단점: 도메인 서비스의 책임이 없거나 너무 얇음,
  • 추후 개선 여지(있다면):
    • 애플리케이션 서비스가 비대해지면 유스케이스 단위 서비스로 분리 (예: OrderCancelService, OrderCreateService)해서 트랜잭션 경계는 유지하되 응집도 높이기
    • 도메인 경계 협력이 많아지면 동기 호출 대신 일부를 도메인 이벤트 기반 후처리로 전환해 결합도/락 범위 축소

🏗️ Design Overview

변경 범위

  • 영향 받는 모듈/도메인:
    • apps/commerce-api 전 계층
    • Domain: Member, Product, Brand, Order, Like, Category
    • Application/Interfaces/Infrastructure 전반
  • 신규 추가:
    • Facade: BrandAdminFacade, OrderFacade, LikeFacade, ProductAdminFacade, ProductQueryFacade
    • Application: 도메인별 서비스 + Command 객체 + Product View 모델
    • Admin 보안: AdminLdapInterceptor + WebConfig#addInterceptors
  • 제거/대체:
    • application/example, infrastructure/example, interfaces/api/example 제거
    • User 네이밍/흐름을 Member 중심으로 리팩토링

주요 컴포넌트 책임

  • AdminLdapInterceptor: /api-admin/v1/** 요청의 X-Loopers-Ldap 인증 검증
  • BrandAdminFacade: 브랜드 삭제 시 연관 흐름(예: 상품/좋아요 처리 포함) 오케스트레이션
  • OrderFacade: 주문 생성/조회에서 다중 서비스 조합 흐름 조정
  • LikeFacade: 좋아요 등록/취소/조회 흐름 오케스트레이션
  • ProductQueryFacade: 상품/브랜드/좋아요 조합해 조회 응답 구성

🔁 Flow Diagram

Main Flow

sequenceDiagram
  autonumber
  participant Client
  participant API as Controller
  participant Auth as AdminLdapInterceptor
  participant Facade as Facade/Application
  participant Domain as Domain Service/Entity
  participant Repo as Repository
  participant DB

  Client->>API: request
  API->>Auth: admin path header check
  Auth-->>API: pass/fail
  API->>Facade: command/query DTO
  Facade->>Domain: business orchestration
  Domain->>Repo: read/write
  Repo->>DB: SQL
  DB-->>Repo: result
  Repo-->>Domain: domain model
  Domain-->>Facade: result
  Facade-->>API: response DTO/view
  API-->>Client: response
Loading

Product Query Flow

sequenceDiagram
  autonumber
  participant Client
  participant API as Product/Like Controller
  participant QF as ProductQueryFacade
  participant PS as ProductService
  participant BR as BrandRepository
  participant LR as LikeRepository
  participant DB

  Client->>API: list query(page/size/sort)
  API->>QF: ProductListQuery 전달
  QF->>PS: criteria 구성 및 상품 조회
  PS->>DB: products select
  QF->>BR: 브랜드 메타 조회
  QF->>LR: like 집계 조회
  DB-->>QF: data sets
  QF-->>API: ProductListView
  API-->>Client: ProductListResponse
Loading

Commit Range (reference)

  • Base: 9e7a901
  • Included (oldest -> newest):
    • e1b7116 Merge branch 'feature/user' into shAn-kor
    • 39744a9 feat: product 도메인 기본 구현 추가
    • c359f93 Merge branch 'feature/product' into shAn-kor
    • ef4b5db feat: 브랜드 도메인과 API 기본 구현 추가
    • 45f134b docs: 브랜드 삭제 정책을 soft-delete 흐름으로 정리
    • a7f8767 test: user 시그니처 보정과 product-like 스캐폴드 테스트 추가
    • a8728f7 feat: Order 도메인 기본 구현 추가
    • 4fb5f05 Merge branch 'feature/order' into shAn-kor
    • 96b374d refactor: User 도메인을 Member로 리팩토링 및 Like/Category 도메인 추가
    • 0eace1f feat: 어드민 카테고리 조회 API 추가
    • dac5e95 Merge branch 'feature/category' into shAn-kor
    • eebec67 docs: AI 작업 규칙과 검증 스크립트 정리
    • 436fe1f refactor: 도메인 레이어 구조 정리 및 example 도메인 제거
    • 7fe2ff7 refactor: 응용/인프라/인터페이스 계층을 도메인 경계에 맞게 재구성

클로드, 코덱스 관련 문서 작성
CodeRabbit 추천 수정사항 반
다이어그램 가이드 및 다이어그램 리팩토링
오픈코드, 코덱스 관련 문서 업데이트

링# --- TYPE ---
유저 관련 리팩토
구현할 체크리스트 작성
- Phone VO 생성 (010-XXXX-XXXX 형식 검증)
- User 엔티티 phone 필드 추가
- RegisterCommand, UserDto phone 필드 추가
- 로그인 ID 중복 검사 API 구현 (GET /users/duplicate)
- 관련 테스트 코드 업데이트
- Order/OrderItem/OrderStatus 도메인 모델 추가
- OrderEntity/OrderItemEntity JPA 엔티티 추가
- OrderRepository 인터페이스 및 구현체 추가
- OrderApplicationService 구현 (주문/취소/조회)
- OrderController, AdminOrderController, OrderDto 추가
- Product에 decreaseStock/increaseStock 메서드 추가
- ProductRepository에 findAllByIdInWithLock(비관적 락) 추가
- UserRepository에 findDbIdByUserId 추가
- ErrorType에 FORBIDDEN 추가
- Order/OrderItem/Product 단위 테스트 추가
- OrderApplicationServiceTest, OrderControllerTest, OrderApiE2ETest 추가
- domain/user → domain/member 패키지 전체 이동
- UserId → MemberId 네이밍 변경
- UserRepository → MemberRepository 전환 및 findDbIdByMemberId 추가
- UserApplicationService → MemberApplicationService 교체
- UserAuthenticationService → MemberAuthenticationService 교체 (findDbIdByMemberId 포함)
- AuthUser 어노테이션 → AuthMember 리네임
- OrderController, AdminOrderController를 AuthMember 기반으로 전환
- AdminOrderController에 X-Loopers-Ldap 기반 어드민 인증 추가
- ProductApplicationService에 브랜드/카테고리 존재 검증 추가
- Category, Like 도메인 및 인프라 구현 추가
- 테스트 코드에서 하드코딩된 ID를 실제 엔티티 생성 방식으로 개선
@coderabbitai
Copy link

coderabbitai bot commented Feb 27, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@shAn-kor shAn-kor changed the title Sh an kor [3주차] 도메인 주도 설계 구현 - 안성훈 Feb 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant