spec: billing dashboard for operators (draft)
Billing section in the operator console: ARR/MRR, money received from Stripe, per-account earnings against Economics costs, who is paying and why not. Euros throughout; hidden when billing is off.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+308
−0
docs/superpowers/specs/2026-11-09-billing-dashboard-design.md+308 −0
CI passed — run details
diff --git a/docs/superpowers/specs/2026-11-09-billing-dashboard-design.md b/docs/superpowers/specs/2026-11-09-billing-dashboard-design.md| new file mode 100644 |
| index 000000000..a2354c64f |
| --- /dev/null |
| +++ b/docs/superpowers/specs/2026-11-09-billing-dashboard-design.md |
| @@ -0,0 +1,308 @@ |
| +# Billing dashboard for operators |
| + |
| +Status: draft for Paul's read, 2026-11-09. Mockups: the brainstorm |
| +session's `billing-v4.html` (summarised in §5; the mockup is not kept in |
| +the repo). |
| + |
| +## 1. Why |
| + |
| +Carloku has its first paying customer. The operator console can show who |
| +uses the platform (Dashboard, People and accounts) and what it costs to run |
| +(Economics), but nothing shows what it earns, who pays, or whether the |
| +earnings cover the costs. Paul wants one place, very clear, that answers: |
| + |
| +- How much recurring revenue do we have (ARR, MRR), and is it growing? |
| +- How much money actually reached us, and what did Stripe and refunds take? |
| +- Who is paying, who isn't, and why not? |
| +- What does each account earn and cost us, and are we making a profit? |
| +- Who is likely to start paying next? |
| + |
| +It is modelled loosely on Tito Go's fleet dashboard ("Money and machines, |
| +as recorded": a per-day fees page with a per-account table and a single |
| +euro total). |
| + |
| +## 2. Goals, non-goals, anti-goals |
| + |
| +**Goals** |
| + |
| +1. A **Billing** section in the operator rail, with its own pages, and an |
| + entry tile on the main Dashboard. |
| +2. Recurring revenue: ARR and MRR from active subscriptions. |
| +3. Money received: real payments, once-off charges, refunds and Stripe |
| + fees, recorded from Stripe, not modelled. |
| +4. Per-account earnings against per-account costs (costs from Economics), |
| + giving a margin per account and a profit for the platform. |
| +5. A clear split of who is paying and who isn't, with the reason. |
| +6. Everything shown in **euros** (Paul, 2026-11-09). |
| +7. Invisible on any console where billing is off. Self-hosters without |
| + `CARLOS_BILLING` never see the rail item, the tile or the routes. |
| + |
| +**Non-goals (v1)** |
| + |
| +- Replacing the Stripe dashboard: no invoice editing, refunds, disputes or |
| + payouts from here. |
| +- Tax or VAT reporting, accounting exports, CSV. |
| +- Forecasting, cohort retention curves, churn modelling. |
| +- Changing how customers are billed. Nothing here writes to Stripe. |
| + |
| +**Anti-goals** (would make it a failure even if it works) |
| + |
| +- A number that looks exact but is an estimate, without saying so. Every |
| + modelled figure (per-account cost, converted ARR) is labelled as an |
| + estimate where it appears. |
| +- Silently adding up different currencies, or mixing euros and dollars on |
| + one row. |
| +- A total AWS cost that includes things that aren't CARLOS (§4.5). |
| +- A slow page. Pages read the console's own database and bucket only; |
| + nothing calls Stripe, Cost Explorer or a rate source while rendering. |
| +- Showing up on a self-hosted console that never turned billing on. |
| + |
| +## 3. Constraints |
| + |
| +- **Provider-neutral core.** Stripe stays behind the existing billing |
| + adapter (`internal/billing`, `internal/billingstripe`). New payment |
| + records use neutral types in `internal/billing`; the Stripe adapter maps |
| + Stripe objects into them. Same for the AWS bill, which already sits |
| + behind the `billPass` seam. |
| +- **Yearly plans only.** The adapter accepts only `interval=year` |
| + (`billingstripe/adapter.go`). So MRR is ARR ÷ 12, and cash arrives in |
| + yearly lumps. |
| +- **Three selling currencies** (usd, eur, gbp). Billing itself never |
| + converts; this dashboard converts **for display only** and never feeds a |
| + converted figure back into billing. |
| +- **Today the console has no general payment record.** It keeps |
| + subscription state in `billing_accounts`, refreshed by webhook and the |
| + hourly sync; webhooks for `invoice.paid` only trigger a subscription |
| + re-read. The one exception is `domain_purchases`, which keeps amount, |
| + currency and payment intent for domain registrations, but no settled |
| + amount or fee. This design adds the general payment record; domain |
| + purchases feed it like any other once-off payment. |
| +- **Old price books.** Only the configured book is loaded, so a |
| + subscription on an older book has no price in the console. ARR must not |
| + depend on the book (§4.2). |
| +- **Test mode.** Dev runs `CARLOS_BILLING=test`. The pages work there and |
| + say plainly that the figures are Stripe test-mode figures. |
| +- Operator-only, like every `/fleet/*` page (`operatorOnly`). |
| +- UI copy goes through the copy-review gate before it is written. Paul's |
| + bans apply: no em dashes in copy, no coloured left-border accents, no |
| + Bricolage Grotesque. |
| + |
| +## 4. How it works (decided) |
| + |
| +### 4.1 Where it appears |
| + |
| +- New rail item **Billing**, placed directly under Dashboard. Shown only |
| + when billing is on (`s.billing != nil`). `opRailItem` gains a gate for |
| + this (today only `StoreOnly` exists). |
| +- Routes, all registered only when billing is on, otherwise unknown |
| + routes (404) like the rest of the console: |
| + - `GET /fleet/billing`: the overview (§5.2). |
| + - `GET /fleet/billing/accounts`: the full account list (§5.3). |
| + - `GET /fleet/billing/payments`: the full payment list (§5.4). |
| +- Main Dashboard: one extra tile in the existing tile row, **Paying |
| + accounts**, with the count and ARR, linking to `/fleet/billing`. Only |
| + when billing is on. |
| + |
| +### 4.2 ARR and MRR |
| + |
| +- **ARR** is the sum, over **paying** accounts, of what the subscription |
| + will charge for its next year, **after discounts and before tax**. It |
| + includes plan seats and packs. |
| +- **Paying** (my call, from the review): the provider status is `active` |
| + or `past_due`, and at least one payment for the subscription has been |
| + received. `trialing` and `incomplete` (never paid) are not paying. |
| + `billing_accounts.state='paid'` is the entitlement view and covers |
| + trials too, so it is not used on its own. (The `live` column means "the |
| + provider may still collect", not live/test mode; the console's mode |
| + comes from `CARLOS_BILLING`.) |
| +- The amount comes **from the provider at sync time**, not from the price |
| + book: the hourly sync and the webhook re-read already fetch the |
| + subscription, so they also store its yearly amount and currency on |
| + `billing_accounts` (new columns). This covers old books and coupons. |
| +- **House accounts** (100% coupon) therefore contribute 0, correctly. |
| +- An account that has asked to **cancel at renewal** leaves ARR the moment |
| + it cancels (Paul, 2026-11-09), not at the period end. It still shows in |
| + the paying list as "Cancels at renewal". |
| +- A paying account whose renewal is **failing** (`past_due`) stays in ARR |
| + but is counted under "Needs attention". |
| +- **MRR** = ARR ÷ 12. |
| +- **ARR history.** A daily snapshot (date, ARR per currency, ARR in |
| + euros, paying-account count) is written once a day, so ARR over time and |
| + "+€X this month" can be shown. History starts on the day this ships; |
| + older months are rebuilt where the recorded payments allow, otherwise |
| + the chart starts at the first snapshot. |
| + |
| +### 4.3 Money received |
| + |
| +- A new local record of **payments**: each successful charge, refund and |
| + once-off payment, with the provider's id, the account, kind |
| + (subscription, once-off, refund), amount and currency charged, the |
| + **settled euro amount and the provider's fee** (from Stripe's balance |
| + transaction, so the conversion is Stripe's own), and when it happened. |
| +- **Once-off** is any money received that isn't a subscription renewal |
| + or first payment: mid-year charges for packs or seats added, domain |
| + registrations when those switch on, anything else billed outside the |
| + subscription cycle. |
| +- Fed three ways, all idempotent on the provider id: |
| + 1. Webhook events for paid invoices, charges and refunds. |
| + 2. An hourly reconcile that lists the provider's balance transactions |
| + since its last cursor, so a lost webhook never loses money. |
| + 3. A one-time backfill of all history, run automatically the first time |
| + the record is empty, so it needs no operator step. |
| +- **The provider account belongs to this deployment.** Carloku's Stripe |
| + account takes payments for Carloku only (Paul, 2026-11-09), so every |
| + payment in it counts towards the totals and the backfill takes all of |
| + its history. |
| +- A payment whose customer doesn't map to a known account still counts, |
| + and is listed as **Unmatched** so someone can look at it. |
| +- "Net received" = charged − refunds − provider fees, in euros as settled. |
| +- **Tax** (my call, from the review): revenue everywhere on these pages is |
| + **before tax**. VAT and other tax collected is recorded with each payment |
| + and shown as its own column in the money-received table, never counted |
| + as revenue or profit. |
| + |
| +### 4.4 Converting to euros |
| + |
| +- **Money received** uses the provider's settled amount (Stripe's own |
| + conversion into the account's settlement currency). Carloku's settles in |
| + euros. If a deployment's settlement currency is not euros, convert the |
| + settled amount with the daily rate below. |
| +- **ARR, MRR and modelled costs** use a daily reference rate. My call: the |
| + ECB's published daily reference rates, fetched once a day by a console |
| + pass and kept with the date they apply to. Pages show the rate date |
| + ("at ECB rates of 8 Nov") wherever a converted figure appears. |
| +- The native-currency breakdown stays visible next to every converted |
| + total (e.g. ARR tile note: "€24 + $0 + £0"). |
| + |
| +### 4.5 Costs, CARLOS resources only (Paul, 2026-11-09) |
| + |
| +- **Platform cost** is the AWS bill from Economics (`economics/bills/`), |
| + but it must count **only CARLOS resources**, never the whole AWS bill. |
| + Today `billPass` pulls the whole account by service, and `bill.go` notes |
| + both AWS accounts hold non-CARLOS resources. |
| +- Default: the bill pull filters Cost Explorer to resources carrying the |
| + deployment's CARLOS tag (`carlos:deployment=<name>`, already used by |
| + `internal/awsmanaged`), activated as a cost allocation tag. Untagged |
| + CARLOS resources (shared infrastructure made outside the console, such |
| + as buckets and networking from the infra repo) must be tagged for this |
| + to be complete; listing and tagging them is part of the build. |
| +- A deployment whose AWS account holds **only** CARLOS can say so with |
| + one setting, and then the whole account counts. Carloku's account is |
| + CARLOS-only (Paul), so it uses this. |
| +- The page always says which basis it used ("AWS, CARLOS-tagged only" or |
| + "AWS, whole account: CARLOS only"). With neither, the cost figures are |
| + hidden behind a one-line explanation rather than shown wrong. |
| +- **Per-account cost** is Economics' modelled `CostUSD` per account |
| + (`economics.PriceAccount` / `AllocateBox`), converted to euros and |
| + labelled as an estimate. It is not expected to add up to the AWS bill; |
| + the gap (idle boxes, shared overhead) is shown as **Shared and idle**. |
| + |
| +### 4.6 Profit, two views |
| + |
| +**Per-account margin** (my call, from the review): per-account rows |
| +compare the **last complete month**, labelled with its name ("October"): |
| +earns = MRR plus that month's once-off payments less refunds, before tax; |
| +costs = Economics' modelled cost for that month. Month-to-date figures are |
| +not used per account, because a part-month cost against a full-month MRR |
| +misleads. |
| + |
| + |
| +- **Earned** (the steady view): MRR + once-off received − platform cost, |
| + for the same period. For the current month, MRR is pro-rated to the days |
| + elapsed so it compares with the month-to-date AWS bill. |
| +- **Cash** (the bank view): net received − platform cost, per month. |
| +- Both appear; neither is called "the" profit without its label. |
| + |
| +### 4.7 Who isn't paying, and why |
| + |
| +Every account falls in exactly one group, decided in this order: |
| + |
| +| Group | Rule | |
| +|---|---| |
| +| Ours | `planExempt` (the ops account) | |
| +| Paying | §4.2 active subscription with a non-zero amount | |
| +| House | row in `billing_house` | |
| +| Sponsored | `account_plans.source='sponsored'` or a sponsorship (launch sponsorship included) | |
| +| Free | everything else (the catalog's default plan) | |
| + |
| +Free accounts closest to their limits come from `plan_cap_state` |
| +(`used` / `cap_limit`), highest first. |
| + |
| +## 5. The pages |
| + |
| +All lists show at most **5 rows** with a link to the full list. Every row |
| +in every list is **clickable across its whole width** (Paul, 2026-11-09), |
| +not just a name link. |
| + |
| +### 5.1 Dashboard tile |
| + |
| +"Paying accounts": count, ARR in euros, link to Billing. |
| + |
| +### 5.2 `/fleet/billing`, overview |
| + |
| +Top to bottom (as `billing-v4.html`, minus the banner Paul removed): |
| + |
| +1. **Tiles:** ARR (with change this month and the per-currency note), MRR, |
| + Received this month (net), Paying accounts (of all accounts, with |
| + percentage and change), Needs attention (failed payments plus pending |
| + cancellations). |
| +2. **Paying accounts**, newest 5: account, plan (packs and seats under |
| + it), earns a month, costs a month (estimate), margin, renews, status |
| + (Paid, Cancels at renewal, Payment failing). Rows open the account's |
| + page. Link: All paying accounts. |
| +3. **This month, earned** (§4.6) beside **From sign-up to paying**, |
| + counted in accounts (my call): accounts created, accounts with an app, |
| + accounts active in the last 30 days (a person on the account signed in |
| + or something was deployed), paying. |
| +4. **Money received, by month**, last 6 months: subscriptions, once-off, |
| + refunds, Stripe fees, net received, platform cost, cash after costs. |
| + Rows open the payments list for that month. |
| +5. **Recent payments**, latest 5: when, account, what, amount, status. |
| + Rows open the paying account. Link: All payments. |
| +6. **New paying accounts, by week**: bar chart, last 12 weeks. |
| +7. **Not paying, by reason**: one row per group in §4.7 with count, cost |
| + to run and the costliest account. Rows open the Accounts list on that |
| + tab. |
| +8. **Free accounts closest to their limits**, top 5: account, nearest |
| + limit, used. Rows open the account. Link: All. |
| + |
| +### 5.3 `/fleet/billing/accounts` |
| + |
| +Tabs Paying, Free, Sponsored, House, Ours, with counts. Columns: account, |
| +plan, apps, earns a month, costs a month, margin, joined. Sort by earns, |
| +costs, margin, joined, or nearness to a limit. 50 per page. Rows open the |
| +existing account page. |
| + |
| +### 5.4 `/fleet/billing/payments` |
| + |
| +Every recorded payment, newest first, filterable by month and kind |
| +(subscription, once-off, refund, unmatched). Columns: when, account, what, |
| +charged (original currency), net in euros, fee, status. 50 per page. |
| + |
| +## 6. Left to the builder |
| + |
| +- Table and column names, schema migration, and how the payment record is |
| + shaped in `internal/billing`. |
| +- Which Stripe events to subscribe to beyond invoices, charges and refunds, |
| + and the reconcile cursor's shape. |
| +- How the daily rate is fetched and stored, and what the page does on a day |
| + the fetch fails (use the last good rate, and show its date). |
| +- Cost Explorer filter mechanics, and the name of the "CARLOS-only |
| + account" setting. |
| +- Caching (Economics already caches 60 s; the overview may do the same). |
| +- Chart rendering, reusing the Dashboard's bar chart. |
| +- Whether the census (#280) needs an entry for any new bucket writes. |
| +- Copy, through copy review. |
| + |
| +## 7. Done means |
| + |
| +- On flagship (billing live): the Billing rail item and tile appear; the |
| + first customer shows as paying with the right ARR, and their payment |
| + shows with Stripe's fee and the net in euros. |
| +- On dev (billing test): the same, marked as test mode. |
| +- On a console without `CARLOS_BILLING`: no rail item, no tile, and the |
| + routes return 404. |
| +- Killing the webhook for an hour loses no payments (the reconcile catches |
| + up). |
| +- The platform cost matches the CARLOS-only AWS figure, and the page says |
| + which basis it used. |