Architecture Diagram

Streamix is a single Next.js application plus two optional background processes. This page shows the pieces and how a request, a stream and a video upload move through them.

System context

TEXT
                         ┌──────────────────────────────┐
  Members (browser) ───▶ │  Next.js app                 │ ───▶ PostgreSQL (Neon / Postgres)
  Admins  (browser) ───▶ │  · storefront  (site)        │
                         │  · admin       (admin/panel) │ ───▶ Email (SMTP / add-on)
                         │  · REST API    (/api/v1)     │ ───▶ Payment gateways (PayPal, add-ons)
                         │  · installer, docs           │ ───▶ Web push services (VAPID)
                         └──────────────┬───────────────┘
                                        │ presigned URLs, public URLs
                                        ▼
                         ┌──────────────────────────────┐
  Browser uploads ─────▶ │ S3-compatible bucket (+ CDN) │ ◀──── Transcode worker (ffmpeg)
  Player fetches  ◀───── │ artwork · MP4 · HLS · VTT    │        reads/writes DB + bucket
                         └──────────────────────────────┘
                                        ▲
  Scheduler (Vercel Cron / cron job) ──▶ /api/v1/cron (hourly)

Application layers

TEXT
src/app/(site)/**        Server components: landing, browse, title, watch, account, help
src/app/admin/(panel)/** Admin screens (server shell + client managers)
src/app/api/v1/**        Route handlers (auth → validate → scoped SQL → ok/err)
        │
        ▼
src/lib/ott/*            Streaming domain: catalog, profiles, playback, account,
                         renewal, recommendations, lifecycle, transcode, tracks, settings
src/lib/*                Platform: db, auth, billing, r2 (storage), mailer, i18n,
                         rate-limit, secrets, notify, web-push
src/core/*               Pluggable seams: payments, channels, adapters, plugins, install
src/product/*            This product's config: admin nav, add-ons, install profile, emails
        │
        ▼
PostgreSQL               Tables created by ensure*Schema() on first use

Browse request

TEXT
GET /browse
  └─ middleware: locale, x-pathname
  └─ page (server component)
       ├─ getViewer()  → member session cookie → active profile cookie (validated)
       ├─ billboard(viewer, "home")
       ├─ pageRows(viewer, "home")  → first rows rendered on the server
       └─ render OttShell + Billboard + TitleRows
  └─ client scrolls → GET /api/v1/browse/rows?cursor=… for more rows
  └─ hover a card → title details prefetched; click → ?jbv=<title> modal

Every catalogue query applies the same visibility filter: published, inside the availability window, within the profile's maturity level, not blocked, allowed in the viewer's country.

Playback flow

TEXT
/watch/[slug]
  ├─ server: playbackFor(viewer, slug)
  │     ├─ entitlement: live subscription? plan limits
  │     ├─ title/episode checks: maturity, availability
  │     └─ source: capped HLS master (if transcoded) or MP4/HLS URL, tracks, markers, resume
  ├─ client Player
  │     ├─ POST /api/v1/playback/session   → 409 if screens are full
  │     ├─ hls.js / native HLS / MP4 from the bucket URL
  │     ├─ PATCH /api/v1/playback/session  every ~30 s (410 = stopped elsewhere)
  │     ├─ POST  /api/v1/playback/progress every ~10 s and on exit
  │     └─ sendBeacon /api/v1/playback/session-end on tab close
  └─ post-play: next episode countdown or recommendations

Media bytes never pass through the app server; the browser fetches them from the bucket or CDN.

Upload and transcode flow

TEXT
Admin → Titles → video field
  ├─ POST /api/v1/admin/upload/presign → presigned PUT URL
  ├─ browser PUT file → bucket (ott/…)
  ├─ save title/episode → video_assets row (MP4: transcode_status = queued)
  └─ transcode worker (npm run worker:transcode, on a VM/container)
        ├─ claim job (FOR UPDATE SKIP LOCKED, 10-min lease)
        ├─ download source → ffprobe → ffmpeg HLS ladder + sprite + thumbnails.vtt
        ├─ upload to ott/hls/<asset id>/<version>/
        └─ set hls_url, renditions, transcode_status = ready

Billing flow

TEXT
/signup/planform → /checkout/[plan]
  ├─ POST /api/v1/checkout/quote          (display price, coupon check)
  ├─ POST /api/v1/checkout/subscription   (server computes amount; pending subscription + transaction)
  ├─ payment driver: redirect (PayPal, gateway add-ons) or offline (bank, cash)
  ├─ /checkout/return → POST /api/v1/checkout/verify (capture with provider → active)
  └─ renewal: /account/membership/renew → POST /api/v1/checkout/renew → verify → extend
Hourly cron: reminder at T-7 days · active→on_hold at expiry · on_hold→expired after 30 days

Configuration sources

Source Holds
.env DATABASE_URL, JWT_SECRET, SECRET_KEY, CRON_SECRET, site URL
integration_connections (encrypted) Storage, payments, email, SMS, social, captcha, analytics and other add-on credentials
settings table Streaming settings, landing copy, general settings, web-push keys
Theme and app settings tables Branding, colours, fonts, menus

Deployment shapes

Shape Web app Cron Transcode worker
Vercel + Neon + R2 Vercel Vercel Cron (vercel.json) Separate VM/container, or none (MP4 only)
Single VM next start behind nginx/Caddy system cron + curl Same VM (CPU permitting) or a second one
Containers App container(s) Scheduler job Worker deployment, scale by replicas

© CreativeCape Solutions · creative-cape.com · support@creative-cape.com