How uday-choudhary/synccube works
Project Type and Purpose
• SyncCube is a full-stack, real-time web application for synchronized video watching.
• The frontend is a React/Vite SPA styled with Tailwind CSS and shadcn/ui, and the backend is a Node.js server using Socket.io for real-time events.
• Key use cases: create/join a room, input YouTube URLs, play/pause/seek in sync across clients.
File Structure
• Top-level:
• server/ – Node.js Socket.io server (index.js, package.json).
• src/ – React app (components, context, pages, hooks, lib).
• Configs: Vite (vite.config.ts), Tailwind (tailwind.config.ts), TypeScript (tsconfig*.json).
• public/ – static assets (robots.txt).
• Patterns:
• SPA structure under src/, MVC-light (pages vs components).
• Context API for socket management (src/context/SocketContext.jsx).
• Utility libs in src/lib.
• shadcn/ui folder for reusable UI primitives.
Extract Architecture Insights from README
• Lists Frontend/Backend separation and real-time flow via Socket.io.
• Outlines room lifecycle: creation, join, event broadcasting, state tracking.
• Mentions ngrok for exposing local server.
Main Components
a. Frontend (Browser)
• React App (entry main.jsx/main.tsx, root App.jsx/tsx).
• UI layer: shadcn/ui components + custom components (HeaderNav, VideoInput, YouTubePlayer, RoomInfo, JoinRoomForm).
• Context: SocketContext manages io() connection.
• Pages: Index, RoomPage, NotFound.
• Hooks/utilities: use-mobile, use-toast, utils.js/ts.
b. Backend (Node.js Server)
• Express (implicit) + Socket.io server in server/index.js.
• In-memory store of room states (video URL, play/pause, timestamp).
• Event handlers: video_play, video_pause, video_seek, join_room, etc.
c. External Services
• YouTube iFrame API (embedded player).
• ngrok (for tunnel during development).
d. Infrastructure (Dev/Prod)
• Vite dev server on localhost:8080.
• Socket.io server on localhost:3001.
• Static assets served from public/.
Relationships and Data Flows
• On room creation: Frontend emits create_room → Server generates ID + stores video URL → emits back room_created.
• On join: Frontend emits join_room → Server adds socket to room, sends current state → Frontend sets up player.
• Playback events: Frontend emits video_play/video_pause/video_seek → Server broadcasts to all sockets in room → Frontends update player state.
• New joiners request current state from the server.
• UI feedback: connection status, user count via room_users events.
Architectural Patterns & Principles
• Separation of Concerns: UI components vs context vs utils vs pages
• Real-time Pub/Sub via Socket.io rooms
• Stateless frontend, stateful server for sync coordination
• Responsive design (use of use-mobile hook)
1. Sketch three tiers: Client Browser, Backend Server, External Services.
8. Validate against README flow: room creation, join, event broadcast, new-user sync.