CopyPatch v2 Documentation
CopyPatch adds inline copy editing to the React applications you already own. Authorized editors and clients can click, edit, and publish copy directly on the live page at ?copypatch=1, while your code, JSX structure, and CSS styling remain 100% untouched.
Core Principle: CopyPatch is an embedded library runtime, not an external SaaS or standalone server. It lives inside your application at the same-origin /__copypatch/api/v2 path, eliminating CORS configuration, proxy layers, and extra hosting infrastructure.
How It Works
- Mark Approved Strings: Wrap text nodes with
<EditableText contentKey="...">or read text values withuseCopyPatch(). - Embed the Backend: Mount the v2 backend at
/__copypatch/api/v2inside your host framework (Next.js App Router, Astro SSR, React Router, Express, Fastify, or Hono). - Choose Storage: Use
@copypatch/storage-sqlitefor single-server or container deployments, or@copypatch/storage-postgresfor horizontally scaled clusters. - Edit On-Page: Authorized team members navigate to
?copypatch=1, authenticate via Argon2id passphrase or host-auth session, and edit inline. - Draft & Publish: Save revisions in draft mode for review, or publish live instantly when holding the
publisherrole.
Quick Integration Preview
QuickStart.tsx
// 1. Mount in your host server (e.g. Next.js, Express, Fastify, Hono)
// app/%5F%5Fcopypatch/api/v2/[...path]/route.ts
import { createCopyPatchRouteHandlers } from '@copypatch/next/server';
import { copypatch } from '@/lib/copypatch';
export const { GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS } =
createCopyPatchRouteHandlers(copypatch);
// 2. Wrap components in your client layout
import { CopyPatchProvider, EditableText } from '@copypatch/react';
export function Hero() {
return (
<CopyPatchProvider locale="en">
<EditableText contentKey="hero.title" as="h1">
Let clients edit the copy. Not the website.
</EditableText>
</CopyPatchProvider>
);
} Framework Compatibility Matrix
| Host Framework | Server Integration | Deployment Notes |
|---|---|---|
| Next.js App Router | @copypatch/next catch-all route handlers | Direct server snapshot reads via readPublishedSnapshot() for SSR/RSC. |
| Astro SSR | @copypatch/node native adapter | Mount in an Astro SSR endpoint; static-only mode renders fallback text only. |
| React Router v7 | @copypatch/node native adapter | Framework Mode with server entry point. |
| Vite + Node / Express / Fastify / Hono | @copypatch/node middleware & handlers | Mount before request body parsers and SPA catch-all fallbacks. |
| Static-Only Hosting (SSG) | Not Supported for Editing | Can render bundled fallback copy, but cannot host API routes or write mutations. |
Key Differences from v1
- Embedded Same-Origin Runtime: v2 runs inside your existing Node/Next server at
/__copypatch/api/v2. No second port, standalone daemon, or CORS proxy. - Pluggable Storage Adapters: Native SQLite (
better-sqlite3) and PostgreSQL (pg) adapters with versioned, idempotent migrations. - Dual Authentication Architecture: Built-in Argon2id passphrase session management with CSRF protection, or pluggable
authAdapterto reuse host user accounts. - Role Separation: Explicit
editorrole for draft updates andpublisherrole for live releases. - Optimistic Concurrency Control: Atomic compare-and-swap (CAS) validation on revisions prevents accidental overwrites between simultaneous editors.
Next Steps
Follow the step-by-step guides to install and configure CopyPatch in your stack:
- Installation & CLI Guide – Install packages and scaffold project files.
- Next.js App Router Guide – Set up server routes and server component snapshots.
- React Integration Guide – Configure the provider, text components, and hooks.
- Security Architecture – Learn about same-origin isolation and threat protections.