MCPcopy
hub / github.com/nextjs/saas-starter

github.com/nextjs/saas-starter @main sqlite

repository ↗ · DeepWiki ↗
105 symbols 294 edges 42 files 0 documented · 0%
README

Next.js SaaS Starter

This is a starter template for building a SaaS application using Next.js with support for authentication, Stripe integration for payments, and a dashboard for logged-in users.

Demo: https://next-saas-start.vercel.app/

Features

  • Marketing landing page (/) with animated Terminal element
  • Pricing page (/pricing) which connects to Stripe Checkout
  • Dashboard pages with CRUD operations on users/teams
  • Basic RBAC with Owner and Member roles
  • Subscription management with Stripe Customer Portal
  • Email/password authentication with JWTs stored to cookies
  • Global middleware to protect logged-in routes
  • Local middleware to protect Server Actions or validate Zod schemas
  • Activity logging system for any user events

Tech Stack

Getting Started

git clone https://github.com/nextjs/saas-starter
cd saas-starter
pnpm install

Running Locally

Install and log in to your Stripe account:

stripe login

Use the included setup script to create your .env file:

pnpm db:setup

Run the database migrations and seed the database with a default user and team:

pnpm db:migrate
pnpm db:seed

This will create the following user and team:

  • User: test@test.com
  • Password: admin123

You can also create new users through the /sign-up route.

Finally, run the Next.js development server:

pnpm dev

Open http://localhost:3000 in your browser to see the app in action.

You can listen for Stripe webhooks locally through their CLI to handle subscription change events:

stripe listen --forward-to localhost:3000/api/stripe/webhook

Testing Payments

To test Stripe payments, use the following test card details:

  • Card Number: 4242 4242 4242 4242
  • Expiration: Any future date
  • CVC: Any 3-digit number

Going to Production

When you're ready to deploy your SaaS application to production, follow these steps:

Set up a production Stripe webhook

  1. Go to the Stripe Dashboard and create a new webhook for your production environment.
  2. Set the endpoint URL to your production API route (e.g., https://yourdomain.com/api/stripe/webhook).
  3. Select the events you want to listen for (e.g., checkout.session.completed, customer.subscription.updated).

Deploy to Vercel

  1. Push your code to a GitHub repository.
  2. Connect your repository to Vercel and deploy it.
  3. Follow the Vercel deployment process, which will guide you through setting up your project.

Add environment variables

In your Vercel project settings (or during deployment), add all the necessary environment variables. Make sure to update the values for the production environment, including:

  1. BASE_URL: Set this to your production domain.
  2. STRIPE_SECRET_KEY: Use your Stripe secret key for the production environment.
  3. STRIPE_WEBHOOK_SECRET: Use the webhook secret from the production webhook you created in step 1.
  4. POSTGRES_URL: Set this to your production database URL.
  5. AUTH_SECRET: Set this to a random string. openssl rand -base64 32 will generate one.

Other Templates

While this template is intentionally minimal and to be used as a learning resource, there are other paid versions in the community which are more full-featured:

  • https://achromatic.dev
  • https://shipfa.st
  • https://makerkit.dev
  • https://zerotoshipped.com
  • https://turbostarter.dev

Core symbols most depended-on inside this repo

cn
called by 24
lib/utils.ts
logActivity
called by 10
app/(login)/actions.ts
getUser
called by 8
lib/db/queries.ts
getUserWithTeam
called by 6
lib/db/queries.ts
validatedActionWithUser
called by 5
lib/auth/middleware.ts
question
called by 4
lib/db/setup.ts
hashPassword
called by 3
lib/auth/session.ts
comparePasswords
called by 3
lib/auth/session.ts

Shape

Function 104
Enum 1

Languages

TypeScript100%

Modules by API surface

components/ui/dropdown-menu.tsx15 symbols
lib/db/setup.ts9 symbols
app/(dashboard)/dashboard/page.tsx9 symbols
components/ui/card.tsx7 symbols
lib/db/queries.ts6 symbols
lib/auth/session.ts6 symbols
lib/payments/stripe.ts5 symbols
app/(dashboard)/layout.tsx5 symbols
app/(dashboard)/dashboard/general/page.tsx4 symbols
lib/auth/middleware.ts3 symbols
components/ui/avatar.tsx3 symbols
app/(dashboard)/dashboard/activity/page.tsx3 symbols

Dependencies from manifests, versioned

@types/node22.15.18 · 1×
@types/react19.1.4 · 1×
@types/react-dom19.1.5 · 1×
autoprefixer10.4.21 · 1×
bcryptjs3.0.2 · 1×
class-variance-authority0.7.1 · 1×
clsx2.1.1 · 1×
dotenv16.5.0 · 1×
drizzle-kit0.31.1 · 1×
drizzle-orm0.43.1 · 1×
jose6.0.11 · 1×

Datastores touched

postgresDatabase · 1 repos

For agents

$ claude mcp add saas-starter \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact