Choose how decisions run
The embedded engine, the Sharing module and its HTTP API, the decision service, and signed offline snapshots, and when to use each.
Rolebook has one evaluator: the engine in the rolebook package. Everything else is a way to bring a
question to it. This page explains the five ways, what each one needs from your application, and how
they fit together. They are not alternatives to pick once; most products combine two or three.
At a glance
| You have | Use | Where the engine runs | Who supplies the facts |
|---|---|---|---|
| TypeScript or JavaScript on your server, with roles your application already loads | The embedded engine (rolebook) | In your process | Your code, per request |
| A product where users share items with people and teams | The Sharing module (@rolebook/sharing) | In your process | Sharing’s storage and identity adapters |
| Browser code, or Python, Go, or Rust code, that works with shared items | The Sharing HTTP API (@rolebook/server) | On your server | The Sharing module behind the handler |
| Other services that need a plain check on a subject, an action, and a resource | The decision service (@rolebook/decision-service) | On your server | An authority provider you write |
| A device or edge process that must decide without a connection | Signed offline snapshots (@rolebook/offline) | On the device | An issuer you run, which signs them |
Every row ends in the same call: a policy, a binding, and a trusted resource go to
createAuthorizer(policy).bind(binding).check(request). No package contains a second evaluator, a
compiled-to-SQL policy, or an engine in another language.
The embedded engine
rolebook evaluates a policy against the subject, assignments, and
trusted resource your code passes to it. It has no database, network,
authentication-provider, framework, or UI dependency, and nothing in its request path leaves the process.
Use it when the code that asks runs on your server in TypeScript or JavaScript. It is the shortest path: a check adds no network hop and does not depend on another service being available. Route checks for Hono, Express 5, and Fastify 5 are thin middleware over it.
Your application owns the inputs: the authenticated subject, assignments from an authoritative store, and a resource loaded through a tenant-scoped query with its complete ancestry. Start with the quick start and the multi-tenant guide.
The Sharing module
@rolebook/sharing adds the state most collaborative products need: per-resource
ownership, memberships, invitations, expiry, revocation, and audit events, stored in your own PostgreSQL
or SQLite database. It loads that state through its adapters, projects it into assignments, and asks the
embedded engine for every decision.
Use it when access to an item depends on who it was shared with. It also answers the questions screens ask: every action a person may take on one item, who the item is shared with, the items a person can reach, and your own tables filtered to what a person may open. On PostgreSQL and SQLite, you can also turn on inherited folder access, run protected writes that decide an application update inside the transaction that performs it, and deliver signed access-change webhooks when memberships change.
If your app already uses Better Auth, @rolebook/better-auth wires up the
Sharing server endpoints, client, and React bindings as a single plugin.
The module is a library in your server process. It is the only path with transactional guarantees: a sharing change commits with its audit event, and a protected write commits with its decision.
The Sharing HTTP API
@rolebook/http, @rolebook/server, and @rolebook/client expose one Sharing instance
over HTTP as seven operations, sharing.authorize through sharing.explain, plus
sharing.executeIfUnchanged, the conditional form of sharing.execute. The handler is a
web-standard (request) => Promise<Response> function that you mount in your own server.
Use it for browser code (either directly with @rolebook/client or with the accessible components
in @rolebook/react), and for Python, Go, and Rust services that work with shared
items through the SDKs. The tenant and the actor always come from getContext,
which reads your trusted session; they are never in the request body. A caller therefore asks about
itself, in the tenant its session belongs to. The one exception is sharing.explain, the opt-in
privileged inspection: an actor who holds a resource’s inspect permission names another subject and
reads why that subject can or cannot act.
The HTTP API is the Sharing module’s surface, not a general check endpoint: its operations are about shared resources, and results are deliberately smaller than in-process ones. Named authorized queries and protected writes are not served over it.
The decision service
@rolebook/decision-service answers Core checks for other services. A caller
sends a subject, a resource, and a concrete action, optionally with one field, to one of two routes:
POST /v1/scopes/{scopeId}/decisions:check
POST /v1/scopes/{scopeId}/decisions:checkBatch {
"contract": "rolebook/decision-service/v1",
"semanticProfile": "rolebook/core-v4",
"scalarProfile": "rolebook/scalars-p1/v1",
"model": { "kind": "current" },
"freshness": { "kind": "captured_inputs" },
"check": {
"subject": { "type": "user", "id": "alice" },
"resource": { "type": "project", "id": "p1" },
"action": "read",
"field": "title"
}
} A request carries no assignments, facts, context, principals, or policy. The service authenticates the caller through a credential verifier you supply, matches a grant that names the scope, the operations, and the subjects that caller may ask about, and then loads the binding and the resource through the authority provider registered for that scope. The provider is your code over your own source of truth. The engine evaluates what it returns.
Use it when services that do not embed the engine need the same answers, including services in other languages and callers that ask about subjects other than themselves. It differs from the Sharing HTTP API in three ways:
| Sharing HTTP API | Decision service | |
|---|---|---|
| Caller | An end user’s session | An authenticated service credential with a grant |
| Subject of the check | The session’s actor; sharing.explain, when enabled, takes a named subject | Any subject the grant allows: one bound subject, or any in the scope |
| Facts come from | The Sharing module’s adapters | Your authority provider, for any Core policy |
| Operations | Authorize, permissions, describe, list, audit, execute, explain | Check and batch check only |
| A failure to load facts | A domain code or an error response, as the Sharing module reports it | A typed no-decision, distinct from every denial |
The package is a fetch handler with no listener. Before you expose it, your deployment supplies and
qualifies a credential verifier, an authority provider for each scope, and an HTTP host that terminates
TLS, rejects duplicate headers, and limits request rates. See the
deployment responsibilities.
Signed offline snapshots
@rolebook/offline carries one exact check to a place that cannot call your server. An
issuer signs a bundle that contains the policy, the binding, the resource, the permission, and the
optional field. A verifier authenticates the bundle under a trust lease signed by your root key, checks
its audience, validity window, and fact age, applies its stored anti-rollback state, and evaluates the
carried input with the engine.
Use it for a device, a kiosk, or an edge process that must keep answering during a disconnection. Know what a snapshot is not:
- It is not a general offline policy engine. One bundle answers one check; the verifier accepts no local policy and no caller-supplied facts.
- It is not a write authorization or a one-time token. A decision is reusable while the bundle is valid.
- It is not instantly revocable. A revoked signer stays usable until the device installs a newer root-signed lease that no longer authorizes its key. Until then, the bound is the key horizon (at most 7 days), the bundle expiry (at most 24 hours), and fact freshness.
A verifier constructed as ui_only returns results labelled ui_hint, suitable for showing or hiding a
control. Enforcement requires enforcement_qualified construction with a host qualification record, and
host adapters you have reviewed: a clock that cannot be set back, a state store that cannot be rolled
back, strict Ed25519 verification, and out-of-band root provisioning. The package ships none of these.
A hint is not a lower bar for integrity. Both modes run the same signature, trust, schema, time, and stored-rollback checks, and both return a no-decision when the clock cannot vouch for the time or the trust state is missing or lost; the difference is that only enforcement records the accepted bundle in the state store. The verifier stops accepting a signer when a newer root-signed lease that no longer authorizes its key is installed, and otherwise when the bundle or the key expires.
The package runs on Node.js 24 or later and on Bun.
Decisions and no-decisions
The embedded engine always decides: malformed input becomes a denial with its own code, because the caller supplied the facts and a bad fact is the caller’s fault.
The decision service and the offline verifier load or receive facts on the caller’s behalf, so they separate two results:
| Result | Codes | Meaning |
|---|---|---|
| Decision | ALLOWED, EXPLICIT_DENY, NOT_GRANTED | The inputs passed every configured admission and verification check, and the engine evaluated them. |
| No-decision | error from the service, reason from the verifier | The inputs could not be loaded, verified, or admitted in time. |
A decision does not certify its inputs beyond those checks. Completeness stays the obligation of the
trusted source: the service checks that an authority document is well formed, pinned to the right policy,
and within the fact age you configured, and the verifier checks signatures, validity, and the declared
manifest, but neither can tell that a provider or an issuer left an assignment out. Freshness follows the
contract the request selects: with captured_inputs, the service reports when the facts were observed and
when they were evaluated, not that they are still current.
A no-decision is never an allow, and it is not a denial either: it says the question was not answered. Treat it as a refusal to proceed, and report it as an availability problem, not as an access denial. Neither component falls back to cached facts, an empty assignment set, or an earlier answer.
One reader for bytes that cross a boundary
The decision service and offline snapshots parse every JSON boundary with
@rolebook/scalars-p1, the rolebook/scalars-p1/v1 profile: strict UTF-8 JSON with
duplicate member names rejected at every depth, and explicit budgets for bytes, depth, values, members,
entries, and string size. A number is admitted when the exact value of its token is at most
253 − 1 in magnitude, and is then rounded to the nearest binary64 value, ties to even. That is
a range check, not exact-decimal arithmetic: 4503599627370496.5 is admitted and becomes
4503599627370496. Send identifiers and values that must stay exact as strings. Authority
providers and issuers produce raw P1 bytes; stringifying an already parsed JavaScript value cannot show
that the original input met the profile. The Sharing HTTP API keeps its own JSON contract and does not
use P1.
What stays the same everywhere
- The semantics. Deny before allow across every applicable assignment, unknown conditions that never grant, field rules, flat group principals, and the hard limits.
- The trust model. A decision says the policy matched the supplied facts. Whoever supplies the facts (your request handler, a Sharing adapter, an authority provider, or an issuer) is trusted to supply complete and authoritative ones. No component can detect a deny assignment that its source left out.
- Point-in-time answers. A decision describes the facts when it was made. Only Sharing commands and protected writes bind a decision to a write in one transaction. A response from the decision service or a verified snapshot does not fence a later write.
- The model’s shape. Roles are scoped to a declared resource hierarchy, each resource has one ancestry chain, and core group principals are flat. Sharing and Teams offer opt-in, bounded folder inheritance and nested team lineage on PostgreSQL and SQLite, but none of these packages traverses an open-ended relationship graph.
Combining them
A typical product embeds the engine in its API server for route checks, uses the Sharing module for per-item access, serves the Sharing HTTP API to its own front end, and mounts the decision service for internal services written in other languages. One policy definition feeds all of them: the decision service takes the policy as P1 bytes for each scope, and an offline issuer signs the policy into each bundle and pins its digest in the trust lease.
Quick start
Define a policy, bind a subject, and check a permission in-process.
Resource sharing
Memberships, invitations, ownership, audit, and listing in your own database.
Decision service
Authenticated single and batch checks for other services.
Offline snapshots
Signed exact-check bundles, trust leases, and host qualification.
Security model
What each component guarantees, and what your application must establish.