AlphaChat V7 — Self-Hosted Discord Alternative
A Discord-style chat platform you can host yourself: guilds, channels, voice and DMs — with true end-to-end encryption the server can never read.

Overview
AlphaChat V7 is a from-scratch rebuild of the Alpha Chat messenger into a Discord-scale communication platform, split into four independently deployable services. A FastAPI REST API owns auth, users, guilds, channels, messages, invites, blocks and uploads on PostgreSQL (async SQLAlchemy 2 + Alembic). A separate, completely stateless WebSocket gateway holds the live connections and fans events out over Redis pub/sub, so any edge node can serve any guild — no sticky sessions, no shared memory. Two background workers round it out: a media worker that thumbnails and AV-scans attachments into S3/MinIO, and a push worker that delivers Web Push (VAPID), FCM and APNs notifications off a Redis stream. The part that separates it from a Discord clone is the cryptography: direct messages use a real Signal-style stack — X3DH for the handshake, a Double Ratchet per message, Sender Keys for group channels so cost stays O(1) instead of one ratchet per member, and safety numbers so two people can verify each other out of band. Private keys are generated in the browser and never leave IndexedDB; the API only ever stores public prekey bundles and opaque ciphertext. The front end is Next.js 16 App Router with React 19, TypeScript in strict mode, Tailwind 4 and Zustand, with a virtualized message list, live presence, typing indicators, unread counts, mentions and WebRTC voice channels.
Outcomes
- Stateless WebSocket gateway: connections fan out over Redis pub/sub, so any edge node can serve any guild without sticky sessions
- The server never sees DM plaintext — X3DH + Double Ratchet run in the browser and private keys stay in IndexedDB
- Snowflake IDs are serialized as strings end to end, so JavaScript cannot silently round them past 2^53
Key Features
- Guilds, text & voice channels, direct messages, invites, and Discord-style bitfield roles with per-channel permission overwrites
- End-to-end encrypted DMs: X3DH key agreement + Double Ratchet, with Sender Keys for group channels
- Safety numbers for out-of-band identity verification, and per-device key bundles
- Stateless WebSocket gateway with Redis pub/sub fanout, heartbeats and bounded per-connection backpressure
- Live presence, typing indicators, read state, unread counts and mention notifications
- WebRTC voice channels with Redis-tracked voice state and signaling relayed through the gateway
- Attachments to S3/MinIO with a media worker for thumbnails and antivirus scanning
- Push notifications via Web Push (VAPID), FCM and APNs, consumed from a Redis stream
- Hardened auth: short-lived JWT access tokens, rotating refresh tokens in HttpOnly SameSite=Strict cookies, device sessions, email verification, hCaptcha and sliding-window rate limits per IP and per account
- Observability built in: structured JSON logs, Prometheus metrics and OpenTelemetry tracing across API and gateway
- Virtualized message list, optimistic sends and auto-reconnect with sequence-number resume
- Test suites across API, gateway and push workers, plus client-side tests for the ratchet, sender keys and safety numbers
Role
Architect & Full-Stack Developer
Challenge
Build a self-hostable Discord alternative that scales horizontally and still keeps message content genuinely private — the operator of the server should not be able to read direct messages.
Solution
Split the system into a REST API, a stateless WebSocket gateway and background workers coordinated through Redis, then pushed encryption to the client: X3DH + Double Ratchet for DMs and Sender Keys for groups, so the server only ever stores prekey bundles and ciphertext it cannot decrypt.