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

# How Bijection works

> Follow facts, labels, roles, transactions and tasks through one app

A Bijection app is one tree of declarations. Its tables hold labelled facts.
Its functions read those facts and change them in transactions. Work outside
the transaction, such as a call to another company's API, is a task toward a
declared target, committed atomically with the writes. Clients watch query
values, which stay current as facts change.

```mermaid theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
flowchart LR
    Provider[External systems] -->|feeds| Tables[Labelled tables]
    Tables --> Queries[Queries and watches]
    Queries --> Apps[Apps and agents]
    Apps --> Mutations[Mutations]
    Mutations -->|one transaction| Tables
    Mutations -->|submit| Tasks[Tasks toward targets]
    Tasks --> Provider
    Tasks -->|then| Continuations[Continuations]
    Continuations --> Tables
```

The [customer tutorial](https://docs.bijection.com/start/tutorial) follows this loop through a complete
maintained example. [Architecture](https://docs.bijection.com/start/architecture.md) explains what each
boundary establishes.

## One tree names everything

`app(tree)` is the app's one namespace. A name is a path in the tree:
`orders.place` is a function, `orders.orders` a table, `access.clerk` a role.
No declaration takes a string name. A library is a module or a function that
returns a subtree, and mounting a mountable app is calling it at a path. See
[Components](https://docs.bijection.com/mountable-apps).

## Facts live in tables

| Declaration | What it holds |
| - | - |
| `table(fields, options)` | One fact per key |
| `series(fields, options)` | One sample per key and instant |
| `timeline(fields, options)` | One fact per key and valid period |

Every read and write names an **address**: a point such as `orders(id)`, or a
selection such as `orders.where({ customer }).by("placed").first(20)`. Indexes
are declared, unnamed and matched by structure. [Database](https://docs.bijection.com/database) covers
the declarations, the five reads and the six writes.

A feed that copies an external system's records into a table makes the feed
that table's writer. Your app keeps its own decisions in its own tables, beside
those observations, and a later sync does not overwrite them.
[Integrations](https://docs.bijection.com/integrations) covers sources and feeds.

## Labels decide who may know a fact

A **label** is an audience. A table's `label` labels its facts. A function runs
`under` one label: everything it reads must be cleared by its frame, and
everything it writes carries that label. A **role** clears labels, and a
principal holds a role through a **grant**. A function's `allow` lists the roles
that may enter it from outside; without `allow` a function is internal.

A **guard**, declared with `forbid`, refuses acts that the roles would
otherwise allow, such as "no one approves their own expense". Guards only
refuse. Data moves to a wider audience only through a declared `release`.
A mutation can use one with `ctx.open(sealed, { release })`. [Access](https://docs.bijection.com/access) explains labels, roles,
grants and guards.

## Functions are queries and mutations

A [query](https://docs.bijection.com/functions/queries.md) reads and commits nothing, and a client can watch
it. A [mutation](https://docs.bijection.com/functions/mutations.md) runs as one transaction under one label.
A strict write such as `ctx.patch` assumes the fact is present, and that
assumption joins the transaction's read set: if another commit removed the fact,
the transaction refuses `Absent`. Blind writes, `ctx.put` and `ctx.retract`,
read nothing and never refuse; other readers see them exactly.

Every boundary answers a `Result`: `{ ok: true, value }`, or
`{ ok: false, code, message }` with an app code from the function's `refuses`
or one of the twelve host codes. See [Errors](https://docs.bijection.com/functions/errors.md).

## Effects are tasks toward targets

A function cannot make network requests. A mutation reaches the outside world
with `ctx.submit(target, args, { once, then })`. The task commits with the
transaction's writes, and the host performs it after the commit. `once` is the
identity of the effect: asking again with the same `once` returns the original
task. The task's result is delivered to the continuation named by `then`.

A lost answer is the host code `Unknown`: it may have happened. On a call,
call again with the same `once`, and the host answers the original commit's
result. On a task the result is final: the host never resends it, and the
same `once` returns the same settled task, so reconcile with the receiver
(`reconciled(target)` from `@bijectionhq/library-recovery`). A task performed by people is a
target with `via: [roles]`, settled with `ctx.answer`. Standing sources such as
`every`, `cron`, `route.post` and `selection.changes` start reactions through a
mutation's `on`. See [Effects](https://docs.bijection.com/functions/effects.md).

## Grave acts change who can do what

A small set of named acts changes the host's own facts in `sys`: `grant` and
`revoke`, `open(sealed, { release })`, `erase`, `branch`, `land` and `discard`, `pin` and
`unpin`, and `answer` and `withdraw`. The six data writes cannot touch `sys`.
`bijection check` lists every function's grave acts in `bijection.lock`, the
committed file that reviewers read to see what a deployment exposes.

## Worlds hold alternatives

A function reads and writes at the head by default. A **branch** is a writable
world over a version: changes made in it stay there until `ctx.land` applies
them to the head, or `ctx.discard` ends it. A **trial** runs a call in a
discarded world and reports what it would write, without committing anything.
See [Branches](https://docs.bijection.com/branches).

## Clients watch values

Use `api<typeof App>()` for typed callable paths. Pass those refs to the
client returned by `connect(url)`.

## Compute stays external

Bijection runs transactions and coordination. Bulk transformations, model
training and other specialist work run on runtimes you configure. Their
results come back as ordinary writes that the app accepts. See
[Transformations](https://docs.bijection.com/transforms).

Start with [the first app](https://docs.bijection.com/start/quickstart.md), follow the
[business tutorial](https://docs.bijection.com/start/tutorial), or choose a capability from the
[platform map](https://docs.bijection.com/platform.md).


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