Micro SaaS guides

Architecture

AI-First SaaS Monorepo Architecture in 2026: Next.js, TanStack Start, Mobile & MCP

A practical December 2026 architecture blueprint for multi-surface SaaS products: pnpm + Turborepo boundaries, shared Better Auth & Polar billing, tRPC-to-REST/OpenAPI/MCP routing, and choosing Next.js vs TanStack Start vs local-first sync.

Building a SaaS in late 2026 rarely stops at one web app. Buyers expect a fast web workspace, a companion mobile app, often a browser extension, and an API or MCP endpoint their AI agents can call safely. At the same time, your own coding agents (Claude Code, Cursor, Codex) write code far faster when your repository has strict TypeScript contracts and clear workspace boundaries instead of scattered glue scripts. Here is the exact multi-surface monorepo blueprint that holds up in production — and when starting from a pre-wired starter saves weeks of repetitive plumbing.

Turn the guide into a product · 4 flavors included

Skip the SaaS plumbing and ship all surfaces on day one.

Zero To Shipped unlocks ZTS Classic (Next.js 16 + Prisma 7), ZTS TanStack (TanStack Start + Drizzle), ZTS PowerSync (offline SQLite + Swift/Kotlin), and ZTS Zero (Rocicorp Zero) — with Better Auth, Polar billing, MCP/REST, mobile, extension, and lifetime updates.

One-time payment · Regional PPP applied · 14-day refund · Lifetime updates

1. Why workspace boundaries matter more in an AI-assisted codebase

When an AI coding agent edits a monolithic single-folder Next.js app, business logic, database queries, auth checks, and UI state quickly tangle together. Separating apps from shared domain packages in a pnpm + Turborepo workspace gives both humans and agents a single source of truth for schemas, auth sessions, and typed RPC contracts.

  • Keep deployable surfaces under apps/ (web, mobile, browser extension) with thin UI code and zero duplicate auth or billing logic.
  • Put every reusable boundary in packages/: database schema (db), Better Auth session & RBAC policy (auth), Zod-validated environment schema (env), shared tRPC routers (trpc), AI provider catalog (ai), transactional emails (email), and generated SDK/CLI clients.
  • Enforce strict TypeScript across workspace references so a schema rename in packages/db immediately surfaces compile errors across web, mobile, extension, and CLI before code ever deploys.
pnpm-workspace-layout.txt
monorepo/
├── apps/
│   ├── web/        # Next.js 16 or TanStack Start UI + /api/trpc, /api/rest, /api/mcp
│   ├── mobile/     # Expo 58 React Native (or Native Swift iOS + Kotlin Android)
│   └── extension/  # WXT browser extension sharing auth + typed API client
├── packages/
│   ├── trpc/       # Single router compiled to tRPC, REST/OpenAPI, and MCP tools
│   ├── auth/       # Better Auth config, session policy, RBAC, and API keys
│   ├── db/         # Prisma 7 or Drizzle ORM schema, migrations, and seed scripts
│   ├── env/        # Fail-fast Zod environment validation for every runtime
│   ├── ai/         # Model registry, streaming tools, and provider resolution
│   ├── email/      # Transactional email templates (Resend, Plunk, or SMTP)
│   ├── sdk/        # Typed TypeScript SDK generated from OpenAPI
│   └── cli/        # Terminal CLI talking to your REST surface
├── turbo.json
└── pnpm-workspace.yaml

2. One tRPC router -> First-party UI, public REST/OpenAPI, and MCP server

Writing separate route handlers for your web app, mobile app, public REST API, and Model Context Protocol (MCP) server guarantees drift. The cleanest 2026 pattern defines every procedure once with Zod input/output schemas and mounts three transports over the exact same authorization middleware.

  • First-party web & Expo apps call /api/trpc with zero codegen lag and end-to-end autocomplete.
  • External integrations, webhooks, and the generated TypeScript SDK + CLI hit /api/rest documented automatically at /api/openapi.json.
  • IDE and desktop AI agents (Cursor, Claude Desktop, Codex) connect to /api/mcp with /.well-known/oauth-protected-resource discovery, reusing the same workspace-scoped permission checks.
