PermDock
Concepts

Presets

A preset is an archetype plus the features, auth, backend, framework, integrations and PermDock Cloud services an app needs, encoded as a short versioned code; permdock/preset generates the application's own files from it, the same in permdock init, the @permdock registry and the /create page.

A preset describes a starting point: a SaaS archetype and the features and stack it runs on. /create builds one in the browser, permdock init writes it into a project, and the code that names it can be shared, opened and changed again.

PartPreset keypermdock init flagChoices
Archetypearchetype--archetypeb2b, agent, marketplace, api, internal, consumer
Featuresfeatures--featuretenancy, custom-roles, approvals, operations, decision-log, limits, plans, ownership, api-keys, rls
Authauth--authcustom, supabase, better-auth, clerk, jwt
Backendbackend--backendmemory, supabase, drizzle, prisma
Frameworkframework--frameworknext, hono, express, none
Integrationsintegrations--integrationAgent runtimes ai-sdk, mcp; UI recipes shadcn, react-native
Servicesservices--servicecloud-decision-log, cloud-approvals, cloud-snapshots, cloud-hosted-grants

The /create steps, the preset keys and the permdock init flags read one catalogue, so they offer the same ids. PRESET_DEFAULTS holds the defaults both start from: b2b, custom auth, the memory backend and next, with no integrations or services. PRESET_FLAGS maps each key to its flag, and presetFlags(preset) returns the flags that select a preset.

An archetype turns on the features it needs (b2b adds tenancy, custom-roles and decision-log); an agent runtime adds operations; custom-roles adds tenancy. Features are only ever added.

Codes

A code is p1 and base64url bytes: the archetype, auth, backend and framework, then a bitset per multi-select list. Each list only grows at the end, so a code keeps its meaning as choices are added; a new layout gets a new prefix, and a version that cannot read it says so.

Generating

permdock/preset is pure: no file system, no network, the same in Node and the browser.

import { encodePreset, generatePreset, resolvePreset } from "permdock/preset";

const preset = resolvePreset({ archetype: "b2b", framework: "hono" });
const { code, files, dependencies, recipes, docs } = generatePreset(preset);
FileWhat
src/permissions.tsThe archetype's resources with crud() or readable() and Zod schemas
src/policy.tsRoles and grants as data: on, min and assigns with tenancy; where on the owner field with ownership; approval: "human" on destructive actions with approvals; limit with limits; a plan("pro") grant with plans
src/permdock.tsdefinePermDock with the features and services the preset picked and profile from NODE_ENV (apps and profiles)
src/data.tsRow loaders: demo rows in memory; Drizzle or Prisma queries with toWhere() lists on those backends, next to src/schema.ts and src/db.ts or prisma/schema.prisma
src/session.tsThe caller: currentUser() returning null until wired with custom auth, so every check fails closed; currentSubject() through the provider's subjectFrom* otherwise, plus src/auth.ts for Better Auth
Framework filesrc/permdock/server.ts (Next.js) or src/server.ts (Hono, Express, core)
src/operations.ts, src/agent.ts, src/mcp.tsWith agent runtimes
src/keys.tsWith api-keys: a decideCredential call
permdock.config.tsAlways: permissions, policy, operations with agent runtimes, and rls with that feature

permdock init lists what each choice writes.

generatePreset(preset, { clientInfo }) passes clientInfo to supabase-js's global.clientInfo in the Supabase clients session.ts and permdock.ts create, so their requests carry the parameters in X-Client-Info, such as via=permdock/<version> (client info specification). supabase-js added the option in 2.120 and its earlier types reject it, so leave it unset for older releases; unset, the clients pass none. proxy.ts refreshes the application's own session and never carries it.

Every generated file is the application's own code. The rules (role ceilings, holder counts, approval binding, limits, verification) are in the permdock package that these files call, so updating the package updates them.

Why

A preset generates declarations and wiring, never rules. A starter that copied authorization logic into the application could not receive a security fix; one that generates definePolicy data and definePermDock wiring can, because npm update replaces everything the generated code calls. The code format is versioned and append-only for the same reason as the wire formats: a link shared today opens the same preset after the catalogue grows.

Last updated on

On this page