A modern, production-ready Next.js 15.4.6 application with React 19, configured to deploy on Cloudflare Workers using the OpenNext Cloudflare adapter. Includes authentication, database integration, and file storage capabilities.
- β‘ Next.js 15.4.6 with React 19 and App Router
- π Authentication - Complete auth system with better-auth, supporting email/password and Google OAuth
- ποΈ Database - PostgreSQL with Drizzle ORM and Cloudflare Hyperdrive acceleration
- π File Storage - Cloudflare R2 integration with automatic metadata handling
- π¨ Modern UI - Tailwind CSS v4 with shadcn/ui components
- π§ Developer Experience - TypeScript, Biome formatter/linter, Git hooks, and hot reload
- π Edge Deployment - Global CDN performance with Cloudflare Workers
This template is designed to work seamlessly with AI development tools like Claude Code. It includes comprehensive documentation in CLAUDE.md with detailed development guidelines, architecture explanations, and coding standards to help AI assistants understand and contribute effectively to your project.
- Next.js 15.4.6 with React 19 - Latest version with App Router
- TypeScript - Strict configuration with path aliases
- Tailwind CSS v4 - Modern utility-first CSS framework
- Cloudflare Workers - Serverless deployment platform via OpenNext
- better-auth v1.3.29 - Modern authentication solution
- Drizzle ORM v0.44.6 - Type-safe SQL toolkit
- PostgreSQL - Primary database with Cloudflare Hyperdrive
- Google OAuth - Social authentication provider
- shadcn/ui - Component library built on Radix UI
- Biome - Modern linter and formatter
- Husky - Git hooks for code quality
- Drizzle Kit - Database migrations and management
src/
βββ app/ # Next.js App Router
β βββ layout.tsx # Root layout with font configuration
β βββ page.tsx # Homepage
β βββ api/[...auth]/ # Better-auth API route
βββ components/ui/ # shadcn/ui components
βββ lib/ # Utilities and configurations
β βββ auth.ts # Server-side auth configuration
β βββ auth-client.tsx # Client-side auth setup
β βββ env.ts # Environment handling
β βββ storage.ts # R2 file storage utilities
β βββ utils.ts # General utilities
βββ db/ # Database layer
β βββ index.ts # Database connection setup
β βββ schema/ # Database schemas
βββ styles/
βββ globals.css # Global styles with Tailwind v4
- Node.js 18+
- pnpm package manager
- Cloudflare account with Workers, R2, and Hyperdrive
- PostgreSQL database
-
Clone the repository:
git clone <your-repo-url> cd nextjs-boilerplate-cloudflare
-
Install dependencies:
pnpm install
-
Set up environment variables:
cp .dev.vars.example .dev.vars
Edit
.dev.varswith your configuration:DATABASE_URL=postgresql://your-database-url BETTER_AUTH_SECRET=your-auth-secret GOOGLE_CLIENT_ID=your-google-client-id GOOGLE_CLIENT_SECRET=your-google-client-secret
-
Set up the database:
pnpm db:generate # Generate migrations pnpm db:migrate # Run migrations
-
Start the development server:
pnpm dev
Open http://localhost:3000 to see your application.
pnpm dev- Start development server with Turbopackpnpm build- Build the application for productionpnpm validate- Run all quality checks (type-check, lint, format:check, build)
pnpm db:generate- Generate database migrationspnpm db:migrate- Run database migrationspnpm db:push- Push schema changes to databasepnpm db:studio- Open Drizzle Studio for database management
pnpm auth:generate- Generate better-auth client typespnpm auth:migrate- Run auth-specific migrations
pnpm lint- Run Biome linterpnpm format- Format code with Biomepnpm format:check- Check code formatting without changespnpm type-check- Run TypeScript type checking
-
Build and deploy:
pnpm deploy
-
Preview locally before deployment:
pnpm preview
-
Generate Cloudflare types:
pnpm cf-typegen
Uses .dev.vars file for local development environment variables.
Configure environment variables in your Cloudflare Workers dashboard or via Wrangler:
wrangler secret put DATABASE_URL
wrangler secret put BETTER_AUTH_SECRET
wrangler secret put GOOGLE_CLIENT_ID
wrangler secret put GOOGLE_CLIENT_SECRETnext.config.ts- Next.js with Cloudflare dev initializationwrangler.jsonc- Cloudflare Workers configurationopen-next.config.ts- OpenNext adapter configurationdrizzle.config.ts- Database migration configurationbiome.json- Code formatting and linting rulescomponents.json- shadcn/ui component configuration
- Workers - For application deployment
- R2 Bucket - For file storage
- Hyperdrive - For database connection acceleration
- Pages (optional) - For custom domain and SSL
// Server-side auth
import { getCurrentUser, requireAuth } from '@/lib/auth'
// Get current user
const user = await getCurrentUser()
// Protect routes
export default async function ProtectedPage() {
const session = await requireAuth()
// User is authenticated
}// Client-side auth
import { authClient } from '@/lib/auth-client'
// Sign in
await authClient.signIn.email({
email: 'user@example.com',
password: 'password'
})
// Sign in with Google
await authClient.signIn.social({ provider: 'google' })import { db } from '@/db'
import { users } from '@/db/schema'
// Query users
const allUsers = await db.select().from(users)
// Create user
const newUser = await db.insert(users).values({
email: 'user@example.com',
name: 'John Doe'
}).returning()import { uploadFile, getPublicUrl } from '@/lib/storage'
// Upload file
const result = await uploadFile(file, 'user-uploads')
// Get public URL
const url = getPublicUrl(result.key)This project uses shadcn/ui components. Add new components:
npx shadcn-ui@latest add button
npx shadcn-ui@latest add card
# ... more components- Secure Authentication - Better-auth with session management
- Environment Variables - Proper secret management
- Type Safety - TypeScript throughout the application
- Input Validation - Server-side validation for all inputs
- CSRF Protection - Built-in with better-auth
- Content Security Policy - Configurable security headers
The project is set up for testing. Add your test files in the appropriate directories and run:
pnpm test # Run tests
pnpm test:watch # Run tests in watch mode
pnpm test:coverage # Run tests with coverage- CLAUDE.md - Comprehensive development guide for AI assistants
- API Documentation - Add your API documentation here
- Component Docs - Add component documentation here
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Commit your changes:
git commit -m 'feat: add amazing feature' - Push to the branch:
git push origin feature/amazing-feature - Open a Pull Request
Please follow the conventional commit format and ensure all quality checks pass.
License - See LICENSE file for details.
If you encounter any issues or have questions:
- Check the CLAUDE.md file for development guidelines
- Review existing Issues
- Create a new issue with detailed information
Built with β€οΈ for modern web development on Cloudflare's edge platform