Live Chat Context
Relevant source files
The following files were used as context for generating this wiki page:
The Live Chat context is a core domain boundary within the LiveCanvas application responsible for managing real-time communication during live sessions. Its primary scope includes the delivery of live chat messages, moderation of content, and the handling of chat-oriented system events. It operates as a distinct module to separate high-throughput messaging and moderation concerns from the broader Live Session lifecycle management.
Architecture-wise, the Chat context utilizes Phoenix Channels and WebSockets for real-time transport, while persisting durable message history in PostgreSQL for auditability and replay purposes. This ensures that while the active interaction is ephemeral and high-performance, the records remain available for post-session features like replays.
Sources: ARCHITECTURE.md:144-149, ARCHITECTURE.md:151-154, ARCHITECTURE.md:200-203
Architecture and Data Flow
The Chat context is integrated into the modular monolith architecture of LiveCanvas. It relies on the LC.Chat boundary for business logic and coordination. While Live owns the session lifecycle, Chat owns the interaction rules within those sessions.
Real-time Communication Flow
The system uses Phoenix Channels as the primary transport for chat events. When a user sends a message, it is processed through a GraphQL mutation or directly via a WebSocket channel, then broadcast to all authorized participants in the session.
This diagram illustrates the flow of a chat message from a client through the backend boundary to persistence and real-time broadcast.
Sources: ARCHITECTURE.md:112-114, ARCHITECTURE.md:144-154, ARCHITECTURE.md:188-193
Data Models and Schema
The Chat context defines specific structures for messages and system events. Messages are categorized as either user-generated or system-generated events (e.g., notification that a message was removed or a session went live).
Chat Message Structure
The durable state of chat is stored in the chat_messages table.
| Field | Type | Description |
|---|---|---|
id | ID (UUIDv7) | Global Relay ID for the message. |
body | String | The text content of the message. |
kind | ChatMessageKind | Enum: USER_MESSAGE or SYSTEM_EVENT. |
status | ChatMessageStatus | Enum: ACTIVE or REMOVED. |
systemEventType | ChatSystemEventType | Type of event (e.g., MESSAGE_REMOVED). |
sender | User | Reference to the user who sent the message. |
insertedAt | UTC DateTime | Timestamp of message creation. |
Sources: mobile/schema.graphql:533-568, ARCHITECTURE.md:280-282, AGENTS.md:10-13
System Events
System events are specialized messages used to notify the chat interface of state changes.
| Event Type | Description |
|---|---|
MESSAGE_REMOVED | Broadcast when a moderator deletes a specific message. |
SESSION_LIVE | Broadcast when the session media negotiation succeeds. |
SESSION_ENDED | Broadcast when the host terminates the live session. |
Sources: mobile/schema.graphql:542-546, ARCHITECTURE.md:173-181
API and Operations
The Chat context exposes functionality through GraphQL for durable operations and Phoenix Channels for transient state.
GraphQL Mutations
Operations that modify durable state or perform moderation are handled via GraphQL.
removeLiveChatMessage: Used by moderators to hide a message from the session history and live feed.- Input:
RemoveLiveChatMessageInput (chatMessageId: ID!) - Source: mobile/schema.graphql:92-95
- Input:
Connection and Participation
Clients connect to chat via the /live WebSocket endpoint. Authorization is checked at the join phase to ensure the viewer is eligible based on the host's privacy settings and relationship-based rules (e.g., blocks/mutes).
Sequence diagram showing the authorization and presence tracking when a user joins a chat session.
Sources: ARCHITECTURE.md:188-193, assets/js/app.js:24-28, mobile/schema.graphql:111-114
Moderation and Security
Moderation is a distinct concern within the Chat context. It includes the ability to remove messages and enforce interaction rules based on the Social context.
- Identity Resolution: All messages are linked to a
Userthroughuser_tokensand session authentication. - Relationship Checks: The
Socialcontext provides the policy layer; for instance, if a user isBLOCKED, they cannot participate in the host's chat. - Auditability: Every moderation action (like message removal) is recorded with a
moderatedAttimestamp.
Sources: ARCHITECTURE.md:204-209, ARCHITECTURE.md:211-215, mobile/schema.graphql:560
Conclusion
The Live Chat Context provides the high-performance real-time backbone for user interaction during live sessions. By utilizing Phoenix Channels for delivery and PostgreSQL for auditability, it balances the need for low-latency communication with the requirement for content moderation and replay capability. It remains strictly decoupled from media orchestration, focusing solely on the message lifecycle and session-level interaction rules.