# Quickstart for agents

From an empty folder to a deployed app with sign-in and a database, driven
by a coding agent (Claude Code, Cursor, Codex, ChatGPT with a terminal)
through the `spaceboy` CLI. You write the code; Spaceboy builds it, hosts
it, and runs its database, sign-in and functions. A person is needed
twice: to approve the login in a browser, and to pay for publishing to
production. Building and deploying to one development environment are free
(within monthly free deploy minutes). Spaceboy runs no hosted checks: run
your tests with your own agent or CI before you publish.

Two things wait for a published project (`spaceboy billing publish`, a
person approves the price): **custom secrets** (`spaceboy secrets set`, for
example a third-party API key your functions read) and **custom domains**
(`spaceboy domains add`). Until then, build with values that need no
secret, and serve from the Spaceboy address.

To start, a person pastes this into their agent:

> Read https://spaceboy.ai/llms.txt and build me an app with sign-in and a database, hosted on Spaceboy.

The path: **install → start → write the code → push → URL.**

## 1. Install the CLI

```bash
curl -fsSL https://spaceboy.ai/install.sh | bash
spaceboy --version
```

Expected: `0.5.0` or later. Node 20+ and `git` are required. Run by an
agent (no terminal attached), the installer never asks a question: it
installs `spaceboy`, prints the next commands and exits 0. Run by a person
in a terminal, it offers to run `spaceboy start` for them. Alternatives:
`npm install -g @spaceboy-ai/cli`, or no install at all with
`npx -y @spaceboy-ai/cli@latest <command>`. Add `--json` to any command for
exactly one JSON value on stdout.

## Fastest: one command

```bash
spaceboy start --name notes --json
```

It logs in if needed, creates an organization if there is none, creates a
project from the full-stack starter and downloads it into `./notes`, then
ends with `{"projectId":"prj_...","dir":".../notes","next":"..."}`. If a
login is needed it exits 3 with the approval link in `error.action`
(`error.details.verificationUrl` and `userCode`): give them to your person,
and after they approve run the same command again (it resumes that login).
Then continue at step 5. Steps 2 to 4 are the same thing done by hand.

## 2. Log in (a person approves once)

```bash
spaceboy login --json
```

Expected, first line:

```json
{"event":"verification","verificationUrl":"https://spaceboy.ai/cli/login?code=XXXX-XXXX","userCode":"XXXX-XXXX","expiresAt":"..."}
```

Give your person the URL and code. They open it, sign in or sign up, and
approve. The command then prints `{"event":"logged_in", ...}` and stores an
API key in `~/.spaceboy/config.json`.

