Skip to content

[VOLUME-3] 도메인 & 객체 설계 및 아키텍처, 패키지 구성 #130

Open
simoncho91 wants to merge 5 commits intoLoopers-dev-lab:ymchofrom
simoncho91:main
Open

[VOLUME-3] 도메인 & 객체 설계 및 아키텍처, 패키지 구성 #130
simoncho91 wants to merge 5 commits intoLoopers-dev-lab:ymchofrom
simoncho91:main

Conversation

@simoncho91
Copy link

Summary

배경: 부트캠프 과제로 상품·브랜드·좋아요·주문 기능을 구현하면서, DDD와 레이어드 아키텍처를 적용했습니다.
목표: 단순 CRUD가 아니라 도메인 모델링과 계층 분리를 고려하여, Product, Brand, Like, Order 도메인과 API를 설계·구현했습니다.
결과: 재고 차감·좋아요 집계·주문 흐름을 도메인과 서비스에 나누어 구현했습니다.

Context & Decision

  1. 문제 정의
  • 문제(또는 리스크): 상품에 좋아요 수를 어떻게 둘지, 재고 차감은 누가 할지, 주문과 재고를 어떻게 맞출지 등 설계 결정이 필요했습니다.
  • 성공 기준(완료 정의): 상품 목록/상세 조회, 좋아요 등록/취소, 주문 생성 시 재고 차감 및 재고 부족 예외 처리, 도메인 로직 단위 테스트 작성입 니다.
  1. 선택지와 결정
  • 고려한 대안:
    A: Product에 likeCount 필드를 두고, 좋아요할 때마다 Product를 업데이트하는 방식
    B: Like를 별도 도메인으로 두고, 조회 시점에 집계하여 붙이는 방식
    최종 결정: B를 선택했습니다. Product는 상품 정보에만 집중하고, Like는 좋아요 관계만 담당하도록 했습니다.

  • 트레이드오프: 조회 시 Like 집계 쿼리가 추가되지만, Product의 단일 책임과 확장성을 우선했습니다.

  • 추후 개선 여지: 할인·재고 예약 등이 생기면 Stock, Discount 도메인 분리를 생각해 보았습니다..

Design Overview

  1. 변경 범위
  • 영향 받는 모듈/도메인: commerce-api
  • 신규 추가: Product, Brand, Like, Order 도메인 및 관련 Application, Infrastructure, API
  • 제거/대체: 없음
  • 주요 컴포넌트 책임
  • Product: 상품 정보, decreaseStock()로 재고 차감 및 음수 방지
  • ProductFacade: Product + Brand + Like 조합, 상품 목록/상세 조회
  • LikeService: 좋아요 등록/취소, 멱등 처리
  • OrderDomainService: Order 생성, Product 재고 차감, 재고 부족 시 예외
  • OrderService: 트랜잭션 관리, OrderDomainService 위임

🔁 Flow Diagram

Web Interfaces to-2026-02-27-084417

-> 이미지가 안올라가서 머메이드 코드로 대체합니다.
sequenceDiagram
autonumber
participant Client
participant OrderController
participant OrderService
participant OrderDomainService
participant ProductRepo
participant OrderRepo

Client->>OrderController: POST /api/v1/orders
OrderController->>OrderService: placeOrder(memberId, items)
OrderService->>OrderDomainService: placeOrder(memberId, items)

loop 각 주문 항목
OrderDomainService->>ProductRepo: findById(productId)
ProductRepo-->>OrderDomainService: Product
OrderDomainService->>OrderDomainService: product.decreaseStock(quantity)
Note over OrderDomainService: 재고 부족 시 예외 → 롤백
end

OrderDomainService->>OrderDomainService: Order.create(memberId, orderLines)
OrderDomainService->>OrderRepo: save(order)
OrderRepo-->>OrderDomainService: Order
OrderDomainService-->>OrderService: Order
OrderService-->>OrderController: OrderResult
OrderController-->>Client: OrderCreateResponse

hanyoung-kurly and others added 5 commits February 2, 2026 01:26
- 유효한 정보로 회원 생성 성공 테스트
- 각 필드 null/blank 검증 테스트
- loginId, password, name, birthDate, email 필수값 검증
- 필수 필드 5개 (loginId, encryptedPassword, name, birthDate, email)
- 생성자에서 각 필드 null/blank 검증
- BaseEntity 상속으로 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.

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.

2 participants