Skip to content

Latest commit

Β 

History

21 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Templator

TypeScript Next.js

AI-first Next.js template for rapid development with authentication, database, and Cloudflare Workers deployment.

⭐ Star this repo if you find it useful!

πŸ“‹ Table of Contents

🎯 Who Is This For?

Perfect for:

  • πŸš€ Startup founders building MVPs rapidly with AI assistance
  • πŸ’Ό Indie hackers needing auth + RBAC + email flows out-of-the-box
  • πŸ€– AI-first developers using Cursor, Claude Code, GitHub Copilot
  • πŸŽ“ Learners exploring modern Next.js App Router + Drizzle architecture

Not ideal for:

  • Teams requiring extensive testing infrastructure from day 1
  • Projects with highly custom authentication requirements
  • Applications needing complex multi-tenancy from the start
  • Real-time applications (WebSocket, live collaboration)
  • Heavy computation workloads (video processing, ML inference)

⚠️ Conscious Trade-offs & Known Limitations

This template prioritizes speed and simplicity for MVP development. Here's what you should know before choosing Templator:

What's NOT Included (By Design)

Testing Infrastructure

  • No Vitest/Jest, Testing Library, or E2E tests
  • Why: 90% of MVPs don't need tests day 1. TypeScript + ESLint catch most bugs.
  • When to add: Before first paying customers or when team grows beyond 3 developers
  • See docs/LIMITATIONS.md for migration guide

Error Monitoring & Analytics

  • No Sentry, Axiom, or analytics integration
  • Why: Adds complexity and cost for early prototypes
  • When to add: Week 1 of production traffic
  • See docs/LIMITATIONS.md for setup guide

Advanced Features

  • ❌ WebSocket/real-time (Cloudflare Workers limitation)
  • ❌ File uploads (needs R2 bucket configuration)
  • ❌ Payment processing (Stripe integration needed)
  • ❌ Multi-tenancy (single-organization RBAC only)
  • ❌ Internationalization (English-only by default)
  • Why: Keep template focused, add these when business validated

Cloudflare Workers Constraints

Free Tier Limits (100,000 requests/day):

  • 10ms CPU time per request
  • 128MB memory
  • 1MB response size
  • Good for: Content sites, forms, auth flows

Paid Tier ($5/mo for 10M requests):

  • 30s CPU time (Workers Standard) or 15min (Workers Unbound)
  • Still 128MB memory
  • 25MB+ response size
  • Good for: API-heavy apps, complex queries

What Doesn't Work: WebSocket, filesystem access, long-running background jobs

See docs/LIMITATIONS.md for workarounds and alternatives.

When NOT to Use Templator

❌ Enterprise with strict compliance (SOC2, HIPAA day 1) β†’ Use custom build or commercial starter ❌ Complex B2B SaaS (multi-tenancy, teams, 10+ permission levels) β†’ Fork and extend RBAC ❌ Real-time apps (chat, multiplayer, live collaboration) β†’ Consider Supabase integration or traditional server ❌ Heavy computation (video encoding, ML inference) β†’ Use serverless functions or dedicated servers

βœ… Perfect for: Content sites, SaaS MVPs, internal tools, API-first apps, landing pages with auth

For detailed limitations and migration paths, see docs/LIMITATIONS.md. For adding real-time features, see docs/SUPABASE_INTEGRATION.md.

Tech Stack

Core

  • Next.js 15 - App Router, Server Components, Server Actions
  • React 19 - Latest React with Suspense and Transitions
  • TypeScript - Strict mode with full type safety
  • Tailwind CSS 4 - Utility-first styling
  • shadcn/ui - Beautiful, accessible components

Database & Auth

  • Drizzle ORM - TypeScript-first ORM with edge support
  • Neon PostgreSQL - Serverless Postgres with branching
  • Better Auth - Modern authentication with built-in security

Deployment

  • Cloudflare Workers - Edge deployment with zero cold starts
  • OpenNext - Next.js adapter for Cloudflare

