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
ā ā āāā payments/ # Polar webhooks
ā āāā 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 PUBLIC_STARTER_SLUG=your-starter-slug
OPENAI_API_KEY=your-openai-api-key
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:25src/lib/server/auth.ts:24 for production)npm 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 - sets event.locals.session/dashboard/* requires authentication/sign-in, /sign-up redirect to /dashboard if already authenticated/api/payments/webhooks bypasses authentication# 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/src/lib/server/db/schema.tsnpx drizzle-kit generate and npx drizzle-kit pushsrc/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.