docs: Music and shared accounts plan (#21)
Plan for T5DE Music and the account and payment changes it needs. Docs only; no code changes. - `docs/music.md`: an IMVU room music bot. The website is music.t5de.dev (at home); streams are radio.t5de.dev (Oracle Cloud's free tier, dhkatz/infra `music-oracle`). Covers one account system with Discord sign-in and basic accounts, the hub as an OIDC provider with Music as its first client, room ownership from linked IMVU accounts, chat commands and permissions, pluggable sources modelled on HorizonRadio's (stations, own streams, YouTube), relayed vs direct streams, and the paid tier (sell the hosting; $1.99 a month per room). - `docs/payments.md`: billing in the hub's API, shared by Music and the hub. Separate merchants per product (adult content needs different processors), processor adapters, entitlements, credits, and selling as an individual. - `README.md`: links to both. Decisions are marked **Decided**; the rest are proposals, with the open ones at the end of each doc. Plan for T5DE Music and the account and payment changes it needs. Docs only; no code changes. - `docs/music.md`: an IMVU room music bot. The website is music.t5de.dev (at home); streams are radio.t5de.dev (Oracle Cloud's free tier, dhkatz/infra `music-oracle`). Covers one account system with Discord sign-in and basic accounts, the hub as an OIDC provider with Music as its first client, room ownership from linked IMVU accounts, chat commands and permissions, pluggable sources modelled on HorizonRadio's (stations, own streams, YouTube), relayed vs direct streams, and the paid tier (sell the hosting; $1.99 a month per room). - `docs/payments.md`: billing in the hub's API, shared by Music and the hub. Separate merchants per product (adult content needs different processors), processor adapters, entitlements, credits, and selling as an individual. - `README.md`: links to both. Decisions are marked **Decided**; the rest are proposals, with the open ones at the end of each doc. Co-authored-by: dhkatz <[email protected]>
This commit was merged in pull request #21.
This commit is contained in:
1 parent
cc6959082c
commit
a66a3a4b6a
3 files changed
+494
-1
No files matched your search
@@ -3,7 +3,8 @@
|
||||
T5DE's hub: accounts linked to IMVU accounts, presence, and (to come) the registry of community products and
|
||||
catalogs, T5DE-hosted rooms, and the moderation console. Part of T5DE (git.t5de.dev/t5de). Design:
|
||||
[docs/design.md](docs/design.md); the API: [docs/api.md](docs/api.md); what a room needs from a server:
|
||||
[docs/imq-rooms.md](docs/imq-rooms.md).
|
||||
[docs/imq-rooms.md](docs/imq-rooms.md); Music and shared accounts (plan): [docs/music.md](docs/music.md), with
|
||||
payments in [docs/payments.md](docs/payments.md).
|
||||
|
||||
## What works
|
||||
|
||||
|
||||
+359
@@ -0,0 +1,359 @@
|
||||
# T5DE Music and shared accounts (plan)
|
||||
|
||||
Status: draft (2026-11-18). Decisions marked **Decided** were agreed in discussion; the rest are proposals. Open
|
||||
decisions are at the end.
|
||||
|
||||
A cheap music bot for IMVU rooms: a bot account sits in the room and takes chat commands, and the room's radio plays
|
||||
a stream we serve for that room. A small paid tier from the start (Paid tier, below). Room owners manage it at music.t5de.dev. People sign in with Discord and link IMVU
|
||||
accounts there without making a T5DE account first; one can be added later without losing anything.
|
||||
|
||||
## Goals
|
||||
|
||||
- **Cheap at scale**: listeners pull audio from a bandwidth-cheap host (Oracle Cloud's free tier to start), never
|
||||
through home or the relay. A paid tier priced near cost, billed through a payments backend shared with the hub
|
||||
(docs/payments.md).
|
||||
- **Three things to play** to start (**Decided**): existing internet radio stations (a searchable list from
|
||||
radio-browser.info), the owner's own stream (bring your own), and a queue of songs found on YouTube. **More
|
||||
sources later** without reworking anything (Sources, below). Jamendo and Audius are out for now: Jamendo's API is
|
||||
free only for non-commercial use, and the paid tier makes this commercial.
|
||||
- **Owners decide who can do what**: which commands, for whom (everyone, chosen IMVU users, the room's moderators,
|
||||
the owner), with cooldowns and bans.
|
||||
- **Sign in with Discord**, IMVU linking without a T5DE account, and a T5DE account later on the same identity.
|
||||
- **T5DE accounts as an OAuth/OIDC provider**, first for our own sites, later for anyone's.
|
||||
|
||||
Non-goals: a client feature (this works for every IMVU user, T5DE or not), and hosting anyone's music files.
|
||||
|
||||
## Overview
|
||||
|
||||
```
|
||||
browser IMVU room (every visitor's client)
|
||||
│ │ plays https://radio.t5de.dev/r/<room>
|
||||
▼ ▼
|
||||
home (t5de-apps) music.t5de.dev ───────────────┐ Oracle Cloud (t5de-music)
|
||||
music web + API + Postgres │ streamer (Go) ◄── sources: stations, own streams,
|
||||
(rooms, permissions, queue, audit) │ ▲ search → yt-dlp/ffmpeg
|
||||
│ OIDC │ │ control
|
||||
▼ └──────► bot (TS, @imvu/bot) ──► IMVU (chat, presence)
|
||||
home (t5de-apps) hub.t5de.dev: T5DE accounts config + events, cached so home being down
|
||||
Discord sign-in, IMVU links, OIDC provider doesn't stop the radio
|
||||
```
|
||||
|
||||
Two planes:
|
||||
|
||||
- **Control plane, at home** (Komodo stack on t5de-apps, like the hub): the music website and its API, with their
|
||||
own Postgres. Small traffic; backups and deploys as for every other stack.
|
||||
- **Data plane, on Oracle** (`domains/t5de/music.tf` in dhkatz/infra): the streamer and the bot. All the bandwidth.
|
||||
It keeps the last config it was given, so the radio keeps playing if home is down; only managing it pauses.
|
||||
|
||||
Hostnames: `music.t5de.dev` for the website (Cloudflare-proxied to the relay, like the hub) and `radio.t5de.dev` for
|
||||
streams (DNS-only, straight to Oracle). The infra branch currently gives music.t5de.dev to the Oracle VM; that moves
|
||||
to radio.t5de.dev. (The 1 GB free VM can't also hold Next.js and Postgres.)
|
||||
|
||||
## Accounts
|
||||
|
||||
### One account system, two front doors (**Decided**)
|
||||
|
||||
Discord sign-in is added to **the hub's** Better Auth, and the music site signs in through it (OIDC). A person who
|
||||
only ever uses Music has a **basic account**: made by signing in with Discord, no username or password, invisible to
|
||||
the hub's community features. Becoming a **T5DE member** later means adding a username and password (and approval,
|
||||
when registration is closed) to that same account.
|
||||
|
||||
On music.t5de.dev the button says "Sign in with Discord". It goes to the hub's authorize endpoint with a hint to use
|
||||
Discord, which redirects straight on to Discord, so the person sees Discord's consent screen and comes back. They
|
||||
never fill in a T5DE form.
|
||||
|
||||
Why not a separate user database in Music, merged with T5DE accounts later:
|
||||
|
||||
- IMVU links would live in two places, and "the most recent proof wins" (design.md, Identity) can't hold across two
|
||||
databases: the same IMVU account could belong to different people in each.
|
||||
- Every later service (more bots, a T5DE-run catalog, others' sites) would repeat sign-in, linking and merging.
|
||||
- The OIDC provider is needed eventually anyway; Music becomes its first client instead of something to migrate.
|
||||
|
||||
The cost: Music's sign-in depends on the hub being up, and the hub gains a second kind of account.
|
||||
|
||||
### Kinds of account
|
||||
|
||||
| | Basic | Member |
|
||||
| --- | --- | --- |
|
||||
| Made by | Discord sign-in (from Music or the hub) | Sign-up with username and password, or a basic account finishing setup |
|
||||
| Sign-in | Discord | Username and password, plus Discord once linked |
|
||||
| IMVU links | Yes (same table, same cap and rules) | Yes |
|
||||
| Hub features (products, catalogs, proxy, rooms) | No: "Finish setting up your T5DE account" | Yes, once approved |
|
||||
| Other sites (OIDC) | Yes | Yes |
|
||||
|
||||
Stored as a column on `user` (`kind: basic | member`); permissions treat basic accounts like unapproved ones on the
|
||||
hub's own routes.
|
||||
|
||||
Email (**Decided**):
|
||||
|
||||
- Better Auth needs one, so a basic account takes Discord's, and only when Discord says it's verified. A Discord
|
||||
account without a verified email can't sign in; the message says to verify it in Discord and try again.
|
||||
- **Never link or merge by matching email.** Better Auth's implicit linking (signing in with a provider whose email
|
||||
matches an existing account adds it to that account) is turned off; check the option's name in 1.7. Discord is
|
||||
linked to an account only from that account's signed-in session. Otherwise anyone who puts a member's address on
|
||||
a Discord account could take theirs over.
|
||||
- Signing in with a Discord account whose email already belongs to a member it isn't linked to: no new account;
|
||||
"This email belongs to a T5DE account. Sign in to it and link Discord from Account."
|
||||
- The email is for account messages only. Music and other clients don't get it unless a later scope asks.
|
||||
|
||||
### Linking Discord to an existing T5DE account
|
||||
|
||||
- **Member links Discord** (Account page) and the Discord account is new to the hub: it's simply added (Better Auth
|
||||
account linking).
|
||||
- **The Discord account already belongs to a basic account**: offer to **merge** it into the member. The basic
|
||||
account's IMVU links move over (the most recent proof wins, so nothing conflicts), the Discord sign-in moves, and
|
||||
the basic account is deleted. The hub tells its OIDC clients (`user.merged {from, into}`, a signed back-channel
|
||||
call) so Music moves rooms and permissions to the surviving account.
|
||||
- Never merge two members automatically; that stays a moderator action (console, audited).
|
||||
|
||||
### IMVU linking
|
||||
|
||||
- Same rules as today (tagline code, link cap, the most recent proof wins), on the hub, for both kinds of account.
|
||||
- Music shows its own linking screens and calls the hub's link routes with the person's access token (scope
|
||||
`imvu:link`), so people link without leaving music.t5de.dev.
|
||||
- The hub's challenge code moves to `@imvu/verify` (imvu.js; the same tagline proof, stateless, already published).
|
||||
Optional, but it removes the hub's own copy.
|
||||
|
||||
### The OIDC provider
|
||||
|
||||
- Better Auth's OAuth 2.1 / OIDC provider plugin on the hub's API, issuer `https://hub.t5de.dev/api/auth` (a separate
|
||||
`accounts.t5de.dev` can come later without changing clients, if the issuer is a config value from day one).
|
||||
Check what Better Auth 1.7 ships and which plugin is current before starting.
|
||||
- Tokens stay Ed25519 JWTs from the existing JWKS (`jwt` plugin).
|
||||
- **First-party clients** (Music now) are configured in code, trusted (no consent screen), and may ask for `imvu`:
|
||||
the real IDs and names of the person's linked IMVU accounts. Music needs real IDs: it acts in IMVU rooms and
|
||||
checks ownership. This is an exception to "Alts stay private" (design.md), limited to T5DE's own services and
|
||||
stated in the privacy text.
|
||||
- **Third-party clients** (later): registered in the console, consent screen, pairwise `sub`, and pairwise IMVU IDs
|
||||
only, as design.md already says for catalogs.
|
||||
|
||||
## Music
|
||||
|
||||
### Repository
|
||||
|
||||
`t5de-music` on git.t5de.dev, set up like the hub (Bun, Turborepo, same release flow, `modules/app-repo` in
|
||||
dhkatz/infra):
|
||||
|
||||
| Path | What |
|
||||
| --- | --- |
|
||||
| `apps/web` | Next.js 16, Tailwind 4, shadcn/ui from `@t5de/ui`: music.t5de.dev |
|
||||
| `apps/api` | Elysia on Bun, Drizzle and its own Postgres: rooms, permissions, queues, audit; the bot's config and events |
|
||||
| `apps/bot` | TypeScript on `@imvu/bot` (imvu.js): joins rooms, reads commands, enforces permissions |
|
||||
| `streamer/` | Go: one station per room, sources, the `/r/<room>` streams (Go like t5de-catalog) |
|
||||
|
||||
Its own database (**Decided**): a Postgres container in Music's stack, as each hub environment has in its own
|
||||
(`stacks/t5de-hub/compose.yaml` in dhkatz/infra), so deploying works as it does now. Music never reads the hub's
|
||||
database: it knows people by their OIDC `sub` and asks the hub's API for anything else. Migrations, backups and
|
||||
restores stay per app, and either can move to another host alone. The cost, no joins across the two, doesn't matter
|
||||
at this size.
|
||||
|
||||
### Rooms and who manages them
|
||||
|
||||
- **Owner**: whoever has linked the IMVU account that owns the room. A room's ID is `<ownerCid>-<n>`, so this needs
|
||||
no call to IMVU, just the person's links (from the `imvu` claim).
|
||||
- **Managers**: people the owner adds on the site (by IMVU username they've linked, or an invite link). They change
|
||||
settings but can't remove the owner or other managers.
|
||||
- Adding a room: pick one of your linked accounts' rooms (paste its link or ID; IMVU can't list a user's rooms), see
|
||||
the stream URL to paste into the room's radio settings, turn the bot on.
|
||||
|
||||
### Chat commands
|
||||
|
||||
| Command | What | Default for |
|
||||
| --- | --- | --- |
|
||||
| `!np` | What's playing | Everyone |
|
||||
| `!play <search>` | Search and queue the first match | Everyone |
|
||||
| `!queue`, `!remove <n>` | Show the queue, remove your own (managers: any) | Everyone |
|
||||
| `!skip` | Skip (vote among listeners for non-DJs, later) | DJs |
|
||||
| `!station <name>` | Switch to a station from the room's list | DJs |
|
||||
| `!stop`, `!resume` | Stop or resume the radio | Room moderators |
|
||||
| `!help` | Whispered list of what you may use | Everyone |
|
||||
|
||||
Levels: everyone, **DJs** (IMVU accounts the owner lists on the site), the room's **IMVU moderators** (read from the
|
||||
room, re-read every few minutes), owner and managers. Each command's level is a setting, plus cooldowns, a per-person
|
||||
queue limit, the longest song allowed, and banned IMVU accounts. The bot checks the sender by IMQ's `user_id`, never
|
||||
the message text.
|
||||
|
||||
### What plays
|
||||
|
||||
- **Stations**: a directory from radio-browser.info (HorizonRadio's `RadioBrowserClient`, ported to Go: mirror
|
||||
discovery, failover). The owner picks the room's list; `!station` switches among them. Now-playing comes from the
|
||||
station's ICY metadata (HorizonRadio's `IcyStreamReader`).
|
||||
- **Own stream**: an Icecast/Shoutcast URL the owner (or a DJ) gives on the site. The bot announces who's on air.
|
||||
- **Search and queue**: tracks found by search, starting with HorizonRadio's YouTube source (yt-dlp search, ffmpeg
|
||||
decode).
|
||||
- **Fallback**: when the queue is empty, the room's default station (or silence), so the stream never ends.
|
||||
|
||||
Each is a source provider (below).
|
||||
|
||||
### Sources
|
||||
|
||||
Modelled on HorizonRadio's source SDK (`HorizonRadio.Sdk/Sources`), in Go:
|
||||
|
||||
- **A provider** (HorizonRadio's source factory) is a Go package registered at startup: an ID, a name, its kind, and
|
||||
a settings schema the site renders as a form (as HorizonRadio's Sources tab does). Optional capabilities are small
|
||||
interfaces the streamer checks for:
|
||||
- `Searcher`: a query to results (track, playlist, album, station), each a **ref**: `{source, locator, title}`.
|
||||
- `Recognizer`: claims pasted links (a YouTube URL, an `.m3u`/`.pls`, an Icecast address), so `!play <link>` and
|
||||
the site's "paste a link" pick the provider by themselves. Only unambiguous ones, as in HorizonRadio.
|
||||
- `Enumerator`: expands a ref into its tracks (a playlist, an album).
|
||||
- `Describer`: names a collection without expanding it.
|
||||
- `Account`: needs an account or API key connected first, for the service or per room.
|
||||
- **Content providers** (YouTube now; later SoundCloud, Jamendo, Bandcamp, owners' uploads) play through the room's
|
||||
queue and can be mixed into playlists. A track is fetched once into a shared audio cache (HorizonRadio's
|
||||
`AudioCache`: whole files only, size-limited, least recently used goes first), already loudness-normalized and in
|
||||
the stream's format.
|
||||
- **Live providers** (radio-browser stations and own streams now; others later) play as one endless item: switched
|
||||
to, not queued, like HorizonRadio's self-driven sources.
|
||||
- **Metadata providers** are separate (MusicBrainz first, as in HorizonRadio): they tidy titles and artists for
|
||||
now-playing and the queue page.
|
||||
- Everything stored keeps refs (queues, playlists, a room's station list, history), so a new provider needs no
|
||||
migration, and a removed one leaves rows shown as unavailable.
|
||||
- Rooms choose which providers they allow; an operator setting turns one off for everyone (for example when YouTube
|
||||
blocks us).
|
||||
- Providers are compiled in. If one ever has to be written in another language, the same capabilities become a small
|
||||
HTTP contract to a sidecar.
|
||||
|
||||
On the free VM, CPU runs out before the network does: re-encoding audio for every room would allow only a few rooms
|
||||
on 1/8 of a CPU. So tracks are encoded once, into the cache (44.1 kHz stereo, constant-bitrate MP3), and playing them
|
||||
only copies frames. Live sources already in a compatible MP3 format pass straight through; the rest are transcoded,
|
||||
a handful at a time.
|
||||
|
||||
### Relayed or direct
|
||||
|
||||
A station or own stream can reach listeners two ways:
|
||||
|
||||
- **Relayed**: the room's radio stays set to our URL (`radio.t5de.dev/r/<room>`), and our streamer plays the station
|
||||
into it. Switching is instant and needs nothing from IMVU, but every listener uses our bandwidth.
|
||||
- **Direct**: the room's radio is set to the station's own URL, so listeners pull from the station and we use no
|
||||
bandwidth. Switching by chat command then means the bot changes the room's radio setting itself.
|
||||
|
||||
Seen in IMVU (2026-11-18): a room's moderators, not just its owner, can change its stream URL and turn it on and off
|
||||
("On Air"). So a bot the owner makes a moderator should be able to do the same, through whatever call IMVU's client
|
||||
makes; phase 0 finds that call. Relayed first; direct per room once the call is known. The bot also turns On Air on
|
||||
when it starts playing, so owners don't have to.
|
||||
|
||||
### Streamer
|
||||
|
||||
- One goroutine per active room: reads frames from the current source, paces them in real time, fans out to
|
||||
listeners with a small ring buffer (instant start; slow listeners are dropped). ICY metadata for now-playing.
|
||||
- MP3 for compatibility (bitrate per room, 96-128 kbps); rooms with nobody listening cost nothing.
|
||||
- Control API on the compose network only: the bot and Music's API call it, never the internet.
|
||||
- Counts listener-hours per room, for Music's dashboard and the 10 TB budget.
|
||||
|
||||
### Bot
|
||||
|
||||
- One IMQ connection per bot account, many rooms each; rooms spread over a few accounts (bot accounts verify their
|
||||
email, per `@imvu/bot`'s README).
|
||||
- Config (rooms, permissions) from Music's API over a WebSocket with a local cache; events back (joined, booted,
|
||||
commands used, errors) for the room's activity page.
|
||||
- Booted from a room: leaves, and tells the owner on the site.
|
||||
|
||||
### Paid tier (**Decided**: sell the hosting)
|
||||
|
||||
What's paid for is the service around the music (quality, capacity, features), never a source. Every source is in
|
||||
both tiers, free with limits:
|
||||
|
||||
- **If YouTube breaks or has to go** (blocked, a takedown, a processor's demand), paid rooms keep everything they
|
||||
paid for, and it's switched off without refunds.
|
||||
- **What the pricing page sells** is music bot hosting, not "pay to play YouTube songs".
|
||||
- **Free YouTube is the trial**: people use it, reach the limits, and upgrade.
|
||||
|
||||
| | Free | Paid ($1.99 a month per room) |
|
||||
| --- | --- | --- |
|
||||
| Rooms | 1 | One subscription per room |
|
||||
| Stations and own streams | Yes (direct where possible, so they cost nothing) | Yes |
|
||||
| YouTube search and queue | Short queue, a few songs an hour | Unlimited queue, longer songs |
|
||||
| Audio | 64 kbps | 128 kbps |
|
||||
| Listeners | A small cap (about 10) | Up to the room's capacity |
|
||||
| Saved playlists, scheduled playback | No | Yes |
|
||||
| Relayed stations (when direct isn't possible) | No | Yes |
|
||||
| Linked rooms | No | An add-on, later |
|
||||
|
||||
The free limits are what keep free YouTube affordable: it's always relayed (bandwidth) and fetched once per track
|
||||
(CPU), unlike direct stations. The bot also leaves free rooms when they're empty. Exact limits are settings, tuned
|
||||
once there's usage to look at.
|
||||
|
||||
Another way to pay, to check: **IMVU credits**, which every IMVU user already has. Buying a product we list in
|
||||
IMVU's shop (a "Music Pass") is the payment, and the bot checks the buyer owns it. No processor at all, but it
|
||||
depends on IMVU's rules for selling services and on how its credits cash out now; both to read before relying on it.
|
||||
|
||||
The paid entitlement is `music.room` with the room as its scope (docs/payments.md, Entitlements). Pricing: about
|
||||
$1.99 a month per room (the most popular community bot starts at $4.99 for one room); on PayPal's micropayments
|
||||
pricing that loses about 19¢ to fees. A yearly price at a discount on top.
|
||||
|
||||
**One stream URL, many rooms.** The stream is plain HTTP, so anyone can paste a room's URL into other rooms (or any
|
||||
player), and they'll all hear it. Only the bot's own room has commands, but every extra listener costs bandwidth,
|
||||
and a paid stream shared this way is a second room for free. So:
|
||||
|
||||
- **Listener cap**: a stream takes at most the room's capacity in listeners, plus a small margin (the bot knows
|
||||
capacity and who's there). A stream with far more listeners than its room has people is being played elsewhere,
|
||||
and shown so on the room's page.
|
||||
- **Rotating URLs**, once the bot can set the room's radio (phase 0): the room's URL carries a token the bot
|
||||
replaces every day or so; the old one keeps working for a while, then stops, so copies elsewhere die out.
|
||||
- **Linked rooms** as a feature later: one stream played in several rooms on purpose (a club with more than one
|
||||
room), with the bot in each and the cap set from their total capacity.
|
||||
|
||||
Bandwidth cost per room, for the price: at 96 kbps, 10 listeners for 8 hours a day is about 100 GB a month, free
|
||||
within Oracle's 10 TB and about 90¢ past it at Oracle's rate ($0.0085/GB). Busy relayed rooms past the free tier
|
||||
need an unmetered host, not a higher price.
|
||||
|
||||
### Website
|
||||
|
||||
Pages: home (what it is, how to add it), sign in, my rooms, and for each room: overview (status, now playing,
|
||||
listeners, the stream URL), what plays (stations, own stream, queue), commands and permissions, DJs, managers and
|
||||
bans, activity. Account: Discord, IMVU links, and "Make it a T5DE account" (goes to the hub).
|
||||
|
||||
Same look as the hub and t5de.dev (neutral, light/dark following the system, color only for status, short copy,
|
||||
Title Case headings), the same header and footer ("unofficial: not made by or affiliated with IMVU").
|
||||
|
||||
## Shared code
|
||||
|
||||
| Package | From | Used by |
|
||||
| --- | --- | --- |
|
||||
| `@t5de/ui` | the hub's `components/ui`, `globals.css`, header and footer shell | hub web, t5de-site, Music web |
|
||||
| `@t5de/auth` | new: OIDC sign-in for T5DE's Next.js sites (redirect, callback, session cookie, refresh, `getMe`) | Music web, later t5de-site |
|
||||
| `@imvu/verify` | imvu.js (published) | hub (IMVU linking) |
|
||||
| `@imvu/bot`, `@imvu/client` | imvu.js (published) | Music bot |
|
||||
|
||||
`@t5de/*` packages go to git.t5de.dev's npm registry (Gitea has one; the image registry is already there), built and
|
||||
published by CI like images. t5de-site moves from its copies to `@t5de/ui` when convenient.
|
||||
|
||||
## Risks
|
||||
|
||||
- **Licensing**: songs played on request are interactive streaming, which internet-radio licenses don't cover, and
|
||||
charging for it makes it commercial. Relaying stations and owners' own streams is the safest part. Search providers
|
||||
stay pluggable, so a licensed one can replace or join YouTube.
|
||||
- **Payment processors**: Stripe and the merchants of record forbid selling services that infringe copyright, and
|
||||
review what they're selling. A paid service built on YouTube's audio can get the merchant account closed, with
|
||||
funds held. Music's merchant account is kept separate from T5DE's (docs/payments.md), so that can't take the hub's
|
||||
payments with it.
|
||||
- **YouTube from a datacenter**: yt-dlp from cloud IPs is often blocked ("confirm you're not a bot") and needs a
|
||||
token provider, a JavaScript runtime and sometimes an account's cookies; it's also against YouTube's terms. Paying
|
||||
users will expect it to work, so the operator setting that turns it off, and the status page, matter more.
|
||||
- **IMVU**: bot accounts can be flagged or banned; per-account room limits and long-run behaviour are untested
|
||||
(imvu.js ROADMAP.md, "Still open").
|
||||
- **Free tier**: Oracle reclaims idle free VMs (upgrade the account to Pay As You Go); 10 TB a month is about 300
|
||||
listeners on average at 96 kbps.
|
||||
|
||||
## Phases
|
||||
|
||||
0. **Check the assumptions** (days): IMVU's room radio plays an HTTPS MP3 stream from our host; which call sets a
|
||||
room's radio, and whether a moderator bot may make it (direct mode; reading room data needs a signed-in session,
|
||||
and the test account's cached one has expired); one bot account in ~20 rooms for a few hours. The Oracle VM up
|
||||
(dhkatz/infra `music-oracle`, with the rename to radio.t5de.dev).
|
||||
1. **Accounts** (hub): Discord sign-in, basic accounts, the OIDC provider with Music as a trusted client and the
|
||||
`imvu` scope, link routes that take access tokens. `@t5de/ui` extracted, hub web on it.
|
||||
2. **Music, managing** (t5de-music): repo and CI, web and API, sign-in, rooms and ownership, managers, permissions,
|
||||
DJs, bans, the stream URL. Infra: its stack and Postgres on t5de-apps, music.t5de.dev.
|
||||
3. **Music, playing**: streamer with stations (relayed) and own streams, the bot with commands and permissions,
|
||||
config sync. **Beta** (free tier).
|
||||
3b. **Payments** (hub, docs/payments.md phases 1-2): entitlements, Music's processor, checkout; the paid tier.
|
||||
4. **Search and queue**: content providers and the audio cache, the YouTube provider from HorizonRadio, MusicBrainz
|
||||
metadata, `!play`, the queue page. (Phase 3's stations and own streams are already live providers.)
|
||||
5. **Accounts, later**: merging basic into member accounts, `user.merged`, third-party OIDC clients (console,
|
||||
consent, pairwise IDs).
|
||||
|
||||
## Open decisions
|
||||
|
||||
- The free tier's exact limits, and the yearly price (Paid tier, above).
|
||||
- Direct mode's details, once phase 0 has found the call that sets a room's radio and On Air.
|
||||
@@ -0,0 +1,133 @@
|
||||
# Payments (plan)
|
||||
|
||||
Status: proposal for review (2026-11-18). Nothing here is **Decided** yet; open decisions are at the end.
|
||||
|
||||
Paid offerings for Music now (docs/music.md, Paid tier) and for the hub later, through one billing backend. More
|
||||
than one payment processor from the start, because T5DE has adult content and the mainstream processors forbid it,
|
||||
while Music has none.
|
||||
|
||||
## Goals
|
||||
|
||||
- **One place** for prices, subscriptions and what people have paid for, keyed by the T5DE account (basic or member:
|
||||
someone who only uses Music can pay).
|
||||
- **Several processors**, chosen per merchant, behind one interface: switching one touches no app.
|
||||
- **No card data** anywhere of ours: hosted checkout pages and portals only.
|
||||
- **Apps ask one question**: does this account have entitlement X (for room Y)? They never talk to a processor.
|
||||
|
||||
## Where it lives
|
||||
|
||||
In the hub's API, next to accounts (a module, `billing`), because the customer is the account. It moves with
|
||||
accounts if they're ever split out (`accounts.t5de.dev`, docs/music.md). Apps reach it through the hub's API with the
|
||||
person's access token, and the hub tells them about changes over the same signed back-channel as `user.merged`.
|
||||
|
||||
```
|
||||
music.t5de.dev ──checkout──► hub API (billing) ──hosted checkout──► processor (Stripe for Music)
|
||||
▲ │ ▲ │
|
||||
└── entitlement.changed ──┘ └──────────── webhooks ◄─────────────────┘
|
||||
```
|
||||
|
||||
## Concepts
|
||||
|
||||
| | What |
|
||||
| --- | --- |
|
||||
| **Merchant** | Who sells, with its processor account: `music` and `t5de`. Products belong to one merchant and never mix, so a processor that bans adult content only ever sees Music's sales, and one merchant account being closed can't take the other's payments with it. |
|
||||
| **Product, price** | What's sold and for how much (`music.room`, yearly). |
|
||||
| **Customer** | An account at one merchant's processor: `(account, merchant) → processor customer ID`. |
|
||||
| **Subscription** | Mirrored from the processor: status, period end, cancel at period end. |
|
||||
| **Payment event** | Every webhook, kept as received. Unique by `(processor, event ID)`, so a replay changes nothing. |
|
||||
| **Entitlement** | What apps check: `{account, key, scope, from, until, source}`, e.g. `music.room` scoped to a room. Made from subscriptions, from moderators' grants (gifts, testers; console, audited) and later from codes. |
|
||||
|
||||
Processing a webhook doesn't trust its order: it fetches the subscription's current state from the processor and
|
||||
recomputes that account's entitlements from it. Late, repeated or reordered events then all end in the same place.
|
||||
|
||||
## Processor adapters
|
||||
|
||||
```ts
|
||||
interface Processor {
|
||||
checkout(customer, price, scope, returnURL): Promise<{ url: string }>;
|
||||
portal(customer, returnURL): Promise<{ url: string }>;
|
||||
cancel(subscription, { atPeriodEnd: boolean }): Promise<void>;
|
||||
refund(payment, amount?): Promise<void>;
|
||||
// Verifies the signature and maps the processor's event to ours.
|
||||
webhook(request): Promise<BillingEvent | null>;
|
||||
subscription(id): Promise<SubscriptionState>;
|
||||
}
|
||||
```
|
||||
|
||||
Webhooks arrive at `POST /api/v1/billing/webhooks/<processor>` on the hub's API. Processors retry for days, so a hub
|
||||
outage only delays them.
|
||||
|
||||
## Processors
|
||||
|
||||
| Merchant | Candidates | Notes |
|
||||
| --- | --- | --- |
|
||||
| `music` | **Stripe** directly | 2.9% + 30¢ (US cards). We are the seller: sales tax and VAT are ours (Stripe Tax calculates; registering and filing are ours). EU VAT on digital services applies from the first sale to an EU consumer. |
|
||||
| | **PayPal** (business account, micropayments pricing) | 4.99% + 9¢ once opted in (it applies to the whole account; standard is 3.49% + 49¢), so the cheapest for small charges, and familiar to buyers. We are the seller, as with Stripe. Same rules against infringing goods; known for sudden limits, funds held up to 180 days, and disputes that favour buyers of digital goods. Goods and services payments only, never friends and family. |
|
||||
| | A **merchant of record** (Paddle, Polar, Stripe Managed Payments, which absorbed Lemon Squeezy) | About 5% + 50¢. They're the seller and handle tax everywhere. They review what they sell before onboarding, and a YouTube-based music service may not pass. |
|
||||
| `t5de` | **Adult-friendly processors** (CCBill, Segpay, Verotel, Epoch) | Around 10-15% plus reserves, quoted per merchant. Their own content and age-verification rules (the hub's age checks help); read them before building anything adult that's paid. |
|
||||
| | Crypto (self-hosted BTCPay Server) | No processor fees; an extra option, not the only one. |
|
||||
|
||||
## Pricing near cost
|
||||
|
||||
Card fees are mostly the fixed part, so small charges lose a lot:
|
||||
|
||||
| Charge | PayPal micropayments (4.99% + 9¢) | Stripe (2.9% + 30¢) | Merchant of record (5% + 50¢) |
|
||||
| --- | --- | --- | --- |
|
||||
| $1 a month | 14¢ (14%) | 33¢ (33%) | 55¢ (55%) |
|
||||
| $10 a year | 59¢ (6%) | 59¢ (6%) | $1.00 (10%) |
|
||||
| $5 of credits | 34¢ (7%) | 45¢ (9%) | 75¢ (15%) |
|
||||
|
||||
So: a yearly price (about $10 a room), or credits bought in $5 steps that pay $1 a month per room. A real $1 a month
|
||||
only works on PayPal's micropayments pricing.
|
||||
|
||||
### Credits
|
||||
|
||||
Credits change the fees, not who will process them: processors approve what credits are spent on, so a processor
|
||||
that won't sell Music's paid tier won't sell credits for it either. If we sell them:
|
||||
|
||||
- **Per merchant**: Music's credits are spent only on Music. Credits usable in the hub too would put T5DE's sales
|
||||
through Music's processor (or the reverse), which undoes the separation above.
|
||||
- **Never transferable or cashable**: credits that move between people or turn back into money start to look like
|
||||
money transmission.
|
||||
- **No expiry, and refunds of unspent credits on request**: some US states treat expiring prepaid balances like gift
|
||||
cards, and EU buyers have withdrawal rights. A ledger (bought, spent, refunded) per account, not a balance column.
|
||||
|
||||
### Selling as an individual
|
||||
|
||||
- No company is needed to start: Stripe and the merchants of record accept individuals (sole proprietors), with a
|
||||
tax ID (SSN in the US) and a bank account. Income goes on a personal return (Schedule C in the US), with
|
||||
self-employment tax on the profit.
|
||||
- **With Stripe directly** we are the seller: the receipts show a business name (a trade name, which some states
|
||||
require registering as a DBA), and EU sales legally need the seller's name and address shown.
|
||||
- **With a merchant of record** the merchant of record is the seller: buyers see its name, and it handles tax
|
||||
everywhere.
|
||||
- A single-member LLC later: state filing fees vary widely (some states also charge a yearly minimum tax), plus a
|
||||
free EIN and a registered agent to keep a home address off public records. It shields personal assets from the
|
||||
business's debts and contracts, but not from claims about what its owner did personally, such as infringement.
|
||||
- An hour with an accountant before the first sale; this section isn't tax or legal advice.
|
||||
|
||||
## Lapses, refunds and chargebacks
|
||||
|
||||
- A failed renewal gets a grace period (7 days), then the room drops to the free tier. Nothing is deleted.
|
||||
- A refund or chargeback ends the entitlement at once. Repeated chargebacks: no new checkouts for that account.
|
||||
- Every grant, refund and revocation is in the audit log.
|
||||
|
||||
## Phases
|
||||
|
||||
1. **Entitlements without money**: tables, moderators' grants in the console, the back-channel to Music, and
|
||||
Music's paid features behind `music.room`. Lets the paid tier be tested and given away before anyone pays.
|
||||
2. **Music's processor**: the adapter, checkout, webhooks, a Billing page under Account on the hub, links from Music.
|
||||
3. **T5DE's processor**, when the hub has something to sell.
|
||||
4. **Credits and codes**; a merchant of record if tax work grows.
|
||||
|
||||
## Before taking money
|
||||
|
||||
Terms of service with a refund policy, a privacy policy, and the accountant's hour (Selling as an individual, above).
|
||||
|
||||
## Open decisions
|
||||
|
||||
- Music: PayPal (cheapest for $1 charges, what the popular community bot uses), a merchant of record (it's the
|
||||
seller and handles tax; a refusal at onboarding costs nothing), Stripe directly, or IMVU credits (docs/music.md,
|
||||
Paid tier). Several can run side by side behind the adapter interface.
|
||||
- Yearly price or credits for the paid tier.
|
||||
- Whether the Billing page lives only on the hub, or Music also shows its own subscriptions.
|
||||
Reference in new issue
Block a user