@startuml
!theme mono

title Distribution Service 클래스 다이어그램 (요약)

package "com.kt.distribution" {

    package "controller" {
        class DistributionController <<Controller>>
    }

    package "service" {
        class DistributionService <<Service>>
        class KafkaEventPublisher <<Service>>
    }

    package "adapter" {
        interface ChannelAdapter <<Interface>>
        abstract class AbstractChannelAdapter <<Abstract>>
        class UriDongNeTvAdapter <<Adapter>>
        class RingoBizAdapter <<Adapter>>
        class GiniTvAdapter <<Adapter>>
        class InstagramAdapter <<Adapter>>
        class NaverAdapter <<Adapter>>
        class KakaoAdapter <<Adapter>>
    }

    package "dto" {
        class DistributionRequest <<DTO>>
        class DistributionResponse <<DTO>>
        class ChannelDistributionResult <<DTO>>
        class DistributionStatusResponse <<DTO>>
        class ChannelStatus <<DTO>>
        enum ChannelType <<Enum>>
    }

    package "repository" {
        class DistributionStatusRepository <<Repository>>
        interface DistributionStatusJpaRepository <<JPA Repository>>
    }

    package "entity" {
        class DistributionStatus <<Entity>>
        class ChannelStatusEntity <<Entity>>
    }

    package "mapper" {
        class DistributionStatusMapper <<Mapper>>
    }

    package "event" {
        class DistributionCompletedEvent <<Event>>
        class DistributedChannelInfo <<Event>>
    }

    package "config" {
        class KafkaConfig <<Configuration>>
        class OpenApiConfig <<Configuration>>
        class WebConfig <<Configuration>>
    }
}

' 주요 관계만 표시
DistributionController --> DistributionService
DistributionService --> ChannelAdapter
DistributionService --> KafkaEventPublisher
DistributionService --> DistributionStatusRepository

AbstractChannelAdapter ..|> ChannelAdapter
UriDongNeTvAdapter --|> AbstractChannelAdapter
RingoBizAdapter --|> AbstractChannelAdapter
GiniTvAdapter --|> AbstractChannelAdapter
InstagramAdapter --|> AbstractChannelAdapter
NaverAdapter --|> AbstractChannelAdapter
KakaoAdapter --|> AbstractChannelAdapter

DistributionStatusRepository --> DistributionStatusJpaRepository
DistributionStatusRepository --> DistributionStatusMapper
DistributionStatusJpaRepository ..> DistributionStatus

DistributionStatus "1" *-- "many" ChannelStatusEntity

KafkaEventPublisher ..> DistributionCompletedEvent
DistributionCompletedEvent --> DistributedChannelInfo

note top of DistributionController
  **Controller 메소드 - API 매핑**
  
  distribute: POST /distribution/distribute
  - 다중 채널 배포 요청
  
  getDistributionStatus: GET /distribution/{eventId}/status
  - 배포 상태 조회
end note

note top of DistributionService
  **핵심 비즈니스 로직**
  
  • 다중 채널 병렬 배포
  • ExecutorService 기반 비동기 처리
  • 배포 상태 관리 (저장/조회)
  • Kafka 이벤트 발행
  
  distribute(request)
  → 병렬 배포 실행
  → 결과 집계
  → 상태 저장
  → 이벤트 발행
end note

note top of AbstractChannelAdapter
  **Resilience4j 패턴 적용**
  
  • Circuit Breaker
  • Retry (지수 백오프)
  • Bulkhead (리소스 격리)
  • Fallback 처리
  
  각 채널별 독립적 장애 격리
end note

note top of DistributionStatusRepository
  **배포 상태 영구 저장**
  
  • PostgreSQL 저장
  • JPA Repository 패턴
  • Entity ↔ DTO 매핑
  
  save(eventId, status)
  findByEventId(eventId)
end note

note right of ChannelType
  **배포 채널 종류**
  
  TV 채널:
  • URIDONGNETV (우리동네TV)
  • GINITV (지니TV)
  
  CALL 채널:
  • RINGOBIZ (링고비즈)
  
  SNS 채널:
  • INSTAGRAM
  • NAVER (Blog)
  • KAKAO (Channel)
end note

note bottom of DistributionStatus
  **배포 상태 엔티티**
  
  전체 배포 상태 관리:
  • PENDING: 대기중
  • IN_PROGRESS: 진행중
  • COMPLETED: 완료
  • PARTIAL_FAILURE: 부분성공
  • FAILED: 실패
  
  1:N 관계로 채널별 상태 관리
end note

note bottom of KafkaEventPublisher
  **Kafka 이벤트 발행**
  
  Topic: distribution-completed
  
  배포 완료 시 이벤트 발행
  → Analytics Service 소비
end note

@enduml
