RolebookDocs

Introduction

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 compares each option so you can pick only what you need.

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

LayerAnswers
Identity providerWho is signed in, and which workspaces do they belong to?
Your applicationWhich 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

PackageWhat it does
rolebookThe core engine (definePolicy, check, enforce, explain), optional rolebook/authoring fact-schema checks, and Hono, Express 5, and Fastify 5 middleware.
@rolebook/sharingPer-resource ownership, memberships, invitations, expiring access, folder inheritance, audit logs, and accessible-resource listing.
@rolebook/sharing-postgresPostgreSQL storage adapter, migrations, transactional fences, authorized queries, and protected writes.
@rolebook/sharing-sqliteSQLite storage adapter for local-first, edge, and desktop apps (Bun, Node, better-sqlite3, local libSQL).
@rolebook/teamsTeam principals for sharing: flat teams by default, with optional bounded nested team lineage on PostgreSQL and SQLite.
@rolebook/better-authDrop-in Better Auth plugin for Sharing: session-bound endpoints, PostgreSQL/SQLite kits, client plugin, and React bindings.
@rolebook/sharing-better-authBetter Auth identity adapter (users and workspace membership).
@rolebook/sharing-clerkClerk identity adapter (users and organization membership).
@rolebook/sharing-workosWorkOS User Management identity adapter (users, memberships, Directory Sync groups).
@rolebook/sharing-testkitReusable security contract tests that every sharing storage adapter must pass.
@rolebook/http, @rolebook/server, @rolebook/clientThe Sharing HTTP API (wire contract, OpenAPI, mountable fetch/Hono/Next.js handler, typed client) plus signed access-change webhooks.
@rolebook/reactAccessible React sharing components (MembersList, InviteMember, OwnershipTransfer, AuditLog) and headless state (@rolebook/react/core).
@rolebook/cliThe rolebook CLI for setup, checks, explanations, access changes, policy diffs, and the local MCP server.
@rolebook/connectorConnects your application to Rolebook Console: signed commands, applied through your own Sharing instance.
@rolebook/decision-serviceA fetch handler for authenticated single and batch permission checks over HTTP, using an authority provider you supply.
@rolebook/offlineSigned bundles for one exact check, verified under a root-signed trust lease and evaluated offline by the engine.
@rolebook/scalars-p1The strict, bounded JSON parser shared by the decision service and offline snapshots.
@rolebook/migrateCasbin-subset and role-table import planning, plan diffs, and read-only shadow comparison.

Where to go next