Developer Experience

  • Turbopack - Ultra-fast bundler for development (built into Next.js 15)
  • ESLint - Code linting
  • Prettier - Code formatting
  • React Hook Form + Zod - Type-safe form validation

✨ Features

πŸ” Authentication & RBAC

  • βœ… Email/password with Better Auth
  • βœ… Email verification & password reset (built-in)
  • βœ… Role-Based Access Control (user/editor/admin)
  • βœ… Protected routes with middleware
  • βœ… Rate limiting for security
  • βœ… Custom PBKDF2 hashing (Cloudflare Workers compatible)

πŸ“§ Email System

  • βœ… React Email templates
  • βœ… Mock mode for development
  • βœ… Resend integration for production
  • βœ… Transactional email flows
  • βœ… Password reset & verification

πŸ—„οΈ Database

  • βœ… Drizzle ORM with Neon PostgreSQL
  • βœ… Type-safe queries with TypeScript
  • βœ… Migrations with Drizzle Kit
  • βœ… Edge-compatible architecture

🎨 UI Components

  • βœ… shadcn/ui components library
  • βœ… Dark mode support (next-themes)
  • βœ… Responsive design
  • βœ… Toast notifications (Sonner)

πŸ“ Feature Modules

  • βœ… Contact form with Server Actions
  • βœ… Newsletter with double opt-in
  • βœ… Blog system (draft/publish workflow)
  • βœ… Profile management
  • βœ… User management (admin only)

πŸš€ Developer Experience

  • βœ… AI-optimized architecture
  • βœ… Type-safe end-to-end
  • βœ… Hot reload with Turbopack
  • βœ… ESLint + Prettier configured
  • βœ… Comprehensive documentation

πŸ”’ Security & SEO

  • βœ… Security headers configured (HSTS, X-Frame-Options, CSP, etc.)
  • βœ… Dynamic sitemap.xml with blog posts
  • βœ… robots.txt with search engine directives
  • βœ… Open Graph & Twitter Cards metadata
  • βœ… Structured logging for debugging

βœ… Pages

  • Landing page with Hero, Features, CTA
  • Pricing page
  • Contact page
  • Blog listing and individual post pages
  • Authentication pages (login/register)
  • Dashboard with role-based sections
    • Dashboard overview (all users)
    • Profile management (all users)
    • Blog management (editor/admin)
      • List all posts (draft + published)
      • Create new post
      • Edit existing post
      • Delete post
    • Newsletter subscribers (editor/admin)
    • Contact messages (editor/admin)
    • User management (admin only)

Quick Start

1. Clone & Install

# Using this template on GitHub (recommended)
# Click "Use this template" button at the top of this repo

# Or clone directly
git clone https://github.com/yourusername/templator.git
cd templator
pnpm install

2. Environment Setup

Create .env file:

# Database (Neon PostgreSQL)
DATABASE_URL="postgresql://..."

# Better Auth
BETTER_AUTH_URL="http://localhost:3000"
BETTER_AUTH_SECRET="run: openssl rand -base64 32"
NEXT_PUBLIC_APP_URL="http://localhost:3000"

# Email (optional - mock by default)
ADMIN_EMAIL="admin@yourdomain.com"
# RESEND_API_KEY="re_xxxxx" # Uncomment to enable real emails

Generate Better Auth secret:

openssl rand -base64 32

3. Database Setup

# Generate migration
pnpm db:generate

# Push to database
pnpm db:push

# Open Drizzle Studio (optional)
pnpm db:studio

4. Run Development Server

pnpm dev

Open http://localhost:3000

Project Structure

