Bootstrap your SaaS with a modern tech stack built to move quick. Follow the guide to get started.
- Supabase - Postgres database & user authentication
- Stripe - Checkout, subscriptions, and customer portal
- React Email - Easily build emails and send them with Resend
- Tailwindcss - CSS framework
- shadcn/ui - Prebuilt accessible components
- Webhooks to automatically synchronize Stripe with Supabase
- Stripe fixture to bootstrap product data
- Supabase migrations to bootstrap and manage your db schema
- Responsive, performant, and accessible prebuilt pages
- Animated button borders! Now you can look cool without nerds saying you shipped too late
- Go to supabase.com and create a project
- Go to Project Settings → Database → Database password and click reset database password then click generate a new password. (I know you already made one, but this fixes a bug with their CLI where it doesn't like special characters in the password)
- Save this password somewhere, you can't see it after closing the box
- Go to stripe.com and create a project
- Go to Customer Portal Settings and click the
Active test link
button
- Go to resend.com and create an account
- Go to the API Keys page and create an API Key
- Add the Supabase Resend integration
- Next click the deploy button ⬆️
- On the form create a new repo and add the Supabase integration
- Add the environment variables that you have available. For the stripe webhook secret just put any value - we will come back to update this after configuring the webhook
- Click Deploy
- While you wait, clone your new repo and open it in your code editor. Then create a file named
.env.local
. Copy and pase the contents of.env.local.example
into this file and add the correct values. They should be the same values you added in above.
- After deploying go to your Vercel dashboard and find your Vercel URL
- Next go to your Stripe dashboard, click
Developers
in the top nav, and then theWebhooks
tab - Add an endpoint. Enter your Vercel URL followed by
/api/webhooks
- Click
Select events
- Check
Select all events
- Scroll to the bottom of the page and click
Add endpoint
- Click to
Reveal
signing secret and copy it - Go to your
Vercel project settings
→Environment Variables
- Update the value of the
STRIPE_WEBHOOK_SECRET
env with your newly acquired webhook secret. PressSave
Now we're going to run the initial Supabase Migration to create your database tables.
- Run
npx supabase login
- Run
npx supabase init
- Open your
package.json
and update bothUPDATE_THIS_WITH_YOUR_SUPABASE_PROJECT_ID
strings with your supabase project id - Run
npm run supabase:link
- Run
npm run migration:up
Stripe fixtures are an easy way to configure your product offering without messing around in the Stripe UI.
- Install the Stripe CLI. For Macs run:
brew install stripe/stripe-cli/stripe
- Run (make sure to update the command with your Stripe sk)
stripe fixtures ./stripe-fixtures.json --api-key UPDATE_THIS_WITH_YOUR_STRIPE_SK
- Do a
Search All
in your code editor forUPDATE_THIS
and update all instances with the relevant value (except for .env.local.example!) - Delete the
delete-me
dir
You did it! You should be able to look in your Stripe dashboard and see your products, and you should also see the same data has been populated in your Supabase database. Now let's test everything.
- Run
npm i
- Run
npm run dev
. - Go to the app and click
Get started for free
- this will take you to the login page - We haven't configured auth providers, so for now click
Continue with Email
and submit your email address - Click the link sent to your email and you should be redirected back to your app - authenticated
- Click
Get Started
on one of the plans. This will take you to a Stripe checkout page (In test mode) - Enter
4242424242424242
as your credit card number. Fill out the rest of the form with any valid data and click Subscribe - You should be redirect to the Account page where you can see your active subscription
- Click the
Manage your subscription
button
That's the end of the setup. The following are guides to help you code in your new codebase.
Your products and prices are managed via the stripe-fixtures.json
file. You can delete your test data in Stripe on the Developers page, make the changes you'd like, and then run the fixture command from above. When changes are made in Stripe the webhook hits the api route at src/app/api/webhooks
. The handler will synchronize the data sent from Stripe to your Supabase database.
The metadata
field in your fixture is where we can store info about the product that can be used in your app. For example, say you have a basic product, and one of the features of the product includes a max number of team invites. You can add a field to the metadata like team_invites
. Then update the Zod schema in src/features/pricing/models/product-metadata.ts
Then you can make use of it like this:
const products = await getProducts();
const productMetadata = productMetadataSchema.parse(products[0].metadata); // Now it's typesafe 🙌!
productMetadata.teamInvites; // The value you set in the fixture
Migrations are a powerful concept for managing your database schema. Any changes you make to your database schema should be done through migrations.
Say you want to add a table named invites
.
First run npm run migration:new add-invites-table
Then edit your file to include:
create table invites (
id uuid not null primary key default gen_random_uuid(),
email text not null,
);
alter table invites enable row level security;
Then run npm run migration:up
and your table will be added.
There are many auth providers you can choose from. See the Supabase docs for the full the list and their respective guides to configure them.
- Learn more about shadcn/ui components
- Learn more about theming with shadcn/ui
- Learn more about the Tailwindcss theme config
Your emails live in the src/features/emails
dir. Emails are finicky and difficult to style correctly, so make sure to reference the React Email docs. After creating your email component, sending an email is as simple as:
import WelcomeEmail from '@/features/emails/welcome';
import { resendClient } from '@/libs/resend/resend-client';
resendClient.emails.send({
from: 'no-reply@your-domain.com',
to: userEmail,
subject: 'Welcome!',
react: <WelcomeEmail />,
});
The file structure uses the group by feature
concept. This is where you will colocate code related to a specific feature, with the exception of UI code. Typically you want to keep your UI code in the app
dir, with the exception of reusable components. Most of the time reusable components will be agnostic to a feature and should live in the components
dir. The components/ui
dir is where shadcn/ui
components are generated to.
Follow these steps when you're ready to go live:
- Activate your Stripe account and set the dashboard to live mode
- Repeat the steps above to create a Stripe webhook in live mode, this time using your live url
- Update Vercel env variables with your live Stripe pk, sk, and whsec
- After Vercel has redeployed with your new env variables, run the fixture command using your Stripe sk
If you need help with the setup, or developing in the codebase, feel free to reach out to me on Twitter @kolbysisk - I'm always happy to help.
PRs are always welcome.
This project was inspired by Vercel's nextjs-subscription-payments.