Skip to content

billyribeiro-ux/streaming-cloud

Repository files navigation

Trading Room SaaS Platform

Enterprise-grade, multi-tenant Trading Room SaaS with ultra-low latency WebRTC streaming powered by Mediasoup SFU cluster architecture.

Architecture Overview

┌─────────────────────────────────────────────────────────────────────────────┐
│                         TRADING ROOM SAAS PLATFORM                          │
├─────────────────────────────────────────────────────────────────────────────┤
│                                                                             │
│   ┌──────────┐     ┌──────────────┐     ┌─────────────┐     ┌──────────┐  │
│   │ Svelte   │────▶│  Signaling   │────▶│  Mediasoup  │────▶│  TURN    │  │
│   │ Frontend │     │   Server     │     │  SFU Cluster│     │  Server  │  │
│   └──────────┘     └──────────────┘     └─────────────┘     └──────────┘  │
│        │                  │                    │                           │
│        │                  │                    │                           │
│        ▼                  ▼                    ▼                           │
│   ┌──────────────────────────────────────────────────────────────────┐    │
│   │                    Neon (Serverless PostgreSQL)                  │    │
│   └──────────────────────────────────────────────────────────────────┘    │
│        │                                                                   │
│        ▼                                                                   │
│   ┌──────────────┐     ┌──────────────┐     ┌──────────────┐             │
│   │  Rust  API   │────▶│    Redis     │────▶│ Cloudflare   │             │
│   │  SaaS API    │     │    Cache     │     │  R2 Storage  │             │
│   └──────────────┘     └──────────────┘     └──────────────┘             │
│                                                                             │
└─────────────────────────────────────────────────────────────────────────────┘

Tech Stack

Backend - Core SaaS (backend-rs/)

  • Rust with Axum + Tokio - Core SaaS API
  • sqlx - Postgres access (migrations + typed queries)
  • Sanctum-compatible tokens, Argon2id password hashing
  • Stripe billing (REST + signed webhooks), Cloudflare R2 (presigned URLs)
  • PostgreSQL via Neon (Serverless) · Redis - cache / coordination

Realtime & Media

  • Node.js 24.16.0 with TypeScript
  • Mediasoup v3.20 - SFU (Selective Forwarding Unit)
  • WebRTC - Real-time media streaming
  • Coturn - TURN/STUN server

Frontend (frontend-svelte/)

  • Svelte 5 + SvelteKit (adapter-node, SSR) with TypeScript
  • Cookie-based BFF auth (token never exposed to client JS)
  • Vite 8 - Build tool · TailwindCSS 4 - Styling
  • Svelte 5 runes for state · mediasoup-client v3 - WebRTC client

Infrastructure

  • Hetzner Cloud - Primary hosting
  • Cloudflare - CDN, DNS, WAF
  • Cloudflare R2 - Object storage
  • Docker - Containerization
  • GitHub Actions - CI/CD

Project Structure

streaming-cloud/
├── backend-rs/                 # Rust SaaS API (Axum + Tokio + sqlx)
│   └── crates/api/
│       ├── src/
│       │   ├── domain/         # Domain models
│       │   ├── db/             # sqlx repositories
│       │   ├── http/           # Axum routers + handlers
│       │   ├── auth/           # password hashing, tokens, extractors
│       │   ├── signaling/      # SFU control-plane + token mint
│       │   ├── stripe.rs       # Stripe REST client + webhooks
│       │   └── s3.rs           # R2 SigV4 presigner
│       └── migrations/
│
├── frontend-svelte/            # SvelteKit frontend (adapter-node, SSR)
│   └── src/
│       ├── routes/             # File-based routes (+page/+server/+layout)
│       └── lib/                # BFF client, stores, components
│
├── signaling/                  # Node.js Signaling Server
│   └── src/
│       ├── config/
│       ├── controllers/
│       ├── services/
│       │   ├── SignalingServer.ts
│       │   ├── RoomManager.ts
│       │   └── AuthService.ts
│       └── types/
│
├── sfu/                        # Mediasoup SFU Cluster
│   └── src/
│       ├── workers/
│       │   └── WorkerManager.ts
│       ├── routers/
│       │   └── RouterManager.ts
│       └── transports/
│
├── infrastructure/             # DevOps & Infrastructure
│   ├── docker/
│   │   ├── docker-compose.yml
│   │   └── Dockerfile.*
│   ├── terraform/
│   └── scripts/
│
├── docs/                       # Documentation
│   ├── ARCHITECTURE.md
│   └── DATABASE_SCHEMA.md
│
└── .github/
    └── workflows/
        └── ci-cd.yml

Features

