@startuml
!theme mono

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

' ============================================================
' Presentation Layer - Controller
' ============================================================
package "com.kt.event.analytics.controller" <<Rectangle>> #F0F8FF {

    class AnalyticsDashboardController {
    }
    note right of AnalyticsDashboardController
      **API Mapping:**
      getEventAnalytics: GET /api/v1/events/{eventId}/analytics
      - 성과 대시보드 조회
    end note

    class ChannelAnalyticsController {
    }
    note right of ChannelAnalyticsController
      **API Mapping:**
      getChannelAnalytics: GET /api/v1/events/{eventId}/analytics/channels
      - 채널별 성과 분석
    end note

    class RoiAnalyticsController {
    }
    note right of RoiAnalyticsController
      **API Mapping:**
      getRoiAnalytics: GET /api/v1/events/{eventId}/analytics/roi
      - 투자 대비 수익률 분석
    end note

    class TimelineAnalyticsController {
    }
    note right of TimelineAnalyticsController
      **API Mapping:**
      getTimelineAnalytics: GET /api/v1/events/{eventId}/analytics/timeline
      - 시간대별 참여 추이 분석
    end note

    class UserAnalyticsDashboardController {
    }
    note right of UserAnalyticsDashboardController
      **API Mapping:**
      getUserEventAnalytics: GET /api/v1/users/{userId}/analytics
      - 사용자 전체 이벤트 성과 대시보드
    end note

    class UserChannelAnalyticsController {
    }
    note right of UserChannelAnalyticsController
      **API Mapping:**
      getUserChannelAnalytics: GET /api/v1/users/{userId}/analytics/channels
      - 사용자 채널별 성과 분석
    end note

    class UserRoiAnalyticsController {
    }
    note right of UserRoiAnalyticsController
      **API Mapping:**
      getUserRoiAnalytics: GET /api/v1/users/{userId}/analytics/roi
      - 사용자 ROI 분석
    end note

    class UserTimelineAnalyticsController {
    }
    note right of UserTimelineAnalyticsController
      **API Mapping:**
      getUserTimelineAnalytics: GET /api/v1/users/{userId}/analytics/timeline
      - 사용자 시간대별 분석
    end note
}

' ============================================================
' Business Layer - Service
' ============================================================
package "com.kt.event.analytics.service" <<Rectangle>> #E6F7E6 {

    class AnalyticsService {
    }
    note right of AnalyticsService
      **핵심 역할:**
      - 대시보드 데이터 통합
      - Redis 캐싱 (1시간 TTL)
      - 외부 API 호출 조율
      - ROI 계산 로직
    end note

    class ChannelAnalyticsService {
    }
    note right of ChannelAnalyticsService
      **핵심 역할:**
      - 채널별 성과 분석
      - 채널 간 비교 분석
      - 외부 채널 API 통합
    end note

    class RoiAnalyticsService {
    }
    note right of RoiAnalyticsService
      **핵심 역할:**
      - ROI 상세 분석
      - 투자/수익 분석
      - 비용 효율성 계산
    end note

    class TimelineAnalyticsService {
    }
    note right of TimelineAnalyticsService
      **핵심 역할:**
      - 시간대별 추이 분석
      - 트렌드 분석
      - 피크 시간 분석
    end note

    class UserAnalyticsService {
    }
    note right of UserAnalyticsService
      **핵심 역할:**
      - 사용자별 통합 분석
      - 여러 이벤트 집계
    end note

    class UserChannelAnalyticsService {
    }
    note right of UserChannelAnalyticsService
      **핵심 역할:**
      - 사용자별 채널 분석
      - 채널별 통합 성과
    end note

    class UserRoiAnalyticsService {
    }
    note right of UserRoiAnalyticsService
      **핵심 역할:**
      - 사용자별 ROI 분석
      - 전체 투자/수익 계산
    end note

    class UserTimelineAnalyticsService {
    }
    note right of UserTimelineAnalyticsService
      **핵심 역할:**
      - 사용자별 시간대 분석
      - 여러 이벤트 타임라인 통합
    end note

    class ExternalChannelService {
    }
    note right of ExternalChannelService
      **외부 API 통합:**
      - 우리동네TV API
      - 지니TV API
      - 링고비즈 API
      - SNS APIs
      - Circuit Breaker 패턴
      - Fallback 처리
    end note

    class ROICalculator {
    }
    note right of ROICalculator
      **ROI 계산 로직:**
      - ROI 계산
      - 비용 효율성 계산
      - 수익 예측
    end note
}

' ============================================================
' Data Access Layer - Repository
' ============================================================
package "com.kt.event.analytics.repository" <<Rectangle>> #FFF8DC {

    interface EventStatsRepository {
    }
    note right of EventStatsRepository
      **이벤트 통계 저장소**
      JpaRepository 상속
    end note

    interface ChannelStatsRepository {
    }
    note right of ChannelStatsRepository
      **채널 통계 저장소**
      JpaRepository 상속
    end note

    interface TimelineDataRepository {
    }
    note right of TimelineDataRepository
      **타임라인 데이터 저장소**
      JpaRepository 상속
    end note
}

