# Introduction (/docs)

> Permissions and resource sharing for TypeScript: roles, conditions, field rules, teams, invitations, webhooks, and audit logs.

Rolebook decides who can do what in your app, and tells you why.

At its core, `rolebook` is a small TypeScript library that runs inside your own server process. You
define your resources and roles once, pass in who is asking and what they are trying to touch, and
Rolebook returns `allowed` or a coded denial, with the matching rule whenever one decided it. The
core engine has no database, network, authentication, framework, or UI dependency.

When you need more than role checks, first-party packages build on the same engine:

- **Resource sharing** (`@rolebook/sharing`): per-item owners, members, expiring access,
  invitations, folder inheritance, filtered lists, and audit logs stored in your own PostgreSQL or
  SQLite database.
- **Identity & teams**: read users and organizations from Better Auth (including a drop-in Better
  Auth plugin), Clerk, or WorkOS, and share with flat or optionally nested teams.
- **HTTP, React UI, webhooks & SDKs**: serve sharing from your own server (`@rolebook/server`), call
  it from browsers (`@rolebook/client`, `@rolebook/react`) or Python, Go, and Rust clients, and send
  signed access-change webhooks.
- **Route middleware, CLI & remote/offline checks**: guard Hono, Express 5, and Fastify 5 routes,
  inspect and manage access with `@rolebook/cli` (and its local MCP server), answer checks for other
  services with `@rolebook/decision-service`, or verify signed checks offline with
  `@rolebook/offline`.

[Choose how decisions run](/docs/choosing) compares each option so you can pick only what you need.

## The model in one paragraph [#the-model-in-one-paragraph]

A **policy** lists the things in your app (organizations, workspaces, projects), what actions each
supports, and the roles that allow or block those actions at a **scope**. A **subject** (such as a
user) never carries roles on itself. On each request, your app loads that person's scoped
**assignments** and passes the target item as a **trusted resource** along with its parent chain.
Rolebook validates every input, checks deny rules before allow rules across all roles and teams, and
returns a **decision** with a stable code, a reason, the deciding rule, and optionally a trace of
every rule it checked.

## Where it sits [#where-it-sits]

| Layer | Answers |
| --- | --- |
| Identity provider | Who is signed in, and which workspaces do they belong to? |
| Your application | Which role assignments and which item does this request involve? |
| The Rolebook engine (`rolebook`) | Is this action allowed, and why? |
| Rolebook Sharing (optional) | Who has access to this specific item, and who may change it? |
| Decision service (optional) | The same permission check, asked over HTTP by another service you authenticate. |
| Offline snapshots (optional) | The same check for one prepared action, verified on a device with no connection. |

## Packages [#packages]

| Package | What it does |
| --- | --- |
| [`rolebook`](/docs/api) | The core engine (`definePolicy`, `check`, `enforce`, `explain`), optional `rolebook/authoring` fact-schema checks, and [Hono](/docs/hono), [Express 5](/docs/api/express), and [Fastify 5](/docs/api/fastify) middleware. |
| [`@rolebook/sharing`](/docs/sharing) | Per-resource ownership, memberships, invitations, expiring access, folder inheritance, audit logs, and accessible-resource listing. |
| [`@rolebook/sharing-postgres`](/docs/sharing-postgres) | PostgreSQL storage adapter, migrations, transactional fences, authorized queries, and protected writes. |
| [`@rolebook/sharing-sqlite`](/docs/sharing-sqlite) | SQLite storage adapter for local-first, edge, and desktop apps (Bun, Node, better-sqlite3, local libSQL). |
| [`@rolebook/teams`](/docs/teams) | Team principals for sharing: flat teams by default, with optional bounded nested team lineage on PostgreSQL and SQLite. |
| [`@rolebook/better-auth`](/docs/better-auth) | Drop-in Better Auth plugin for Sharing: session-bound endpoints, PostgreSQL/SQLite kits, client plugin, and React bindings. |
| [`@rolebook/sharing-better-auth`](/docs/sharing-better-auth) | Better Auth identity adapter (users and workspace membership). |
| [`@rolebook/sharing-clerk`](/docs/sharing-clerk) | Clerk identity adapter (users and organization membership). |
| [`@rolebook/sharing-workos`](/docs/sharing-workos) | WorkOS User Management identity adapter (users, memberships, Directory Sync groups). |
| [`@rolebook/sharing-testkit`](/docs/sharing-testkit) | Reusable security contract tests that every sharing storage adapter must pass. |
| [`@rolebook/http`, `@rolebook/server`, `@rolebook/client`](/docs/http-api) | The Sharing HTTP API (wire contract, OpenAPI, mountable fetch/Hono/Next.js handler, typed client) plus signed [access-change webhooks](/docs/sharing/webhooks). |
| [`@rolebook/react`](/docs/react) | Accessible React sharing components (`MembersList`, `InviteMember`, `OwnershipTransfer`, `AuditLog`) and headless state (`@rolebook/react/core`). |
| [`@rolebook/cli`](/docs/cli) | The `rolebook` CLI for setup, checks, explanations, access changes, policy diffs, and the local [MCP server](/docs/agents/mcp). |
| [`@rolebook/connector`](/docs/connect-to-rolebook-console) | Connects your application to Rolebook Console: signed commands, applied through your own Sharing instance. |
| [`@rolebook/decision-service`](/docs/decision-service) | A `fetch` handler for authenticated single and batch permission checks over HTTP, using an authority provider you supply. |
| [`@rolebook/offline`](/docs/offline) | Signed bundles for one exact check, verified under a root-signed trust lease and evaluated offline by the engine. |
| [`@rolebook/scalars-p1`](/docs/scalars-p1) | The strict, bounded JSON parser shared by the decision service and offline snapshots. |
| [`@rolebook/migrate`](/docs/migrate) | Casbin-subset and role-table import planning, plan diffs, and read-only shadow comparison. |

## Where to go next [#where-to-go-next]

<Cards>
  <Card title="Choose how decisions run" href="/docs/choosing">
    Embedded engine, Sharing, the HTTP API, the decision service, or offline snapshots.
  </Card>
  <Card title="Installation" href="/docs/installation">
    Packages, runtimes, and peer dependencies.
  </Card>
  <Card title="Quick start" href="/docs/getting-started">
    Define a policy, bind a subject, check a permission.
  </Card>
  <Card title="Concepts" href="/docs/policies">
    Policies, roles, assignments, resources, conditions, and decisions.
  </Card>
  <Card title="Security model" href="/docs/security-model">
    What Rolebook guarantees, and what your application must establish.
  </Card>
</Cards>