If it fails: `The login request expired` means nobody approved in time; run
it again. In CI, set `SPACEBOY_API_KEY` instead (see
[Authentication](https://spaceboy.ai/docs/agents/authentication.md)).

## 3. Organization and project

```bash
spaceboy whoami --json                                  # "account": null means no organization yet
spaceboy orgs create --name "My Studio" --json          # only when there is none
spaceboy projects create --name notes --template full-stack --json
```

Expected from the last command: `{"id":"prj_...","name":"notes", ...}`. Keep
the id. `--template full-stack` picks the full-stack starter: sign-in
(emailed one-time codes), a Postgres database and email. Without
`--template`, the project is a client-only site.

## 4. Get the code

```bash
mkdir notes && cd notes
spaceboy init --project prj_...
```

Expected: the folder now holds the project's repository as a git checkout
with one commit, linked to the project (`.spaceboy/project.json`, kept out
of git), so later commands need no `--project`.

The starter is a complete app: Postgres + a GraphQL API on Cloud Functions,
sign-in, a React web app, and iOS/Android apps on the same API. **Read
`AGENTS.md` first**: it says where the data model, migrations, services,
API and pages go, and which commands check the code.

## 5. Write the app

For the notes example, following `AGENTS.md`:

1. `firebase/functions/migrations/<timestamp>__create_note.sql`: the table.
2. `firebase/functions/src/Data/Note/`: the Drizzle mirror.
3. `firebase/functions/src/Services/Note/`: create and list notes for the
   signed-in user (`context.principal.userId`), checking ownership.
4. `Graphql/` + `firebase/functions/src/Graphql/Resolvers/`: the API.
5. `web/app/src/`: a page that lists and creates notes.

Optional checks before pushing: `npm install`, then `npm run check:all`
(the CI-equivalent gate); `npm run dev:up` runs everything locally with
Postgres in Docker (or `DB_MODE=embedded` without Docker). Details:
[Database and migrations](https://spaceboy.ai/docs/agents/database-and-migrations.md),
[Sign-in and users](https://spaceboy.ai/docs/agents/sign-in-and-users.md),
[Functions and HTTP endpoints](https://spaceboy.ai/docs/agents/functions-and-http-endpoints.md).

Then commit; `push` sends committed files only:

```bash
git add -A && git commit -m "Notes"
```

## 6. Push

```bash
spaceboy push
```

Progress goes to stderr:

```
[1/4] Upload and preflight
[2/4] Commit and pull request
[3/4] Merge into main
[4/4] Deploy to development
```

Expected at the end, on stdout:

```
App:        https://<site>.dev-sites.spaceboy.ai
GraphQL:    https://us-central1-<project>.cloudfunctions.net/<prefix>__graphql__request__api
Functions:  https://us-central1-<project>.cloudfunctions.net/<prefix>__<export name>
```

`App` is the live app; its sign-in emails a code from Spaceboy's mail
domain, so it works with no DNS setup. With `--json`, the result is one
object with `adoption`, `deploy` and `endpoints`.

If it fails:

- **Uncommitted changes** (exit 1, `error.code` = `UNCOMMITTED_CHANGES`):
  the folder has changes that are not committed, and `push` sends the last
  commit only. Nothing was uploaded; the block above the error lists the
  files. Commit them and push again (`--allow-dirty` pushes the last commit
  anyway, still printing the list).
- **Preflight blocked** (exit 1): the report lists each problem with its
  file and line, such as a committed secret, a `.env` file, `node_modules`
  or a changed design-system file. Nothing was merged. Fix, commit, push again.
- **Preflight warnings** (exit 1): review them; if they are fine, run the
  command in `error.action`: `spaceboy push --acknowledge <digest>`. Only
  files you changed are listed; notes about untouched starter files are
  counted, not shown (`spaceboy projects adoption show <id>` for the full
  report).
- **Deploying to development is free** for every app, sign-in and database
  included, and needs no payment. The exit-4 case here is a free
  development limit: `error.code` = `FREE_DEVELOPMENT_LIMIT` (one free
  development environment per organization, a 1 GB database; the message
  names the limit). `error.action` names how to free it, or publish a
  project. Paying is only for **publishing to production** (step 8).
- **Deploy `FAILED`**: read `failureReason`, check
  `spaceboy logs --since 1h`, fix, commit, push again.

## 7. Check it

```bash
spaceboy db tables
spaceboy app request --query '{ __typename }'
```

`db tables` lists the new `note` table. `app request` calls the deployed
app's own GraphQL API and prints `{"data":{"__typename":"Query"}}`
(development only). A fresh deploy's endpoint can take up to a minute to
become reachable; `app request` retries over that minute with one
`the app is still becoming reachable` line rather than a raw error.

To check what is behind sign-in, run the smoke steps in
`spaceboy.verify.json` (the starter ships three: the home page, an
anonymous refusal, and a signed-in test persona reading `currentUser`):

```bash
spaceboy app verify
```

Each step prints PASS or FAIL, and the command exits non-zero when one
fails. Signed-in steps run as **test personas** declared in the file, on a
15-minute test session the platform mints for the development app; no email
is sent. Add a step for every feature you build (the "Sign-in, users and
organizations" page has the format). Never read sign-in codes from the
database or sign in as a real person's address.

## 8. Iterate, then go live

Each change is: edit → `git commit` → `spaceboy push`. `spaceboy deploy`
does not ship new commits: it redeploys what is already hosted. Production
builds the same `main`, so after a push:

```bash
spaceboy deploy --target production
```

## Other ways in

- Organizations that connected their own GitHub before creating
  the project can also `git push` to the repository directly.

## Next

- [Bring your own code](https://spaceboy.ai/docs/agents/bring-your-own-code.md): what the preflight checks
- [Secrets and settings](https://spaceboy.ai/docs/agents/secrets-and-settings.md)
- [Deploys](https://spaceboy.ai/docs/agents/deploys.md) and [Logs](https://spaceboy.ai/docs/agents/logs.md)
