cmsaasstarter
repository·main·Indexed 25 days ago
https://github.com/scosman/cmsaasstarterA high-performance, open-source SvelteKit boilerplate for building SaaS applications. It includes integrated authentication via Supabase Auth, Stripe-powered subscriptions and billing portals, a blog engine, and marketing tools. The stack utilizes TailwindCSS, DaisyUI, and is optimized for deployment on Cloudflare Pages and Workers.
What's inside cmsaasstarter
- SaaS Starter is a feature-rich SvelteKit boilerplate designed for building SaaS applications. It provides a complete foundation including user authentication (Supabase Auth), marketing sites with SEO, a blog engine, user dashboards, Stripe-powered subscriptions, and a billing portal. The template is optimized for high performance (100/100 Google PageSpeed) using pre-rendering and edge-optimized deployment patterns.
Tech Stack and Suggested Hosting
mainThe project uses the following technologies:
Core Stack:
- Framework: SvelteKit
- Styling: TailwindCSS and DaisyUI
- Payments: Stripe Checkout and Stripe Portal
Suggested Hosting (Free Tier):
- Host + CDN: Cloudflare Pages
- Serverless Compute: Cloudflare Workers
- Authentication: Supabase Auth
- Database: Supabase Postgres
Note: The free tier is suitable for hobby projects or pre-revenue companies (up to ~50,000 monthly active users). For production with paid customers, a $30/mo tier (Supabase Pro + Cloudflare Workers Paid) is recommended to ensure database backups and prevent database pausing.
Configure Git Hooks for Pre-commit Checks
mainTo prevent committing code that breaks the build, formatting, or linting, you can add a local git hook. Create or edit the file at
.git/hooks/pre-commitand add the following script. Ensure the hook file is executable.#!/bin/sh # Run standard checks before committing cd "$(dirname "$0")" sh ../../checks.shRun Developer Tools Locally
mainThe repository includes a
checks.shscript to manually run CI-style checks (build, formatting, linting, typechecking, and spell checking) on your local machine. This ensures your code meets the project's standards before pushing.Run the following commands:
# first time only: chmod +x ./checks.sh ./checks.shSet up email capabilities
mainTo enable email functionality in the SaaS Starter, you must configure the following environment variables.
Warning: The template includes a default welcome email that is automatically enabled once the Resend API key is set. You should customize or remove this email BEFORE setting these environment variables to avoid sending unbranded emails to your users.
Required/Optional Environment Variables:
PRIVATE_RESEND_API_KEY: Your Resend API key. Note that you must verify your 'from' domain with Resend before use.PRIVATE_ADMIN_EMAIL: The destination email address for admin notifications (e.g., new signups). If unset, admin emails will not be sent.PRIVATE_FROM_ADMIN_EMAIL: The 'from' address used for admin emails. Defaults to the value ofPRIVATE_ADMIN_EMAILif not explicitly set.
Deploy to Cloudflare Pages
mainThe recommended deployment target is Cloudflare Pages.
- Follow Cloudflare's Git integration instructions.
- Select SvelteKit as the framework.
- Add the following production environment variables:
PUBLIC_SUPABASE_URLPUBLIC_SUPABASE_ANON_KEYPRIVATE_SUPABASE_SERVICE_ROLEPRIVATE_STRIPE_API_KEY
Add PostHog analytics
mainTo integrate PostHog for event tracking, follow these steps:
- Install the library: Run
npm install posthog-jsin your terminal. - Initialize in SvelteKit: Add the PostHog initialization code to the
<script>section ofsrc/routes/+layout.svelte. It is recommended to follow the PostHog Svelte Guide for the specific implementation details. Tip: Ensure you are logged into your PostHog dashboard when copying code to ensure your unique API key is included. - Verify: Navigate through several pages on your local site and check your PostHog dashboard to confirm events are being captured.
npm install posthog-js- Install the library: Run
Customize Site Content and SEO
mainTo brand the template with your own content:
- Site Identity: Set the name, description, and base URL in
src/config.tsfor SEO purposes. - Blog:
- Update metadata in
src/routes/(marketing)/blog/posts.ts. - Replace post pages in
src/routes/(marketing)/blog/poststo match the URLs defined inposts.ts. - To remove the blog, delete the
src/routes/(marketing)/blogdirectory and remove links in the header/footer.
- Update metadata in
- SEO: Update title and meta description tags for every public page. Blog post SEO is handled automatically via
posts.tsmetadata. - Dynamic Content Warning: If you add dynamic (server-side rendered) content to the marketing, pricing, or blog pages, you must set
prerender = falsein the corresponding+page.tsfile.
- Site Identity: Set the name, description, and base URL in
Setup Supabase Project
mainTo use Supabase for authentication and database, follow these steps:
- Database Schema:
- For new projects: Run the SQL from
database_migration.sqlin the Supabase SQL Editor. - For existing projects: Apply migrations from the
supabase/migrationsdirectory in chronological order via the SQL Editor.
- For new projects: Run the SQL from
- Authentication Configuration:
- Enable user signups in the Supabase Auth settings.
- Auth Callbacks: Set your default callback URL (e.g.,
https://yourdomain.com/auth/callback) and add it to the "allowed redirect URL" list. Include a wildcard version (e.g.,https://yourdomain.com/auth/callback?*) to allow parameters. For local development, addhttp://localhost:5173/auth/callbackandhttp://localhost:5173/auth/callback?*. - OAuth: Configure providers in the Supabase Auth console. Update the
oauthProviderslist in/src/routes/(marketing)/login/login_config.tsto match your chosen providers. - SMTP: Configure a custom SMTP provider to avoid the 4-email-per-hour limit on Supabase development servers.
- Environment Variables: Create a
.env.localfile with the following keys:PUBLIC_SUPABASE_URLPUBLIC_SUPABASE_ANON_KEYPRIVATE_SUPABASE_SERVICE_ROLE
PUBLIC_SUPABASE_URL=https://your-project.supabase.co PUBLIC_SUPABASE_ANON_KEY=your-anon-key PRIVATE_SUPABASE_SERVICE_ROLE=your service_role secret- Database Schema:
Setup Stripe for Subscriptions
mainTo integrate Stripe for billing, follow these steps:
- Products and Prices: Create products and prices in the Stripe Dashboard. It is recommended to define each tier (e.g., Free, Pro, Enterprise) as a separate product. Include both monthly and annual prices for each.
- Environment Variables: Add your Stripe Secret API key to
PRIVATE_STRIPE_API_KEYin your.env.local(local) or Cloudflare environment (production). - Pricing Plan Data: Align the app's pricing data with Stripe in
/src/routes/(marketing)/pricing/pricing_plans.ts.- Fill in
stripe_price_idandstripe_product_idfor all paid plans. - Only one "free" plan should exist; it should omit the
stripe_price_id. - Set
defaultPlanIdto the plan users see after signup (typically the free plan).
- Fill in
- Stripe Portal: In the Stripe Dashboard, configure the billing portal to disallow editing email under customer information (as the app handles this) and optionally set a custom domain.
Customize the Welcome Email
mainThe welcome email is sent to users when they create their profile. You can customize it by modifying three specific areas:
- Metadata: Edit properties like company name, 'from' email, and subject line in
src/routes/(admin)/account/api/+page.server.tswithin thesendTemplatedEmailfunction call. - Plaintext Content: Edit
src/lib/emails/welcome_email_text.hbs. Use triple braces{{{property}}}for variables in plaintext files. - HTML Content: Edit
src/lib/emails/welcome_email_html.hbs. Use double braces{{property}}for variables in HTML files. Ensure you update the address and preheader text.
To disable the welcome email entirely, remove the
sendTemplatedEmailcall fromsrc/routes/(admin)/account/api/+page.server.ts.- Metadata: Edit properties like company name, 'from' email, and subject line in
Add Google Analytics
mainTo add Google Analytics to your project, follow the official Google Analytics Guide.
For this SvelteKit template, the recommended location to insert your Google Analytics tracking code is within
src/routes/+layout.svelte.