Skip to main content
Full-Stack·14 min read

Next.js 16 + Prisma SaaS Tutorial

Build a scalable SaaS with Next.js 16 App Router, Prisma, Auth.js, and Tailwind. Production patterns, Server Actions, and deployment guide.

By Mussawar Hayat

Build a Production SaaS with Next.js 16

This tutorial walks through a scalable SaaS skeleton on Next.js 16 App Router with Prisma, Auth.js, PostgreSQL, and Tailwind CSS. Focus is on production patterns: Server Components for data, thin Server Actions, a server-only DAL, and deploy-ready configuration.

What You Will Build

  • App Router project structure for multi-tenant SaaS
  • Prisma schema and singleton client
  • Auth.js session gate and protected routes
  • Server Actions for create/update with validation
  • Deployment notes for Vercel and VPS

1. Project Shape

app/
  (marketing)/page.tsx
  (app)/dashboard/page.tsx
  actions/
lib/
  prisma.ts
  auth.ts
data/   # server-only DAL
prisma/schema.prisma

2. Prisma Schema Baseline

Use a User model with related Project rows owned by user id. Apply the singleton client pattern and set connection_limit for your host.

3. Auth.js Gate

Protect dashboard layouts by reading the session on the server and redirecting unauthenticated users.

// app/(app)/layout.tsx
import { auth } from '@/lib/auth'
import { redirect } from 'next/navigation'

export default async function AppLayout({ children }: { children: React.ReactNode }) {
  const session = await auth()
  if (!session?.user) redirect('/login')
  return <div className="app-shell">{children}</div>
}

4. Thin Actions + DAL

Keep use server files thin. Put Zod validation, session checks, and Prisma calls in import 'server-only' modules. Return DTOs only.

5. Deploy

  • Vercel: DATABASE_URL (Accelerate recommended), AUTH_SECRET, OAuth credentials
  • VPS: PM2 + Nginx, migrations in CI, pooling in front of Postgres

6. Production Checklist

  • Singleton Prisma client
  • Auth on layouts and every mutation
  • Zod on all Server Action inputs
  • Ownership checks on update/delete
  • Minimal use client boundaries

Summary

A durable SaaS on Next.js 16 is about boundaries: server by default, validated actions, and a clear DAL.

Key Takeaway

Structure for multi-tenant safety from day one: session-gated layouts, thin actions, and ownership-scoped Prisma queries.


Building a SaaS and need an architecture review?

I help teams set up Next.js 16 + Prisma foundations that scale. Get in touch.