Nextbase Docs
Nextbase Docs
HomeBlogWelcome to Nextbase v5!Choose your starterGetting startedLocal Supabase per agent
Next.js + Cloudflare D1InstallationEnvironment variablesAuthenticationAgent connectionsProject structureDeployment
AuthenticationWorkspaces and the admin area
Building with agentsEmails with Resend
TroubleshootingNextbase v5
The 8 starter kitsNext.js + Cloudflare D1

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

LayerWhat the kit uses
FrontendNext.js 16 (App Router), compiled to a Cloudflare Worker by OpenNext
Admin appA second Next.js 16 application (apps/admin) compiled to its own Worker and served from its own origin
DatabaseCloudflare D1 with Drizzle ORM; D1 is the system of record
AuthenticationBetter Auth, stored in the same D1 database
Background workA third Worker (apps/platform-worker) with Cloudflare Queues, a cron trigger and a Durable Object for realtime channels
FilesCloudflare R2 for uploads and public media
CacheOpenNext R2 incremental cache, D1 tag cache and a Durable Object cache queue
EmailsReact Email templates, Mailpit locally, Resend in production
Hosting used by the demoCloudflare 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:3001 in 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 .nvmrc with v24, and apps/web and apps/admin require >=24.0.0.
  • pnpm 11. The root package.json declares pnpm@11.1.2 in packageManager, so corepack enable picks 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

  1. Installation: clone, install, migrate the local D1 databases and start the dev servers.
  2. Environment variables: every variable in the .dev.vars and .env.local example files of the three Workers.
  3. Authentication: how Better Auth is configured, how an account becomes an application admin and where the admin app lives.
  4. Agent connections: the User and Admin MCP endpoints, tools and OAuth details.
  5. Project structure: the five apps in the monorepo and where to make changes.
  6. 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.

Deployment

Provision Neon roles, apply migrations, and deploy the TanStack + Neon starter's web and admin apps as two Vercel projects.

Installation

Clone the Next.js + Cloudflare D1 starter, create the local D1 databases and run the web app, the admin app and the platform Worker on your machine.

On this page

The stackWhat you get out of the boxPrerequisitesNext steps