How oceans404/fullstack-sockets-demo works
Project type and purpose
• This is a full-stack, real-time chat application.
• Frontend: React (Vite) SPA that renders a chat UI and connects to a WebSocket server.
• Backend: Node.js server using Socket.io to manage bi-directional, event-based communication.
File structure
• Top level:
• README.md (project overview, tutorial steps)
• frontend/ (React app)
• server/ (Node.js Socket.io server)
• frontend/:
• vite.config.js, package.json – build and dependency definitions
• src/ – React components (App.jsx, SingleFieldForm.jsx) and CSS
• public/ & index.html – static host page
• server/:
• package.json – scripts (start: nodemon server.js), dependencies (socket.io, dotenv)
• server.js (implicitly present) – Socket.io server logic, CORS setup, custom event handlers
• Config files:
• .gitignore in both packages
• .env files (frontend/.env with VITE_SERVER_URL; server/.env with NODE_CLIENT_ORIGIN)
• Deployment manifests are handled externally (Fleek, Render).
Core README insights
• Establishes Socket.io connection (client ↔ server) over port 3000.
• CORS configuration on the server to permit the frontend origin (localhost:5173 or deployed URL).
• Tracks special events (connect, disconnect) and custom events (“set-username”, “new-user”, “send-message”, “new-message”).
• Environment variable setup for runtime URLs.
• Deployment processes using Fleek (IPFS) for frontend and Render for backend.
Main components and their interactions
a. Components
• Client App (React SPA)
• Socket.io Client (in App.jsx)
• Socket.io Server (Node.js + socket.io)
• Environment Layer (.env variables)
• Optional Infrastructure: IPFS/CDN (frontend), Render service (backend), DNS/CORS gateway
b. Relationships & data flow
1. User types into the React UI → form component emits “send-message” over socket.
2. Socket.io Client connects to Socket.io Server; handles built-in events (connect, disconnect).
3. Server listens, logs, emits back to all connected clients (“new-message”, “new-user”).
4. React App useEffect hooks capture “new-message” and “new-user” events → update UI state.
5. Env vars inject proper server URL on both sides.
c. Architectural patterns & principles
• Separation of Concerns: distinct client and server codebases.
• Event-driven messaging: pub/sub style socket events.
• Configuration via environment variables for portability.
• Stateless server: messages are broadcasted, no persistent storage (could be extended).
d. Key technologies
• React (Vite) – fast dev server, JSX components, state/hooks
• Socket.io – real-time websockets fallback to polling, server & client libraries
• Node.js – Express-style server script (server.js) with nodemon for development
• dotenv – config loader for .env files
• Fleek (IPFS/CDN) & Render.com – hosting/deployment platforms