Architecture
System flow
text
REST (JSON) WebSocket (auth via 1st frame)
│ │
┌─────────▼─────────┐ ┌─────────▼─────────┐
│ React │ │ React │
│ (Vite, Zustand) │ │ (same client) │
└─────────┬─────────┘ └─────────┬─────────┘
│ │
│ Bearer token │
└──────────────┬───────────────────┘
│
┌────────▼────────┐
│ Go (Chi + WS) │
│ auth, routes │
│ hub, broadcast│
└────────┬────────┘
│
┌───────────────────┼───────────────────┐
│ │ │
▼ ▼ ▼
┌─────────┐ ┌─────────┐ ┌─────────┐
│ Postgres│ │ ScyllaDB│ │ Redis │
│ users │ │ messages│ │ Pub/Sub │
│ convos │ │ │ │ ◄──────┼── Hub subscribes,
│ members │ │ │ │ │ pushes to WS
└─────────┘ └─────────┘ └─────────┘REST: login, signup, CRUD for conversations and members, paginated messages. WebSocket: chat and typing; server saves to ScyllaDB, publishes to Redis; the hub subscribes to Redis and delivers to connected clients
Frontend layout
text
frontend/src/
├── components/ # ChatBubble, Sidebar, modals, etc.
├── pages/ # Login, ChatRoom
├── hooks/ # useAuth, useWebSocket
├── store/ # chatStore, userStore (Zustand)
├── services/ # api (Axios)
└── types/ # shared TypeScript interfacesBackend layout
text
backend/
├── cmd/server/ # main, wiring
├── internal/
│ ├── api/ # HTTP handlers, router, auth middleware
│ ├── ws/ # WebSocket hub, client, upgrade handler
│ ├── config/ # env config
│ ├── models/ # request/response and DB shapes
│ ├── repository/ # PostgreSQL, ScyllaDB
│ └── service/ # auth, chat (message persist + Redis publish)
└── pkg/logger/ # zap loggerReal-time events
| Type | Direction | Purpose |
|---|---|---|
chat | client→server | Send message; broadcast |
typing | client→server | Typing in conversation |
chat / typing | server→client | To conversation members |
new_conversation | server→client | Refresh conversation list |
conversation_deleted | server→client | Conversation removed |
key_rotated | server→client | Clear cached E2EE key |
removed_from_conversation | server→client | Drop conversation from UI |