How skushagra9/redisws-hub works
Project type and purpose
• This is a backend service—a real-time WebSocket hub implemented in Node.js/TypeScript.
• Purpose: accept WebSocket client connections (no auth), receive a user ID from each client, subscribe to Redis pub/sub channels, and broadcast incoming events back to the relevant connected clients in real time.
File structure
• package.json / package-lock.json
– Defines Node.js dependencies (e.g., “ws” or “socket.io”, “redis”) and scripts.
• tsconfig.json
– TypeScript compiler settings.
• src/index.ts
– Entry point. Instantiates the WebSocket server, attaches connection‐handling logic, wires up Redis publisher or subscriber.
• src/subscriber.ts
– Encapsulates Redis subscription logic: connects to Redis, subscribes to topics, emits messages back to the WebSocket server.
• .gitignore, README.md
– Standard repo metadata.
README for additional insights
• Confirms the architecture: WebSocket server + Redis pub/sub.
• Usage steps clarify that the server script holds both the WebSocket listener and the Redis subscriber.
• No separate frontend—clients are any WebSocket‐capable frontends.
Detail
• “Connection Manager” (handles WebSocket accept, tracks userID→socket)
• “Redis Subscriber” (handles channel subscription and invokes broadcaster)
– Call out in-memory data structures (e.g., a Map<userID, WebSocket>).
– If more advanced: note reconnection logic, error handling, or scaling via Redis Cluster or horizontal Node.js instances behind a load balancer.