How scarllet-hash/chat_hub works
Project Type and Purpose
• ChatHub is a full-stack, real-time multi-user chat application.
• Frontend: React app running in the browser, communicating over WebSocket.
• Backend: Native C TCP server (chat_server.c) handling chat logic in memory.
• Bridge: websocketd + socat acting as a WebSocket-to-TCP proxy.
• Containerized via Docker and orchestrated by docker-compose.
File-structure Analysis
• Top-level:
• client/ (React code + Dockerfile)
• server/ (C server + Dockerfile)
• websocketd/ (proxy scripts + Dockerfile)
• docker-compose.yml
• No database directory: state is in-memory in the C server.
• Presence of shell script (tcp-proxy.sh) and websocketd config indicates a 3-tier pipeline.
Key Architecture Insights from README
• Clients connect via WebSocket to websocketd (port 8080).
• websocketd invokes tcp-proxy.sh, which uses socat to open a TCP socket to the C server (port 12345).
• The C server handles all chat features (private, group, online list, notifications) over plain TCP.
Main Components
a. React Client (Browser)
• Runs on port 3000 (dev) or 80/8080 (Docker)
b. WebSocket Bridge
• Inside: tcp-proxy.sh → socat
• Exposes ws://localhost:8080
c. Chat Server
• Listens on TCP port 12345
• In-memory user/session management
d. Orchestration Layer
• Docker Compose service definitions for client, websocketd, server
• Network overlay: each container in the same Docker network
Architectural Patterns & Design Principles
• Separation of Concerns: UI (React) vs. Chat Logic (C) vs. Transport (websocketd+socat).
• Micro-service-like proxy layer to avoid adding WebSocket code to the legacy C server.
• Containerization: decoupled services with explicit network links.
Detail Checklist
• [✓] React client entry point (App.js, WebSocket connection)
• [✓] websocketd container invoking tcp-proxy.sh
• [✓] socat TCP bridge
• [✓] C server listening on POSIX sockets
• [✓] Docker Compose service names & links
• [✓] Data-flow directions and protocols