open source saas template

Built for AI Agents and Discerning Humans

$ npx create-a2saas my-app

Architecture

Agent-Scannable Architecture

Three route groups. Two database tables. Zero magic.

(marketing)
Public pages

Landing, pricing, features. Shared header and footer layout. No auth required.

(auth)
Sign in & sign up

Minimal layout with just a logo. Clerk handles the forms. Redirects to dashboard on success.

(app)
Protected dashboard

Sidebar navigation layout. Auth required via middleware. Your product lives here.

Database: Two tables — users and subscriptions. That's it. Add your own tables as you build.
The Stack

The Stack

A collection of the industries most widely adopted technologies, implemented for developer and AI agent experience.

Framework
Next.js + Zod

App Router, Server Actions, Turbopack. End-to-end type safety with runtime validation.

UI
Tailwind + shadcn

Compose beautiful interfaces with the building blocks your AI was trained on.

Data
Drizzle + Neon

Type-safe ORM and serverless PostgreSQL. Schema defined in one code file, so agents understand data immediately.

Auth
Clerk

Vendor-lock removed. We wrap Clerk in a clean abstraction layer, keeping business logic decoupled.

Payments
Stripe

Webhooks wired, subscriptions synced. Just set your prices.

Email
Resend

Email with high deliverability. No SMTP config or ugly HTML strings—just clean React components.

Structure

Optimized Project Structure

Designed for context window efficiency. Logic is colocated, distinct, and predictable.

src/
src/
├── app/
│   ├── (auth)/                   # Auth routes (minimal layout)
│   │   ├── sign-in/[[...sign-in]]/page.tsx
│   │   └── sign-up/[[...sign-up]]/page.tsx
│   ├── (marketing)/              # Public routes (landing, pricing)
│   │   ├── layout.tsx            # Shared header/footer
│   │   ├── page.tsx              # Landing page
│   │   └── pricing/page.tsx      # Pricing page
│   ├── (app)/                    # Protected routes (dashboard)
│   │   ├── layout.tsx            # Sidebar layout
│   │   └── dashboard/
│   │       ├── page.tsx          # Dashboard home
│   │       └── profile/page.tsx  # User profile
│   ├── setup/page.tsx            # Setup status page
│   └── api/
│       ├── v1/                   # Versioned API routes
│       └── webhooks/             # Clerk & Stripe webhooks
├── components/
│   ├── auth/                     # Auth abstraction components
│   ├── dashboard/                # Dashboard layout components
│   └── ui/                       # Shadcn components
├── server/db/
│   ├── index.ts                  # Drizzle client
│   ├── schema.ts                 # Table definitions
│   └── ensure-user.ts            # User provisioning helper
├── lib/
│   ├── auth/                     # Auth abstraction layer
│   ├── api.ts                    # API response helpers
│   ├── plans.ts                  # Subscription plans
│   ├── stripe.ts                 # Stripe client
│   └── resend.ts                 # Email client
├── env.ts                        # Type-safe env validation
└── proxy.ts                      # Auth middleware
Config

Environment Variables

Copy .env.example to .env.local and fill these in

.env.local
# Database
DATABASE_URL=                    # Neon PostgreSQL connection string

# Clerk Authentication
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=   # Clerk publishable key
CLERK_SECRET_KEY=                # Clerk secret key
CLERK_WEBHOOK_SECRET=            # Clerk webhook signing secret

# Stripe Payments
STRIPE_SECRET_KEY=               # Stripe secret key
STRIPE_WEBHOOK_SECRET=           # Stripe webhook signing secret

# Email
RESEND_API_KEY=                  # Resend API key

# App Config
NEXT_PUBLIC_APP_URL=             # Your app URL (e.g., http://localhost:3000)
Endpoints

API Routes

What's already wired up

REST API
POST
/api/v1/checkout
Create Stripe checkout session
GET
/api/v1/users/me
Get current user with subscription
GET
/api/v1/debug/health
Health check with env status
Webhooks
HOOK
/api/webhooks/clerk
Syncs Clerk users to database
HOOK
/api/webhooks/stripe
Handles subscription lifecycle
Files

Key Files

The files you'll work with most often

Key Files
src/server/db/schema.ts

Database table definitions (users, subscriptions)

src/server/db/ensure-user.ts

User provisioning helper for protected pages

src/lib/auth/

Auth abstraction layer (swappable providers)

src/lib/api.ts

API response helpers (success, error, handleApiError)

src/app/api/webhooks/

Clerk and Stripe webhook handlers

Setup Status

Service Configuration

Includes a Setup Status Widget, showing the services configured and active.

Status
Database✓ Active
Authentication✓ Active
Payments✓ Active
Email✓ Active
App Config✓ Active

Frequently Asked Questions

Start Building

Start building from a production-ready SaaS foundation with auth, billing, database, and email.

$ npx create-a2saas my-app