Chat Service Diagram Source

이 문서는 Notion Mermaid 블록이나 SA 문서에 붙여넣기 위한 Chat Service 다이어그램 원본이다.

다이어그램은 현재 합의된 문서 기준을 따른다.

주의:

1. 채팅 시스템 데이터 플로우

flowchart LR
    Client([Client])

    subgraph ChatDomain["Chat Service"]
        Chat[chat-service<br/>WebSocket/STOMP + REST]
    end

    subgraph Storage["Storage Layer"]
        direction TB
        PG[(PostgreSQL<br/>rooms / participants<br/>read state)]
        Mongo[(MongoDB<br/>chat messages)]
        Redis[(Redis<br/>online / active_room<br/>dedup)]
    end

    subgraph External["External Services"]
        direction TB
        US[user-service]
        Noti[notification-service]
        Push[Push Provider]
    end

    Kafka{{Kafka}}

    Client ==>|REST<br/>방 생성 · 목록 · 메시지 조회| Chat
    Client ==>|STOMP SEND<br/>메시지 · 읽음 · presence| Chat
    Chat ==>|WebSocket push<br/>메시지 · 읽음 이벤트| Client

    Chat <-->|방 / 참여자 / 읽음 상태| PG
    Chat <-->|메시지 원본 저장 · 조회| Mongo
    Chat <-->|접속 · 현재 방 · dedup| Redis

    Chat -.->|차단 관계 · 사용자 검증| US

    Chat ==>|알림 이벤트 발행| Kafka
    Kafka ==>|consume| Noti
    Noti ==>|푸시 발송| Push
    Push ==>|디바이스 푸시| Client

2. 메시지 처리 경로 분리

flowchart TB
    Client[Client 발신자<br/>메시지 전송]
    Chat[chat-service<br/>검증 / 멱등성 체크]

    subgraph Storage["Storage 경로"]
        direction TB
        Mongo[(MongoDB<br/>메시지 원본 저장)]
        PG[(PostgreSQL<br/>last_message_id / last_message_at 갱신)]
        Mongo --> PG
    end

    subgraph Delivery["Delivery 경로"]
        direction TB
        Push[WebSocket push<br/>방 구독자에게 실시간 전달]
        Receiver[수신자 Client]
        Push --> Receiver
    end

    subgraph Notification["알림 경로"]
        direction TB
        Redis[(Redis<br/>active_room 조회)]
        Kafka[Kafka 이벤트]
        Noti[notification-service]
        PushProvider[Push Provider]
        Offline[수신자 Client<br/>다른 방 또는 미접속]
        Redis --> Kafka
        Kafka --> Noti
        Noti --> PushProvider
        PushProvider --> Offline
    end

    Client --> Chat
    Chat -->|1. MongoDB 저장 후 메타데이터 갱신| Storage
    Chat -->|2. 저장 성공 후 브로드캐스트| Delivery
    Chat -.->|3. 현재 방이 아닌 수신자만| Notification