A production-ready Next.js template optimized for Cloudflare deployment with all the essential packages and best practices for modern web development.
- β‘ Next.js 15 - Latest App Router with Turbopack for lightning-fast development
- βοΈ Cloudflare Ready - Optimized for Cloudflare Pages/Workers deployment
- π¨ Tailwind CSS 4 - Latest version with enhanced performance
- ποΈ Database Ready - Prisma ORM with PostgreSQL and Accelerate integration
- π§ͺ Testing Suite - Vitest, React Testing Library, and Playwright E2E tests
- π± State Management - Zustand for lightweight, type-safe state management
- π Type Safety - Full TypeScript configuration with strict mode
- π Code Quality - ESLint, Prettier, and pre-commit hooks
- π UI Components - shadcn/ui compatible setup with CVA and utilities
- π§ Developer Experience - Hot reload, devtools, and comprehensive tooling
| Category | Technology |
|---|---|
| Framework | Next.js 15 with App Router |
| Runtime | Cloudflare Workers/Pages |
| Language | TypeScript 5.x |
| Styling | Tailwind CSS 4.x |
| Database | PostgreSQL + Prisma + Accelerate |
| State Management | Zustand 5.x |
| Testing | Vitest + React Testing Library + Playwright |
| Package Manager | pnpm (recommended) |
| Code Quality | ESLint + Prettier |
| UI Utilities | CVA, clsx, tailwind-merge |
| Forms | React Hook Form + Zod validation |
| Icons | Lucide React |
| Data Fetching | TanStack Query |
- Node.js 20.x or later
- pnpm (recommended) or npm
- PostgreSQL database (local or cloud)
# Clone the repository
git clone https://github.com/Hussain-7/cloudflare-nextjs-prisma-template.git my-app
cd my-app
# Install dependencies
pnpm install# Copy environment variables
cp .env.example .env.local
# For Cloudflare (optional)
cp .dev.vars.example .dev.varsUpdate your environment variables:
# Database
DATABASE_URL="postgresql://username:password@localhost:5432/mydb"
# Cloudflare (optional)
# Add your Cloudflare-specific variables in .dev.vars# Generate Prisma client
pnpm generate
# Run database migrations
pnpm migrate
# Seed database (optional)
pnpm seed# Start development server with Turbopack
pnpm dev
# Open http://localhost:3000βββ app/ # Next.js App Router
β βββ api/ # API routes
β βββ components/ # React components
β β βββ __tests__/ # Component tests
β βββ lib/ # Utilities and configurations
β β βββ db/ # Database connection
β βββ stores/ # Zustand state stores
β β βββ __tests__/ # Store tests
β βββ types/ # TypeScript type definitions
βββ e2e/ # Playwright E2E tests
βββ prisma/ # Database schema and migrations
β βββ schema.prisma # Database schema
β βββ seed.ts # Database seed data
βββ public/ # Static assets
βββ tests/ # Test configuration and utilities
β βββ setup.ts # Test setup file
βββ .claude.md # AI development context
βββ playwright.config.ts # E2E test configuration
βββ vitest.config.mjs # Unit test configuration
βββ next.config.ts # Next.js configuration
This template includes a comprehensive testing setup:
# Run tests in watch mode
pnpm test
# Run tests once
pnpm test:run
# Run tests with UI
pnpm test:ui
# Run tests with coverage
pnpm test:coverage# Run E2E tests
pnpm test:e2e
# Run E2E tests with UI
pnpm test:e2e:ui
# Run E2E tests in headed mode
pnpm test:e2e:headed# Run ESLint
pnpm lint
# Run TypeScript check
pnpm typecheck
# Format code with Prettier
pnpm format
# Check formatting
pnpm format:check# Generate Prisma client
pnpm generate
# Create and run migrations
pnpm migrate
# Reset database
pnpm prisma db reset
# Open Prisma Studio
pnpm studio
# Seed database
pnpm seed- Edit
prisma/schema.prisma - Create migration:
pnpm prisma migrate dev --name your-migration - Update seed data in
prisma/seed.ts - Generate types:
pnpm generate
Zustand stores are located in app/stores/:
// Example store usage
import { useAppStore } from '@/stores'
function MyComponent() {
const { theme, setTheme } = useAppStore()
return (
<button onClick={() => setTheme(theme === 'light' ? 'dark' : 'light')}>
Toggle Theme
</button>
)
}This template uses the latest Tailwind CSS with:
- CSS-first configuration
- Enhanced performance
- Built-in container queries
- Modern CSS features
Ready for shadcn/ui integration with:
- Class Variance Authority (CVA)
- clsx and tailwind-merge utilities
- Consistent design tokens
# Build for production
pnpm build
# Deploy to Cloudflare
pnpm deploy
# Preview deployment locally
pnpm previewFor Cloudflare deployment, add your environment variables in:
- Local development:
.dev.vars - Production: Cloudflare Dashboard β Pages/Workers β Settings β Environment Variables
The template is optimized for Cloudflare with:
- Server-side rendering
- Edge runtime compatibility
- Minimal bundle size
- Fast cold starts
| Script | Description |
|---|---|
pnpm dev |
Start development server with Turbopack |
pnpm build |
Build for production |
pnpm start |
Start production server |
pnpm lint |
Run ESLint |
pnpm typecheck |
Run TypeScript check |
pnpm format |
Format code with Prettier |
pnpm test:run |
Run unit tests |
pnpm test:e2e |
Run E2E tests |
pnpm generate |
Generate Prisma client |
pnpm migrate |
Run database migrations |
pnpm studio |
Open Prisma Studio |
pnpm seed |
Seed database |
pnpm deploy |
Deploy to Cloudflare |
- Delete
app/api/brainlifts/(example API) - Update
app/stores/with your own stores - Modify
prisma/schema.prismafor your data model - Update
app/types/index.tswith your types
mkdir app/components/ui
# Add your components here- Update
next.config.tsfor custom webpack config - Modify
tailwind.config.tsfor custom design system - Edit
tsconfig.jsonfor TypeScript preferences
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Commit changes:
git commit -m 'Add amazing feature' - Push to branch:
git push origin feature/amazing-feature - Open a Pull Request
This template is MIT licensed. See LICENSE for details.
- Next.js team for the amazing framework
- Cloudflare for the edge platform
- Vercel for development tools
- Prisma for the database toolkit
- All the open source contributors
Happy coding! π
If this template helped you, please give it a β on GitHub!