src/
β”œβ”€β”€ app/
β”‚ β”œβ”€β”€ (routes)/ # Page routes
β”‚ β”œβ”€β”€ dashboard/ # Protected dashboard with RBAC
β”‚ β”œβ”€β”€ api/auth/ # Better Auth handler
β”‚ β”œβ”€β”€ layout.tsx # Root layout with providers
β”‚ └── providers.tsx # Client providers (Theme)
β”œβ”€β”€ components/
β”‚ β”œβ”€β”€ ui/ # shadcn/ui components
β”‚ β”œβ”€β”€ layout/ # Navbar, Footer, ThemeToggle
β”‚ β”œβ”€β”€ auth/ # RBAC components (RoleGate, RoleGateClient)
β”‚ β”œβ”€β”€ dashboard/ # Dashboard components (DashboardNav)
β”‚ └── common/ # Shared components (PageHeader, Section)
β”œβ”€β”€ features/
β”‚ β”œβ”€β”€ auth/ # Authentication (schema, actions)
β”‚ β”œβ”€β”€ users/ # User management (admin actions)
β”‚ β”œβ”€β”€ profile/ # Profile editing (actions, form)
β”‚ β”œβ”€β”€ blog/ # Blog posts (schema, actions, PostForm)
β”‚ β”œβ”€β”€ contact/ # Contact form feature
β”‚ └── newsletter/ # Newsletter feature
β”œβ”€β”€ lib/
β”‚ β”œβ”€β”€ auth.ts # Better Auth config
β”‚ β”œβ”€β”€ auth-client.ts # Client-side hooks
β”‚ β”œβ”€β”€ permissions.ts # RBAC permission system
β”‚ β”œβ”€β”€ password.ts # PBKDF2 hashing (Cloudflare Workers compatible)
β”‚ └── utils.ts # Utility functions (cn, etc.)
β”œβ”€β”€ db/
β”‚ β”œβ”€β”€ schema.ts # Drizzle schema (users with roles)
β”‚ └── index.ts # Database client
β”œβ”€β”€ hooks/ # Custom React hooks
└── types/ # TypeScript types (NextAuth extensions)

Available Scripts

# Development
pnpm dev              # Start dev server with Turbopack
pnpm build            # Production build
pnpm start            # Start production server

# Code Quality
pnpm lint             # Run ESLint
pnpm format           # Format code with Prettier
pnpm format:check     # Check code formatting
pnpm typecheck        # TypeScript type checking

# Database
pnpm db:generate      # Generate migrations
pnpm db:push          # Push schema to database
pnpm db:studio        # Open Drizzle Studio

# Cloudflare
pnpm deploy           # Deploy to Cloudflare
pnpm preview          # Preview Cloudflare build
pnpm cf-typegen       # Generate Cloudflare types

πŸ“§ Email Configuration

By default, emails are mocked (logged to console). To enable real emails with Resend:

Note: Resend is already installed in this template.

  1. Get API key from Resend
  2. Add to .env:
    RESEND_API_KEY="re_xxxxx"
    EMAIL_FROM="noreply@yourdomain.com"
    EMAIL_PROVIDER="resend"
  3. Verify your domain in Resend dashboard (required for production)

See docs/EMAIL_SYSTEM.md for detailed configuration and templates guide.

Deployment

Cloudflare Workers (Recommended)

Why Cloudflare Workers?

  • Global edge network with zero cold starts
  • Free tier: 100k requests/day
  • Perfect match with Neon PostgreSQL
  • OpenNext adapter maintains Next.js compatibility

First-time setup:

# Login to Cloudflare
pnpm wrangler login

# Set secrets (don't use plain env vars for sensitive data)
pnpm wrangler secret put DATABASE_URL
pnpm wrangler secret put NEXTAUTH_SECRET

Deploy:

# Build and deploy to production
pnpm deploy

# Or preview before deploying
pnpm preview

Configuration:

  • Edit wrangler.jsonc for worker settings
  • OpenNext config in open-next.config.ts

Environment Variables

Local development (.env):

DATABASE_URL="postgresql://..."
NEXTAUTH_URL="http://localhost:3000"
NEXTAUTH_SECRET="..."
ADMIN_EMAIL="admin@yourdomain.com"

Production (Cloudflare):

Set secrets via Wrangler CLI (recommended):

