API
Base URL: same origin (this app uses relative /api and /ws). Errors: { "error": "message" }.
Auth (no token)
| Method | Path | Body | Response |
|---|---|---|---|
| POST | /api/auth/signup | username, email, password | 201 token + user |
| POST | /api/auth/login | email, password | 200 token + user |
User: id, username, email, last_seen, created_at. Signup/Login need non-empty fields; username and email unique.
Protected (Bearer token)
Header: Authorization: Bearer <token>
| Method | Path | Description |
|---|---|---|
| GET | /api/users/search?q= | Search users; exclude self |
| PUT | /api/users/me | Body { "username" }. |
| GET | /api/users/keys?ids=<id>&ids=<id> | Device keys for users |
| POST | /api/conversations | type, title?, member_ids |
| GET | /api/conversations | List conversations |
| GET | /api/conversations/:id | Conversation + members |
| DELETE | /api/conversations/:id | Admin only; full delete |
| GET | /api/conversations/:id/members | Participant list |
| POST | /api/conversations/:id/members | Body { "member_ids" }. |
| DELETE | /api/conversations/:id/members/:userId | Admin only; remove member |
| POST | /api/conversations/:id/read | Mark conversation read |
| GET | /api/messages?conversation_id=... | Paginated; next_page |
| GET | /api/messages/unread?conversation_id=... | Unread messages (paginated) |
| POST | /api/e2ee/devices | Register current device key |
| GET | /api/e2ee/devices | List my devices |
| DELETE | /api/e2ee/devices/:id | Revoke my device |
| GET | /api/users/me/e2ee/backup | Get encrypted key backup |
| PUT | /api/users/me/e2ee/backup | Upsert encrypted key backup |
POST conversations: GROUP requires title. Creator is ADMIN. DIRECT conversations are de-duplicated: if a DIRECT conversation already exists between the two users, the server returns it instead of creating a new one.
POST conversations and member changes require X-Device-Id header. The body must include e2ee_keys (wrapped conversation keys) for all participants/devices. GET messages supports page_size and page_state. Response is { "messages", "next_page" }; each message has sender_name.
GET /api/conversations?include_unread=1 adds unread_count (capped at 99) and unread_overflow to each conversation.
GET /api/messages/unread returns messages where created_at is newer than the caller's participants.last_read_at for that conversation.
POST /api/conversations/:id/read accepts optional body { "read_at_ms": <unix_ms> }.
WebSocket
URL: ws(s)://<host>/ws
Auth: the client must send {"type":"auth","content":"<jwt>"} as the first frame within 5 seconds of the upgrade. The server closes with code 4001 on missing/invalid/expired token. The token is intentionally not passed in the URL to keep it out of access logs and browser history.
Origins: the upgrade is gated by the backend's ALLOWED_ORIGINS env var (comma-separated list of allowed Origin headers). If unset, only same-origin requests with no Origin header are accepted.
Client → server (JSON):
- auth: type, content=
<jwt>(first frame only). - chat: type, conversation_id, content (non-empty, max 5000; must be member).
- typing: type, conversation_id.
Server → client: type one of chat, typing, new_conversation, conversation_deleted, key_rotated, removed_from_conversation. For chat: sender_id, sender_name, content, timestamp set by server.