How cb7chaitanya/streamly works
Project type and purpose
• This is a full-stack, microservices-style monorepo (Turborepo + pnpm) implementing a live video-streaming platform.
• Key user flows: user authentication and profile management, real-time media routing via an SFU, on-the-fly stream mixing/encoding, and optional live broadcasting (e.g. to YouTube).
High-level file-structure analysis
• apps/frontend – React + Vite SPA, handles UI, user auth pages (Login/Signup), studio view, SFU client signaling via WebSocket, and uses shared UI components & types.
• apps/user-be – Node service exposing REST endpoints for user & stream metadata, implements controllers, routes, middleware (JWT auth), persists via packages/db (Prisma).
• apps/sfu-server – Node WebSocket SFU (Peer, Room, SFU classes), mediacodec config, signaling utilities, worker threads for scalable media forwarding.
• apps/mixer – Node background service leveraging FFmpeg and YouTube Data API to pull media streams and re-encode/mix for live broadcast.
• packages/common/types – Shared TypeScript message, payload, room, SFU-protocol definitions.
• packages/db – Prisma client and schema; the single source of truth for persistence.
• packages/ui – Shared React components (Button, Card, Code snippet) consumed by frontend.
• packages/{eslint-config,typescript-config,zod} – Build and lint configurations; not part of runtime.
• Browser (frontend SPA):
– UI layer, UI library (packages/ui), shared types.
– SFU client hooks → WebSocket signaling channel to SFU server.
• User-BE (REST API):
– Express/Koa-style HTTP server, JWT auth middleware, controllers for /user and /stream.
– Persists user and stream metadata via Prisma → Postgres/MySQL.
• SFU-Server (WebSocket SFU):
– Signaling channel, Room & Peer managers, media forwarding (no direct DB access).
• Mixer Service (batch/job worker):
– Fetches live streams or recorded segments from SFU or storage → runs FFmpeg pipelines → pushes output to YouTube Live via YouTube API.
• Database:
– Postgres (Prisma).
• External Service:
– YouTube Live Data API.
Relationships and data flows
• User-BE ←→ Database: HTTP requests for auth, user data, stream metadata.
• Frontend (HTTP) → User-BE for signup/login and metadata.
• Frontend (WebSocket) ↔ SFU-Server for WebRTC signaling (offer/answer, ICE).
• Clients send/receive RTP media via SFU-Server (UDP or TCP transports managed in utils/transport.ts).
• Mixer polls SFU-Server or pulls from a storage endpoint, runs FFmpeg (apps/mixer/ffmpeg.ts), then pushes to YouTube API (apps/mixer/yt-api.ts).
• All code built, linted, typed via common build configs (turborepo pipelines).
Architectural patterns and principles
• Microservices: each app in apps/ is a separate deployable unit.
• Domain-driven layering: controllers → services/utilities → persistence.
• Shared code via packages/ for DRY, strict typing and UI consistency.