Define

Resources

Resources are the records Charter serves through every interface.

A resource is a named collection of records, much like a table. You define its fields once in the config file. Charter then serves the same records over Representational State Transfer (REST), Model Context Protocol (MCP), and the CLI, with validation and permissions on every request.

To get a feel for the shape, here is a small resource with two fields:

[[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" }

You may import that file with charter import config --apply, or let charter dev watch charter.toml and apply saves for you. There is no admin console in the open release binary; manage resources with charter import config, or with charter resources and charter fields.

What you get#

Defining a resource gives you:

  • REST endpoints at /v1/<resource> (list, create, get, replace, patch, delete, and CSV import)
  • Validation against the field definitions on every write
  • Role-based permissions on every read and write
  • An entry in the generated OpenAPI document
  • An audit ledger entry for every mutation
  • Matching webhooks when you subscribe to lifecycle events
  • Server-Sent Events on the same GET paths when Accept prefers text/event-stream

Naming and flags#

Resource names must start with a letter or underscore, use only letters, digits and underscores, and stay within 100 characters. Names under Charter's own metadata_ prefix are reserved.

Flag Default Effect
enabled true When false, routes stay offline without deleting the definition or data
readOnly false Blocks all writes
allowAnonymousAccess false Allows unauthenticated requests when a public permission also exists
description (none) Optional text, up to 500 characters

System columns#

Every resource table includes these columns. You should not declare them as fields.

Column Role
id UUID primary key, assigned by Charter
created_at Set when the record is created
updated_at Updated on every modification
deleted_at Set on delete (soft delete)
data JSON storage for your field values

Soft delete is always on. A deleted record sets deleted_at. A later retrieve for that id looks like a missing row (404). Responses always include created_at and updated_at in attributes.

Field types#

Field definitions live in [[fields]] and are bound onto resources. Charter supports ten types:

Type Use for
string Short text
text Long-form text
number Integers or floating-point values
boolean True or false
datetime ISO 8601 date-time
timestamp Unix-style numeric timestamps
uuid UUID strings you manage yourself
json Arbitrary JSON object or array
enum One of a fixed set of strings (enumValues required)
relation Foreign key to another resource

You may also set optional metadata on a definition: displayName, description, and contentType (a display hint such as plain_text, markdown, email or slug). The registry accepts any short contentType string; the try-it docs form offers a fixed allowlist.

Bindings#

Each resource lists the fields it uses. Over HTTP, an operator attaches one with POST /registry/resources/{resource}/fields (field is the definition's id or name). GET lists the bindings. PATCH and DELETE on /registry/resources/{resource}/fields/{field} update the rules or detach the field. {resource} and {field} each accept a UUID or a name.

Per-resource rules:

Property Meaning
required Must be present on create
sortable Allowed in _sort
searchable Allowed for text pattern filters (contains, like, and so on)
unique Values must be unique across records
defaultValue Used when the field is omitted on create
validations Write-time rules (see below)
generatedFrom Derive the value from a sibling field

Generated transforms: slug, lowercase, uppercase, trim, prefix, suffix. The source field must be another binding on the same resource.

Validation#

Rules that run on write:

Rule Aliases Applies to
minLength min_length string, text
maxLength max_length string, text
pattern regex string (optional flags)
integer number
min minValue, min_value number
max maxValue, max_value number

Unknown rule names are rejected. There is no built-in email or url validator; you may use pattern when you need that shape.

Relations#

A relation field links records across resources. You declare the cardinality in config; Charter creates the storage (foreign keys, uniqueness, and junction tables) for you.

type Meaning Write shape
many-to-one Many records point at one target UUID string on this resource
one-to-one Same as many-to-one, with uniqueness enforced UUID string on this resource
one-to-many One parent has many children Array of child UUIDs on the parent (Charter keeps the foreign key on the child)
many-to-many Either side links to many on the other Array of UUIDs (Charter keeps a hidden junction table)
[[fields]]
name = "author_id"
type = "relation"
relations = { resource = "users", type = "many-to-one", name = "author" }

[[fields]]
name = "profile_id"
type = "relation"
relations = { resource = "profiles", type = "one-to-one", name = "profile" }

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

[[fields]]
name = "tags"
type = "relation"
relations = { resource = "tags", type = "many-to-many", name = "tags" }

field defaults to id when omitted. name is the optional alias for ?include= on REST (for example ?include=author). Without it, clients include by the field name.

Create, replace, update, and get return that same value in attributes, under the field name. A to-many array is present even when it is empty. Send ids as attributes. A relationships object on a write is rejected.

List and retrieve add relationships and included only when the query includes include. The relationship name is name, or the field name when name is omitted. A to-many linkage is an array of { "type", "id" } objects. A to-one linkage is one of those objects, or null. See REST API.

Next steps#