Cloudflare Workers/Next.js SaaS Template
Cloudflare Workers/Next.js SaaS Template
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.
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.
pnpm stripe:setup).md URL suffix, or Accept: text/markdown on the page URLllms.txt index for the API specification, MCP endpoint, and docs treecreateNextIntlPlugin wrapper needed)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):
"fr" to LOCALES and a fr entry to LOCALE_LABELS in src/i18n/config.ts.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.
pnpm installpnpx wrangler login - Login to your Cloudflare account to use Cloudflare bindings while testing locally..env.example to .env and 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 - Starts the Vinext development serverBilling 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:
sk_test_... / pk_test_... into .env (STRIPE_SECRET_KEY, NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY).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.stripe listen --forward-to localhost:3000/api/stripe/webhook, then copy the printed whsec_... into .env as STRIPE_WEBHOOK_SECRET.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./api/stripe/webhook, and copy the price IDs + signing secret into your env.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 andNo open issues yet, or sync has not completed.