# sushmitadasari/webrtc-video-chat-nextjs architecture

> Architecture diagram of the GitHub repository sushmitadasari/webrtc-video-chat-nextjs, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sushmitadasari/webrtc-video-chat-nextjs
- Repository: https://github.com/sushmitadasari/webrtc-video-chat-nextjs

## Overview

This repository implements a multi-peer video meeting application: participants enter a room, grant camera/microphone access, exchange WebRTC signaling through a custom Socket.IO server, and use direct peer connections for media. The room page coordinates media, signaling, status, chat and cleanup; its components render the meeting interface. The README also documents isolated rooms, participant join/leave handling and a health endpoint. Evidence is strongest for the sampled room, hooks and server code; deployment and some UI behavior are documented but not mapped as runtime components.

Main entry points: [`app/room/[roomId]/page.tsx`](https://github.com/sushmitadasari/webrtc-video-chat-nextjs/blob/main/app/room/%5BroomId%5D/page.tsx) (Room coordinator), [`hooks/useSocket.ts`](https://github.com/sushmitadasari/webrtc-video-chat-nextjs/blob/main/hooks/useSocket.ts) (Socket client hook), [`hooks/useWebRTC.ts`](https://github.com/sushmitadasari/webrtc-video-chat-nextjs/blob/main/hooks/useWebRTC.ts) (Peer connections), [`server.ts`](https://github.com/sushmitadasari/webrtc-video-chat-nextjs/blob/main/server.ts) (Custom server)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Meeting client"]
  node_room["Room coordinator<br/>[page.tsx]"]
  node_video["Remote video grid<br/>[VideoGrid.tsx]"]
  node_controls["Call controls<br/>[Controls.tsx]"]
  node_chatui["Chat panel<br/>[ChatPanel.tsx]"]
end

subgraph group_media["Media and signaling"]
  node_socketclient["Socket client hook<br/>[useSocket.ts]"]
  node_localmedia["Camera and mic<br/>[useUserMedia.ts]"]
  node_webrtc["Peer connections<br/>[useWebRTC.ts]"]
end

subgraph group_server["Server runtime"]
  node_customserver["Custom server<br/>[server.ts]"]
  node_roomstate[("Room membership<br/>[server.ts]")]
end

subgraph group_health["Health monitoring"]
  node_healthroute["Health endpoint<br/>[route.ts]"]
end

node_participant(("Participant"))
node_peers(("Other participants"))
node_stun["STUN service"]
node_operator(("Health requester"))

node_participant -->|"enters room"| node_room
node_room -->|"renders"| node_video
node_room -->|"renders"| node_controls
node_room -->|"renders"| node_chatui
node_room -->|"opens socket"| node_socketclient
node_room -->|"gets media"| node_localmedia
node_room -->|"coordinates peers"| node_webrtc
node_localmedia -->|"captures devices"| node_participant
node_controls -->|"invokes actions"| node_room
node_room -->|"provides remote streams"| node_video
node_video -->|"renders streams"| node_peers
node_chatui -->|"submits message"| node_room
node_room -->|"sends chat and signaling"| node_socketclient
node_webrtc -->|"sends signaling"| node_socketclient
node_socketclient -->|"connects"| node_customserver
node_customserver -->|"updates membership"| node_roomstate
node_customserver -->|"routes room events"| node_socketclient
node_webrtc -->|"exchanges media"| node_peers
node_webrtc -->|"uses for ICE"| node_stun
node_operator -.->|"requests status"| node_healthroute

click node_room "https://github.com/sushmitadasari/webrtc-video-chat-nextjs/blob/main/app/room/%5BroomId%5D/page.tsx"
click node_video "https://github.com/sushmitadasari/webrtc-video-chat-nextjs/blob/main/components/VideoGrid.tsx"
click node_controls "https://github.com/sushmitadasari/webrtc-video-chat-nextjs/blob/main/components/Controls.tsx"
click node_chatui "https://github.com/sushmitadasari/webrtc-video-chat-nextjs/blob/main/components/ChatPanel.tsx"
click node_socketclient "https://github.com/sushmitadasari/webrtc-video-chat-nextjs/blob/main/hooks/useSocket.ts"
click node_localmedia "https://github.com/sushmitadasari/webrtc-video-chat-nextjs/blob/main/hooks/useUserMedia.ts"
click node_webrtc "https://github.com/sushmitadasari/webrtc-video-chat-nextjs/blob/main/hooks/useWebRTC.ts"
click node_customserver "https://github.com/sushmitadasari/webrtc-video-chat-nextjs/blob/main/server.ts"
click node_roomstate "https://github.com/sushmitadasari/webrtc-video-chat-nextjs/blob/main/server.ts"
click node_healthroute "https://github.com/sushmitadasari/webrtc-video-chat-nextjs/blob/main/app/api/health/route.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_room,node_video,node_controls,node_chatui toneBlue
class node_socketclient,node_localmedia,node_webrtc toneAmber
class node_customserver,node_roomstate,node_operator toneMint
class node_healthroute toneRose
class node_participant,node_peers,node_stun toneIndigo
```

## Components

### Meeting client

- [Room coordinator](https://github.com/sushmitadasari/webrtc-video-chat-nextjs/blob/main/app/room/%5BroomId%5D/page.tsx): `app/room/[roomId]/page.tsx`
- [Remote video grid](https://github.com/sushmitadasari/webrtc-video-chat-nextjs/blob/main/components/VideoGrid.tsx): `components/VideoGrid.tsx`
- [Call controls](https://github.com/sushmitadasari/webrtc-video-chat-nextjs/blob/main/components/Controls.tsx): `components/Controls.tsx`
- [Chat panel](https://github.com/sushmitadasari/webrtc-video-chat-nextjs/blob/main/components/ChatPanel.tsx): `components/ChatPanel.tsx`

### Media and signaling

- [Socket client hook](https://github.com/sushmitadasari/webrtc-video-chat-nextjs/blob/main/hooks/useSocket.ts): `hooks/useSocket.ts`
- [Camera and mic](https://github.com/sushmitadasari/webrtc-video-chat-nextjs/blob/main/hooks/useUserMedia.ts): `hooks/useUserMedia.ts`
- [Peer connections](https://github.com/sushmitadasari/webrtc-video-chat-nextjs/blob/main/hooks/useWebRTC.ts): `hooks/useWebRTC.ts`

### Server runtime

- [Custom server](https://github.com/sushmitadasari/webrtc-video-chat-nextjs/blob/main/server.ts): `server.ts`
- [Room membership](https://github.com/sushmitadasari/webrtc-video-chat-nextjs/blob/main/server.ts): `server.ts`

### Health monitoring

- [Health endpoint](https://github.com/sushmitadasari/webrtc-video-chat-nextjs/blob/main/app/api/health/route.ts): `app/api/health/route.ts`

### Other components

- **Participant**
- **Other participants**
- **STUN service**
- **Health requester**

## Connections

- Participant → Room coordinator: enters room (evidence: `README.md`)
- Room coordinator → Remote video grid: renders (evidence: `app/room/[roomId]/page.tsx`)
- Room coordinator → Call controls: renders (evidence: `app/room/[roomId]/page.tsx`)
- Room coordinator → Chat panel: renders (evidence: `app/room/[roomId]/page.tsx`)
- Room coordinator → Socket client hook: opens socket (evidence: `app/room/[roomId]/page.tsx`)
- Room coordinator → Camera and mic: gets media (evidence: `app/room/[roomId]/page.tsx`)
- Room coordinator → Peer connections: coordinates peers (evidence: `app/room/[roomId]/page.tsx`)
- Camera and mic → Participant: captures devices (evidence: `hooks/useUserMedia.ts`)
- Call controls → Room coordinator: invokes actions (evidence: `app/room/[roomId]/page.tsx`)
- Room coordinator → Remote video grid: provides remote streams (evidence: `app/room/[roomId]/page.tsx`)
- Remote video grid → Other participants: renders streams (evidence: `components/VideoGrid.tsx`)
- Chat panel → Room coordinator: submits message (evidence: `app/room/[roomId]/page.tsx`)
- Room coordinator → Socket client hook: sends chat and signaling (evidence: `app/room/[roomId]/page.tsx`)
- Peer connections → Socket client hook: sends signaling (evidence: `hooks/useWebRTC.ts`)
- Socket client hook → Custom server: connects (evidence: `hooks/useSocket.ts`)
- Custom server → Room membership: updates membership (evidence: `server.ts`)
- Custom server → Socket client hook: routes room events (evidence: `server.ts`)
- Peer connections → Other participants: exchanges media (evidence: `README.md`)
- Peer connections → STUN service: uses for ICE (evidence: `hooks/useWebRTC.ts`)
- Health requester → Health endpoint: requests status (evidence: `README.md`)