' ============================================================
' Domain Layer - Entity
' ============================================================
package "com.kt.event.analytics.entity" <<Rectangle>> #FFFACD {

    class EventStats {
    }
    note right of EventStats
      **이벤트 통계 엔티티**
      - 이벤트 기본 정보
      - 참여자, 조회수
      - ROI, 투자/수익 정보
    end note

    class ChannelStats {
    }
    note right of ChannelStats
      **채널별 통계 엔티티**
      - 채널명, 유형
      - 노출/조회/클릭/참여/전환
      - SNS 반응 (좋아요/댓글/공유)
      - 링고비즈 통화 정보
      - 배포 비용
    end note

    class TimelineData {
    }
    note right of TimelineData
      **시간대별 데이터 엔티티**
      - 시간별 참여자 수
      - 조회수, 참여, 전환
      - 누적 참여자 수
    end note
}

' ============================================================
' DTO Layer
' ============================================================
package "com.kt.event.analytics.dto.response" <<Rectangle>> #E6E6FA {

    class AnalyticsDashboardResponse {
    }
    note right of AnalyticsDashboardResponse
      **대시보드 응답**
      통합 성과 데이터
    end note

    class ChannelAnalyticsResponse {
    }
    note right of ChannelAnalyticsResponse
      **채널 분석 응답**
      채널별 상세 데이터
    end note

    class RoiAnalyticsResponse {
    }
    note right of RoiAnalyticsResponse
      **ROI 분석 응답**
      투자/수익 상세 데이터
    end note

    class TimelineAnalyticsResponse {
    }
    note right of TimelineAnalyticsResponse
      **타임라인 분석 응답**
      시간대별 추이 데이터
    end note

    class UserAnalyticsDashboardResponse {
    }
    note right of UserAnalyticsDashboardResponse
      **사용자 대시보드 응답**
      여러 이벤트 통합 데이터
    end note

    class UserChannelAnalyticsResponse {
    }
    note right of UserChannelAnalyticsResponse
      **사용자 채널 분석 응답**
      사용자별 채널 통합 데이터
    end note

    class UserRoiAnalyticsResponse {
    }
    note right of UserRoiAnalyticsResponse
      **사용자 ROI 분석 응답**
      사용자별 ROI 통합 데이터
    end note

    class UserTimelineAnalyticsResponse {
    }
    note right of UserTimelineAnalyticsResponse
      **사용자 타임라인 분석 응답**
      사용자별 타임라인 통합 데이터
    end note
}

' ============================================================
' Messaging Layer - Kafka Consumer
' ============================================================
package "com.kt.event.analytics.messaging.consumer" <<Rectangle>> #FFE4E1 {

    class EventCreatedConsumer {
    }
    note right of EventCreatedConsumer
      **이벤트 생성 Consumer**
      Topic: sample.event.created
      - EventStats 초기화
      - 멱등성 처리
      - 캐시 무효화
    end note

    class ParticipantRegisteredConsumer {
    }
    note right of ParticipantRegisteredConsumer
      **참여자 등록 Consumer**
      Topic: sample.participant.registered
      - 참여자 수 증가
      - TimelineData 업데이트
      - 캐시 무효화
    end note

    class DistributionCompletedConsumer {
    }
    note right of DistributionCompletedConsumer
      **배포 완료 Consumer**
      Topic: sample.distribution.completed
      - ChannelStats 업데이트
      - 배포 비용, 노출 수 저장
      - 캐시 무효화
    end note
}

package "com.kt.event.analytics.messaging.event" <<Rectangle>> #FFE4E1 {

    class EventCreatedEvent {
    }

    class ParticipantRegisteredEvent {
    }

    class DistributionCompletedEvent {
    }
}

' ============================================================
' Batch Layer
' ============================================================
package "com.kt.event.analytics.batch" <<Rectangle>> #FFF5EE {

    class AnalyticsBatchScheduler {
    }
    note right of AnalyticsBatchScheduler
      **배치 스케줄러**
      - 5분 단위 캐시 갱신
      - 초기 데이터 로딩
      - 캐시 워밍업
    end note
}

' ============================================================
' Configuration Layer
' ============================================================
package "com.kt.event.analytics.config" <<Rectangle>> #F5F5F5 {

    class RedisConfig {
    }
    note right of RedisConfig
      Redis 연결 설정
    end note

    class KafkaConsumerConfig {
    }
    note right of KafkaConsumerConfig
      Kafka Consumer 설정
    end note

    class KafkaTopicConfig {
    }
    note right of KafkaTopicConfig
      Kafka Topic 설정
    end note

    class Resilience4jConfig {
    }
    note right of Resilience4jConfig
      Circuit Breaker 설정
    end note

    class SecurityConfig {
    }
    note right of SecurityConfig
      Spring Security 설정
    end note

    class SwaggerConfig {
    }
    note right of SwaggerConfig
      Swagger/OpenAPI 설정
    end note
}

