Documentation

Quick Start

# Clone the template
npx degit shaneburrell/svelteship my-saas
cd my-saas
npm install
# Configure environment
cp .env.example .env
# Edit .env with your API keys
# Set up database
npx drizzle-kit push
# Start development
npm run dev

Project Structure

src/
├── lib/server/
│   ├── auth/       Auth.js config (Google + Email)
│   ├── db/         Drizzle schema + connection
│   ├── email/      Resend templates
│   └── stripe/     Checkout, portal, webhooks
├── routes/
│   ├── +page.svelte          Landing page
│   ├── login/                Sign-in (OAuth + magic link)
│   ├── dashboard/            Auth-gated main app
│   ├── settings/             Profile + billing
│   ├── admin/                Role-gated admin panel
│   └── api/
│       ├── billing/          Checkout + portal endpoints
│       └── webhooks/stripe/  Webhook handler
├── app.css                   Tailwind styles
├── app.html                  HTML shell
└── hooks.server.ts           Auth middleware

Environment Variables

Database

DATABASE_URL PostgreSQL connection string

Authentication

AUTH_SECRET Random string for session encryption
AUTH_GOOGLE_ID Google OAuth client ID
AUTH_GOOGLE_SECRET Google OAuth client secret

Stripe

STRIPE_SECRET_KEY Stripe secret API key
STRIPE_WEBHOOK_SECRET Webhook signing secret (whsec_...)
STRIPE_PRICE_MONTHLY Price ID for monthly subscription

Email

RESEND_API_KEY Resend API key for sending email

App

PUBLIC_APP_URL Your app URL (e.g. https://myapp.com)

Authentication Setup

Google OAuth: Create credentials at console.cloud.google.com. Add http://localhost:5173/auth/callback/google as an authorized redirect URI.

Magic Link Email: Get a Resend API key at resend.com. Verify your sending domain. The template sends styled verification emails automatically.

Adding Providers: Auth.js supports 80+ providers. Add any provider by installing its package and adding it to src/lib/server/auth/index.ts.

Stripe Billing Setup

1. Create a product in the Stripe dashboard with a recurring price. Copy the price ID to STRIPE_PRICE_MONTHLY.

2. Set up webhooks — add an endpoint pointing to https://yourdomain.com/api/webhooks/stripe. Listen for: checkout.session.completed, customer.subscription.updated, customer.subscription.deleted.

3. Test locally with stripe listen --forward-to localhost:5173/api/webhooks/stripe.

Deployment

# Build Docker image
docker build -t my-saas .
# Run with env vars
docker run -p 3000:3000 --env-file .env my-saas

Works with any platform that runs Docker: Railway, Fly.io, Render, AWS ECS, Google Cloud Run, or your own Kubernetes cluster.