One-time payment, perpetual commercial licence · Full source code
A Next.js 16 + PostgreSQL starter for multi-tenant B2B SaaS — with the hardening tests included.
Organizations, PostgreSQL RLS, RBAC, invitations, Stripe billing, API keys, usage limits and audit logs — already wired. Ships with nine executable hardening suites that exercise defined failure modes against a real PostgreSQL database.
49% of the Pro plan limit (50,000 requests / month)
API requests - last 7 days
illustrative
MonThuSun
Storefront relaunchAcme Retailactive
Loyalty portalAcme Retaildraft
illustrative sample data - the shipped dashboard reads your live PostgreSQL database
01 · Who it's for
Built for people starting a B2B SaaS.
Not a framework, not a course — a working multi-tenant foundation for teams that would rather build their product than their tenancy layer.
01
You're starting a multi-tenant B2B SaaS
You have the product idea and early users asking for team features. You don't want to spend the next month hand-rolling organizations, invitations and RLS — you want them wired end-to-end, with the boundaries verified by executable tests.
02
You're a studio shipping client SaaS
One license covers unlimited projects for you and your clients. Start every engagement from a tenant-isolated, Stripe-ready foundation instead of an empty repo — and hand over code the client can audit.
03
You take tenant boundaries seriously
You've read the RLS docs, so you know “RLS enabled” and “RLS verified” are different claims. The nine hardening suites exist so you can check the second one yourself — in a dedicated test environment, against the included implementation.
02 · What's included
The foundation B2B SaaS needs on day one.
Every piece of multi-tenant infrastructure a B2B product needs before its first paying customer — already connected, already migrated, already tested.
Agency Project Hub: clients, projects, tasks, project members
Plan entitlements enforced at the database level
The adversarial hardening suite itself
Full source code + documentation
03 · The hardening suite
Nine suites. Every row is a shipped test file.
Not a test count — the actual failure modes. Every row below is an executable test file that ships in tests/hardening and runs against a real PostgreSQL database in a dedicated test environment — actual migrations and RLS policies, not mocks.
tests/hardening — 9 filesnpm run test:hardening
Cross-tenant isolation
cross-tenant-isolation.test.ts
attacks: Cross-organization reads and writes, tampered IDs, cross-project access.
SECURITY DEFINER boundaries
security-definer-boundaries.test.ts
attacks: Privileged functions being tricked into acting across tenants.
RBAC privilege escalation
rbac-privilege-escalation.test.ts
attacks: Members promoting themselves; role changes constrained at the database level.
Executable, not aspirational. Nine executable hardening suites exercise defined failure modes in the included implementation against real PostgreSQL. You can inspect the tests, run them in a dedicated, disposable test environment, and adapt them as your application evolves.
npm run test:hardening
The same suite that found these bugs ships with the product. Run it in a dedicated, disposable test environment as your schema and policies evolve.
04 · Four real findings
Found by attacking our own app.
Not theoretical vulnerabilities from a checklist — four bugs that existed in this very codebase, in exactly the places multi-tenant SaaS breaks. Three were caught by the hardening suite; one by a manual security review and then covered by a regression test.
bug_01security-definerfixed · regression-tested
Cross-tenant SECURITY DEFINER
RLS was enabled. But a privileged SECURITY DEFINER function used to record usage ran with elevated rights and trusted a client-supplied tenant identifier — without independently verifying that the caller owned that tenant. A bug in the one code path that bypasses RLS.
Stripe re-delivers events, and delivery order is not guaranteed. An out-of-order event could overwrite newer subscription state with older state — downgrading a customer who had already upgraded.
A webhook processing attempt that failed partway left the event recorded as already seen. When Stripe retried — exactly as designed — the retry failed because the event record already existed. The recovery path itself was broken.
The subscriptions table was client-writable: an organization owner could insert a paid-plan row through the REST API and grant themselves Pro without paying. Entitlement now flows only through the service role — webhook writes, read-only clients.
All four findings were fixed. The three automated findings are covered by the hardening suite; the fourth has regression coverage added after manual discovery.
05 · Evidence
Read the actual code before you pay.
Three excerpts from the package: a fix migration with its authorization helper, the webhook ordering guard, and one of the nine hardening tests. No mockups — this is the shipped source. Nothing on this page is independently audited; it's our code, our bugs and our tests, shown so you can judge the engineering first.
drizzle migrations 0009 + 0010 — excerpt
The Bug 01 fix: the org id is an argument, but membership is verified server-side — the helper compares the caller's auth.uid() from the JWT against organization_members. Supplying another tenant's org id fails the check.
drizzle migrations 0009 + 0010 — excerptsql
-- migration excerpt (usage RPC security fix)
-- FIX 1: Tenant Authorization
-- Verify the caller is a member of the organization they are reporting usage for.
IF NOT public.is_organization_member(p_org_id) THEN
RAISE EXCEPTION 'FORBIDDEN: You are not a member of this organization.';
END IF;
-- drizzle/0009 authorization functions (the helper)
create or replace function public.is_organization_member(target_organization_id uuid)
returns boolean
language sql
stable
security definer
set search_path = ''
as $$ select exists (
select 1
from public.organization_members m
where m.organization_id = is_organization_member.target_organization_id
and m.user_id = auth.uid()
);
$$;
lib/billing/sync.ts
The Bug 02 fix: a late Stripe event is compared against stored state before it can overwrite anything.
lib/billing/sync.tstypescript
// 3. Out-of-order protection: ignore stale events.
if (existing?.last_stripe_event_at) {
if (new Date(existing.last_stripe_event_at) > new Date(eventCreatedAt)) {
console.log(
`[stripe-sync] Ignoring stale event for sub ${subscription.id}.`
);
return;
}
}
The complete file inventory ships in the ZIP — this page shows excerpts, not the whole product. Full write-ups →
06 · Demo
Click through the dashboard before you decide.
The demo runs the actual dashboard shell with clearly-labeled sample data — organization switching, team, billing, usage, API keys, activity and settings. It's static on purpose: no backend, no secrets, nothing leaves your browser. What it can't show — real auth, live Stripe webhooks, RLS under attack — the docs and the hardening suites cover.
Dashboard shell — the same layout the source ships
Sample org, team, billing, usage and API-key data
Labeled demo data — nothing pretends to be real
Mobile-friendly: try it on your phone
new in 2.0
The Agency Project Hub
The 2.0 rebuild adds real client work: clients, projects and tasks per organization, with entitlements enforced in the database and the same RLS tenancy.
01
clients & projects
Client work, org-scoped
Organizations track clients and open projects against them. Project creation runs through a SECURITY DEFINER function that writes on behalf of the caller - the projects table is never client-writable.
02
tasks & roles
A task board per project
Tasks move through todo, in progress, review and done. Two project-level roles (lead, member) sit on top of the org-level Owner / Admin / Member RBAC, and project membership is enforced by RLS policies.
03
billing enforcement
Entitlements enforced in SQL
Every plan tier carries database-enforced limits for projects, members and API requests. Free, Pro and Business ship seeded - a forged client cannot talk its way past a limit.
04
invitations & audit
Invites and audit logs built in
Organization invitations run through SECURITY DEFINER functions for create, accept and decline, and every organization gets an audit log for security-relevant actions.
The live demo walks the hub views - overview, projects, team, billing, usage and the audit log.
07 · Pricing
One-time purchase. Perpetual commercial licence.
No seats on the boilerplate, no revenue share, no runtime license checks.
B2B SaaS OS
One-time payment
$249once
One-time payment, perpetual commercial licence
Full source code, yours forever. One license, unlimited projects for you and your clients.
Node.js 20+, a PostgreSQL database and a Stripe account. No Docker required.
terminal — first run
01Install
unzip b2b-saas-os.zip && cd b2b-saas-os
npm install
02Configure
cp .env.example .env.local
# fill in PostgreSQL + Stripe values
03Push the schema
npm run db:apply
04Run — then attack it
npm run dev
Full environment-variable reference, Stripe setup and troubleshooting live in the documentation.
09 · FAQ
Questions, answered.
Anything else, the documentation covers setup through deployment.
What exactly do I get?
A ZIP with the complete source: the Next.js 16 application (27 pages plus 4 API routes), 11 SQL migrations with the RLS policies inline, the nine executable hardening suites, unit and billing tests, and documentation. $249, one-time.
Is this a subscription?
No. One payment of $249 buys a perpetual commercial licence — updates included while the product is actively maintained.
How does this compare to free starters or the bigger commercial kits?
The free official Next.js SaaS starter is a fine way to learn — it ships Stripe checkout and portal, team CRUD and basic Owner/Member RBAC. The commercial kits are broader: Supastack advertises a $149 Single Stack launch price across web, mobile and desktop targets (PostgreSQL via Drizzle); MakerKit's PostgreSQL edition is $299 lifetime (promotional; regularly $349) with i18n and admin tooling; supastarter's Next.js + PostgreSQL boilerplate is $349 Solo with i18n and Playwright E2E configured (prices checked November 2026 — sources linked on the pricing page). B2B SaaS OS is smaller on purpose: PostgreSQL-native RLS tenancy from migration zero, documented Stripe webhook reliability handling, and nine adversarial suites you can run against a dedicated test database — at $249 one-time. If you need i18n and admin tooling today, buy the bigger kit. If you need tenant boundaries you can verify, this is built for that.
Can I use it for client projects?
Yes. You can build and deploy unlimited projects for your own company or your clients. What you can't do is resell the boilerplate itself or redistribute the source.
What about refunds and support?
Because the product is source code, the purchase is final once the download has been accessed — no refunds. That's stated up front on the pricing and license pages, not buried. For support: if you can't get the product running, email support is included to get you unblocked (installation help). Custom development and consulting on your app are not included.
Does this mean my SaaS is secure if I buy it?
No — and be suspicious of any foundation that claims that. What this gives you is a multi-tenant foundation that was attacked against specific failure modes, four real bugs that those attacks and a security review surfaced (now fixed), and the executable tests that ship so you can re-run the attacks yourself.
What's new in 2.0?
The 2.0 rebuild adds the Agency Project Hub: organizations now manage clients, projects, tasks and role-scoped project members, with invitations and audit logs built in. Tenant-owned tables ship with row level security policies, project creation goes through a SECURITY DEFINER function, and plan entitlements are enforced in the database rather than in client code. The dashboard reads all of it live - there is no demo mode to toggle.
How customizable is it?
Everything is plain TypeScript, Tailwind tokens and shadcn/ui components. Rebrand in config/site.ts, extend the schema with normal SQL migrations, and wire your own product features on top.
What is the hardening suite, exactly?
Nine executable test files that run against a real PostgreSQL database — a dedicated, disposable test environment (a separate PostgreSQL project), with the actual migrations and RLS policies, not mocks. Never point them at a production database. They attack tenant isolation, SECURITY DEFINER functions, RBAC, invitations, webhook reliability, API keys, data integrity and billing enforcement, and run with npm run test:hardening.
Separate service · 3 slots
Already shipped a Next.js + PostgreSQL SaaS?
Free adversarial architecture review — 3 slots.
You get findings and practical fixes across the five areas where multi-tenant SaaS actually breaks. The trade: permission to publish sanitized findings — no secrets, no customer data, no proprietary code. A limited 3-slot launch experiment, not a guaranteed service.
This is a manual architecture review, not a penetration test.