How zulqadar/voice-buddy works
Project Type and Purpose
• Voice Buddy is a full-stack real-time voice chat web application.
• The frontend (“client”) is a React/TypeScript SPA that manages UI, user flow (Home → Room), and WebRTC/PeerJS integration.
• The backend (“server”) is a Node.js/TypeScript signaling service using Socket.IO and PeerJS to match random users and facilitate WebRTC connections.
File Structure
• Top-level:
• client/ – React app (Vite, Tailwind CSS, TS)
• server/ – Node/Socket.IO/PeerJS signaling server (TS)
• client/src/components, pages, context show an MVVM-style separation: components (UI), pages (routing), context (state management and peer logic).
• server/src/room handles room/session logic and pairing.
• Build/config files: client/vite.config.ts, tailwind.config.js, tsconfigs; server:nodemon.json, tsconfig.json.
README for Additional Insights
• Confirms use of WebRTC for media streams, Socket.IO for signaling, PeerJS to simplify peer connections.
• No persistent database—session management is in memory.
Components
a. Main Components
• Client Browser (React App)
• Signaling Server (Node.js + Socket.IO + PeerJS Server)
• Peer-to-Peer WebRTC Connection
• STUN/TURN Infrastructure (external or built into PeerJS)
b. Relationships & Interactions
1) Client connects to Signaling Server via Socket.IO (control connection).
2) Server pairs two clients into a “room.”
3) Server exchanges WebRTC SDP offers/answers and ICE candidates via the Socket.IO channel.
4) Once negotiated, the two clients open a direct WebRTC peer connection carrying audio streams.
c. Architectural Patterns & Design Principles
• Clear frontend/backend separation
• Single-page architecture on the client, with context-based state management for peer actions
• Event-driven messaging via WebSockets (Socket.IO)
• P2P media using WebRTC/PeerJS to offload media traffic from the server
d. Key Technologies
• React, TypeScript, Vite, Tailwind CSS on client
• Node.js, TypeScript, Socket.IO, PeerJS on server
• WebRTC (STUN/TURN) for audio streaming
Detailed Capture of Architectural Elements
• How the React context modules (peer-actions.ts, peer-reducer.ts, room-context.tsx) mediate between UI and peer connections.
• That client/src/assets and client/src/components create the UI for create-button and video-player.
• On the server side, illustrate server/src/room/index.ts handling room lifecycle and signaling events.
Putting It All Together
Layer 1 (Client): Pages & Context → Socket.IO Client → PeerJS Client → WebRTC API
Layer 2 (Network): Socket.IO WS, STUN/TURN, WebRTC ICE connections
Layer 3 (Server): Socket.IO Server → Room Manager → PeerJS Server module
1. Client WS connect → Server
2. Server emits “match” → Client A & B
3. Clients exchange SDP via Server
4. Clients establish P2P audio stream