Use Cases 문서 작성 가이드
Template
문서 목적
Use Cases 문서는 Application Layer의 Use Case들을 정의합니다:
- Domain Model은 "어떻게" (도메인 로직, 불변식)
- Use Cases는 "무엇을" (기능, 흐름, 입출력)
Commands 작성
Command는:
- 시스템 상태를 변경하는 요청
- 비즈니스 의도를 명확히 표현
- 예: CreateCallPlan, CompleteCall, CancelCall
작성 구조:
## 2.1 CommandName
**Input (DTO):**
{필드들}
**Output:**
{반환값}
**Flow:**
1. 단계별 실행 흐름
**Business Rules:**
- 적용되는 비즈니스 규칙
**Error Cases:**
- 발생 가능한 에러
작성 예시:
## 2.1 CompleteCall
**Input (DTO):**
- callPlanId: string
- completedBy: string
- completionReason: string
- memo?: string
**Output:**
- success: boolean
**Flow:**
1. CallPlan Aggregate 조회
2. 완료 가능 여부 확인
3. completeCall() 메서드 호출
4. CallCompleted 이벤트 발행
**Business Rules:**
- 활성 상태의 콜만 완료 가능
- 운영자 권한 필요
**Error Cases:**
- `4001` CALL_NOT_FOUND
- `4002` CALL_ALREADY_COMPLETED
Queries 작성
Query는:
- 시스템 상태를 조회하는 요청
- 데이터 변경 없음
- 예: GetCallPlanDetails, ListActiveCallsByUser
작성 구조:
## 3.1 QueryName
**Input (DTO):**
{필드들}
**Output:**
{반환 데이터 구조}
**Data Source:**
- 어디서 데이터를 가져오는가
**Authorization:**
- 권한 확인 사항
작성 예시:
## 3.1 GetCallPlanDetails
**Input (DTO):**
- callPlanId: string
**Output:**
- id, userId, status, createdAt, memos[]
**Data Source:**
- CallPlan Aggregate (Read Model)
**Authorization:**
- 본인 콜 또는 운영자만 조회 가능
Application Services 작성 (선택)
언제 필요한가:
- 여러 Aggregate를 조율해야 할 때
- 복잡한 트랜잭션 관리가 필요할 때
- 외부 시스템과 통합이 필요할 때
Domain Service vs Application Service:
- Domain Service: 순수 도메인 로직, Aggregate 조율
- Application Service: 트랜잭션 관리, 외부 통합, Use Case 구현
작성 예시:
## 4. Application Services (선택)
**CallOrchestrationService**
**Methods:**
- `assignAndNotify(callPlanId, operatorId)`: 설명
**Dependencies:**
- Repository들
- 외부 서비스들
Integration Events 작성
Published (Outbound):
- 이 도메인에서 다른 Context로 발행하는 이벤트
- 예: CallCompletedNotification → Notification Context
Subscribed (Inbound):
- 다른 Context에서 받아서 처리하는 이벤트
- Handler와 처리 액션 명시
- 예: UserStatusChanged ← User Context
작성 예시:
## 5. Integration Events
**Published (Outbound):**
- `CallCompletedNotification` → Notification Context
**Subscribed (Inbound):**
- `UserStatusChanged` ← User Context
- Handler: UpdateCallPlanStatus
- Action: 비활성 사용자의 콜 자동 취소
작성 순서
Use Cases 문서는 다음 순서로 작성:
-
도메인 모델 완성 후
- Aggregate, Events가 정의되어야 함
-
Use Cases Overview 먼저
- 전체 기능 목록 파악
-
Commands → Queries 순서로
- 상태 변경 먼저, 조회 나중에
-
Integration Events
- 외부 통합 정의