Skip to content

Production-ready Next.js 15 template for Cloudflare with Turbopack, Tailwind CSS 4, Prisma, Zustand & comprehensive testing. Complete starter kit with TypeScript, Vitest, Playwright, ESLint & Prettier - everything you need for modern web development.

Notifications You must be signed in to change notification settings

Hussain-7/cloudflare-nextjs-prisma-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

14 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ Next.js Cloudflare Template

A production-ready Next.js template optimized for Cloudflare deployment with all the essential packages and best practices for modern web development.

Deploy to Cloudflare

✨ Features

  • ⚑ 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

πŸ› οΈ Tech Stack

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

πŸš€ Quick Start

Prerequisites

  • Node.js 20.x or later
  • pnpm (recommended) or npm
  • PostgreSQL database (local or cloud)

1. Use this template

# Clone the repository
git clone https://github.com/Hussain-7/cloudflare-nextjs-prisma-template.git my-app
cd my-app

# Install dependencies
pnpm install

2. Environment Setup

# Copy environment variables
cp .env.example .env.local

# For Cloudflare (optional)
cp .dev.vars.example .dev.vars

Update your environment variables:

# Database
DATABASE_URL="postgresql://username:password@localhost:5432/mydb"

# Cloudflare (optional)
# Add your Cloudflare-specific variables in .dev.vars

3. Database Setup

# Generate Prisma client
pnpm generate

# Run database migrations
pnpm migrate

# Seed database (optional)
pnpm seed

4. Start Development

# Start development server with Turbopack
pnpm dev

# Open http://localhost:3000

πŸ“ Project Structure

β”œβ”€β”€ 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

πŸ§ͺ Testing

This template includes a comprehensive testing setup:

Unit Tests (Vitest + React Testing Library)

# 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

E2E Tests (Playwright)

# 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

πŸ“ Code Quality

Linting and Formatting

# Run ESLint
pnpm lint

# Run TypeScript check
pnpm typecheck

# Format code with Prettier
pnpm format

# Check formatting
pnpm format:check

πŸ—ƒοΈ Database Management

Prisma Commands

# 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

Custom Database Schema

  1. Edit prisma/schema.prisma
  2. Create migration: pnpm prisma migrate dev --name your-migration
  3. Update seed data in prisma/seed.ts
  4. Generate types: pnpm generate

πŸ—οΈ State Management

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>
  )
}

🎨 Styling

Tailwind CSS 4

This template uses the latest Tailwind CSS with:

  • CSS-first configuration
  • Enhanced performance
  • Built-in container queries
  • Modern CSS features

UI Components

Ready for shadcn/ui integration with:

  • Class Variance Authority (CVA)
  • clsx and tailwind-merge utilities
  • Consistent design tokens

πŸš€ Deployment

Cloudflare Pages/Workers

# Build for production
pnpm build

# Deploy to Cloudflare
pnpm deploy

# Preview deployment locally
pnpm preview

Environment Variables

For Cloudflare deployment, add your environment variables in:

  • Local development: .dev.vars
  • Production: Cloudflare Dashboard β†’ Pages/Workers β†’ Settings β†’ Environment Variables

Build Optimization

The template is optimized for Cloudflare with:

  • Server-side rendering
  • Edge runtime compatibility
  • Minimal bundle size
  • Fast cold starts

πŸ“¦ Package Scripts

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

πŸ”§ Customization

1. Remove Example Code

  • Delete app/api/brainlifts/ (example API)
  • Update app/stores/ with your own stores
  • Modify prisma/schema.prisma for your data model
  • Update app/types/index.ts with your types

2. Add Your Components

mkdir app/components/ui
# Add your components here

3. Configure for Your Needs

  • Update next.config.ts for custom webpack config
  • Modify tailwind.config.ts for custom design system
  • Edit tsconfig.json for TypeScript preferences

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Commit changes: git commit -m 'Add amazing feature'
  4. Push to branch: git push origin feature/amazing-feature
  5. Open a Pull Request

πŸ“„ License

This template is MIT licensed. See LICENSE for details.

πŸ™ Acknowledgments

  • 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!

About

Production-ready Next.js 15 template for Cloudflare with Turbopack, Tailwind CSS 4, Prisma, Zustand & comprehensive testing. Complete starter kit with TypeScript, Vitest, Playwright, ESLint & Prettier - everything you need for modern web development.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published