# Config file

One file describes resources, fields, relations, roles and permissions.

The config file is the only copy of your API definition. Charter reads it, applies it to the database, and serves Model Context Protocol (MCP), Representational State Transfer (REST), OpenAPI and docs from that definition. There is no schema version field. The file is TOML. The conventional name is `charter.toml`. A path ending in `.yaml` or `.yml` is refused.

To get started, here is a minimal shape (see `examples/config.toml` in the release for a fuller sample):

```toml
[[resources]]
name = "posts"
description = "Blog posts"
enabled = true
fields = [
  { field = "title", required = true, sortable = true, searchable = true },
  { field = "author_id", required = true },
]

[[fields]]
name = "title"
type = "string"
displayName = "Title"

[[fields]]
name = "author_id"
type = "relation"
relations = { resource = "users", type = "many-to-one", name = "author" }

[[permissions]]
resourceName = "posts"
role = "user"
action = "read"
fields = ["id", "title", "author_id"]
```

You may preview a live diff against the database without writing anything:

```sh
charter import config --path examples/config.toml
```

When you are ready, apply the upsert:

```sh
charter import config --path examples/config.toml --apply
```

> [!INFO]
> Whole-registry import and export are CLI only. The HTTP registry at `/registry/...` is per-entity create, read, update and delete for operators, including the routes that attach a field to a resource. `/registry/ledger` is read-only.

## Sections

Four top-level arrays. Roles are not a section of their own. Import creates a role name when a permission row first mentions it.

| Section | What it holds |
| --- | --- |
| `[[resources]]` | Named collections of records, plus the field bindings for each resource |
| `[[fields]]` | Reusable field definitions (name, type, display metadata) |
| `[[permissions]]` | Per role, resource and action: which fields, row filters and write checks apply |
| `[[webhooks]]` | Optional outbound HTTP callbacks on record changes |

Keys in the file use camelCase (`resourceName`, `allowAnonymousAccess`, `defaultValue`, `eventPattern`, `retryConfig`).

## Format

`charter import config` reads TOML. `charter export` writes TOML. An existing export path is never overwritten. The command fails instead.

TOML has no `null`. Omit optional keys rather than writing null. Floats such as `backoffMultiplier` must be written `2.0`, not `2`.

## Import and export

Rows present in the database but missing from the file stay put unless you also pass `--prune --yes`. That combination deletes those live rows. Without `--apply`, nothing is written.

`charter import config` and `charter export` use `charter.toml` when you leave `--path` off. `--path`, `CHARTER_CONFIG_PATH`, and `CHARTER_EXPORT_PATH` still override that default.

Export the running definition:

```sh
charter export
```

`charter export` still refuses to replace a file that already exists. See the [CLI](/docs/cli/) reference for every flag.

## While `charter dev` is running

`charter dev` keeps `charter.toml` and the database in step. The file is created from the database when it is missing. Saving the file applies it to the database. A resource, field, permission, or webhook added from the CLI, the HTTP API, or MCP is written back into the file.

Pass `--config` to use another TOML path. A path ending in `.yaml` or `.yml` is refused. `CHARTER_CONFIG_PATH` sets this path too, the same variable `charter import config` reads.

Pass `--no-watch`, or set `CHARTER_NO_WATCH`, to leave the file alone. `charter serve` does not watch a config file.

> [!DANGER]
> Removing a resource from the watched file drops that resource's data table, and the rows in it are deleted.

> [!INFO]
> When the file and the database already disagree at startup, Charter changes neither side. The next save applies the file. The next database change rewrites the file. Comments and the order of keys are not kept.

> [!WARNING]
> A file that does not parse is left in place, and the database is not changed.

## Next steps

See [Resources](/docs/resources/) for field types and bindings, and [Roles and permissions](/docs/roles-and-permissions/) for the three-layer permission model.
