Star 历史趋势
数据来源: GitHub API · 生成自 Stargazers.cn
README.md
Cloudflare Workers SaaS Template
Live Demo
Github Repo
This is a SaaS template for Cloudflare Workers. It uses the OpenNext framework to build a SaaS application.
[!TIP] This template is brought to you by 👉 AgenticDev 👈 - 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
- 🏢 Multi-tenancy Support
- 👥 Organization Management
- 👤 User Roles and Permissions
- 🔍 Tenant Isolation
- 🔄 Resource Sharing Controls
- 📊 Per-tenant Analytics
- 🔐 Tenant-specific Configurations
- 💼 Team Collaboration Features
Planned features (TODO):
- Add an eslint rule to check for unused imports and exports
- Add an eslint rule to check for unused variables and functions
- Upgrade to Tailwind 4 and fix the errors and visual regressions. Already started here https://github.com/LubomirGeorgiev/cloudflare-workers-nextjs-saas-template/tree/tailwind-4-upgrade
- Update Meta SEO tags 🔍
- Dynamic OpenGraph images 📸
- sitemap.xml 📄
- robots.txt 📄
- Multi-language support (i18n) 🌐
- Notifications 🔔
- Webhooks 🔗
Running it locally
pnpm installpnpx wrangler login- Login to your Cloudflare account to use Cloudflare AI while testing locally.- Copy
.dev.vars.exampleto.dev.varsand fill in the values. - Copy
.env.exampleto.envand fill in the values. pnpm db:migrate:dev- Creates a local SQLite database and applies migrationspnpm db:seed- Seeds the database with test datapnpm dev- Go to https://localhost:3000/sign-in and login with the test user credentials: test@test.com / password
- Go to https://localhost:3000/admin to manage users and the CMS.
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
- Go to
src/constants.tsand update it with your project details - Update
AGENTS.mdwith your project specification so that Cursor AI can give you better suggestions - Update the footer in
src/components/footer.tsxwith your project details and links - Optional: Update the color palette in
src/app/globals.css - Update the metadata in
src/app/layout.tsxwith your project details - Update
cms.config.tsif necessary
Deploying to Cloudflare with Github Actions
- Create D1 and KV namespaces
- Set either
RESEND_API_KEYorBREVO_API_KEYas a secret in your Cloudflare Worker depending on which email service you want to use. If you are using Brevo go to https://app.brevo.com/security/authorised_ips and disable it. - Create a Turnstile catcha in your Cloudflare account, and set the
NEXT_PUBLIC_TURNSTILE_SITE_KEYas a Github Actions variable. - Set
TURNSTILE_SECRET_KEYas a secret in your Cloudflare Worker. - Update the
wrangler.jsoncfile with the new database and KV namespaces, env variables and account id. 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 asservices->[0]->servicein the same file. - 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:Workers AI:Read
- Account:Queues:Edit
- Account:Vectorize:Edit
- Account:D1:Edit
- Account:Cloudflare Images:Edit
- Account:Workers KV Storage:Edit
- Zone:Cache Purge:Purge
- Add the API token to the Github repository secrets as
CLOUDFLARE_API_TOKEN - Add the Cloudflare account id to the Github repository variables as
CLOUDFLARE_ACCOUNT_ID - Optional: If you want clear the CDN cache on deploy, add
CLOUDFLARE_ZONE_IDto the Github repository variables for the zone id of your domain. This is the zone id of your domain, not the account id. - Push to the main branch