Skip to content
Projets

TangSY/edge-next-starter

Voir sur GitHub

À propos

Un modèle de démarrage full stack Next.js + Cloudflare prêt à l’emploi, qui intègre Edge Runtime, la base de données D1, le stockage R2, le cache KV, des hooks Analytics Engine et un pipeline CI/CD complet.

Données et analyse

Comment ces chiffres sont mesurés

Progression mesurée des étoiles

in 24h
0
in 7 days
0
in 15 days
0
in 1 month
Historique en cours

Variations nettes sur des périodes qui se chevauchent, pas des totaux quotidiens. Les mesures absentes restent vides. Les étoiles indiquent l’intérêt, pas la qualité.

README.md

Original

English | 简体中文


vinext Next.js TypeScript React Tailwind CSS Cloudflare Prisma better-auth Node.js pnpm License


Next.js + Cloudflare Workers Full‑Stack Starter (vinext)

A production‑ready Next.js + Cloudflare Workers full‑stack starter powered by vinext (Vite‑based Next.js reimplementation). Integrates D1 database, R2 storage, KV cache, better‑auth authentication, next‑intl i18n, and a complete CI/CD pipeline — all running natively on Cloudflare Workers edge network.

✨ Features

Core Stack

  • vinext — Vite‑based Next.js reimplementation for Cloudflare Workers (up to 4x faster builds, 57% smaller bundles)
  • Next.js 15.5.2 — App Router with RSC (React Server Components)
  • Cloudflare Workers — Native edge deployment (not Pages)
  • D1 Database — Edge SQLite database
  • R2 Storage — Object storage with zero egress fees
  • KV Storage — High‑performance key‑value cache
  • better‑auth — Edge‑compatible authentication (credentials + Google OAuth)
  • Tailwind CSS — Utility‑first CSS framework

Tooling

  • Vite — Next‑gen frontend build tool (via vinext)
  • pnpm — Fast, disk‑efficient package manager
  • Vitest — Modern unit test framework
  • ESLint + Prettier — Code quality and formatting
  • TypeScript — Type safety

Automation

  • ✅ Vitest covers repositories, database, cache, and storage clients
  • ✅ Automated CI/CD (with build‑cache optimization)
  • ✅ Database migrations auto‑run and verify
  • ✅ Multi‑environment configs (dev/test/prod)
  • ✅ API rate limit (KV‑based sliding window)
  • ✅ Auto‑generate CHANGELOG (Conventional Commits)
  • ✅ Environment variable validation (Zod)
  • ✅ Structured logs and request tracing (built‑in Analytics hooks; extendable to Analytics Engine)
  • ✅ Automated migration validation scripts

📋 Requirements

  • Node.js >= 22.0.0 (recommend nvm)
  • pnpm >= 8.0.0
  • Cloudflare account
  • Git

🚀 Quick Start

For full setup, see Quick Start. It covers dependencies, Cloudflare login, resource creation, migrations, and dev server. This section provides the entry points only.

🌟 Showcase

Projects built with this starter template:

  • imgc AI — A free AI image generation platform powered by DALL-E 3. Supports multiple aspect ratios, artistic styles (cinematic, photography, anime, digital art, etc.), and prompt optimization. Features lightning-fast generation, privacy-first design, and unlimited free usage with no registration required.

📁 Project Structure

cloudflare-worker-template/
├── app/                        # Next.js App Router
│   ├── api/                   # API routes (Edge Runtime)
│   │   ├── health/           # Health check
│   │   ├── users/            # User CRUD examples
│   │   ├── posts/            # Post CRUD examples
│   │   └── upload/           # File upload example
│   ├── layout.tsx            # Root layout
│   ├── page.tsx              # Home page
│   └── globals.css           # Global styles
├── repositories/              # Data access layer (Repository pattern)
│   ├── index.ts              # Repository factory
│   ├── user.repository.ts    # User data ops
│   └── post.repository.ts    # Post data ops
├── lib/                       # Libraries
│   ├── api/                  # API utilities (responses, middleware, DB wrapper)
│   ├── db/                   # D1 client (Prisma singleton)
│   ├── r2/                   # R2 client
│   ├── cache/                # KV cache client
│   ├── errors/               # Unified error handling
│   ├── logger/               # Logging system
│   └── utils/                # Utilities
├── components/                # React components
├── types/                     # TypeScript types
├── migrations/                # Database migrations (SQL)
│   ├── 0001_init.sql         # Initial schema
│   └── 002_example.sql.template
├── prisma/                    # Prisma schema
│   └── schema.prisma         # Models
├── scripts/                   # Automation scripts
│   └── seed.js               # Seed data
├── __tests__/                 # Tests
│   ├── lib/                  # Unit tests
│   └── api/                  # API tests
├── .github/workflows/         # GitHub Actions CI/CD
│   ├── ci.yml                # CI
│   ├── deploy-test.yml       # Test deploy
│   └── deploy-prod.yml       # Prod deploy
├── wrangler.toml              # Local env config
├── wrangler.test.toml         # Test env config
├── wrangler.prod.toml         # Prod env config
├── .nvmrc                     # Node.js version
├── .npmrc                     # pnpm config
├── vitest.config.ts           # Test config
└── package.json               # Project config

