A modern, full-stack Next.js template optimized for Cloudflare Workers with a complete development setup.
- Next.js 15 - Latest React framework with App Router
- Cloudflare Workers - Edge-first deployment with OpenNext
- tRPC - End-to-end typesafe APIs
- Drizzle ORM - TypeScript ORM with Cloudflare D1 + KV caching
- Better Auth - Modern authentication system
- Zustand - Lightweight state management with persistence
- Tailwind CSS - Utility-first CSS framework
- shadcn/ui - Beautiful, accessible UI components
- TypeScript - Full type safety with strict mode
- ESLint & Prettier - Code quality and formatting
- Playwright - End-to-end testing
- Bruno - API testing
- GitHub Actions - Complete CI/CD pipeline
- Bun - Fast package manager and runtime
- ⚡ Drizzle ORM Caching - KV-based query caching with automatic invalidation
- ⚡ OpenNext Optimizations - Worker separation, edge converter, R2 cache
- ⚡ React Query - 60s stale time, optimized refetch behavior
- ⚡ Image Optimization - Automatic WebP conversion with Sharp compression
- ⚡ Static Asset Caching - 1-year cache for immutable assets
- ⚡ Security Headers - HSTS, CSP, XSS protection, and more
- ⚡ Bundle Optimization - CSS chunking, tree shaking, minification
chmod +x scripts/setup.sh
./scripts/setup.shbun installCopy the environment example file:
cp .env.example .env.localUpdate .env.local with your configuration:
DATABASE_URL="file:./dev.db"
BETTER_AUTH_SECRET="your-secret-key-change-this-in-production"
BETTER_AUTH_URL="http://localhost:3000"
NEXT_PUBLIC_APP_URL="http://localhost:3000"Create and configure your D1 databases:
npx wrangler d1 create b3-db-dev
npx wrangler d1 create b3-db-prodUpdate the database IDs in wrangler.jsonc and wrangler.production.jsonc.
Generate and run migrations:
bun run db:generate
bun run db:migrate:devCreate R2 buckets:
npx wrangler r2 bucket create b3-storage-dev
npx wrangler r2 bucket create b3-storage-prodCreate KV namespaces for caching:
npx wrangler kv namespace create CACHE_KV
npx wrangler kv namespace create CACHE_KV --env productionUpdate the KV IDs in wrangler.jsonc and wrangler.production.jsonc.
Start the development server:
bun run devOpen http://localhost:3000 in your browser.
.
├── api-tests/ # Bruno API tests
├── drizzle/ # Database migrations
├── src/
│ ├── app/ # Next.js app router pages
│ ├── components/ # React components
│ │ └── ui/ # shadcn/ui components
│ ├── lib/ # Utility functions
│ │ └── utils/ # Helper utilities
│ ├── server/ # Server-side code
│ │ ├── db/ # Database schema and config
│ │ ├── lib/ # Server utilities
│ │ └── routers/ # tRPC routers
│ ├── stores/ # Zustand stores
│ ├── trpc/ # tRPC client setup
│ ├── types/ # TypeScript type definitions
│ └── env.ts # Environment validation
├── tests/
│ └── e2e/ # Playwright E2E tests
├── .github/
│ └── workflows/ # CI/CD pipelines
└── wrangler.jsonc # Cloudflare Workers config
bun run dev- Start development serverbun run build- Build for productionbun run start- Start production serverbun run cf:dev- Start with Wrangler dev
bun run lint- Run ESLintbun run lint:fix- Fix ESLint errorsbun run format- Format code with Prettierbun run type-check- Run TypeScript compiler
bun run db:generate- Generate migrationsbun run db:migrate:dev- Run dev migrationsbun run db:migrate:prod- Run prod migrationsbun run db:push- Push schema changesbun run db:studio- Open Drizzle Studio
bun run test:e2e- Run Playwright testsbun run test:e2e:ui- Run Playwright with UIbun run test:e2e:debug- Debug Playwright testsbun run test:api- Run Bruno API tests
bun run deploy- Deploy to developmentbun run deploy:prod- Deploy to productionbun run preview- Create preview deployment
- Next.js 15 - React framework with App Router
- React 19 - Latest React features
- Tailwind CSS - Utility-first CSS
- shadcn/ui - Component library
- Zustand - State management
- React Query - Data fetching (via tRPC)
- tRPC - End-to-end typesafe APIs
- Drizzle ORM - TypeScript ORM
- Better Auth - Authentication
- Cloudflare D1 - SQLite at the edge
- Cloudflare R2 - Object storage with image compression
- TypeScript - Type safety
- ESLint - Linting
- Prettier - Code formatting
- Husky - Git hooks
- lint-staged - Pre-commit checks
- Playwright - E2E testing
- Bruno - API testing
- Cloudflare Workers - Edge computing
- GitHub Actions - CI/CD
- OpenNext - Next.js adapter for Workers
This template includes a comprehensive R2 file upload system with automatic image compression and WebP conversion:
import { uploadFileWithCompression, UploadFolder } from "@/server/lib/r2-storage";
const result = await uploadFileWithCompression(
fileBuffer,
UploadFolder.PROFILE_PICTURES,
"avatar",
{
compression: {
quality: 80,
maxWidth: 2000,
maxHeight: 2000,
format: "webp"
}
}
);Features:
- Automatic image compression
- WebP conversion for optimal performance
- File validation
- Multiple upload folders
- Public URL generation
Preview deployments are automatically created for pull requests:
git checkout -b feature/my-feature
git push origin feature/my-featurePush to the stable branch to deploy to production:
git checkout stable
git merge main
git push origin stableBETTER_AUTH_SECRET- Secret key for Better Auth (min 32 chars)BETTER_AUTH_URL- Base URL for authenticationNEXT_PUBLIC_APP_URL- Public application URL
GITHUB_CLIENT_ID- GitHub OAuth client IDGITHUB_CLIENT_SECRET- GitHub OAuth client secretCLOUDFLARE_ACCOUNT_ID- For Drizzle migrationsCLOUDFLARE_DATABASE_ID- D1 database IDCLOUDFLARE_D1_TOKEN- D1 API token
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
MIT License - see LICENSE for details
For issues and questions, please open an issue.