# Craftkit Documentation

Developer toolkit for generating documents from templates. Each doc is also available as raw markdown by appending `.md` to the URL (e.g., /documentation/quickstart.md). The full corpus is at /llms-full.txt.

## Get started

- [Welcome](http://localhost:3000/documentation/welcome.md): What Craftkit is, who it's for, and how the pieces fit.
- [Quickstart](http://localhost:3000/documentation/quickstart.md): Render your first PDF from a template in under five minutes.
- [Concepts](http://localhost:3000/documentation/concepts.md): Templates, versions, variables, manifests — the mental model.
- [Integration guide](http://localhost:3000/documentation/integration-guide.md): End-to-end implementation playbook: API rendering, builder embed, form embed, and production hardening.
- [AI setup prompt](http://localhost:3000/documentation/ai-setup.md): One-prompt setup — paste into any AI assistant to generate a complete integration for your stack.

## REST API

- [Authentication](http://localhost:3000/documentation/api/authentication.md): Authenticate every request with a project API key.
- [POST /v1/templates/:slug/render](http://localhost:3000/documentation/api/render-template.md): Enqueue a render job against a template version.
- [GET /v1/renders/:id](http://localhost:3000/documentation/api/render-status.md): Poll a render until it succeeds, fails, or times out.
- [POST /v1/hooks/:token](http://localhost:3000/documentation/api/inbound-webhook.md): Trigger a render from any external system via signed inbound webhook.
- [Webhooks](http://localhost:3000/documentation/api/webhooks.md): Receive signed outgoing webhooks for render, document-engagement, and signature lifecycle events, and verify them — event triggers, per-family payload structures, and retries.
- [POST /v1/embed/catalogs](http://localhost:3000/documentation/api/embed-catalogs.md): Publish a named variable catalog version via API.
- [Errors](http://localhost:3000/documentation/api/errors.md): Error envelope, codes, and retries.
- [Template management](http://localhost:3000/documentation/api/templates.md): Create, read, list, update (create-or-republish), and delete templates from a variable manifest. Covers the create body (name, manifest, optional description/slug/layout/pageConfig), derived-slug auto-suffix vs explicit-slug 409, PUT idempotent create-or-republish with version increment, DELETE soft-delete + slug tombstoning, and the manifest/jsonSchema fields returned by GET.
- [Shares & delivery](http://localhost:3000/documentation/api/shares.md): Share a succeeded render: create/list/revoke durable revokable share links (channel link|email, recipientEmail/message/expiresAt, shareUrl/shareToken), and email the document via Resend returning emailMessageId/sentAt. Covers 409 not_ready and 503 email_not_configured.
- [Engagement & analytics](http://localhost:3000/documentation/api/engagement.md): Read aggregate engagement counts and recent activity for a render, and record partner-side events.
- [Download a render](http://localhost:3000/documentation/api/render-download.md): Stream a succeeded render's PDF straight from storage, authenticated with your project API key.
- [Digital signatures](http://localhost:3000/documentation/api/signatures.md): Send a rendered PDF for digital signature: create requests with recipients/fields/anchor tags, list and poll status through the sent|viewed|signed|declined|expired|cancelled|completed lifecycle, cancel in-flight requests, and download the archived signed PDF and completion certificate (authenticated only). Covers the 20MB limit, idempotency, 402/413/502/503 errors, and signature.* outgoing webhooks.
- [Health check](http://localhost:3000/documentation/api/health.md): Public liveness/readiness probe. GET /v1/health returns {status, version, checks:{database}} with 200 when healthy and 503 when degraded. No auth.

## Embed

- [Overview](http://localhost:3000/documentation/embed.md): Drop the Craftkit builder into your SaaS so your customers design their own templates.
- [Quickstart](http://localhost:3000/documentation/embed/quickstart.md): Mint a session, render the iframe, listen for events.
- [Multi-tenant setup](http://localhost:3000/documentation/embed/multi-tenant.md): Admin provision API — one admin key auto-provisions isolated Craftkit projects per org.
- [Styling & themes](http://localhost:3000/documentation/embed/styling.md): Brand the embed for your customers — variables, rules, presets, and four delivery channels.
- [JWT spec](http://localhost:3000/documentation/embed/jwt.md): Session token shape, signing, rotation, and verification.
- [postMessage protocol](http://localhost:3000/documentation/embed/postmessage.md): Bidirectional event bus between host page and iframe.
- [Host SDK](http://localhost:3000/documentation/embed/sdk.md): TypeScript helper for mounting the iframe and listening to events.
- [Builder embed](http://localhost:3000/documentation/embed/builder.md): Embed the template designer in your SaaS — scope modes, permissions, events, imperative commands, and the template creation lifecycle.
- [Form-fill embeddable](http://localhost:3000/documentation/embed/form-route.md): Drop-in form for end-users to fill template variables and produce documents — with optional Stripe-style submit interception and client-side dataset prefill.
- [Variable catalog](http://localhost:3000/documentation/embed/variable-catalog.md): Inject your data model so partner end-users see the right fields.
- [Admin UI & class catalogue](http://localhost:3000/documentation/embed/admin-ui.md): Stable .ck-* class names you can target for theming.
- [Failure modes](http://localhost:3000/documentation/embed/failure-modes.md): What can go wrong and how the iframe surfaces it.
- [Session API (mint & refresh)](http://localhost:3000/documentation/embed/sessions-api.md): Mint a signed embed session (POST /v1/embed/sessions) and rotate it with the single-use renew token (POST /v1/embed/sessions/refresh).
- [Builder & renders API](http://localhost:3000/documentation/embed/builder-api.md): Server-side embed endpoints: create a template from a builder draft (partner API key OR session JWT), list a project's builder templates (API key only), and list the project's renders for the embedding host (API key only).
- [Form submit API](http://localhost:3000/documentation/embed/form-submit-api.md): Iframe-side form-fill endpoints (embed session JWT only): submit filled form data to validate against the manifest and enqueue a form render (202), and upload an image via multipart to get back a public URL.

## Architecture

- [Overview](http://localhost:3000/documentation/architecture/overview.md): High-level system diagram and component responsibilities.
- [Data model](http://localhost:3000/documentation/architecture/data-model.md): Postgres schema for projects, templates, versions, renders, embeds.
- [Render pipeline](http://localhost:3000/documentation/architecture/render-pipeline.md): How a render request becomes a PDF.
- [Tenancy model](http://localhost:3000/documentation/architecture/tenancy.md): Users, projects, partners, tenants, actors — who owns what.
- [Tech stack](http://localhost:3000/documentation/architecture/tech-stack.md): Languages, frameworks, runtime choices.
