# Bring your own code

How code that you or your agent wrote gets into a Spaceboy project, and
what Spaceboy checks before it is merged.

## The one-step path: init and push

```bash
spaceboy init --project prj_...     # the project's code, as a git checkout in an empty folder
# ... write code, following AGENTS.md ...
git add -A && git commit -m "..."
spaceboy push                       # preflight → commit + pull request → merge into main → deploy
```

`push` sends the last commit (`git archive HEAD`): tracked, committed files
only, so ignored files, `.env` files and history never leave the machine.
It stops before merging when the preflight blocks or has warnings you have
not acknowledged (`spaceboy push --acknowledge <digest>`). Organization
owners and admins only (exit code 4 for members).

## Other ways in

| Way | How |
| --- | --- |
| Step by step | `spaceboy projects adopt --source . [--dry-run]`, then `projects adoption confirm`, `accept`, and `spaceboy deploy`: the steps `push` runs, for when you want to inspect the report or the pull request in between |
| Your own GitHub | Organizations that connected their own GitHub before creating the project get the repository in their GitHub organization: `git clone`, commit, `git push` to `main`, then `spaceboy deploy` |

## What the code must look like

Spaceboy deploys a **starter-shaped** repository: the project's starter
(the "kernel") with your product built inside it. `spaceboy init` gives you
exactly that tree; its `AGENTS.md` and `docs/` say where everything goes:

| Path | What goes there |
| --- | --- |
| `firebase/functions/migrations/*.sql` | Database schema: forward-only SQL migrations |
| `firebase/functions/src/Data/<Domain>/` | Drizzle table definitions mirroring the SQL |
| `firebase/functions/src/Services/<Domain>/` | Business logic and per-row authorization |
| `Graphql/` + `firebase/functions/src/Graphql/Resolvers/` | The GraphQL API (schema first, resolvers as thin adapters) |
| `firebase/functions/src/CloudFunctions/` + `src/index.ts` | HTTP and Pub/Sub functions |
| `web/app/src/` | The React web app (pages, routes, GraphQL operations) |
| `ios/`, `android/` | Native apps on the same API |
| `env.manifest.json` | Every environment variable the code reads |
| `repobot.deploy.json` | What a deploy provisions: `clientOnly`, `capabilities` (`AUTH`, `DATABASE`, `EMAIL`, `BACKEND`, `STORAGE`, `JOBS`, `PAYMENTS`, `AI`, `DOCUMENTS`, `PUSH`, `IOS`, `ANDROID`), `authMethods` |

## The preflight

Before anything is written, the preflight blocks on a wrong starter
version, invalid manifests, changed design-system files, `node_modules`,
`.env` or key files and detectable secrets, and warns on weaker signals.
The full list: [Preflight](https://spaceboy.ai/docs/agents/preflight.md).

Each push is one commit on branch `adopt/<id>` with a pull request against
`main`; the project's CI runs on it, and `push` merges it (rebase). History
from your machine is not imported: each push is one commit.

Exit codes: 0 success; 1 blocked, failed, or warnings not acknowledged
(the `--json` error carries the adoption in `details` and the next command
in `action`); 2 usage; 3 authentication; 4 permission or plan.
