How livekit/node-sdks works
Project Type and Purpose
• This is a monorepo for two complementary Node.js SDKs for LiveKit:
• *livekit-rtc* – a realtime client SDK that lets your Node apps participate in WebRTC-based audio/video/data rooms using a Rust-based core with an FFI layer.
• *livekit-server-sdk* – a server-side API client that wraps LiveKit’s Twirp/gRPC endpoints for room management, ingress/egress, tokens, and webhooks.
• It provides libraries and examples so that developers can embed LiveKit-powered video/audio/data features into their applications.
File-Structure Analysis
• Top-level tooling and config: Turborepo (turbo.json), pnpm workspaces, TS/ESLint/Prettier, GitHub workflows.
• packages/livekit-rtc:
• Rust submodule (.cargo/, build.rs, Cargo.toml) and generated protobuf code under src/proto.
• JavaScript/TypeScript wrappers and FFI bindings in src/napi & .ts files.
• packages/livekit-server-sdk:
• Pure TypeScript RPC clients, token generators, webhook receivers under src/.
• examples/: multiple demo apps showing how to use each SDK in real environments (Next.js, simple Node scripts).
Key README Insights
• Monorepo using pnpm & Turborepo: build orchestration across packages and examples.
• Two main deliverables: realtime SDK (with audio/video/data) and server SDK (API/management).
• Examples illustrate both server event handling (webhooks) and media publish/subscribe flows.
a. Main Components to Represent
1. Developer Application (e.g., your Node.js service or example apps)
2. livekit-server-sdk (Twirp/gRPC client layer)
3. livekit-rtc (FFI → Rust core → WebRTC stack)
4. LiveKit Server Cloud / Self-hosted (external service providing rooms, media routing)
5. Build & Tooling (Turborepo, pnpm workspace, submodule fetch, CI)
b. Relationships and Interactions
• Build pipeline: local code edits → pnpm install/build → package artifacts → npm publish
c. Architectural Patterns & Principles
• Modular Monorepo: clear separation of server vs. realtime concerns, shared configs.
• FFI Boundary: JS ↔ Rust for performance-critical media handling.
• Protobuf-driven API: shared proto definitions generate code in both packages.
• Examples as Integration Tests: showcases extendability and usage patterns.
d. Key Technologies & Frameworks
• TypeScript, Node.js, Rust, N-API (for FFI), Protobuf, gRPC/Twirp, WebRTC, pnpm workspaces, Turborepo.
1. Sketch out the boundary between your *app code* and the two SDK packages.
4. A side-view of the monorepo build flow: root config → package builds → CI/CD → npm registry.