# Build a site

A connected website keeps its **schema in its own repo** and its **content in Borkol**. The site declares the content types, page fields and section types it renders in one file (`borkol.content.ts`, written with `@borkol/content`). A push sends that schema to the store as a compiled manifest; the merchant then edits the content in the client dashboard and the site reads it through the [Objects](/api/objects/index) endpoints.

A store has at most one connected site. Types and section types a push creates are **managed by the site**: the dashboard can edit their records, never their structure (a structure write answers `409 {"code": "managed_by_site"}`). That keeps the merchant from breaking the fields the site code depends on.

## The two keys

A connected site gets two API keys, each shown once:

| Key | Scopes | Where it lives |
| --- | --- | --- |
| Site key | `objects:read` (plus `forms:read` and `forms:write` when the Forms module is on) | The deployed site's environment. It reads content and the schema. |
| Push key | `objects:schema`, `objects:write`, `objects:read` | Only on the developer's own machine. It pushes the schema and uploads section thumbnails. |

`objects:schema` is granted only to a connected site's push key; an API key created in the dashboard can never carry it (asking for it answers `422`). **Never put the push key in a deployed environment or a repo.** A leaked site key can read content but never change the schema.

## The flow

1. Declare types, page fields and section types in `borkol.content.ts`. The compiled shape is the [manifest](/api/build-a-site/manifest).
2. Upload one thumbnail per section type with `POST /v1/api/objects/media` and put the returned `id` in the section type's `thumbnail_media_id`.
3. Plan the push with `PUT /v1/api/objects/schema?dry_run=1`. The response lists every op the push would apply.
4. Apply it with `PUT /v1/api/objects/schema`. A push that archives stored values needs `yes=1`; a push with any `refuse` op applies nothing. Pushing the same manifest again plans nothing.
5. Read the result back with `GET /v1/api/objects/schema` (the CLI's drift check uses it) and the section vocabulary with `GET /v1/api/objects/section-types`.

An applied push sends the webhook event `object_schema.updated` (see [Webhooks](/api/webhooks/index#object_schemaupdated)); flush every cached page when it arrives. The endpoints are described on [Schema](/api/build-a-site/schema).

The `borkol` CLI of [`@borkol/content`](/api/build-a-site/package) runs this flow for you (`borkol push`), seeds starter content (`borkol seed`) and checks the setup (`borkol doctor`). Render images with [Images](/api/build-a-site/images): resized URLs and crops that keep the merchant's focal point in view.

## Rules for the agent

Coding agents that build a site on Borkol follow these rules:

1. Design and build the site freely first: layout, motion, any animation library.
2. Then model the meaning: every text, image and list the client might change is a field.
3. One `defineSection` per visual section component, with `looks` for its variants and a `help` on every field. Collections become `defineType`, global content `defineSingleton`.
4. No layout fields. Unknown section types or looks render `null`.
5. Upload a thumbnail per section type: part of done.
6. Seed realistic content so the client sees the real site on day one.
7. Pages read the preview token from `searchParams` and pass it to every fetcher.
8. Run `borkol doctor` before reporting done. Never commit keys.

## Endpoints

| Endpoint | Scope | Purpose |
| --- | --- | --- |
| `PUT /v1/api/objects/schema` | `objects:schema` | Plan or apply a manifest. |
| `GET /v1/api/objects/schema` | `objects:read` | The connected site, every type and every active section type. |
| `GET /v1/api/objects/section-types` | `objects:read` | Active section types only. |
| `POST /v1/api/objects/media` | `objects:schema` | Upload a section type thumbnail. |
| `POST /v1/api/objects/seed` | `objects:write` | Queue a create-only seed of starter content. See [Seed](/api/build-a-site/seed). |
| `GET /v1/api/objects/seed/{job_id}` | `objects:write` | A seed run's progress. |
| `GET /v1/api/objects/preview` | `objects:read` | What a preview token opens. See [Preview](/api/build-a-site/preview). |
| `POST /v1/api/objects/preview-tokens` | `objects:schema` | Mint a preview token, the home page by default. |
