Skip to content

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 interfaces

Backend 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 logger

Real-time events ​

TypeDirectionPurpose
chatclient→serverSend message; broadcast
typingclient→serverTyping in conversation
chat / typingserver→clientTo conversation members
new_conversationserver→clientRefresh conversation list
conversation_deletedserver→clientConversation removed
key_rotatedserver→clientClear cached E2EE key
removed_from_conversationserver→clientDrop conversation from UI