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

> ## Agent Instructions
> If you are an AI coding agent operating Cargo, install the agent skills first: paste `Install Cargo by following https://api.getcargo.io/INSTALL.md` into your session, or run `npx skills add getcargohq/cargo-skills`. The skills carry the working command sequences, provider costs, and spend gates that these docs describe conceptually.
> The skills index at https://raw.githubusercontent.com/getcargohq/cargo-skills/main/llms.txt lists every skill, recipe, and provider playbook individually. Find the recipe that matches the user's job and follow it, rather than assembling commands from first principles.
> Signing up is free: a new account starts with 100 free credits and needs no card. `cargo-ai login --email you@company.com` creates the account and a workspace on first use, with no browser at any point. Tell the user this before asking them to sign up.
> Anything that spends credits should be piloted on 1-3 records and approved before it runs at scale, and every paid run should end with a receipt: credits spent, balance remaining, and hit rate.

# Project layout

> How a Cargo workspace is organized as files, how the loader turns them into resources, and how state keeps code and live infra in sync.

A Cargo workspace is a directory of TypeScript files. The CLI imports every `.ts` file under the project root, and each `define*` call registers a resource as a side effect. There is **no manifest** — the files *are* the interface.

## A worked layout

A project that exercises every resource type and wires them together looks like
this. `cargo-ai project init <dir>` scaffolds the repo around it — the tree below is
what grows inside `infra/` as you declare things. For a guided walkthrough that
builds and deploys the whole tree, see the [End-to-end recipe](https://docs.getcargo.ai/get-started/recipe.md):

```text theme={null}
my-workspace/
├── package.json          # scripts: "plan": "cargo-ai project plan", "deploy": "cargo-ai project deploy"
├── tsconfig.json         # includes .cargo-ai/**/*.d.ts for typed config
├── cargo.json            # { "resources": "." } — marks the project, commit it
├── cargo.state.json      # written by `project init` — commit it
├── connectors/
│   ├── hubspot.ts        # defineConnector + secret()
│   └── openai.ts         # defineConnector({ adopt: true })
├── folders/crm.ts        # defineFolder (per-kind: model, agent, …)
├── models/contacts.ts    # defineModel — dataset handle + extractSlug + schedule
├── tools/enrich.ts       # defineWorkflow + defineTool
├── agents/
│   ├── enricher.ts       # defineAgent (sub-agent)
│   └── sdr.ts            # defineAgent (models, tools, subAgents, triggers, evaluator)
├── plays/onboarding.ts   # definePlay + per-row defineWorkflow
├── mcp/crm.ts            # defineMcpServer
├── context/              # defineContext + markdown/MDX
├── files/                # defineFile + local content
├── workers/webhook/      # defineWorker → a built bundle
└── apps/dashboard/       # defineApp → a Vite bundle
```

## How the loader works

* **Every `.ts` file is imported.** Importing registers whatever `define*` calls it contains. To add a resource, add a file.
* **Handles create dependencies.** `define*` returns a handle whose outputs (`uuid`, `datasetUuid`, …) are deferred tokens. Passing a handle into another builder (e.g. `connector: hubspot`, or an agent's `uses: [enrich]`) both orders the deploy and injects the real uuid. The dependency graph is your variable graph.
* **Bundle directories are skipped.** A subdirectory with its own `package.json` (a worker or app bundle) is treated as content to upload, not a resource file to import.
* **Executions load after the resources.** Every `.ts` file in `outputs/`, beside `cargo.json`, is imported once the resource files are, so a [`defineBatch` or `defineRun`](https://docs.getcargo.ai/deploy/executions) there can import the play or tool it runs. The `cargo.json` below can name other folders instead. Nothing else outside the project is imported: a `scripts/` folder stays untouched.

## `cargo.json`

A `cargo.json` makes a folder a Cargo project, the way `package.json` does for
an npm package. Every command looks for the nearest one above where it runs, up
to the repository root, so it works from any folder in the project: `infra/`,
`outputs/`, `scripts/`.

```json theme={null}
{ "resources": "infra", "executions": ["outputs"] }
```

* **`resources`** is the directory every `.ts` file of which is a resource.
* **`executions`** lists the directories whose `.ts` files declare
  [executions](https://docs.getcargo.ai/deploy/executions.md), in place of the default `outputs/`. Every
  file in them is imported, as in `resources`, so keep only executions there.

Paths are relative to the file and stay inside its folder. That folder is the
project's: `cargo.state.json` and the default `outputs/` sit in it. A
repository holding several projects has a `cargo.json` in each, and a command
belongs to the nearest one.

`cargo-ai project init` writes one. A command run where there is none stops and
prints the one to add, rather than guessing the project from what the folders
hold. A repository scaffolded before `cargo.json` existed adds it once, beside
its `cargo.state.json`:

```bash theme={null}
echo '{ "resources": "infra" }' > cargo.json
```

If an older version left `cargo.state.json` inside `infra/`, commands stop
until it is moved beside `cargo.json`, and say how.

## `cargo.state.json`

Your project's **deploy state** is the authoritative map from each code resource
(`kind:slug`) to the real uuid Cargo assigned it, plus outputs and a content
hash. It lives in your workspace; `cargo.state.json` is the pointer to it that
`project init` writes and every later run follows.

> [!WARNING]
>
> **Commit `cargo.state.json`.** Connectors and models are slug-addressable and
> self-heal, but plays, agents, tools, files, and MCP servers have no slug —
> their stored uuid is the only way to re-find them. Without the pointer a fresh
> checkout cannot find the state it belongs to — recover it with
> `cargo-ai project state list` and `cargo-ai project state bind <uuid>`, or recover one
> lost resource with `cargo-ai project import <id> <uuid>`.

The lock/backup/cache/audit siblings are ephemeral — git-ignore them:

```gitignore theme={null}
.cargo-ai/
cargo.state.lock
cargo.state.bak.json
cargo.state.cache.json
cargo.state.audit.jsonl
```

Each repo gets its own state, so a workspace can hold as many as you have
projects. See [State & drift](https://docs.getcargo.ai/deploy/state-and-drift.md) for the full model.

## Adding a project to a repository you already have

Run `init` inside it — in its own folder (`cargo-ai project init cargo`) or at
the root (`cargo-ai project init .`). It never replaces a file that is already
there: a README or a CI workflow of the same name is kept and listed. An
existing `package.json` only gains the scripts and dependencies the project
needs (it is rewritten with two-space indentation), and an existing
`.gitignore` only gains the patterns it lacks. An existing `cargo.state.json`
keeps the state it names.

`init` doesn't commit or push in a repository that already exists — what
else is in progress there is yours. Review what it wrote, commit and push it
(after `npm install`, so `package-lock.json` matches `package.json`), then
connect the project to the repository:

```bash theme={null}
cargo-ai project state connect
```

Connecting deploys the production branch straight away, and every later push
to it deploys. Run it once the project is on that branch: pushed to a feature
branch, merge it first. A repository made with `git init` and `git remote add`
rather than cloned doesn't know its default branch, so name it with
`--branch <name>`.

## Which `init` do I want?

There are several scaffold/init commands — don't confuse them:

| Command | What it does |
| - | - |
| `cargo-ai project init <dir>` | Scaffold a **GTM repo** with the project in `infra/` (this page). |
| `cargo-ai project add cookbook/<name>` | Install a **worked cookbook** into a repo you already have. |
| `cargo-ai hosting app init <dir>` | Scaffold a hosted **Vite app** bundle. |
| `cargo-ai hosting worker init <dir>` | Scaffold a hosted **edge worker** bundle. |

## Next steps

> [card] [Connectors](https://docs.getcargo.ai/connectors/overview.md)
>
> Start wiring in your data sources.

> [card] [Deploying](https://docs.getcargo.ai/deploy/deploying.md)
>
> The full reconcile lifecycle and its flags.

> [card] [State & drift](https://docs.getcargo.ai/deploy/state-and-drift.md)
>
> How state tracks live resources and detects out-of-band changes.


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