Simple realtime chat built with a Go WebSocket backend and a React frontend. No database — all state is kept in memory for teaching/demo purposes.
- Go backend (
apps/backend): HTTP server + WebSocket chat hub (join/leave, broadcast, user IDs) - Web frontend (
apps/web): Minimal chat UI (connect, send, users list)
- Go (1.21+ recommended)
- Bun or Node.js (for the web app)
cd apps/backend
go mod tidy
go run .
# backend runs on http://localhost:8080cd apps/web
cp .env.example .env
# edit .env and set the backend URL (defaults shown)
# VITE_BACKEND_URL=http://localhost:8080
bun install # or npm install / pnpm install / yarn
bun dev # or npm run dev / pnpm dev / yarn dev
# frontend runs on http://localhost:3001 (per your dev setup)- Start the backend, then the frontend
- Open the web app in multiple tabs
- Enter a username and Connect
- Send messages; see join/leave and broadcasts in realtime
GET /healthz— health checkGET /api/users— list of connected users and IDsGET /api/stats— basic server statsWS /ws?username=YourName— WebSocket chat endpoint
- Explicit error handling in Go (
value, err) - Goroutines + channels for concurrency
- WebSocket lifecycle (upgrade, read/write pumps, heartbeats)
- In‑memory hub pattern for broadcast and membership
- IDs are simple incrementing numbers for clarity in demos
- All state is ephemeral; restarting the backend resets the room