Skip to content

Production-ready Next.js 15 SaaS template with NextAuth (Google + Email), Stripe payments, PostgreSQL, Drizzle ORM, and Resend email

Notifications You must be signed in to change notification settings

wojciechos/nextjs-saas-template

Repository files navigation

Next.js SaaS Template

A production-ready Next.js 15 SaaS starter template with authentication, payments, and email functionality built-in.

⚡ Quick Start

Click "Use this template" button above to create a new repository from this template.

# Clone your new repository
git clone https://github.com/YOUR_USERNAME/YOUR_PROJECT_NAME.git
cd YOUR_PROJECT_NAME

# Install dependencies
npm install

# Set up environment variables
cp .env.example .env.local
# Edit .env.local with your actual values

# Start PostgreSQL database
docker-compose up -d

# Run database migrations
npm run db:migrate

# Start development server
npm run dev

Visit http://localhost:3000 to see your app!

🚀 What's Included

Authentication

  • NextAuth.js with JWT sessions
  • Google OAuth - One-click sign in
  • Email/Password - Full auth flow with registration
  • Password Reset - Token-based with email verification
  • Protected Routes - Middleware-based route protection
  • Security - bcrypt password hashing (12 rounds)

Payments

  • Stripe Checkout - One-time payment integration
  • Webhook Handling - Automatic purchase verification
  • Purchase Tracking - Database records for all transactions
  • Access Control - Content protection based on purchase status

Database

  • PostgreSQL with Docker setup
  • Drizzle ORM - Type-safe database queries
  • Migrations - Version-controlled schema changes
  • Drizzle Studio - Built-in database GUI

Email

  • Resend Integration - Transactional emails
  • Password Reset Emails - Pre-built templates
  • Email Verification - Ready to implement

UI/UX

  • Tailwind CSS - Utility-first styling
  • shadcn/ui - Beautiful, accessible components
  • Responsive Layout - Header, footer, and page structure
  • Toast Notifications - User feedback with react-hot-toast
  • Modern Design - Clean, professional interface

Developer Experience

  • TypeScript - Full type safety throughout
  • Zod Validation - Schema validation for forms and API
  • ESLint - Code quality enforcement
  • Prettier - Consistent code formatting
  • Turbopack - Fast development builds

📦 Tech Stack

  • Framework: Next.js 15 (App Router)
  • Language: TypeScript
  • Styling: Tailwind CSS + shadcn/ui
  • Database: PostgreSQL + Drizzle ORM
  • Authentication: NextAuth.js
  • Payments: Stripe
  • Email: Resend
  • Validation: Zod

🛠️ Setup Guide

Prerequisites

  • Node.js 20 or higher
  • Docker Desktop (for PostgreSQL)
  • A Stripe account (for payments)
  • A Resend account (for emails)
  • A Google Cloud project (for OAuth)

Detailed Setup Instructions

See SETUP.md for comprehensive setup instructions including:

  • Google OAuth configuration
  • Stripe payment setup
  • Resend email configuration
  • Database setup and migrations

Environment Variables

Copy .env.example to .env.local and fill in your values:

# Database
DATABASE_URL=postgresql://postgres:postgres@localhost:5433/your_db_name

# NextAuth
NEXTAUTH_URL=http://localhost:3000
NEXTAUTH_SECRET=your-secret-here  # Generate with: openssl rand -base64 32

# Google OAuth
GOOGLE_CLIENT_ID=your-google-client-id
GOOGLE_CLIENT_SECRET=your-google-client-secret

# Stripe
STRIPE_SECRET_KEY=your-stripe-secret-key
STRIPE_PUBLISHABLE_KEY=your-stripe-publishable-key
STRIPE_WEBHOOK_SECRET=your-webhook-secret
STRIPE_PRODUCT_ID=your-product-id

# Resend
RESEND_API_KEY=your-resend-api-key
[email protected]

📝 Available Scripts

npm run dev          # Start development server with Turbopack
npm run build        # Build for production
npm run start        # Start production server
npm run lint         # Run ESLint
npm run format       # Format code with Prettier
npm run db:generate  # Generate new migrations from schema changes
npm run db:migrate   # Run pending migrations
npm run db:studio    # Open Drizzle Studio (database GUI)

📂 Project Structure

├── app/                    # Next.js App Router
│   ├── api/               # API routes
│   │   ├── auth/         # NextAuth.js endpoints
│   │   ├── checkout/     # Stripe checkout
│   │   └── webhooks/     # Stripe webhooks
│   ├── dashboard/        # Protected dashboard page
│   ├── login/            # Login page
│   ├── register/         # Registration page
│   └── page.tsx          # Landing page
├── components/            # React components
│   ├── layout/           # Header, footer
│   ├── ui/               # shadcn/ui components
│   └── ...               # Feature components
├── lib/                   # Utility functions
│   ├── auth.ts           # NextAuth configuration
│   ├── stripe.ts         # Stripe client
│   ├── email.ts          # Email utilities
│   └── utils.ts          # General utilities
├── db/                    # Database
│   ├── index.ts          # Database connection
│   └── schema.ts         # Drizzle schema
├── types/                 # TypeScript types
├── migrations/            # Database migrations
└── docker-compose.yml     # PostgreSQL setup

🗄️ Database Schema

The template includes three main tables:

users - User accounts with OAuth and credentials support passwordResetTokens - Secure password reset tokens purchases - Payment tracking and access control

See db/schema.ts for full schema definition.

🎨 Customization

Branding

  1. Update app/layout.tsx with your app name
  2. Replace app/favicon.ico with your logo
  3. Customize colors in app/globals.css

Features

  • Add new pages in app/ directory
  • Create components in components/ directory
  • Add database tables in db/schema.ts and run npm run db:generate

Styling

  • Modify Tailwind config in tailwind.config.js
  • Add new shadcn/ui components: npx shadcn@latest add [component]

🚢 Deployment

Vercel (Recommended)

  1. Push your code to GitHub
  2. Import project in Vercel
  3. Add environment variables in Vercel dashboard
  4. Deploy!

Database Hosting

Use a managed PostgreSQL service:

  • Vercel Postgres
  • Supabase
  • Neon
  • Railway

Update DATABASE_URL in your environment variables.

📚 Learn More

🤝 Contributing

This template is maintained to provide a solid starting point for SaaS projects. Feel free to customize it for your needs!

📄 License

MIT License - feel free to use this template for your projects!


Built with ❤️ for the Next.js community

Need help? Check out SETUP.md for detailed configuration instructions.

About

Production-ready Next.js 15 SaaS template with NextAuth (Google + Email), Stripe payments, PostgreSQL, Drizzle ORM, and Resend email

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published