# Relay Flow Reference

This note outlines the server relay path shown by the published reference files.

## Direct-message relay path

1. Client encrypts payload locally and sends ciphertext envelope to `messages` router.
2. Server stores ciphertext metadata and conversation identifiers.
3. Server attempts realtime websocket fanout to active recipient device sessions.
4. Recipient client decrypts locally and sends acknowledgement/read events.

## Group-message relay path

1. Client encrypts group payload with sender-key state on device.
2. Server stores encrypted group payload and sender-key metadata.
3. Server fans out group events over websocket to active group members.
4. Clients decrypt locally and update local read/delivery state.

## Call signaling relay path

1. Offer/answer/ICE payloads are encrypted on device.
2. Server relays signaling payloads through websocket channels.
3. If recipient is offline, queue/push fallback can wake client for reconnect.

## Reference files for this flow

- `backend_reference/app/routers/messages.py`
- `backend_reference/app/routers/websocket.py`
- `backend_reference/app/models/message.py`
- `backend_reference/app/models/message_key.py`
- `backend_reference/app/models/group.py`