pnpm wrangler secret put DATABASE_URL
pnpm wrangler secret put NEXTAUTH_SECRET
pnpm wrangler secret put ADMIN_EMAIL

Or set in Cloudflare dashboard β†’ Workers β†’ Settings β†’ Variables and Secrets

Required:

  • DATABASE_URL - Neon connection string
  • BETTER_AUTH_URL - Your production URL (e.g., https://yourapp.workers.dev)
  • BETTER_AUTH_SECRET - Same as local (use openssl rand -base64 32)
  • NEXT_PUBLIC_APP_URL - Same as BETTER_AUTH_URL

Optional:

  • ADMIN_EMAIL - For contact form notifications
  • RESEND_API_KEY - If using real email (instead of mock)

Development Workflow

  1. Add new feature:

    mkdir -p src/features/my-feature
    # Create: schema.ts, actions.ts, MyFeatureForm.tsx, README.md
  2. Add database table:

    • Edit src/db/schema.ts
    • Run pnpm db:generate
    • Run pnpm db:push
  3. Add new page:

    • Create in src/app/my-page/page.tsx
    • Add link to Navbar.tsx
  4. Validation loop (before commit):

    pnpm format      # Format code
    pnpm lint        # Check linting
    pnpm typecheck   # Check types
    pnpm build       # Test build

Documentation

See docs/ folder for detailed guides:

  • LIMITATIONS.md - Known limitations, platform constraints, and migration paths
  • SUPABASE_INTEGRATION.md - Adding real-time, storage, and enhanced database features with Supabase
  • AUTHENTICATION.md - Complete Better Auth guide (email/password, verification, password reset)
  • AUTHENTICATION_ADVANCED.md - Advanced auth flows (security, edge compatibility)
  • RBAC.md - Role-Based Access Control system (user/editor/admin)
  • ARCHITECTURE.md - Project structure and conventions
  • AI_WORKFLOW.md - Working with AI assistants (includes /changelog and /release commands)
  • STACK.md - Technology choices and rationale (Drizzle, Better Auth, Cloudflare)
  • DEPLOYMENT.md - Cloudflare Workers deployment guide
  • MIDDLEWARE.md - Authentication middleware (edge-compatible)
  • EMAIL_SYSTEM.md - Email configuration and templates
  • recipes/ - Step-by-step guides for common tasks

πŸ“Š Comparison

How does Templator compare to other Next.js starters?

Feature Templator create-t3-app Next.js SaaS Starter
Auth System βœ… Better Auth + RBAC βœ… NextAuth ⚠️ Custom
Email Verification βœ… Built-in ❌ Manual setup ❌ Manual setup
Password Reset βœ… Built-in ❌ Manual setup ❌ Manual setup
Role-Based Access βœ… 3-tier RBAC ❌ DIY ❌ DIY
Email Templates βœ… React Email ❌ ❌
Edge Deployment βœ… Cloudflare Workers ⚠️ Vercel-focused ⚠️ Vercel-focused
AI-Optimized βœ… Feature-based architecture ❌ ❌
Documentation βœ… Comprehensive docs/ ⚠️ Basic ⚠️ Basic
Database ORM Drizzle Drizzle/Prisma Prisma
Blog System βœ… Built-in ❌ ❌

Tech Stack Details

Why Drizzle over Prisma?

  • TypeScript-first with native type inference
  • Better performance for serverless/edge
  • Smaller bundle size
  • Perfect Cloudflare Workers compatibility

Why Better Auth?

  • Modern, actively maintained (Auth.js/NextAuth is now maintained by Better Auth team)
  • Built-in rate limiting, email verification, password reset
  • TypeScript-first with excellent type inference
  • Cloudflare Workers compatible (custom PBKDF2 hashing)
  • No SessionProvider wrapper needed

Why Cloudflare Workers?

  • Global edge deployment
  • Zero cold starts
  • Generous free tier (100k req/day)
  • Perfect with Neon PostgreSQL

Credits

Built with:

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages