payload-template-project

Next.js 16, Payload 3, Clerk auth, Postgres and S3 storage wired up as a baseline for new projects

payload-template-project preview

Overview

Summary generated from the README

A general-purpose starter that combines Next.js 16 App Router, Payload CMS 3, PostgreSQL, Clerk authentication, S3-compatible media storage and Resend email. The UI uses Tailwind CSS 4 and shadcn/ui. The Postgres adapter runs with migrations only, so migrations must be applied before the first run. Admin access is through Clerk users with a role set in public metadata.

Features

  • Clerk authentication replacing Payload's local login, with role-based admin access
  • PostgreSQL via the Payload adapter with migration-only schema changes
  • Media uploads collection with image sizes and focal point stored in S3-compatible storage
  • Resend transactional email, redirects and SEO plugins, and live preview
  • Tailwind CSS 4, shadcn/ui, Lucide icons and Motion for the front end
  • Dockerfile-based deployment compose file and semantic-release tooling

Good for

  • Bootstrapping customer websites or landing pages on a consistent stack
  • Starting SaaS applications that need Clerk sign-in alongside Payload CMS
  • Standardizing team projects on shared auth, storage and email wiring

From the author

Get started quickly with Next.js, Clerk Auth, Payload CMS and Postgres.

Get started

This repository is a GitHub template: create your own copy of it in one click.

Create a repository from this template

README

Payload Template Project

Internal starter template for building customer websites, landing pages, and SaaS applications on a consistent stack. Bootstrap new projects from this repo instead of starting from scratch — auth, CMS, storage, and UI conventions are already wired up.

Stack

  • Framework: Next.js 16 (App Router)
  • CMS: Payload CMS 3
  • Database: PostgreSQL (via @payloadcms/db-postgres)
  • Auth: Clerk
  • Storage: S3-compatible object storage (media uploads)
  • Email: Resend
  • UI: Tailwind CSS 4, shadcn/ui, Lucide icons, Motion

Requirements

  • Node.js ^22.14.0 or >=24.10.0
  • pnpm ^9, ^10, ^11, or ^12
  • A PostgreSQL connection string (local, Docker, or hosted)