🛠️ Commands

See Development Guide for details.

# Development
pnpm dev                    # vinext dev server (Vite + Workers runtime)

# Testing
pnpm test                   # Run all tests
pnpm run test:watch         # Watch mode

# Build & Deploy
pnpm build                  # Build app (vinext + Vite)
pnpm deploy                 # Deploy to Cloudflare Workers

🔄 CI/CD

See Deployment Guide for details.

  • CI: On every push — tests, type‑check, build
  • Auto deploy:
    • develop → test
    • main → production

Secrets

Add in repo settings:

  • CLOUDFLARE_API_TOKEN
  • CLOUDFLARE_ACCOUNT_ID

📦 API Examples

Health Check

curl https://your-domain.com/api/health

Users (with cache)

# Get all users
curl https://your-domain.com/api/users

# Create user
curl -X POST https://your-domain.com/api/users \
  -H "Content-Type: application/json" \
  -d '{"email": "[email protected]", "name": "Zhang San"}'

Upload to R2

# Upload file via API
curl -X POST https://your-domain.com/api/upload \
  -F "[email protected]"

# Download file
curl https://your-domain.com/api/upload?key=uploads/1234567890-image.jpg

### Upload UI (R2 demo)

- Visit `/upload` to try the browser-based upload UI that posts to `/api/upload` and shows a preview.

🧪 Testing

pnpm test                   # Core unit tests
pnpm run test:coverage      # Coverage report

Coverage includes D1, R2, KV, and error handling.

🌍 Environments

  • Local: wrangler.toml
  • Test: wrangler.test.toml — auto‑deploy from develop
  • Prod: wrangler.prod.toml — auto‑deploy from main

Details on binding names, secrets, and seeding: docs/ENVIRONMENTS.md.

📈 Cloudflare Workers Free Quotas

Summary under Workers Free plan (subject to official docs):

  • Workers

    • Daily requests: 100,000
    • CPU time: 10 ms per request
    • Workers: unlimited
  • D1 Database

    • Databases: 10
    • Total storage: 5 GB (shared)
    • Daily row reads: 5,000,000
    • Daily row writes: 100,000
  • R2 Storage

    • Storage: 10 GB per month
    • Class A ops (write/delete): 1,000,000 per month
    • Class B ops (read): 10,000,000 per month
    • Egress: free ($0)
  • KV Storage

    • Total storage: 1 GB
    • Daily reads: 10,000,000
    • Daily writes/deletes/lists: 100,000 (combined)
  • Analytics Engine

    • Daily data points written: 100,000
    • Daily read queries: 10,000

Tip: For higher quotas or features, upgrade Workers plans. In production, prefer Analytics Engine via feature flags; in dev/test use logs or KV/D1 as fallbacks.

💡 Best Practices

See Development Guide.

  1. Use pnpm — enforced by project config
  2. Follow lint rules — ESLint + Prettier run pre‑commit
  3. Write tests — add test cases for new features
  4. Use migrations — manage DB changes with SQL files

🔧 FAQs

Troubleshooting docs:

📚 Docs

Core

Technical

Specialized

🔗 References

🎯 Start Building

After cloning:

  1. ✅ Complete setup via Quick Start
  2. ✅ Build pages and APIs under app/
  3. ✅ Push code; CI/CD runs tests and deploys
  4. ✅ Focus on business logic — infra is prewired

Explorer des projets similaires

Chargement…