A comprehensive, production-ready SaaS starter kit built with SvelteKit, featuring authentication, subscriptions, AI integration, and modern UI components.
βββ src/
β βββ routes/
β β βββ (legal)/ # Legal pages (privacy policy, etc.)
β β βββ dashboard/ # Protected dashboard area
β β β βββ chat/ # AI chat interface
β β β βββ upload/ # File upload with R2
β β β βββ payment/ # Subscription management
β β β βββ settings/ # User settings & billing
β β βββ pricing/ # Public pricing page
β β βββ sign-in/ # Authentication pages
β β βββ sign-up/ # Registration pages
β β βββ success/ # Post-checkout success
β β βββ api/ # API routes
β β βββ auth/ # Better Auth endpoints
β β βββ chat/ # AI chat API
β β βββ upload-image/ # R2 upload API
β β βββ subscription/ # Subscription API
β βββ lib/
β β βββ components/
β β β βββ ui/ # shadcn-svelte components
β β β βββ homepage/ # Landing page sections
β β β βββ dashboard/ # Dashboard components
β β β βββ pricing/ # Pricing components
β β β βββ common/ # Shared components
β β βββ server/
β β βββ auth.ts # Authentication config
β β βββ subscription.ts # Subscription utilities
β β βββ upload-image.ts # R2 file upload
β β βββ db/ # Database schema & connection
β βββ app.css # Global styles
βββ drizzle/ # Database migrations
Clone the repository
git clone <repository-url>
cd svelte-starter-kit
Install dependencies
npm install
Environment Setup
Create a .env file based on .env.example:
```env
PUBLIC_APP_URL=http://localhost:3000
DATABASE_URL=postgresql://username:password@host.neon.tech/database?sslmode=require
BETTER_AUTH_SECRET=your-secret-key-here
GOOGLE_CLIENT_ID=your-google-client-id.apps.googleusercontent.com GOOGLE_CLIENT_SECRET=your-google-client-secret
POLAR_ENVIRONMENT=sandbox # or 'production' POLAR_ACCESS_TOKEN=your-polar-access-token POLAR_SUCCESS_URL=/success?checkout_id={CHECKOUT_ID} POLAR_WEBHOOK_SECRET=your-polar-webhook-secret
PUBLIC_STARTER_TIER=your-starter-tier-id
OPENAI_API_KEY=your-openai-api-key
RESEND_API_KEY=re_123456789 RESEND_FROM_EMAIL=noreply@example.com
CLOUDFLARE_ACCOUNT_ID=your-cloudflare-account-id R2_UPLOAD_IMAGE_ACCESS_KEY_ID=your-r2-access-key-id R2_UPLOAD_IMAGE_SECRET_ACCESS_KEY=your-r2-secret-access-key R2_UPLOAD_IMAGE_BUCKET_NAME=your-r2-bucket-name
4. **Database Setup**
```bash
# Generate and run migrations
npx drizzle-kit generate
npx drizzle-kit push
# Optional: Open Drizzle Studio to view your database
npx drizzle-kit studio
src/lib/server/upload-image.ts:25https://yourdomain.com/api/auth/polar/webhooks (or https://your-ngrok-url.ngrok.io/api/auth/polar/webhooks for local development)src/lib/server/auth.ts:12 for production)http://localhost:3000 (and your production URL)http://localhost:3000/api/auth/callback/google (and your production URL).env fileRESEND_API_KEY in your .envRESEND_FROM_EMAIL to your verified sender emailnpm run dev
Open http://localhost:3000 to see your application.
getSubscriptionDetails()isUserSubscribed()src/lib/server/subscription.ts:getSubscriptionDetails(event) - Get user's subscription with statusisUserSubscribed(event) - Check if user has active subscriptionhasAccessToProduct(event, productId) - Check access to specific productgetUserSubscriptionStatus(event) - Get status: 'active' | 'canceled' | 'expired' | 'none'streamText()hooks.server.ts which sets event.locals.session/dashboard/* requires authentication, redirects to /sign-in if not logged in/sign-in, /sign-up redirect to /dashboard if already authenticatedsrc/lib/server/auth.ts)/api/auth/polar/webhooks bypasses authentication for Polar webhooks# Start development server (runs on http://0.0.0.0:3000)
npm run dev
# Build for production
npm run build
# Preview production build
npm run preview
# Type checking
npm run check
# Type checking in watch mode
npm run check:watch
# Database migrations (Drizzle)
npx drizzle-kit generate # Generate migrations from schema
npx drizzle-kit migrate # Run migrations
npx drizzle-kit push # Push schema changes directly (dev only)
npx drizzle-kit studio # Open Drizzle Studio GUI
src/lib/components/src/routes/api/npx @better-auth/cli generate to explore available Better Auth schemas that you might needsrc/lib/server/db/schema.tsdrizzleAdapter configuration in src/lib/server/auth.tsnpx drizzle-kit generate to create SQL migration filesnpx drizzle-kit push to apply changes to your Neon databasenpx drizzle-kit studio to inspect your database schemasrc/app.css for global stylescomponents.jsonsrc/lib/server/auth.tsConfigured in svelte.config.js:
$components β src/lib/components$server β src/lib/server$lib β src/lib (SvelteKit default)npm run build
npm run preview
Note: You may need to install a specific adapter for your target environment.
.env.examplePOLAR_ENVIRONMENT should be 'sandbox' for development and 'production' for livesrc/lib/server/upload-image.ts:25 with your actual domainuser, session, account, verificationnpx drizzle-kit generate to create migrationsThis project is licensed under the MIT License.
Contributions are welcome! Please feel free to submit a Pull Request.
Built with β€οΈ using SvelteKit and modern web technologies.