# Server Reference Guide

The server reference in this release is focused on the files that explain how encrypted messaging reaches the relay.

## Main ideas shown by the reference

- each device publishes a public key used for encrypted delivery
- users publish a signed prekey and batches of one-time prekeys for session setup
- direct messages reach the relay as ciphertext plus ratchet metadata
- per-device encrypted message keys are stored for recipient delivery
- group messages are stored with encrypted sender-key payloads and related metadata
- websocket fanout delivers realtime events for messages, typing, and call signaling

## Main folders

- `app/models/`
  - record shapes for devices, prekeys, direct messages, encrypted per-device message keys, and group messages
- `app/routers/`
  - request handlers for prekey exchange, direct-message relay, and realtime websocket delivery

## Good reading order

1. `app/models/device.py`
2. `app/models/signed_prekey.py`
3. `app/models/one_time_prekey.py`
4. `app/models/message.py`
5. `app/models/message_key.py`
6. `app/models/group.py`
7. `app/routers/prekeys.py`
8. `app/routers/messages.py`
9. `app/routers/websocket.py`

## Why these files matter

Taken together, these files make it possible to inspect where public-key material is stored, where ciphertext is accepted, and how encrypted payloads are represented once they reach the server.
