A modern, production-ready template for building full-stack React applications using React Router, Cloudflare (Pages, Workers, D1), Drizzle ORM, and better-auth.
- Framework: React Router v7
- Platform: Cloudflare (Pages, Workers, D1)
- ORM: Drizzle ORM
- Authentication: better-auth
- UI/Styling: Tailwind CSS, shadcn/ui, Lucide Icons
- Tooling: Vite, Biome, TypeScript, Vitest
- 🚀 Server-side rendering
- ⚡️ Hot Module Replacement (HMR)
- 📦 Asset bundling and optimization
- 🔄 Data loading and mutations
Install the dependencies:
npm installCopy the example environment file to both .dev.vars (for local development with Wrangler) and .env (for other scripts like Drizzle Kit).
cp .env.example .dev.vars
cp .env.example .envBe sure to fill in the required variables in both files.
Run the initial database migrations for your local D1 database.
# Generate the auth schema
npm run auth:db:generate
# Migrate the main schema
npm run db:migrateStart the development server with HMR:
npm run devYour application will be available at http://localhost:5173.
dev: Starts the development server with HMR.build: Creates a production-ready build of your application.preview: Serves the production build locally for previewing.deploy: Builds and deploys your application to Cloudflare.db:generate: Generates Drizzle ORM migration files based on schema changes.db:migrate: Applies pending migrations to the local D1 database.db:migrate-production: Applies pending migrations to the production D1 database.auth:db:generate: Generates the database schema forbetter-auth.check: Runs type checking and Biome for code quality.biome:check: Lints and formats the codebase using Biome.test: Runs tests using Vitest.
Deployment is done using the Wrangler CLI.
First, create a D1 database in your Cloudflare account.
npx wrangler d1 create <your-database-name>Update your wrangler.jsonc file with the database_name and database_id from the previous step.
Update your drizzle.config.ts to point to your production database, and then run the production migration command:
npm run db:migrate-productionTo build and deploy your application to production:
npm run deployThis boilerplate uses better-auth for authentication, pre-configured for GitHub. Key files include:
auth.ts: Mainbetter-authserver configuration.app/lib/auth/auth.server.ts: Server-side authentication utilities.app/lib/auth/auth-client.ts: Client-side authentication utilities.app/routes/api.auth.$: Route for handling authentication callbacks.
This template comes with Tailwind CSS and shadcn/ui for a modern, component-based styling experience.
To add new shadcn/ui components, you can use their CLI:
npx shadcn-ui@latest add <component-name>Built with ❤️ using React Router and Cloudflare.