> ## Documentation Index
> Fetch the complete documentation index at: https://docs.streamly.watch/llms.txt
> Use this file to discover all available pages before exploring further.

# Platform Architecture

> How Streamly’s operator admin, viewer storefront, tenant branding, and Supabase control plane fit together.

Streamly is **one Next.js application** with host-aware routing. The same deploy serves the operator console, viewer storefront, marketing/legal pages, and `/api/v1` tenant APIs.

## High-Level Layout

```
Browser
  ├─ Platform host (e.g. streamly.watch)
  │    ├─ /admin/*          Operator console
  │    ├─ /dashboard/*      Tenant-owner console
  │    ├─ /site/*           Platform marketing (pretty URLs rewrite here)
  │    └─ storefront        Default / brand tenant
  └─ Tenant host (slug.streamly.watch or custom domain)
       └─ Viewer routes     Catalog, watch, account, profiles

Supabase
  ├─ Auth (viewer + operator cookie scopes)
  └─ Postgres + RLS (control plane, catalog, billing, plugins)
```

## Surfaces

### Operator (`/admin`)

System-operator console for the purchase/license holder. Sidebar items come from `lib/operator/nav.ts` — Overview, Users, Subscriptions, Plans, Catalog, Addons, Brand & Experience, Themes, Posts, Plugins, Settings.

See [Admin Dashboard Overview](/admin-dashboard/overview).

### Viewer storefront (`app/(viewer)/`)

Public OTT routes: home, browse, movies/shows, title detail, watch, live, pricing, account, profiles. Look is driven by the **active theme package** (`templateEntry`) and Brand & Experience config — not by forking routes per theme.

See [Storefront Overview](/viewer/storefront-overview).

### Marketing & legal

* Platform host pretty URLs (`/about`, `/terms`, …) rewrite to `/site/*`.
* Tenant-branded landing content also exists under `app/(landing)/`.
* Legal markdown is **bundled at build time** for Cloudflare Workers (no runtime `fs`).

See [Legal & Marketing Pages](/viewer/legal-and-marketing).

### APIs

| Prefix                   | Role                                                              |
| ------------------------ | ----------------------------------------------------------------- |
| `/api/v1/*`              | Tenant-scoped product API (catalog, billing checkout, domains, …) |
| `/api/operator/*`        | Operator branding, themes, plans, settings                        |
| `/api/admin/*`           | Activation, onboarding, health checks                             |
| `/api/webhooks/stripe`   | Stripe webhooks                                                   |
| `/api/internal/jobs/run` | Cron jobs (`STREAMLY_CRON_SECRET`)                                |
| `/api/docs`              | OpenAPI reference                                                 |

## Tenant Resolution

Host → tenant via `lib/streamly/tenant-context.ts`:

| Host pattern                                | Resolution                                        |
| ------------------------------------------- | ------------------------------------------------- |
| Platform host / localhost / `*.workers.dev` | Brand / default tenant                            |
| `{slug}.streamly.watch`                     | Tenant by slug                                    |
| Custom hostname                             | `tenant_domains` (+ optional Cloudflare for SaaS) |

Reserved platform hosts include `streamly.watch`, `www`, `admin`, `app`, `api`.

## Themes & Branding Architecture

1. Theme packages live under `themes/<id>/` (`theme.json`, `config.ts`, `skin.ts`, template).
2. One route tree; skins via `templateEntry` → `StorefrontThemeProvider` / `getStorefrontSkin`.
3. HTML sets `data-storefront-theme` so CSS chrome stays isolated per theme.
4. Per-theme look memory: `theme_presets[themeId]` inside landing config.
5. Preview: `/?__theme_preview=<themeId>` (operator-only, in-memory).

Deep dive: [Themes & Skins](/viewer/themes-and-skins), [Themes Package System](/technical/themes-package-system).

## Data Plane

All durable state is in Supabase. Apply every file in `supabase/migrations/` in numeric order — there is **no** single `schema.sql`. See [Database Schema](/technical/database-schema).

## Deploy Targets

| Target             | Path                                                                      |
| ------------------ | ------------------------------------------------------------------------- |
| Node 20+           | `pnpm run build` + `pnpm run start`                                       |
| Docker / OCI       | Included `Dockerfile`                                                     |
| Cloudflare Workers | `pnpm run deploy:cloudflare` (OpenNext) — production for `streamly.watch` |

## Related

* [What is Streamly?](/introduction/what-is-streamly)
* [Roles Overview](/introduction/roles-overview)
* [Folder Structure](/technical/folder-structure)
* [Cloudflare Workers](/technical/cloudflare-workers)