Multi-Tenant Architecture

  • Organizations (tenants) with isolated data
  • Workspaces for team organization
  • Row-Level Security (RLS) via PostgreSQL policies
  • Role-based access control (Owner, Admin, Host, Co-Host, Moderator, Viewer)

WebRTC Streaming

  • Ultra-low latency video/audio streaming
  • Simulcast for adaptive quality
  • Screen sharing support
  • Multiple concurrent rooms per organization

SaaS Features

  • Stripe subscription billing
  • Multiple pricing tiers (Starter, Professional, Business, Enterprise)
  • Usage-based limits enforcement
  • API access for integrations

Room Features

  • Real-time chat (WebSocket)
  • Trading alerts and announcements
  • File uploads (Cloudflare R2)
  • Participant management
  • Recording support (Business+ plans)

Subscription Plans

Feature Starter Professional Business Enterprise
Price $49/mo $149/mo $449/mo Custom
Workspaces 1 3 10 Unlimited
Rooms 3 10 50 Unlimited
Hosts 1 3 10 Unlimited
Viewers/Room 50 200 1,000 Unlimited
Storage 5GB 25GB 100GB 1TB
Recording -
SSO - -
API Access -

Getting Started

Prerequisites

  • Docker & Docker Compose
  • Node.js 24.16.0
  • Rust (stable) + Cargo
  • Neon account (https://neon.tech)
  • Stripe account
  • Cloudflare account (for R2)

Environment Setup

  1. Clone the repository:
git clone https://github.com/your-org/streaming-cloud.git
cd streaming-cloud
  1. Copy environment file:
cp .env.example .env
  1. Configure environment variables (see .env.example for all options)

  2. Start services with Docker:

cd infrastructure/docker
docker compose up -d

Development

Backend (Rust API)

cd backend-rs
cargo run            # serves on :8080
# migrations: sqlx migrate run --source crates/api/migrations

Frontend (SvelteKit)

cd frontend-svelte
npm ci
npm run dev          # serves on :5173

Signaling Server

cd signaling
npm install
npm run dev

SFU Node

cd sfu
npm install
npm run dev

Frontend

cd frontend
npm install
npm run dev

API Documentation

Authentication

All API requests require authentication via JWT token:

Authorization: Bearer <jwt-token>

Key Endpoints

Organizations

  • GET /api/v1/organizations - List user's organizations
  • POST /api/v1/organizations - Create organization
  • GET /api/v1/organizations/{id} - Get organization details

Rooms

  • GET /api/v1/organizations/{org}/rooms - List rooms
  • POST /api/v1/organizations/{org}/rooms - Create room
  • POST /api/v1/organizations/{org}/rooms/{room}/start - Start stream
  • POST /api/v1/organizations/{org}/rooms/{room}/join - Join room
  • POST /api/v1/organizations/{org}/rooms/{room}/end - End stream

Subscriptions

  • GET /api/v1/subscriptions/plans - List available plans
  • POST /api/v1/subscriptions - Create subscription
  • POST /api/v1/subscriptions/portal - Get billing portal URL

Deployment

Production Deployment (Hetzner)

  1. Provision servers:

    • CPX41 (8 vCPU, 16GB) - SFU Server
    • CX22 (2 vCPU, 4GB) - Signaling, API, TURN
  2. Configure DNS in Cloudflare:

    • tradingroom.io → Frontend
    • api.tradingroom.io → Rust API
    • signaling.tradingroom.io → Signaling Server
    • sfu-*.tradingroom.io → SFU Nodes
    • turn.tradingroom.io → TURN Server
  3. Deploy via GitHub Actions (automatic on push to main)

Scaling

  • Horizontal: Add more SFU nodes for increased capacity
  • Load Balancing: AWS ALB or Hetzner Load Balancer
  • Redis Cluster: For high-availability caching
  • Read Replicas: Neon supports read replicas for scale

Monitoring

Health Endpoints

  • GET /health - All services expose health checks
  • Prometheus metrics available at /metrics

Logging

  • Structured JSON logging
  • Aggregation via Loki/Grafana
  • Error tracking via Sentry

Key Metrics

  • WebRTC: RTT, packet loss, jitter, bitrate
  • Business: Active rooms, concurrent viewers, stream hours
  • Infrastructure: CPU, memory, network

Security

  • TLS 1.3 for all connections
  • DTLS/SRTP for WebRTC media encryption
  • JWT authentication with secure token validation
  • Row-Level Security for data isolation
  • Rate limiting on all endpoints
  • Input validation and sanitization

Contributing

  1. Fork the repository
  2. Create feature branch (git checkout -b feature/amazing-feature)
  3. Commit changes (git commit -m 'Add amazing feature')
  4. Push to branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

Proprietary - All rights reserved.

Support

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors