How kartikeya-guthub/collabhub works
Purpose and entry points
CollabHub is a room-based collaborative workspace combining live code editing, a shared tldraw whiteboard, presence, code execution, and AI assistance. The browser application is a Next.js client rooted at client/src/app/layout.tsx and client/src/app/page.tsx; room collaboration is entered through client/src/app/room/[id]/page.tsx and its join route. The backend process starts from server/src/index.ts.
Identity, rooms, and access boundary
Postgres stores users, rooms, and memberships, established through migrations in server/migrations/1783655038830_create-users-table.ts, server/migrations/1783655079156_create-rooms-table.ts, and server/migrations/1783655093393_create-room-members-table.ts. Authentication endpoints issue JWT-backed identity via server/src/routes/auth.ts; protected HTTP and realtime operations use server/src/middleware/requireAuth.ts. Room creation, membership, and room lookup flow through server/src/routes/rooms.ts.
Client workspace composition
The room UI composes independent collaborative surfaces and auxiliary panels: Monaco/Yjs code editing in client/src/components/CodeEditor.tsx, tldraw canvas integration in client/src/components/Whiteboard.tsx, and merged participant state in client/src/components/UnifiedPresenceList.tsx. The dashboard (client/src/app/dashboard/page.tsx) is the room-discovery/management boundary, while room pages own the active session experience.
Code synchronization and presence
Code collaboration uses Yjs over Socket.IO. Client connection/provider setup is separated into client/src/lib/socket.ts and client/src/lib/yjsProvider.ts; the server-side Socket.IO coordination is in server/src/sockets/index.ts. Redis, configured through server/src/redis.ts, supports code-state rehydration and horizontal scaling. The client merges code and whiteboard presence through client/src/lib/presence.ts, rather than requiring the two sync engines to share a protocol.
Whiteboard synchronization
Whiteboard state runs through a separate raw-WebSocket @tldraw/sync service implemented at server/src/tldrawSync/index.ts and consumed by client/src/components/Whiteboard.tsx. It shares the JWT/room authorization model but not Yjs transport or storage. This is the principal scaling boundary: the code path is Redis-capable across instances, while tldraw sync is currently intended as a single instance.
Execution and AI services
Code submitted from client/src/components/RunTestsPanel.tsx reaches server/src/routes/execute.ts, which uses Judge0-compatible language mapping in server/src/judge0/languages.ts and supports the documented Piston development fallback. Results are broadcast to room participants through the realtime layer. AI requests originate in client/src/components/AskAIPanel.tsx and are handled by server/src/routes/ai.ts using provider selection/client logic in server/src/ai/client.ts; Groq supports fast answers and NVIDIA Nemotron supports deeper streamed responses. client/src/components/DiagramGenerator.tsx applies AI-produced diagram intent to the shared whiteboard.
Runtime and infrastructure
The system consists of a Next.js/TypeScript frontend and Node/TypeScript backend, with Postgres, Redis, and Docker-managed infrastructure declared in docker-compose.yml. The backend integrates external Judge0/RapidAPI and AI provider APIs. A separate local Piston deployment is available under piston-deployment/docker-compose.yml, including its reverse-proxy template.
Main entry points: requireAuth.ts JWT access guard · page.tsx Room session · index.ts Code realtime server · yjsProvider.ts Yjs socket provider
Components 21
Browser client
Next.js collaborative workspace.
- Next.js app · Application shell and client entry points.
client/src/app/layout.tsx - Room dashboard · Room discovery and management boundary.
client/src/app/dashboard/page.tsx - Room session · Active collaborative workspace.
client/src/app/room/[id]/page.tsx - Code editor · Collaborative code surface.
client/src/components/CodeEditor.tsx - Yjs socket provider · Creates Socket.IO-backed document synchronization.
client/src/lib/yjsProvider.ts - Shared whiteboard · Canvas surface using its own sync transport.
client/src/components/Whiteboard.tsx - Unified presence · Combines code and whiteboard participant state.
client/src/lib/presence.ts - Run tests panel
client/src/components/RunTestsPanel.tsx - AI panels · Requests assistance and applies diagram intent.
client/src/components/AskAIPanel.tsx
Backend services
Node API and realtime coordination.
- HTTP API · Authenticated identity, room, execution, and AI endpoints.
server/src/index.ts - JWT access guard · Protects HTTP and realtime room operations.
server/src/middleware/requireAuth.ts - Auth routes · Issues JWT-backed identity.
server/src/routes/auth.ts - Room routes · Creates rooms and manages membership.
server/src/routes/rooms.ts - Code realtime server · Coordinates code synchronization and room broadcasts.
server/src/sockets/index.ts - Whiteboard sync server · Single-instance @tldraw/sync service.
server/src/tldrawSync/index.ts - Execution route · Maps languages and submits code execution.
server/src/routes/execute.ts - AI route and client · Selects Groq or NVIDIA Nemotron providers.
server/src/ai/client.ts
State and infrastructure
Persistent, distributed, and external execution services.
- Postgres · Users, rooms, and memberships.
server/migrations/1783655038830_create-users-table.ts - Redis · Code-state rehydration and multi-instance scaling.
server/src/redis.ts - Judge0 / Piston · External Judge0-compatible service with local Piston fallback.
piston-deployment/docker-compose.yml - AI providers · Groq fast answers and NVIDIA Nemotron streaming.
Connections 24
- Next.js app → Room dashboard: hosts
- Next.js app → Room session: hosts
- Room dashboard → HTTP API: room management
- Room session → Code editor: composes
- Room session → Shared whiteboard: composes
- Room session → Unified presence: shows
- Code editor → Yjs socket provider: syncs through
- Yjs socket provider → Code realtime server: Socket.IO / Yjs
- Shared whiteboard → Whiteboard sync server: raw WebSocket
- Yjs socket provider → Unified presence: code presence
- Shared whiteboard → Unified presence: canvas presence
- Run tests panel → Execution route: submits code
- AI panels → AI route and client: requests assistance
- HTTP API → JWT access guard: protects requests
- JWT access guard → Auth routes: identity flow
- JWT access guard → Room routes: authorizes rooms
- JWT access guard → Code realtime server: authorizes realtime
- JWT access guard → Whiteboard sync server: authorizes rooms
- Auth routes → Postgres: users
- Room routes → Postgres: rooms and members
- Code realtime server → Redis: rehydrates and scales
- Execution route → Judge0 / Piston: runs submissions
- Execution route → Code realtime server: broadcasts results
- AI route and client → AI providers: selects provider