> ## 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.

# Access and governance

> Labels say who may know a fact, roles and grants say who may act, releases lower an audience, and guards refuse acts.

[Authentication](https://docs.bijection.com/access/authentication) establishes who is calling. Signing
in alone clears no label: it only enters the functions that `allow`
`role.signedIn`, through the class grant the program issues at install.
Everything else an app declares
in its tree, with five declarations from `@bijectionhq/bijection`:

| Declaration | What it says |
| - | - |
| `label()`, `label.family(keyType)` | An audience: who may know a fact. A table's `label` sets its facts' audience; a function's `under` is the label it runs under. |
| `role({ clear, include, issue })` | What a principal may do: enter the functions that `allow` it, clear labels, include other roles, and issue roles. |
| A grant (`ctx.grant`) | The fact that a principal holds a role under a label until an instant. Grants are the only source of positive authority; nothing is ambient. |
| `release({ from, to, message })` | A reviewed edge from one label down to a wider audience. A mutation can use it with `ctx.open(sealed, { release })`. |
| `forbid(scope, { message, where })` | A guard: a host-enforced refusal of every act in its scope that its predicate matches. |

## How an act is decided

An act proceeds only when all three hold:

1. **Positive authority.** The principal's surviving grants, together, cover
   it: one holds a role in the function's `allow`, and together they clear
   the function's `under`. The function's own grants must cover it too.
2. **Label flow.** Every read stays at or below the frame's clearance, and
   every write carries its data to a label at or above it. A lowering goes
   through a declared release.
3. **No guard refuses it.** Each guard in the act's scope decides once per
   offered grant. The grants no guard refuses are the act's survivors, and
   only survivors count toward positive authority.

A refusal reaches the caller as a `Result` with a host code: `Disallowed`
when the surviving grants do not cover the act or the frame does not clear a label, and
`Forbidden`, with the guard's path in `guard`, when a guard matched.
[How an act is decided](https://docs.bijection.com/access/decisions.md) states the rules in full.

## A small example

```ts bijection/access.ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { label, role } from "@bijectionhq/bijection";

export const shared = label();
export const member = role({ clear: [shared] });
export const owner = role({ clear: [shared], include: [member], issue: true });
```

```ts bijection/notes.ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { act, forbid, mutation, query, t, table } from "@bijectionhq/bijection";
import { member, owner, shared } from "./access";

export const notes = table({ text: t.string, author: t.principal, written: t.instant }, {
  label: shared,
});

export const list = query(
  { under: shared, allow: [member, owner], args: { size: t.number, cursor: t.cursor } },
  (ctx, { size, cursor }) => ctx.page(notes.byId(), { size, cursor }),
);

export const add = mutation({ under: shared, allow: [member, owner], args: { text: t.string } }, (ctx, { text }) =>
  ctx.insert(notes, { text, author: ctx.frame.as.id, written: ctx.frame.now.entry }),
);

/** A note's author is fixed once the note exists. */
export const fixedAuthor = forbid(act.write(notes, { fields: ["author"] }), {
  message: "A note's author cannot change after creation.",
  // Changes only: an insert has no `before`, a removal no `after`.
  where: (a) => a.before.isNotNull().and(a.after.isNotNull()),
});
```

```ts bijection/app.ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { app } from "@bijectionhq/bijection";
import * as access from "./access";
import * as notes from "./notes";

export default app({ access, notes });
```

`list` and `add` are exposed to holders of `member` or `owner`, and run
`under: shared`, so they may read and write the labelled notes. The labelled
table is [protected](https://docs.bijection.com/database/protected-tables.md). `notes.byId()` serves each
page in fact-id order. Start with `cursor: null` and pass the previous
page's `next` for the next page. The guard's
path, `notes.fixedAuthor`, is its identity: a refused write answers
`{ ok: false, code: "Forbidden", guard: "notes.fixedAuthor" }` with the
guard's `message` as its message. `bijection check --write-lock` records every path's
`allow`, `under`, grave acts and guards in `bijection.lock` for review.

## Pages

| Page | What it covers |
| - | - |
| [Protect an app](https://docs.bijection.com/access/quickstart.md) | Label the notes starter, add two roles and the membership library, and test it on the real kernel |
| [Labels](https://docs.bijection.com/access/labels.md) | Audiences, families, sealed fields, presence, label flow and eventual labels |
| [Roles and grants](https://docs.bijection.com/access/grants.md) | `allow`, `role`, `ctx.grant` and `ctx.revoke`, membership, the first owner and session-bound roles |
| [Guards](https://docs.bijection.com/access/guards.md) | `forbid`, its scopes and two tiers, per-grant decisions, the lock and the analyzer |
| [Releases and disclosure](https://docs.bijection.com/access/disclosure.md) | `release`, `ctx.open`, presence releases and audited returns |
| [How an act is decided](https://docs.bijection.com/access/decisions.md) | Decision inputs as reads, open entries, committed work decided again and labelled explanations |
| [Approval access](https://docs.bijection.com/access/manage-grants.md) | Roles for approval and release functions |


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