$npx -y skills add butterbase-ai/butterbase-skills --skill build-appUse when building a new Butterbase app from scratch, creating a full-stack application, or when the user asks to set up a complete backend with database, auth, and deployment
| 1 | > **Prefer `/butterbase-skills:journey`** — for a fully guided multi-stage build with preflight, planning, deployment verification, and (optionally) hackathon submission. This one-shot skill remains for users who want the legacy linear setup. |
| 2 | |
| 3 | # Build a Complete Butterbase App |
| 4 | |
| 5 | This skill walks through all seven phases of building a production-ready Butterbase application — from provisioning a backend to deploying a live frontend. Follow each phase in order; later phases depend on artifacts (app_id, schema, RLS policies) produced by earlier ones. |
| 6 | |
| 7 | > **Convention:** every JSON body below is the argument object for the tool named in its **Tool:** header. When the header reads `manage_schema` with `action: "apply"`, include `"action": "apply"` alongside the other fields when you make the call. |
| 8 | |
| 9 | --- |
| 10 | |
| 11 | ## Phase 1: Create the App |
| 12 | |
| 13 | Use `init_app` to provision an isolated backend with its own database and auto-generated REST API. |
| 14 | |
| 15 | **Tool:** `init_app` |
| 16 | |
| 17 | ```json |
| 18 | { |
| 19 | "name": "my-blog" |
| 20 | } |
| 21 | ``` |
| 22 | |
| 23 | **Returns:** |
| 24 | ```json |
| 25 | { |
| 26 | "app_id": "app_abc123", |
| 27 | "api_base": "https://api.butterbase.ai/v1/app_abc123" |
| 28 | } |
| 29 | ``` |
| 30 | |
| 31 | **Important:** Save `app_id` and `api_base` — every subsequent tool call requires `app_id`. |
| 32 | |
| 33 | ### Optional: Generate a Service API Key |
| 34 | |
| 35 | If the user needs programmatic access (CI/CD pipelines, server-to-server calls, admin scripts), generate a service key now. |
| 36 | |
| 37 | **Tool:** `manage_auth_config` with `action: "generate_service_key"` |
| 38 | |
| 39 | ```json |
| 40 | { |
| 41 | "name": "Production Deploy Key" |
| 42 | } |
| 43 | ``` |
| 44 | |
| 45 | > ⚠️ The full key (`bb_sk_...`) is shown **only once**. Store it securely — it cannot be retrieved again. |
| 46 | |
| 47 | --- |
| 48 | |
| 49 | ## Phase 2: Design & Apply Schema |
| 50 | |
| 51 | Work with the user to understand their data model before writing any SQL. Ask: |
| 52 | |
| 53 | - What are the primary entities (users, posts, products, orders)? |
| 54 | - Which tables are user-owned vs. shared/public? |
| 55 | - What relationships exist between tables (foreign keys)? |
| 56 | - Are there any boolean flags for public visibility (e.g. `published`, `is_public`)? |
| 57 | |
| 58 | ### Preview First with dry_run_schema |
| 59 | |
| 60 | Always preview schema changes before applying them. |
| 61 | |
| 62 | **Tool:** `manage_schema` with `action: "dry_run"` |
| 63 | |
| 64 | ```json |
| 65 | { |
| 66 | "app_id": "app_abc123", |
| 67 | "schema": { |
| 68 | "tables": { |
| 69 | "posts": { |
| 70 | "columns": { |
| 71 | "id": { "type": "uuid", "primaryKey": true, "default": "gen_random_uuid()" }, |
| 72 | "author_id": { "type": "uuid", "nullable": false }, |
| 73 | "title": { "type": "text", "nullable": false } |
| 74 | } |
| 75 | } |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 | ``` |
| 80 | |
| 81 | Review the generated SQL — make sure it matches intent before applying. |
| 82 | |
| 83 | ### Apply the Schema |
| 84 | |
| 85 | **Tool:** `manage_schema` with `action: "apply"` |
| 86 | |
| 87 | Below is a complete example for a **blog app** with posts and comments: |
| 88 | |
| 89 | ```json |
| 90 | { |
| 91 | "app_id": "app_abc123", |
| 92 | "schema": { |
| 93 | "tables": { |
| 94 | "posts": { |
| 95 | "columns": { |
| 96 | "id": { "type": "uuid", "primaryKey": true, "default": "gen_random_uuid()" }, |
| 97 | "author_id": { "type": "uuid", "nullable": false }, |
| 98 | "title": { "type": "text", "nullable": false }, |
| 99 | "body": { "type": "text" }, |
| 100 | "published": { "type": "boolean", "default": "false" }, |
| 101 | "created_at": { "type": "timestamptz", "default": "now()" } |
| 102 | } |
| 103 | }, |
| 104 | "comments": { |
| 105 | "columns": { |
| 106 | "id": { "type": "uuid", "primaryKey": true, "default": "gen_random_uuid()" }, |
| 107 | "post_id": { "type": "uuid", "nullable": false, "references": "posts.id" }, |
| 108 | "author_id": { "type": "uuid", "nullable": false }, |
| 109 | "body": { "type": "text", "nullable": false }, |
| 110 | "created_at": { "type": "timestamptz", "default": "now()" } |
| 111 | } |
| 112 | } |
| 113 | } |
| 114 | } |
| 115 | } |
| 116 | ``` |
| 117 | |
| 118 | ### Verify the Schema Was Applied |
| 119 | |
| 120 | **Tool:** `manage_schema` with `action: "get"` |
| 121 | |
| 122 | ```json |
| 123 | { |
| 124 | "app_id": "app_abc123" |
| 125 | } |
| 126 | ``` |
| 127 | |
| 128 | Confirm every table and column is present before moving to Phase 3. |
| 129 | |
| 130 | ### Schema Tips |
| 131 | |
| 132 | - Always include `id` as UUID with `gen_random_uuid()` default |
| 133 | - Always include `created_at` with `now()` default |
| 134 | - Use `author_id` / `user_id` UUID columns on user-owned tables — RLS will reference these |
| 135 | - Use `references: "table.column"` for foreign keys (cascades must be set carefully) |
| 136 | - `manage_schema` action `apply` is idempotent — safe to call again if schema is unchanged |
| 137 | |
| 138 | --- |
| 139 | |
| 140 | ## Phase 3: Secure Data with RLS |
| 141 | |
| 142 | Row-Level Security (RLS) ensures users can only access their own data. This phase is **not optional** for any table that holds user-generated content. |
| 143 | |
| 144 | ### Enable User Isolation |
| 145 | |
| 146 | Call `create_user_isolation_policy` for each user-owned table. This single call: |
| 147 | 1. Enables RLS on the table |
| 148 | 2. Creates a policy so users only see their own rows |
| 149 | 3. Installs a BEFORE INSERT trigger to auto-populate the user column |
| 150 | 4. Creates a service bypass policy for admin access |
| 151 | |
| 152 | **Tool:** `manage_rls` with `action: "create_user_isolation"` |
| 153 | |
| 154 | ``` |