By Maciej Pyrc, who maintains Hype Stack.Published .
A SaaS is six pieces of plumbing and one feature. The plumbing is the same in every product, which is the reason to write as little of it as you can.
Most guides on how to build a saas describe phases: idea, validation, MVP, team. Many are written by agencies, and they end where the sales call begins. They rarely say what the thing is made of.
This page lists the parts a SaaS needs before its first feature, says which to install and which to write, and gives the order to build them in. It assumes you write code, or direct a coding agent that does.
Should you build yet, or prototype first?
How to start a SaaS depends on what you do not know yet. If the open question is whether anyone wants the product, code is a slow way to find out. A waitlist page, a spreadsheet run by hand for five customers, or a prototype from an AI app builder answers it in days and can be thrown away.
Building on a codebase wins when one of these is true:
- Somebody has asked to pay, or already depends on the prototype.
- Your customers are teams, so one company's records must stay invisible to another's.
- You will charge a subscription and gate features by plan.
- You expect to keep changing the product for months, by hand or with an agent.
The six parts a SaaS app needs before its first feature
Each of these exists in nearly every B2B SaaS, and none of them is why a customer signs up.
| Part | What it has to do | Write it yourself? |
|---|---|---|
| Sign-in | Sessions, password reset, OAuth, expired links | No. Use a library or a provider |
| Organizations and roles | A tenant boundary on every table and query, invitations, a role check on every route | Install the mechanism. Decide who the customer is |
| Billing with webhooks | Checkout, plan changes, and a handler that survives retried and reordered events | Install the sync. Write the pricing rules |
| Transactional email | Reset, invitation and receipt emails that reach an inbox | Rent delivery. Keep the templates in the repository |
| An admin app | Look up a user or an organization without a SQL client | No. The first screens are the same in most products |
| A deploy | Apps, database, cache and storage on real URLs, migrations run on each release | Script it once, early |
What you must write is the rest: your domain's tables, the one workflow, and the rules about who may do what and which plan includes what. No starter contains those.
How long the six take from nothing is worked out in SaaS Boilerplate vs Building From Scratch, and the kits that ship them are ranked in Best SaaS Boilerplate 2027.
What to build first: tenancy, then one workflow
The common advice is to build the feature first and add accounts later, because accounts take weeks to write. How to Build a Web App gives that order for a generic app. When sign-in and organizations install in one command the order flips, because tenancy touches every table you add after it.
How to build a SaaS product, in order
Deploy the empty app
Get sign-in working on a real URL before any feature exists. Missing environment variables and wrong OAuth callback URLs show up while there is nothing else to debug.
Decide who the customer is
A person or an organization. For teams, every feature table carries an organizationId, every query filters on it, and the id comes from the session rather than the request.
Hard to change laterBuild one workflow
The thing a customer would pay for, from empty state to result, for a single role.
Add billing when someone agrees to pay
The subscription belongs to whatever step two chose. Wire the webhook before the pricing page: it is what tells the app a payment happened.
Steps one and two are the cheapest to do first and the most expensive to redo. Admin screens, a second role and receipt emails wait until a customer needs them.
A SaaS MVP is six small parts and one workflow
The usual advice on how to build an MVP is to cut features. For a SaaS, cut features and keep the plumbing: without password reset or a tenant boundary it is a demo.
The MVP is done when
- A stranger can sign up, reset a password and sign back in
- Two organizations cannot see each other's rowsSign in as the second organization and request a record from the first by id. Expect the same 404 as a record that does not exist.
- One workflow runs from empty state to result
- One paid plan can be bought and cancelled, and the app learns about both from the webhook
- You can find a customer's account without a SQL client
- One command ships a new version, migrations included
Safe to cut: a second paid plan, custom roles, notifications, a mobile app, and settings pages beyond profile and members.
How to build a SaaS with AI without breaking the plumbing
A coding agent writes features quickly, because a feature is mostly new files. Plumbing is a rule that has to hold in every file, and that is where agents slip.
What changes when an agent writes the code
It copies the nearest pattern
If the repository has one route that reads the organization id from the session, the next forty will too. If it has none, the agent decides again each session, and sometimes it reads the id from the request body.
Plumbing fails without an error
A list endpoint with no tenant filter still returns data. A webhook handler that applies each event as a change works until two events arrive out of order. Neither failure shows up in a demo.
So the six parts should exist before the first prompt, installed rather than generated, and the agent's time goes to the workflow.
The review list for generated routes is in Web App Security Best Practices, and the agent setup itself, from rules files to the MCP server, is in How to Build an App with AI.
What to start from
We build one such starting point. Hype Stack is a TypeScript codebase (React, Hono, Prisma, Postgres) that a CLI scaffolds and you own as source. The Hono Prisma starter walkthrough covers running it locally. For a SaaS, start from the Better Studio template:
npx @hype-stack/cli template better-studioWhat lands in the repository:
- Sign-in, organizations, roles and an admin app from the SaaS starter, a free pack that installs without a license:
email and Google sign-in, password reset, email invitations,
adminandmemberroles enforced by ahasAccessmiddleware, and Users and Organizations screens in a separate admin app. Better Auth SaaS Template lists the tables. - Stripe billing, a paid pack, with one Stripe customer per organization. The handler in
libs/stripe/webhook.tsreads only the customer id from each event, then re-reads the subscription from Stripe, so a duplicate or late event lands on the same state. React Stripe Boilerplate walks through it. - A dashboard layout and a landing page. The glass layout is also a paid pack.
- A deploy command.
npx @hype-stack/cli deploy webcreates the three apps, Postgres, Valkey and a bucket on Fly.io or Railway, and runs migrations as a release step, so a failed migration fails the release.
To pay nothing, run npx @hype-stack/cli compose --packs starter-saas-betterauth,layout-basic instead. Both packs are
free, and billing can wait until step four.
With an agent, add npx @hype-stack/cli@latest mcp install, so that "add billing" becomes an add_packs call that
copies the pack in instead of code written from memory.
What you add that is not ours
- Resend for email delivery. The client is wired, but the account, DNS records and bill are yours, and invitations
and password resets do not send until
RESEND_API_KEYis set. - Stripe and a host. Stripe takes its fees, and Fly.io or Railway bills you for hosting. We host nothing.
- WorkOS, when a customer asks for SSO.
starter-saas-workosis the same starter on WorkOS: free to install, billed by WorkOS.
What you write yourself
- Your domain tables, each with an
organizationId, and the routes and screens of the one workflow. - Permissions past
adminandmember: a subject and its grants inpackages/enums/src/permissions/presets.ts, then ahasAccesscall on the route. - Plan gating. The billing pack knows three plan keys,
free,proandpremier. Which feature each one opens is a check you write.
What is not in the box
There is no product in it. After sign-in the dashboard is an empty shell, and that is the state you start from.
The billing pack maps each paid plan to one Stripe price. Per-seat and metered pricing are not in it, so if you charge
by seat you write that against Stripe's API. The Better Auth starter has no two-factor, passkeys or SAML, and it ships
with requireEmailVerification set to false, which you should review before opening signup. Neither starter adds an
audit log, and product analytics is not included. You run the deploy, the backups and the upgrades, because this is a
codebase and not a hosted service.
Below are the template running, the packs it installs with their tiers, and the command.
The agent side of this build is in How to Vibe Code with Claude.