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

# The app tree

> app(tree) is the namespace: every declaration's name is its path, and allow decides what is exposed.

An app is a tree of declarations. `app(tree)` walks it, and every declaration
in it (a table, a label, a role, a release, a guard, a secret, a target, a
query or a mutation) takes its path as its name. Nothing is named by a string.

```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 });
```

Placed this way, `notes.ts`'s `items` table is `notes.items`, its `list` query
is `notes.list`, and `access.ts`'s `member` role is `access.member`. A module
namespace and a plain object are both subtrees; any depth works.

`app(tree)` returns the tree as well, so a declaration is reachable by value:
`root.notes.list` is the `list` query. A name exists only once `app()` has run,
so code reads paths lazily, never while modules load.

## Exposure

A function with `allow` is **exposed**: a client may call it at its path, if
the caller holds one of the roles. A function without `allow` is
**internal**. Its app's code can reach it through a call, continuation,
reaction or performer. Its app can also pass a reference to it down the tree.
Leave out `allow` to declare an internal function.

```ts bijection/notes.ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
export const list = query({ allow: [role.anyone] }, (ctx) =>
  ctx.list(notes.by("written").descending().first(20)),
);

// Internal: no allow.
export const tidy = mutation({ args: { note: t.key(notes) } }, async (ctx, { note }) => {
  await ctx.patch(notes(note), { text: "" });
});
```

`role.anyone` admits every principal, including signed-out callers.
`role.signedIn` admits authenticated people. Each names a principal class: the
program issues the class a grant at install that enters the functions listing
it, and the lock prints that grant. A class grant clears only the public label.

Use `api<typeof App>()` to name callable paths and `connect(url)` to run them.

## The lock file

`bijection check` derives `bijection.lock` from the tree: every path, with
its `allow`, its `under`, its grave acts and the guards on it, plus the class
grants the program issues at install and the app's contract. Commit it.
`bijection check` refuses a lock that differs from the tree, and `bijection check --write-lock` rewrites it for review, so a change
in what the app exposes or may do is a reviewed diff.

## Libraries and mountable apps

A **library** is a module, or a function that returns a subtree. Placing it in
the tree places its tables and functions there, with their paths:

```ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { members } from "@bijectionhq/library-members";

export default app({ notes, team: members({ roles: [member, owner], roster: staff }) });
```

Declare a **mountable app** with `app((options) => tree)` and call it at a
path in the installer's tree. The call records label, role, table, function
and target references in its options as `pass <kind> <path>` lines in the
receiving app's lock block. An installer can pass only references it can
name. A role reference can appear in `allow`. Each app holds its own roles
for entries declared with `roles:`.

App code can call its own functions, the exposed functions of apps it
contains, and functions passed to it. It can read its own tables,
non-private tables of apps it contains, passed tables, and tables that
name its site in `writers`. The caller's clearance still applies.

A mountable app or library that owns its tables declares `writers: () => [landing]` on each
table so only its own functions write to them, and exposes the table to callers
through `table.readOnly(...)` so installers can read and index it without
staging writes. A library whose facts the installer must not read at all
(credentials, codes) declares those tables `private: true` instead: only the
library's own functions read or write them
([private tables](https://docs.bijection.com/database/capabilities.md#private-tables)). See
[Mount an app](https://docs.bijection.com/mountable-apps/using.md) and [Write a mountable app](https://docs.bijection.com/mountable-apps/authoring.md).

## Entry points

| Entry | For |
| - | - |
| `@bijectionhq/bijection` | Every app and library: declarations, `t`, `sys`, `act`, `Result`, receivers, verifiers, `members`, `sys.files` and the types a library signature names |
| `@bijectionhq/bijection/client` | `connect` |
| `@bijectionhq/bijection/react` | `<Bijection>` and the hooks |
| `@bijectionhq/bijection/test` | `kernel(app, { now })` |

These four are the whole SDK. Checks, views, replicas and the partner sync
placement are packages: `@bijectionhq/library-checks`,
`@bijectionhq/library-views`, `@bijectionhq/library-replicas` and
`@bijectionhq/library-sync`; the sync's partner accounts and destinations are
the connector catalog's (`@bijectionhq/library-connectors/sync`).

> [card] [Mount an app](https://docs.bijection.com/mountable-apps/using.md)
>
> Install a mountable app at a path, pass it roles and guard its acts.

> [card] [Write a mountable app](https://docs.bijection.com/mountable-apps/authoring.md)
>
> Scaffold an app or library package and test it on the real kernel.


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