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

# Mount an app

> Install a mountable app by calling it at a path of your tree, pass it your roles, and guard its acts.

A mountable app is a function from its capabilities to `app(...)`. Mount it by
calling it at a path of your tree:

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

export default app({
  notes,
  blog: comments({ allow: [role.signedIn], maxLength: 500 }),
});
```

The mounted app's declarations take their paths under the mount: its
functions are `blog.add` and `blog.list`, and its tables `blog.comments` and
`blog.formatJobs`. Mount it twice at two paths and each mount has its own
tables.

## Pass it what it needs

What a mountable app takes is its own contract, stated by its function's
parameters: the roles that may call its functions, labels to run under,
functions of yours to call, plain options. Pass your own declarations by
value:

```ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
blog: comments({ allow: [editor, reader], prefix: "> " }),
```

The app exposes only the functions it gives `allow`; with the roles you passed,
your callers reach them at their paths (`api<typeof App>().blog.add`).

## Reach its declarations

`app(tree)` returns the tree, so the mounted app's declarations are values of
yours:

```ts bijection/app.ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
const root = app({ notes, blog: comments({ allow: [role.signedIn] }) });
export default root;

// root.blog.comments is the mounted comments table; root.blog.add its function.
```

Your functions read its tables and call its functions like your own, under
the same label rules. A route a mounted app declares is served under the mount:
a `route.post("/hook", verifier.session())` in an app mounted at `blog` serves `/blog/hook`.

## Guard its acts

An installer may add guards over a mounted app's acts. Name the declaration by
value, through the mount:

```ts bijection/app.ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { act, app, forbid, role } from "@bijectionhq/bijection";
import comments from "@acme/comments";

const blog = comments({ allow: [role.signedIn] });

export default app({
  blog,
  guards: {
    quietHours: forbid(act.enter(blog.add), {
      message: "Comments are closed between midnight and six.",
      when: (a) => new Date(a.now.entry.epochMilliseconds).getUTCHours() < 6,
    }),
  },
});
```

`act.enter(blog)` covers every function of the mounted app, and
`act.write(blog.comments)` every write to its table. A guard's path is its
identity: this one is `guards.quietHours`. See [Guards](https://docs.bijection.com/access/guards.md).

## Review it

`bijection check` lists the mounted app's paths in `bijection.lock` with the
rest of yours: their `allow`, `under`, grave acts and guards. Adopting or
upgrading a package is a reviewed lock diff.


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