Simple real‑time chat app with a Next.js frontend and a Go WebSocket backend.
frontend/: Next.js app (App Router, Tailwind v4)backend/: Go WebSocket server (Gorilla WebSocket)
Requirements: Node 18+, npm, Go 1.22+
cd backend
go mod tidy
go run .
# Server at http://localhost:8080 (WebSocket at ws://localhost:8080/ws)cd frontend
npm install
# Optional: configure WebSocket URL
cp .env.local.example .env.local
# edit .env.local if needed (NEXT_PUBLIC_WS_URL)
npm run dev
# Open http://localhost:3000- Username gate → join chat instantly
- Real‑time messaging over WebSockets
- Right‑aligned self messages, left‑aligned others
- Scrollable history with sticky “scroll to bottom” and unread count
- Terminal‑style brutalist UI, red mono theme with leetspeak text
Client → Server (join):
{ "type": "join", "username": "alice" }Client → Server (message):
{ "type": "message", "username": "alice", "text": "hello" }Server → Clients (broadcast):
{ "user": "alice", "text": "hello", "time": 1735752440000 }- Frontend:
NEXT_PUBLIC_WS_URLinfrontend/.env.local - Backend: listens on
:8080by default
Frontend:
npm run dev
npm run build
npm startBackend:
go run .
go build -o chatroom-backend && ./chatroom-backend- No messages / connect errors: ensure the backend is running and
NEXT_PUBLIC_WS_URLmatches (e.g.,ws://localhost:8080/ws). - Mixed content in browser: use
ws://withhttp://andwss://withhttps://. - Port conflicts: change frontend port (
PORT=3001 npm run dev) or backend listen addr inbackend/main.go.