> ## Documentation Index
> Fetch the complete documentation index at: https://docs.superintern.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Your Website's Own Backend

> Give your SuperIntern website code that runs while a visitor waits: an API of its own, a database of its own, your CRM reached from code, outside services, schedules and CRM changes, with nothing going live until you approve what it uses.

**Most websites never need a backend, and SuperIntern never adds one unless you ask for something that needs it.** A website that says what your business does, shows your prices and pictures and lets people get in touch is a marketing site: it needs no backend and no database. Pages that show your CRM tables, contact, enquiry and booking forms, the chat, the shop and customer sign-in come with every SuperIntern website, and what visitors send through them (an enquiry, a booking, an order) goes straight into your CRM.

A **backend** is for the times your website must **keep data of its own or work something out while a visitor waits**:

* something the website's code works on itself: likes, stock it counts, scores, a game's state;
* a quote from your own rates, or "is this day still free?";
* your CRM reached from code: counting bookings, or adding a row after checking something first;
* a supplier's or provider's service called from the website, with a key only SuperIntern holds;
* something that runs on a schedule, or when a row in your CRM changes;
* an API for something else you run, such as your own mobile app.

## How to get one

Ask for what you want, in your own words, and SuperIntern's builder (or Claude, connected to your website) adds the backend for you:

> *"Add a like button to each blog post, and show how many likes it has."*
>
> *"Let visitors check whether a day is still free before they book."*

The backend is part of your website, not a separate service. It lives in your website's code, is built and checked with every change, and goes online when you publish.

## What you approve

Your website's code can only reach what you approve. When you publish a version that asks for something new, it waits for you, and the website's page shows the request in plain words before anything changes. For example:

* **A database of its own**, for what the website keeps for itself;
* **Adding rows to a table**, such as Bookings;
* **Counting rows in a table**, without seeing them;
* **Reading or changing a signed-in customer's own rows**, such as their saved address;
* **An outside service**, such as `api.example.com`, and the key it is sent;
* **Files customers upload**, such as photos for their listing, and whether pictures can show on your website (see [Letting Customers Upload Files](https://docs.superintern.ai/websites/customer-uploads.md));
* **A schedule**, such as a route that runs every hour;
* **Changes to a table sent to the website**, with the columns it is told.

Choose **Approve and publish** and that version goes online. (Approving in **Settings** alone puts nothing online: publish again afterwards.) A later version that asks for the same or less goes online as usual; one that asks for more waits for you again. Pages and addresses need no approval. Only you or a teammate who can change the website can approve: the builder, Claude and website keys can't.

Your website's code never sees your People, Companies or Properties, members-only tables, or another customer's rows, and it never holds a password or key. Of your other tables it sees only what you approve: public rows, and for CRM changes the columns you approved by name.

## Your website's database

A website with a database gets one of its own, separate from your CRM:

| Goes in your CRM | Goes in the website's database |
| - | - |
| What you and your agent should see: a new customer, an order, a booking, a lead, and what signed-in customers keep for themselves (favourites, a wishlist, a saved address) | What the website's code works on itself: likes, stock counts, carts in progress, what its API serves |

* You can look through its tables on your website's **Data** tab, under **Database**.
* Changing the website never deletes data: tables and columns are only ever added.
* SuperIntern copies it every day and keeps each copy for 90 days. Claude Code can list the copies, download one or make one now.
* It can also be put back to any minute of the last 30 days. Contact [support@superintern.ai](mailto:support@superintern.ai) if you need that: putting it back loses everything visitors wrote since that time.
* Going back to an earlier version of your website brings back the earlier pages and code, not earlier data.

## Signed-in customers

On a website with [customer accounts](https://docs.superintern.ai/websites/customer-accounts.md), the backend knows which signed-in customer is asking, so it can show their own bookings or count what is theirs. Favourites, a wishlist or a saved address go in a CRM table where each customer keeps their own rows, not in the website's database: you gain from seeing them, and no backend is needed (a small script on the page saves a row's link to a product, which must be public) (see [Visitors adding items](https://docs.superintern.ai/websites/crm-on-your-website.md#visitors-adding-items)). SuperIntern vouches for who they are; the website's code can't pretend to be someone else.

## Files customers upload

Customers signed in to your website can send you pictures and PDFs, up to 10 MB each: photos of a home they want listed, a CV with an application. The website's database keeps only a note of each file; the file itself is checked and kept safely by SuperIntern, and a picture shows on your website only once you approve it. See [Letting Customers Upload Files](https://docs.superintern.ai/websites/customer-uploads.md).

## Outside services and their keys

Your website's code can call a service outside SuperIntern, such as a supplier's prices or your mail provider, once you approve that service. If it needs a key, you enter it on your website's **Settings** under **Keys for outside services**. SuperIntern adds it to the website's calls to that service only: the key never goes into your website's code, and nobody can read it back, you included. A website can make up to 60 such calls a minute and 5,000 a day.

## Schedules and CRM changes

A backend can run something on a schedule, from every 15 minutes to once a week, such as fetching a supplier's prices each morning. It can also be told when a row in one of your tables changes: "a booking was made" can send the customer a confirmation. It is told only the columns you approved, and never anything from People, Companies, Properties or members-only tables.

## For Claude Code and developers

**Never add a backend or a database on your own.** Add one only when the owner asks for something that pages, forms, table forms, the chat, the shop and sign-in can't do. Not to be ready for later, and not because a template or an example has one.

A backend is TypeScript in the website's own repository, run by the website's own Cloudflare Worker:

| File | What it is |
| - | - |
| `src/pages/api/[...path].ts` | The one route under `/api`, handing every request to the site's API |
| `src/server/app.ts` | The API, a [Hono](https://hono.dev) app |
| `src/db/schema.ts` | The database's tables, with [Drizzle](https://orm.drizzle.team) |
| `db/migrations/` | The SQL that makes them, written by `npx site-kit db:generate` |
| `superintern.backend.json` | What the backend needs: its routes, the database, CRM tables, outside services, schedules and events |

* `npx site-kit backend:add` adds these files from the site kit's template, with one example route.
* After a change to `src/db/schema.ts`, `npx site-kit db:generate` writes the migration. Never write one by hand. Migrations only add tables and columns: the command keeps none that removes or renames.
* `@superintern/site-kit/server` gives the code:
  * `siteApi()`;
  * `siteDatabase(schema)`;
  * `crm(request)`, the CRM door: `create`, `count`, `rows`, `ownRows` and `updateOwn`, for the tables and actions the manifest lists and the owner approved;
  * `visitorOf(request)`: `{ personId }` for a signed-in customer, the one id a route can trust;
  * `scheduledRun(request)`: the platform's scheduled run, or `null`;
  * `crmEvent(request)`: a CRM change, its signature checked.
* **Outside services**: a plain `fetch` to a host listed under `services`, with `{{secret:NAME}}` where the key goes in a header. The owner sets the key (website Settings, or `sites secret set NAME`). Never ask for it, and never write it into a file.
* **Schedules and events**: each names a route of its own, listed with `POST` (`src/pages/api/sync.ts`, handing the request to the API as the catch-all does). Do the work once per `run.at` or `event.id`.
* **Approval**: publishing a version that asks for more stops with "waits for approval". Tell the owner, in plain words, what they will be asked, and let them choose **Approve and publish**.
* `npm run check` must pass before every push. `npm run dev` runs the routes with a local copy of the database (`npx site-kit db:local "select …"` queries it; put test rows there). `SITE_DEV_VISITOR=<a uuid> npm run dev` runs them as that signed-in customer; the published site never trusts it. The CRM is on the published website only, and answers 503 in `npm run dev`.
* **Several rows that change together** (a booking and its stock) go in one `db.batch([...])` of query builders, with a `check` or a foreign key refusing what must not happen, so a refusal undoes all of it. Never put ``db.run(sql`…`)`` in a batch: with a value in it, the batch fails.
* **The published database's rows** are live data. Look at them with `sites db tables`, `sites db rows <table>` and `sites db query "select …"`. Change them only when the owner asks, with `sites db insert`, `update` or `delete` (`--dry-run` first). `sites db history` lists the changes, and `sites db undo` puts one back. See [Working on it yourself](https://docs.superintern.ai/websites/build-with-claude.md#working-on-it-yourself).
* **Any SQL** on the site's own database: `sites db sql "<sql>" --params '[…]'` (or `@file.sql`). Reads, writes and `CREATE`/`ALTER`/`DROP`, several statements at once, all or none, within 30 seconds; it never reaches anything but this site's database. It is recorded in `sites db history` but can't be undone, so read first, use `insert`, `update` or `delete` for a few rows, and put values in `--params`, never in the SQL. Change the tables in `src/db/schema.ts` and `db:generate`, not here: SQL that changes them warns that the site's code doesn't know about it. `sites db schema` prints the SQL that made each table, index and trigger.
* **Copies**: `sites db copy list`, `sites db copy download [<copy>] --out <file>` (SQL that rebuilds the database; the newest unless named) and `sites db copy make` (once every ten minutes). Take one before a change you can't undo.

The full guide is section 5 of the site kit's `GUIDE.md`, in every website at `node_modules/@superintern/site-kit/GUIDE.md`. See also the [Builder Reference](https://docs.superintern.ai/websites/builder-reference.md) and [Build with Claude](https://docs.superintern.ai/websites/build-with-claude.md).

## Containers (beta)

For work a backend can't do on its own, such as a Python program, a headless browser or a long task, a website can run a **container** next to it. Containers are in beta and switched on for each business by SuperIntern: see [Containers (Beta)](https://docs.superintern.ai/websites/container.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.