apps/web/src/app/api/[transport]/route.ts
// Mount one Zod-typed tRPC router across three surfaces:
// - /api/trpc           -> first-party web & mobile apps
// - /api/rest           -> public HTTP API + /api/openapi.json
// - /api/mcp            -> Model Context Protocol tools for AI agents
// All three inherit identical Better Auth session/API-key + workspace RBAC checks.

3. Choosing the right stack flavor for your product (Next.js vs TanStack Start vs Local-First)

Not every SaaS should use the exact same runtime or sync engine. A content-heavy B2B dashboard, a Vite-native developer tool, and an offline-capable mobile workspace have different technical trade-offs — which is why locking yourself into one rigid template slows you down by product #2.

  • Next.js 16 (App Router) + Prisma 7: best default when you want the largest React ecosystem, mature SSR/SEO patterns, and structured migrations.
  • TanStack Start (Vite 8 + srvx) + Drizzle ORM: ideal when you want instant Vite HMR, explicit SQL-first queries, and zero Next.js runtime coupling.
  • Offline-first SQLite (PowerSync 2.7 + GeekNative Swift/Kotlin contracts): built for mobile-heavy field apps, travel tools, or personal trackers that must read and write reliably offline with real native iOS & Android UIs.
  • Instant local-first sync (Rocicorp Zero 1.12 + MobX): built for Linear-speed collaborative workspaces where sub-millisecond reads, optimistic custom mutators, and live multiplayer updates are core to the product.

4. The boring production plumbing that eats weeks if wired from scratch

Founders rarely underestimate the product UI — they underestimate the edge cases hiding inside auth, billing, multi-tenant scoping, and environment setup. Wiring these once cleanly across web and mobile easily consumes two to four weeks of engineering time before a single differentiating feature ships.

  • Auth + multi-tenant workspaces: Better Auth sessions, OAuth callbacks, password resets, org invites, role-based access control, and API key scoping across web + mobile.
  • Merchant-of-record billing: Polar.sh checkout sessions, cryptographic webhook signature verification, regional PPP pricing with coupon non-stacking guards, and idempotent entitlement updates.
  • Operational guardrails: BullMQ background queues and cron jobs, transactional emails, admin user/workspace inspection, Docker/Cloudflare/Vercel deploy configs, and strict env validation.

5. Build from scratch vs starting from a multi-flavor starter kit

Wiring your own auth, billing, and monorepo is a great learning exercise when you have spare weekends and no launch deadline. When your goal is validating paying customers and shipping multiple products or client apps, starting from a clean, auditable codebase you own in Git lets you spend week one on customer value instead of webhook retries.

  • Inspect the real monorepo layout, live demo app, and MCP/REST docs before you buy any starter — never trust mockups alone (browse our real screenshot gallery at /gallery).
  • Model your exact DIY engineering hours against your hourly rate in our interactive Build-vs-Buy ROI Calculator before committing.
  • Ensure one license covers unlimited commercial and client projects with lifetime Git updates — zero recurring boilerplate subscriptions.

FAQ

Should a solo founder use a pnpm + Turborepo monorepo in 2026?

Yes, as soon as you plan to ship more than one surface (web + mobile, web + browser extension, or web + CLI/MCP server). Sharing packages/db, packages/auth, and packages/trpc prevents type drift and makes AI coding agents dramatically more accurate.

Why expose an MCP server alongside REST and tRPC in a new SaaS?

More B2B and developer customers connect their daily SaaS tools directly into Cursor, Claude, and internal AI workflows. Generating MCP tools from your existing Zod-validated tRPC procedures takes almost zero extra maintenance while enforcing your real workspace permissions.

When should I pick TanStack Start + Drizzle over Next.js + Prisma?

Pick Next.js 16 + Prisma 7 when you want the broadest mainstream ecosystem and schema-driven migrations. Pick TanStack Start + Drizzle when you prefer Vite 8 dev speed, SQL-close TypeScript queries, and framework portability.

Does Zero To Shipped include all four architectures in one license?

Yes. One one-time Zero To Shipped license unlocks private zerotoshipped GitHub organization access to ZTS Classic (Next.js + Prisma), ZTS TanStack (TanStack Start + Drizzle), ZTS PowerSync (offline SQLite + native Swift/Kotlin), ZTS Zero (Rocicorp Zero), and zts-matrix (180 composable combinations) with lifetime updates.