Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
C

cloudflare-workers-nextjs-saas-template

> 前端框架
Open source

Cloudflare Workers/Next.js SaaS Template

776 stars0 likes2 views
WebsiteGitHub

About

Cloudflare Workers/Next.js SaaS Template

Cloudflare Workers SaaS Template

Live Demo

Github Repo

This is a SaaS template for Cloudflare Workers. It uses Vinext on Vite to run a Next.js App Router application directly on Cloudflare Workers.

What is Vinext?

Vinext is Cloudflare's experimental implementation of the public Next.js API surface on top of Vite. The goal is to let a Next.js app keep familiar App Router patterns, React Server Components, route handlers, and next/* imports while using Vite as the build and dev toolchain instead of the standard Next.js compiler pipeline.

For this template, Vinext is the runtime and deployment path for Cloudflare Workers. pnpm dev starts the Vinext development server, pnpm build produces the Vinext/Vite production output, and pnpm deploy uses vinext-cloudflare deploy to build and deploy the Worker. Vinext has first-class Cloudflare Workers support, including access to bindings such as D1, KV, R2, Images, Durable Objects, and AI through cloudflare:workers.

Vinext is not a fork of Next.js and is not affiliated with Vercel. It is still experimental, so framework-sensitive changes should be verified with pnpm run check:vinext, pnpm run typecheck, pnpm run lint, and pnpm run build.

[!TIP] This template is brought to you by Aski.Chat - AI customer support agents that answer visitors, capture leads, and surface customer intelligence from every conversation.

  • Website-trained AI agents for support and sales
  • Lead capture and qualification from real conversations
  • Learn what customers keep asking, then improve your docs, FAQs, and product

Turn every visitor question into a faster answer and a sharper product signal.

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
  • 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 Cloudflare Email Service
  • 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
  • Integration Tests
  • End-to-end Tests
  • Deploy Size Tracking
  • 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
  • Team Subscription Billing
  • Per-team plans (Free / Pro / Enterprise) defined in code
  • Embedded Stripe Elements (Payment Element) for checkout — no redirect to hosted pages
  • Webhook-driven subscription lifecycle (Stripe is the source of truth)
  • In-app plan changes and cancellation
  • Stripe Customer Portal for payment methods, invoices, and billing details
  • Plan-based entitlements and feature gating (e.g. seat limits)
  • ️ One-command Stripe setup (pnpm stripe:setup)
  • AI-agent platform (public API, OAuth, MCP)
  • Versioned public REST API built with Hono, reusing the app's own service layer
  • OpenAPI 3.1 document generated from the same Valibot schemas the server validates with
  • Server-rendered API reference with client-side search — no spec-viewer bundle — plus authentication and error-code guides
  • API keys for users and teams, with scopes, optional expiry, and one-time secret display
  • OAuth 2.1 authorization server (PKCE, dynamic client registration, consent screen)
  • Remote MCP server whose tools are derived from the OpenAPI document — no hand-written tool list
  • Connect guides for Claude Code, claude.ai, ChatGPT, Cursor, VS Code, Codex, Antigravity, and Grok CLI
  • Self-service revocation from Settings → API & MCP, plus an admin view of registered OAuth apps
  • Admin Dashboard
  • User Management
  • OAuth app registry with verification and revocation
  • Content Management System
  • ️ Config-driven collections for blog and docs content
  • ✍️ Rich TipTap editor with markdown paste, markdown copy, tables, code highlighting, and alert blocks
  • Docs navigation builder with managed public URLs
  • ️ Media library with R2-backed image uploads, alt text editing, and featured images
  • ️ Tags and categories with entry usage tracking
  • Draft, published, archived, and scheduled entry workflows
  • Version history for CMS entries
  • ⚡ KV-backed CMS entry caching and cache maintenance actions
  • Full-text docs search
  • AI-assisted SEO description generation
  • Blog, docs, sitemap.xml, and JSON-LD schema rendering
  • Markdown views for public pages through the .md URL suffix, or Accept: text/markdown on the page URL
  • llms.txt index for the API specification, MCP endpoint, and docs tree
  • ✨ Validations with Valibot 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
    • Oxlint Configuration
    • Co-located Vitest Unit Tests
    • Cloudflare Workers Vitest Integration Tests
    • Vitest and Playwright E2E Tests
    • ⚡ Vinext and Vite Build Pipeline
    • Type-safe Environment Variables
    • ️ Cloudflare Types Generation
    • AI-powered Development with AI Agents
    • 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
    • ️ Cloudflare Images-powered Image Optimization
    • ⚡ 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
  • Internationalization (i18n) with next-intl
  • Cookie-based locale with Accept-Language negotiation (no URL changes)
  • Locale switcher in the footer
  • ️ JSON message catalogs (English and Spanish included)
  • Auto-detected by Vinext (no createNextIntlPlugin wrapper needed)
  • Type-safe message keys

