# Blueprints & Schema Migrations

> Declarative schema definitions for automated, non-destructive application provisioning on boot or deploy.

- **Category:** Build & Integrate
- **Canonical Guide:** https://pottr.tangble.com/docs/blueprints

---

>
Declarative schema definitions for automated, non-destructive application provisioning on boot or deploy.

## What are Blueprints?

A **Blueprint** is a JSON document declaring your application's required collections, fields, and user authentication profile schema. When submitted to Pottr, the engine provisions missing collections and adds new fields automatically.

## Additive, Non-Destructive Provisioning

Pottr provisioning is strictly **additive**:

<ul>
<li>Existing collections and entries are never dropped or deleted.</li>
<li>Existing fields retain their data.</li>
<li>Any field defined in the blueprint that does not yet exist is safely added to the schema.</li>
<li>The required primary `title` text field is automatically prepended if omitted.</li>
</ul>

## Public vs Secret Provisioning Endpoints

<table class="docs-table">
<thead>
<tr>
<th>Endpoint</th>
<th>Required Credential</th>
<th>Typical Usage</th>
</tr>
</thead>
<tbody>
<tr>
<td>`POST /auth/bootstrap`</td>
<td>**Public Key** (`pk_live_...`)</td>
<td>Client-side web or mobile applications on initial boot. Rejects secret keys.</td>
</tr>
<tr>
<td>`POST /blueprint`</td>
<td>**Secret Key** (`sk_live_...`)</td>
<td>CI/CD deployment pipelines, build scripts, backend provisioning.</td>
</tr>
<tr>
<td>`GET /blueprint/{app}`</td>
<td>Public or Secret Key</td>
<td>Inspect live provisioned schema and version status.</td>
</tr>
</tbody>
</table>

## Blueprint JSON Specification

**File: `blueprint.json`**

```json
{
  "app": "task-manager",
  "version": "1.0.0",
  "auth": {
    "slug": "users",
    "name": "App Users",
    "fields": [
      { "key": "full_name", "type": "text", "required": true },
      { "key": "avatar_url", "type": "text" }
    ]
  },
  "collections": [
    {
      "slug": "project",
      "name": "Projects",
      "fields": [
        { "key": "title", "type": "text", "required": true },
        { "key": "user_id", "type": "relation" }
      ]
    },
    {
      "slug": "task",
      "name": "Tasks",
      "fields": [
        { "key": "title", "type": "text", "required": true },
        { "key": "project_id", "type": "relation", "target_collection": "project" },
        { "key": "completed", "type": "boolean" }
      ]
    }
  ]
}
```

## Rules and Limits

<ul>
<li>Collection slugs match `^[a-z][a-z0-9_-]*$`; field keys match `^[a-z][a-z0-9_]*$`.</li>
<li>Auth fields can use the collection field types plus `select`, `email`, `url` and `password`. They describe the per-app user profile.</li>
<li>Provisioning is additive, so it is safe to run on every deploy or app boot.</li>
<li>If your plan's collection limit is reached part-way, provisioning succeeds partially. Check each item in the response.</li>
</ul>

## Provisioning Response

**File: `Response`**

```json
{
  "app": "task-manager",
  "version": "1.0.0",
  "version_status": "new",
  "auth": { "slug": "users", "status": "created" },
  "results": [
    { "slug": "project", "status": "created" },
    { "slug": "task", "status": "existing" },
    { "slug": "report", "status": "failed", "code": "plan_limit_exceeded" }
  ]
}
```

Each result is `created`, `existing` or `failed`. `version_status` tells you whether this app version is new, unchanged or older than the one Pottr already recorded.

`GET /blueprint/{app}` returns the recorded version, the auth snapshot, timestamps and the live schema of the collections that app manages.
