A real-time chat infrastructure that feels like
useState.
Build scalable real-time applications without dealing with WebSocket complexity directly.
Most real-time systems force you to think in terms of:
- WebSocket connections
- Event listeners
- Manual state synchronization
- Reconnection logic
- Backend coordination
Chat Hooks flips that model.
Instead of managing infrastructure, you use a simple hook:
const { messages, sendMessage, status } = useChat(roomId);This repository is organized as a pnpm workspace:
apps/frontend: Next.js demo applicationapps/backend: WebSocket real-time serverpackages/chat-client: framework-agnostic chat SDK + React adapterpackages/shared: shared contracts, types, and utilities
apps/
frontend/
backend/
packages/
chat-client/
shared/
- Frontend and backend are fully decoupled.
- Shared schemas and contracts are defined only in
packages/shared. - SDK core remains framework-agnostic in
packages/chat-client/src/index.ts. - Framework bindings are isolated in
packages/chat-client/src/react.ts. - Business logic is not duplicated across frontend/backend.
pnpm install
pnpm devEndpoints:
- Frontend: http://localhost:3000
- Backend WebSocket:
ws://localhost:8080
| Command | Description |
|---|---|
pnpm dev |
Run frontend and backend together with hot reload |
pnpm build |
Build all workspaces |
pnpm test |
Run tests across all workspaces |
pnpm typecheck |
Type-check all workspaces |
pnpm lint |
Run lint script in all workspaces |
pnpm --filter @chat-hooks/frontend dev
pnpm --filter @chat-hooks/backend dev
pnpm --filter @chat-hooks/chat-client test
pnpm --filter @chat-hooks/shared build| Package | Responsibility |
|---|---|
@chat-hooks/frontend |
Demo app and UI integration |
@chat-hooks/backend |
Real-time server implementation |
@chat-hooks/chat-client |
Reusable SDK for client communication |
@chat-hooks/shared |
Event contracts and shared domain types |