Next.js + Cloudflare D1
What the Next.js + Cloudflare D1 starter includes, what you need before you start, and where to go next.
This kit uses Next.js through OpenNext on Cloudflare Workers, with D1, Drizzle and Better Auth. You get the account, workspace and project foundation, a separate administrator app, and remote MCP connections for users and application administrators.
Open the live demo · Repository
The stack
| Layer | What the kit uses |
|---|---|
| Frontend | Next.js 16 (App Router), compiled to a Cloudflare Worker by OpenNext |
| Admin app | A second Next.js 16 application (apps/admin) compiled to its own Worker and served from its own origin |
| Database | Cloudflare D1 with Drizzle ORM; D1 is the system of record |
| Authentication | Better Auth, stored in the same D1 database |
| Background work | A third Worker (apps/platform-worker) with Cloudflare Queues, a cron trigger and a Durable Object for realtime channels |
| Files | Cloudflare R2 for uploads and public media |
| Cache | OpenNext R2 incremental cache, D1 tag cache and a Durable Object cache queue |
| Emails | React Email templates, Mailpit locally, Resend in production |
| Hosting used by the demo | Cloudflare Workers on the Workers Paid plan |
Everything runs inside the Cloudflare runtime. The repository rules forbid adding PostgreSQL, Supabase, S3-compatible storage, third-party realtime brokers or Vercel-specific runtime dependencies.
What you get out of the box
- Email and password sign-up with email verification, password reset, magic links, and Google, GitHub and X sign-in when you add credentials
- Better Auth sessions, session revocation, two-factor TOTP with backup codes,
st_API keys and admin impersonation - Onboarding, profile, avatar, notification center and security settings for each user
- Multi-tenant workspaces with owner, admin, member and readonly roles, invitations and member management
- Projects with comments, workspace settings, and workspace deletion and transfer rules
- Stripe products, prices, customers, subscriptions, invoices, checkout, portal and asynchronous webhook projections
- A separate administrator app (
apps/admin,http://localhost:3001in development) with users, workspaces, settings, payment gateway, marketing content, changelog, feedback moderation and media management under/app-admin - A User MCP served by the web app and an Admin MCP served by the admin app, both with OAuth, so agents can read account context, projects, users and workspaces
- R2-backed uploads, Durable Object WebSocket channels, a D1 transactional outbox with Queue retries and dead-letter recovery
- Sentry, PostHog, Google Analytics, OpenAI, Vitest and Playwright integration points
Workspaces and admin roles are explained in workspaces and the admin area. In this kit the admin area is not part of the customer-facing web app; it is the apps/admin Worker, deployed on its own host (https://nextjs-d1-admin.usenextbase.com for the demo).
Prerequisites
- Node.js 24. The repository has a
.nvmrcwithv24, andapps/webandapps/adminrequire>=24.0.0. - pnpm 11. The root
package.jsondeclarespnpm@11.1.2inpackageManager, socorepack enablepicks the right version. - Docker, only if you want to inspect local emails in Mailpit. Without Docker, auth emails stay in the local D1 outbox and sign-up still works.
- A Cloudflare account for deployment. The demo runs on Workers Paid; see deployment.
- Optional: Stripe, Resend, OpenAI, Google, GitHub and X developer accounts for the integrations you plan to use.
You don't need a Cloudflare account to develop locally. Wrangler creates local D1 databases, R2 buckets and queues on your machine.
Next steps
- Installation: clone, install, migrate the local D1 databases and start the dev servers.
- Environment variables: every variable in the
.dev.varsand.env.localexample files of the three Workers. - Authentication: how Better Auth is configured, how an account becomes an application admin and where the admin app lives.
- Agent connections: the User and Admin MCP endpoints, tools and OAuth details.
- Project structure: the five apps in the monorepo and where to make changes.
- Deployment: Cloudflare resources, production bindings, secrets and the deploy commands for all three Workers.
The shared getting started page covers the flow that is the same across all eight kits.