' ============================================================
' Common Components
' ============================================================
package "com.kt.event.common" <<Rectangle>> #DCDCDC {

    abstract class BaseTimeEntity {
    }
    note right of BaseTimeEntity
      JPA Auditing
      - createdAt
      - updatedAt
    end note

    class "ApiResponse<T>" {
    }
    note right of "ApiResponse<T>"
      표준 API 응답 포맷
    end note

    interface ErrorCode {
    }

    class BusinessException {
    }
}

' ============================================================
' Layer Relationships
' ============================================================

' Controller Layer -> Service Layer
AnalyticsDashboardController ..> AnalyticsService
ChannelAnalyticsController ..> ChannelAnalyticsService
RoiAnalyticsController ..> RoiAnalyticsService
TimelineAnalyticsController ..> TimelineAnalyticsService
UserAnalyticsDashboardController ..> UserAnalyticsService
UserChannelAnalyticsController ..> UserChannelAnalyticsService
UserRoiAnalyticsController ..> UserRoiAnalyticsService
UserTimelineAnalyticsController ..> UserTimelineAnalyticsService

' Service Layer -> Repository Layer
AnalyticsService ..> EventStatsRepository
AnalyticsService ..> ChannelStatsRepository
ChannelAnalyticsService ..> ChannelStatsRepository
RoiAnalyticsService ..> EventStatsRepository
RoiAnalyticsService ..> ChannelStatsRepository
TimelineAnalyticsService ..> TimelineDataRepository
TimelineAnalyticsService ..> EventStatsRepository
UserAnalyticsService ..> EventStatsRepository
UserAnalyticsService ..> ChannelStatsRepository
UserChannelAnalyticsService ..> ChannelStatsRepository
UserChannelAnalyticsService ..> EventStatsRepository
UserRoiAnalyticsService ..> EventStatsRepository
UserRoiAnalyticsService ..> ChannelStatsRepository
UserTimelineAnalyticsService ..> TimelineDataRepository
UserTimelineAnalyticsService ..> EventStatsRepository

' Service Layer Dependencies
AnalyticsService ..> ExternalChannelService
AnalyticsService ..> ROICalculator
ChannelAnalyticsService ..> ExternalChannelService
RoiAnalyticsService ..> ROICalculator
UserAnalyticsService ..> ROICalculator
UserRoiAnalyticsService ..> ROICalculator

' Repository Layer -> Entity Layer
EventStatsRepository ..> EventStats
ChannelStatsRepository ..> ChannelStats
TimelineDataRepository ..> TimelineData

' Consumer Layer -> Repository Layer
EventCreatedConsumer ..> EventStatsRepository
ParticipantRegisteredConsumer ..> EventStatsRepository
ParticipantRegisteredConsumer ..> TimelineDataRepository
DistributionCompletedConsumer ..> ChannelStatsRepository

' Consumer Layer -> Event
EventCreatedConsumer ..> EventCreatedEvent
ParticipantRegisteredConsumer ..> ParticipantRegisteredEvent
DistributionCompletedConsumer ..> DistributionCompletedEvent

' Batch Layer -> Service/Repository
AnalyticsBatchScheduler ..> AnalyticsService
AnalyticsBatchScheduler ..> EventStatsRepository

' Entity -> Base Entity
EventStats --|> BaseTimeEntity
ChannelStats --|> BaseTimeEntity
TimelineData --|> BaseTimeEntity

' Controller -> Response DTO
AnalyticsDashboardController ..> AnalyticsDashboardResponse
ChannelAnalyticsController ..> ChannelAnalyticsResponse
RoiAnalyticsController ..> RoiAnalyticsResponse
TimelineAnalyticsController ..> TimelineAnalyticsResponse
UserAnalyticsDashboardController ..> UserAnalyticsDashboardResponse
UserChannelAnalyticsController ..> UserChannelAnalyticsResponse
UserRoiAnalyticsController ..> UserRoiAnalyticsResponse
UserTimelineAnalyticsController ..> UserTimelineAnalyticsResponse

' Controller -> ApiResponse
AnalyticsDashboardController ..> "ApiResponse<T>"
ChannelAnalyticsController ..> "ApiResponse<T>"
RoiAnalyticsController ..> "ApiResponse<T>"
TimelineAnalyticsController ..> "ApiResponse<T>"

' Exception
BusinessException ..> ErrorCode

note top of AnalyticsService
  **Layered Architecture 패턴 적용**
  - Presentation Layer: Controller
  - Business Layer: Service
  - Data Access Layer: Repository
  - Domain Layer: Entity
  - Infrastructure: Config, Messaging, Batch
end note

note bottom of ExternalChannelService
  **핵심 기능:**
  - 외부 채널 API 병렬 호출
  - Resilience4j Circuit Breaker
  - Fallback 메커니즘
  - 비동기 처리 (CompletableFuture)
end note

note bottom of AnalyticsBatchScheduler
  **배치 처리:**
  - @Scheduled (fixedRate = 300000) - 5분
  - @Scheduled (initialDelay = 30000) - 초기 로딩
  - Redis 캐시 확인 후 선택적 갱신
end note

@enduml