Internationalization (i18n)

The template ships with next-intl configured in "without i18n routing" mode: the active locale is resolved from a NEXT_LOCALE cookie, falling back to the request's Accept-Language header and then the default locale, so URLs stay unchanged across the app.

Everything lives in src/i18n/:

  • config.ts — locale list, default locale, cookie name, and switcher labels.
  • request.ts — the Vinext-auto-detected next-intl request config.
  • locale.ts / locale-actions.ts — server-side locale resolution and the cookie-setting server action.
  • messages/.json — one message catalog per locale.

To add a locale (e.g. French):

  1. Add "fr" to LOCALES and a fr entry to LOCALE_LABELS in src/i18n/config.ts.
  2. Create src/i18n/messages/fr.json mirroring the keys in en.json.

Use useTranslations in client components and getTranslations in server components. messages/en.json is the source of truth for type-safe keys via the augmentation in src/i18n/next-intl.d.ts.

Planned features (TODO):

  • Update Meta SEO tags
  • Dynamic OpenGraph images
  • Notifications
  • Webhooks

Running it locally

  1. pnpm install
  2. pnpx wrangler login - Login to your Cloudflare account to use Cloudflare bindings while testing locally.
  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 db:seed - Seeds the database with test data
  6. pnpm dev - Starts the Vinext development server
  7. Go to http://localhost:3000/sign-in and login with the test user credentials: [email protected] / password
  8. Go to http://localhost:3000/admin to manage users and the CMS.

Billing setup (team subscriptions)

Billing is per-team: each team owns a single Stripe subscription to a plan (Free / Pro / Enterprise). Plans are defined in code in src/constants/plans.json and consumed by both the app and the setup script, so Stripe and code never drift. Payment collection uses embedded Stripe Elements (the Payment Element), and plan changes/cancellation are handled by in-app server actions. The hosted Stripe Customer Portal complements this for self-service payment method updates, invoice history, and billing details — the billing page shows a "Manage billing" button once the team has a Stripe customer.

The subscription lifecycle is webhook-driven: Stripe is the source of truth and the DB is a cache updated from webhook events. The app never mutates subscription state from the client's confirmPayment result alone.

Billing is enabled only when STRIPE_SECRET_KEY, STRIPE_WEBHOOK_SECRET, and NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY are all set (see isBillingEnabled() in src/flags.ts); otherwise the billing UI is hidden and the webhook route no-ops.

Happy path:

  1. Create a Stripe account and copy sk_test_... / pk_test_... into .env (STRIPE_SECRET_KEY, NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY).
  2. Run pnpm stripe:setup — this idempotently creates the products + recurring prices for the paid plans and, by default, upserts the resolved STRIPE_PRICE_PRO / STRIPE_PRICE_ENTERPRISE values into .env (replacing existing keys in place, never duplicating). When yearly billing is enabled (see below) it also creates the yearly prices and writes STRIPE_PRICE_PRO_YEAR / STRIPE_PRICE_ENTERPRISE_YEAR. It refuses to run against a live key unless you pass --live. Use --dry-run to preview without changing anything, or --no-write to create the Stripe resources but only print the values instead of touching .env.
  3. Local webhooks: stripe listen --forward-to localhost:3000/api/stripe/webhook, then copy the printed whsec_... into .env as STRIPE_WEBHOOK_SECRET.
  4. Production: pnpm stripe:setup --with-webhook https:///api/stripe/webhook, then set the secrets via wrangler secret put STRIPE_SECRET_KEY and wrangler secret put STRIPE_WEBHOOK_SECRET.
  5. Manual Dashboard alternative: create the Products + recurring Prices yourself, add a webhook endpoint for the subscription/invoice events to /api/stripe/webhook, and copy the price IDs + signing secret into your env.
  6. Customer Portal: pnpm stripe:setup also provisions a portal configuration (written to .env as STRIPE_PORTAL_CONFIG_ID) that enables payment method updates, invoice history, and billing-details editing — including business name, address, and VAT/tax IDs, which Stripe prints on invoices automatically. Plan changes and

Issues· 1 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

TypeScriptcloudflarecloudflare-workersnextjssaas-boilerplate

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category前端框架
PricingOpen source

> Related tools

R
React
用于构建用户界面的 JavaScript 库
V
Vue.js
渐进式 JavaScript 框架
N
Next.js
基于 React 的全栈 Web 框架