Setup

  1. Clone the repo and install dependencies:

    pnpm install
    
  2. Copy the environment file and fill in the values:

    cp .env.example .env
    
    VariablePurpose
    DATABASE_URLPostgreSQL connection string (postgres://user:pass@host:5432/db)
    PAYLOAD_SECRETPayload's signing secret
    PREVIEW_SECRETSecret used for live preview links
    CRON_SECRETSecret for authenticating scheduled/cron jobs
    NEXT_PUBLIC_SERVER_URLPublic URL the app is served from
    CLERK_SECRET_KEY / NEXT_PUBLIC_CLERK_PUBLISHABLE_KEYClerk API keys
    CLERK_WEBHOOK_SIGNING_SECRETVerifies incoming Clerk webhooks
    NEXT_PUBLIC_CLERK_SIGN_IN_URL, ..._SIGN_IN_FALLBACK_REDIRECT_URL, ..._SIGN_UP_FALLBACK_REDIRECT_URLClerk auth flow routing
    S3_BUCKET, S3_ACCESS_KEY_ID, S3_ACCESS_KEY_SECRET, S3_REGION, S3_ENDPOINTMedia storage (S3-compatible)
    RESEND_API_KEY, RESEND_FROM_EMAIL, RESEND_FROM_NAMETransactional email
  3. Apply the database schema:

    pnpm payload migrate
    

    The Postgres adapter runs with push: false (src/payload.config.ts), so tables are created only by migrations. Skip this on a fresh database and every query fails with relation "pages" does not exist (Postgres 42P01), which appears during pnpm build as Failed to collect page data for /[slug]. The command is safe to re-run: applied migrations are tracked in payload_migrations.

  4. Start the dev server:

    pnpm dev
    
  5. Open http://localhost:3000/admin. There is no local first-user screen: the Users collection disables the local strategy and authenticates through Clerk. Create your user in Clerk, set its public metadata to { "role": "admin" }, then sign in at /admin. The default role is user, which cannot enter the admin panel; the Clerk login strategy (or the user.created webhook, when reachable) creates the matching Payload record with the role from that metadata.

Local PostgreSQL (optional)

docker-compose.yml deploys the application itself and expects an external PostgreSQL instance. For local development you can run PostgreSQL with Docker:

  1. Start a PostgreSQL container:

    docker run --name payload-postgres -e POSTGRES_PASSWORD=postgres -p 5432:5432 -d postgres:17
    
  2. Set DATABASE_URL in .env, e.g. postgres://postgres:[email protected]:5432/payload.

  3. Apply the schema: pnpm payload migrate.

Database Migrations

The Postgres adapter runs with push: false, so schema changes are applied through migrations rather than automatic dev-time pushes. After changing any collection, global, or field config:

  1. Generate a migration and review it:

    pnpm payload migrate:create
    
  2. Commit the new files under src/migrations/.

  3. Apply pending migrations to the database:

    pnpm payload migrate
    

CI applies migrations before building the image (.github/workflows/push-to-ghcr.yml), and the build prerenders routes against the database, so migrations must be committed before the workflow runs.

First run and empty databases

Run pnpm payload migrate once before the first pnpm dev or pnpm build, and again after recreating the database or switching DATABASE_URL to a database that has not been migrated. Verify with pnpm payload migrate:status (the initial migration is 20260925_210034).

If a table appears to be missing, confirm you migrated the database you are actually connected to, not just one in Docker or on another port.

Symptoms of an unmigrated database:

  • error: relation "pages" does not exist (code: '42P01')
  • Failed to collect page data for /[slug] during pnpm build
  • relation "payload_migrations" does not exist from migrate:status

Available Scripts

ScriptPurpose
pnpm devStart the Next.js dev server
pnpm buildProduction build
pnpm startServe the production build
pnpm lintRun ESLint
pnpm payloadRun the Payload CLI
pnpm generate:typesRegenerate Payload's TypeScript types from the config
pnpm generate:importmapRegenerate Payload's admin import map
pnpm payload migrate:createGenerate a migration after config changes
pnpm payload migrateApply pending migrations
pnpm payload migrate:statusShow applied and pending migrations

Run pnpm generate:types after changing any collection, global, or field config so generated types stay in sync, and pnpm payload migrate:create so the database schema stays in sync with the config.

Project Structure

  • src/ — application code (Next.js routes, Payload config, collections, components)
  • context/ — living documentation (architecture, UI tokens/rules, code standards, build plan, progress tracker) used to keep new projects built from this template consistent
  • docker-compose.yml — production compose for the app (expects an external PostgreSQL instance)

Collections

  • Users — auth-enabled collection with admin panel access, backed by Clerk.
  • Media — uploads collection with pre-configured image sizes and focal point support, backed by S3-compatible storage.

See the Payload Collections docs to extend either.

Using This as a Starter

When bootstrapping a new internal project from this template:

  1. Update package.json name/description and this README's title.
  2. Review context/ and update it to describe the new project's purpose, scope, and architecture — it should not still describe this template once customized.
  3. Keep the Clerk, Payload, S3, and Resend wiring unless the new project has a reason to diverge — the point of the template is a consistent baseline across projects.

Support

Internal questions: ask in the team channel. For upstream framework issues, see the Payload Discord or Payload GitHub discussions.

Claim this template

More Starters & boilerplates templates

acme-website screenshot

acme-website

Payload 3 starter with Better Auth, Postgres, S3 storage, a blog and composable layout and motion components

126
v3
Next.js
Updated 1 months ago
payload-template-project screenshot

payload-template-project

Next.js 16 and Payload starter with Clerk auth, MongoDB, S3 media storage, Resend email and shadcn/ui

0
v3
Next.js
Updated 2 weeks ago
nextload screenshot

nextload

Next.js and Payload boilerplate with Better Auth, blog, cart, runtime theming and hybrid caching

1
v3
Next.js
Updated 2 months ago