Module unit
Self-serve signup, idempotent tenant provisioning, and credit-based billing on Stripe.
Overview · Modules · Signup and Billing
What it is
Signup and billing is the module that turns a stranger into a tenant and keeps that tenant's commercial state true. It owns two things: the public self-serve signup path on the user lane, and credit-based billing on Stripe. Identity itself is not ours to build; Clerk owns authentication and organization membership, and this module listens to the identity provider's webhook to provision the tenant on our side. Provisioning is idempotent by design, because webhooks retry and a retried event must never mint a second tenant. A newly provisioned tenant is born with a default module policy, so there is no window in which a fresh account exists with an undefined shape.
On the billing side we deliberately keep the module thin. Stripe, as the billing processor, owns plans, payment collection, and the customer portal; our side records the business facts that fall out of those interactions and feeds them to the rest of the platform. What we keep in our own hands are the rules that are product decisions, not payment mechanics: credits as the unit of consumption, downgrades deferred to the end of the paid period so a customer never loses mid-period what they paid for, and a billing pause switch that lets us run a surface dark, exercising the whole path without charging anyone.
The questions it answers
Scope and boundaries
In scope: the self-serve signup path, idempotent tenant provisioning from the identity provider's webhook, the default module policy applied at birth, credit-based plan state, deferred downgrades, and the billing pause switch. Out of scope: authentication and membership (the identity provider owns those), entitlement resolution (the entitlements-and-config unit resolves what a tenant may do, fail-closed, at one choke point; this module only supplies the commercial facts that resolution reads), and everything downstream of a tenant existing.
It is not an identity system, not an entitlement engine, and not a revenue analytics surface. It does not decide what a plan permits; it records what plan a tenant is on and lets the configuration kernel and entitlement resolution turn that into permitted behavior.
Withheld by design Tier 3
Commercial terms are withheld by design: prices, plan names, coupon structure, and margins are held at Tier 3.The contract
What it is responsible for, the commands its write door accepts, the facts it announces, what it guarantees, and what it refuses. Fields, schemas, and payloads are held at Tier 2.
One write door, a small set of commands named by the business action, covering the provisioning of a tenant, the lifecycle of its subscription and plan, and the billing pause switch.
There is no command for editing entitlements, moving deals, or touching another module's data, because those are not this unit's business actions. Like every module, the door is the only way in: human surfaces and the agent use the same commands, under the same rules.
Withheld by design Tier 2
The roster and the shapes are held at Tier 2.Events carry identity plus the fact, never a data dump. In plain words, the unit announces that a tenant was provisioned, that a subscription's state changed, and that billing was paused or resumed. The event roster is held at Tier 2.
Other modules react to these facts through their own doors. Nothing subscribes to this unit's tables, because no module reads another module's tables.
What done means
Done for this unit is not "signup works on the happy path". Done is the set of properties below holding under the cases that would break them, proven by real tests and by the live surface holding up against the real backend in its loading, empty, error, and content states.
Withheld by design Tier 2
The gate descriptions are here; their concrete test inventories are held at Tier 2.Where it connects