Learn WebSockets

A real-time crypto dashboard built to learn WebSockets from the ground up. 8 assets streaming live via Binance, with broadcast, heartbeats, and auto-reconnect.

Tech Stack

img
Next.js 16
React framework
img
TypeScript
Type safety
img
Express
HTTP server
img
ws
WebSocket library
img
Recharts
React charts
img
Tailwind CSS
Utility CSS

Project Structure

FilePurpose
ws-server/src/app.tsExpress + ws backend, Binance connector, broadcast, heartbeat
frontend/src/hooks/useWebSocket.tsReact hook: connect, reconnect, track history
frontend/src/components/Dashboard.tsxMain layout with search, sort, market overview
frontend/src/components/CoinCard.tsxIndividual coin tile with sparkline chart
frontend/src/components/DetailChart.tsxLarge area chart for selected coin
frontend/src/components/SparklineChart.tsxMini inline chart (Recharts)
frontend/src/components/MarketOverview.tsxMarket sentiment, gainers/losers, top performers
frontend/src/lib/types.tsTypeScript types + asset metadata (7 coins + 1 commodity)

Quick Start

1. Clone the Repository

git clone https://github.com/shubhu2002/crypto-pulse-websocket.git

2. Start the WebSocket server

cd ws-server
yarn install
yarn dev          # Runs on port 4000

3. Start the Next.js frontend

cd frontend
pnpm install
pnpm dev        # Runs on port 3000

4. Open in browser

Visit http://localhost:3000— you'll see 8 assets streaming live with charts.

Links & Resources

Try These Experiments

  • Open multiple tabs — watch the server log show client count increasing. All tabs get the same broadcast data.
  • Kill the WS server— watch the frontend show "Disconnected" and auto-reconnect when you restart it.
  • Check DevTools → Network → WS — see every WebSocket frame flowing in real-time.
  • Hit the health endpoint curl http://localhost:4000/health shows connected client count.
  • Add a new coin — add to COINS in server.ts and COIN_META in types.ts, restart server.