https://github.com/lubomirgeorgiev/cloudflare-workers-nextjs-saas-template
Cloudflare Workers/Next.js SaaS Template
https://github.com/lubomirgeorgiev/cloudflare-workers-nextjs-saas-template
cloudflare cloudflare-workers nextjs saas-boilerplate
Last synced: 13 days ago
JSON representation
Cloudflare Workers/Next.js SaaS Template
- Host: GitHub
- URL: https://github.com/lubomirgeorgiev/cloudflare-workers-nextjs-saas-template
- Owner: LubomirGeorgiev
- Created: 2025-01-09T21:42:24.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2025-04-06T22:23:45.000Z (18 days ago)
- Last Synced: 2025-04-10T13:16:31.597Z (15 days ago)
- Topics: cloudflare, cloudflare-workers, nextjs, saas-boilerplate
- Language: TypeScript
- Homepage: https://saas-stack.startupstudio.dev/sign-in
- Size: 755 KB
- Stars: 285
- Watchers: 10
- Forks: 53
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Cloudflare Workers SaaS Template
[](https://github.com/LubomirGeorgiev/cloudflare-workers-nextjs-saas-template/actions/workflows/deploy.yml)
# [Live Demo](https://saas-stack.startupstudio.dev/sign-up)
# [Github Repo](https://github.com/LubomirGeorgiev/cloudflare-workers-nextjs-saas-template)This is a SaaS template for Cloudflare Workers. It uses the [OpenNext](https://opennext.js.org/cloudflare) framework to build a SaaS application.
Have a look at the [project plan](./cursor-docs/project-plan.md) to get an overview of the project.
> [!TIP]
> This template is brought to you by ๐ [StartupStudio.dev](https://startupstudio.dev/?ref=github-readme-nextjs-template) ๐ - where we help businesses automate operations and boost productivity through custom AI implementations. Just like this open-source project demonstrates technical excellence, we deliver:
>
> - Process automation with LLM-powered workflows
> - AI strategy consulting for sustainable scaling
> - Custom SaaS development using cutting-edge stacks
>
> Hundrets of developers already trust our codebase - Just Imagine what we could build for your business.# Supported Features:
- ๐ Authentication with Lucia Auth
- ๐ง Email/Password Sign In
- ๐ Email/Password Sign Up
- ๐ WebAuthn/Passkey Authentication
- ๐ Google OAuth/SSO Integration
- ๐ Forgot Password Flow
- ๐ Change Password
- โ๏ธ Email Verification
- ๐๏ธ Session Management with Cloudflare KV
- ๐ค Turnstile Captcha Integration
- โก Rate Limiting for Auth Endpoints
- ๐ก๏ธ Protected Routes and Layouts
- ๐ Session Listing and Management
- ๐ Anti-Disposable Email Protection
- ๐พ Database with Drizzle and Cloudflare D1
- ๐๏ธ Type-safe Database Operations
- ๐ Automatic Migration Generation
- ๐ป SQLite for Local Development
- โก Efficient Data Fetching
- ๐ Type-safe Queries
- ๐จ Email Service with React Email and Resend or Brevo
- ๐จ Beautiful Email Templates
- ๐ Email Preview Mode
- ๐ง Local Email Development Server
- ๐ฌ Transactional Emails
- โ๏ธ Email Verification Flow
- ๐ฑ Responsive Email Templates
- ๐ Deployment with Github Actions
- โ๏ธ Automatic Deployments
- ๐ Environment Variables Management
- ๐ฆ Database Migrations
- ๐ Comprehensive CI/CD Pipeline
- ๐งน Cache Purging
- โ Type Checking
- ๐จ Modern UI
- ๐จ Tailwind CSS
- ๐งฉ Shadcn UI Components
- ๐ Dark/Light Mode
- ๐ฑ Responsive Design
- โก Loading States and Animations
- ๐ Toast Notifications
- โ๏ธ Settings Dashboard
- ๐ Landing Page
- โจ Beautiful Email Templates
- ๐ค Profile Settings Page
- ๐ฏ Form Validation States
- ๐ณ Credit Billing System
- ๐ฐ Credit-based Pricing Model
- ๐ Monthly Credit Refresh
- ๐ Credit Usage Tracking
- ๐ณ Stripe Payment Integration
- ๐ Transaction History
- ๐ฆ Credit Package Management
- ๐ธ Pay-as-you-go Model
- ๐ Usage Analytics
- ๐ Admin Dashboard
- ๐ฅ User Management
- โจ Validations with Zod and React Hook Form
- ๐ก๏ธ Type-safe Form Validations
- ๐ Server-side Validations
- ๐ Client-side Validations
- ๐งน Input Sanitization
- โก Real-time Validation
- ๐ Form State Management
- ๐จโ๐ป Developer Experience
- ๐งช Local Development Setup
- ๐ TypeScript Support
- ๐ ESLint Configuration
- โจ Prettier Configuration
- ๐ Type-safe Environment Variables
- ๐๏ธ Cloudflare Types Generation
- ๐ค AI-powered Development with Cursor
- ๐ Comprehensive Documentation
- ๐ Project Structure Best Practices
- โก Edge Computing
- ๐ Global Deployment with Cloudflare Workers
- ๐ Zero Cold Starts
- ๐จ Edge Caching
- โ๏ธ React Server Components
- ๐ฅ๏ธ Server-side Rendering
- ๐พ Edge Database with D1
- ๐๏ธ Session Storage with KV
- โก API Rate Limiting## Planned features (TODO):
- [ ] Update Meta SEO tags ๐
- [ ] Dynamic OpenGraph images ๐ธ
- [ ] sitemap.xml ๐
- [ ] robots.txt ๐
- [ ] Multi-language support (i18n) ๐
- [ ] Notifications ๐
- [ ] Webhooks ๐
- [ ] Track bundle size with https://www.npmjs.com/package/webpack-bundle-analyzer ๐# Running it locally
1. `pnpm install`
2. Copy `.dev.vars.example` to `.dev.vars` and fill in the values.
3. Copy `.env.example` to `.env` and fill in the values.
4. `pnpm db:migrate:dev` - Creates a local SQLite database and applies migrations
5. `pnpm dev`
6. Open http://localhost:3000## Changes to wrangler.jsonc
After making a change to wrangler.jsonc, you need to run `pnpm cf-typegen` to generate the new types.
## Things to change and customize before deploying to production
1. Go to `src/constants.ts` and update it with your project details
2. Update the documentation in `./cursor-docs` with your project details so that Cursor AI can give you better suggestions
3. Update the footer in `src/components/footer.tsx` with your project details and links
4. Optional: Update the color palette in `src/app/globals.css`
5. Update the metadata in `src/app/layout.tsx` with your project details## Deploying to Cloudflare with Github Actions
1. Create D1 and KV namespaces
2. Set either `RESEND_API_KEY` or `BREVO_API_KEY` as a secret in your Cloudflare Worker depending on which email service you want to use.
3. Create a Turnstile catcha in your Cloudflare account, and set the `NEXT_PUBLIC_TURNSTILE_SITE_KEY` as a Github Actions variable.
4. Set `TURNSTILE_SECRET_KEY` as a secret in your Cloudflare Worker.
5. Update the `wrangler.jsonc` file with the new database and KV namespaces and env variables. Search for "cloudflare-workers-nextjs-saas-template" recursively in the whole repository and change that to the name of your project. Don't forget that the name you choose at the top of the wrangler.jsonc should be the same as `services->[0]->service` in the same file.
6. Go to https://dash.cloudflare.com/profile/api-tokens and click on "Use template" next to "Edit Cloudflare Workers". On the next, page add the following permissions in addition to the ones from the template:
- Account:AI Gateway:Edit
- Account:Workers AI:Edit
- Account:Queues:Edit
- Account:Vectorize:Edit
- Account:D1:Edit
- Account:Cloudflare Images:Edit
- Account:Workers KV Storage:Edit
- Zone:Cache Purge:Purge
7. Add the API token to the Github repository secrets as `CLOUDFLARE_API_TOKEN`
8. Add the Cloudflare account id to the Github repository variables as `CLOUDFLARE_ACCOUNT_ID`
9. Optional: If you want clear the CDN cache on deploy, add `CLOUDFLARE_ZONE_ID` to the Github repository variables for the zone id of your domain. This is the zone id of your domain, not the account id.
10. Push to the main branch## Email templates
If you want to preview and edit the email templates you can:
1. `pnpm email:dev`
2. Open http://localhost:3001
3. Edit the email templates in the `src/react-email` folder
4. For inspiration you can checkout https://react.email/templates### How to upgrade this template
Since this template is based on the [OpenNext](https://opennext.js.org/cloudflare) framework we need to make sure that we are following the changes they are making and update this template accordingly.To see the changes clone https://github.com/cloudflare/workers-sdk and then do `git diff 869ec7b...main -- packages/create-cloudflare/templates-experimental/next/` you will see the changes that we need to make to this template.