Skip to content

feat!: make spools the headless backend for business software - #57

Open
calvinbrewer wants to merge 7 commits into
mainfrom
feat/headless-backend
Open

calvinbrewer wants to merge 7 commits into
mainfrom
feat/headless-backend

Conversation

@calvinbrewer

@calvinbrewer calvinbrewer commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

What this does

Spools becomes the headless backend for business software you build with coding agents. It runs behind one HTTP API and draws nothing, so the front end is the app's own, on any framework. A CRM is the first thing built on it, and the starter is still one.

  • Operations and the HTTP API. Everything a Spool does for whoever asks is defined once as an operation. httpApi() answers each at POST <base>/<name>, describes itself at GET <base> and as OpenAPI 3.1.
  • Headless server. headlessServer() is a whole Spool with no web framework: the API, every endpoint (sign-in, files, the assistant, webhooks, cron) and the app's own routes. The starter's src/server.ts is that, and bun run dev serves it with no build.
  • Typed client, query options and React hooks. @swirls/spools/client, /query, /react and /state. spools gen writes src/spool.types.ts, so the client knows every field of an app's objects.
  • Who is asking. A session cookie from the same site, a sign-in token from a front end the server names, or an API key that acts as one teammate.
  • Built-in modules. Email sequences, mailbox and calendar sync, marketing and contact tracking are opt-in modules from @swirls/spools/modules. Without one, its tables are not made, its operations and routes are not there, and its part of the config is refused.
  • Two vaults. cipherstash() is the one a new Spool starts with. aes() seals with AES-256-GCM under a VAULT_KEY the app keeps and needs no outside service.
  • The site and docs are rewritten around the backend, with the interface's pages removed.

Breaking changes

  • The interface is gone: the pages, components, layouts, guides, alerts and the starter's routes and build, with the config keys that only described them.
  • The names say Spool. spool.config.json, src/spool.types.ts, bun run gen, defineSpool({ config }), spoolConfig(), staffHandler, StaffUser, SpoolRecord, and spool_event in .swirls files.
  • The CRM features are modules. Add modules: [sequences, mailbox, marketing, contactTracking] to defineSpool to keep all four.
  • A production server does not start without its vault's keys: the four CS_* variables for CipherStash, or VAULT_KEY for AES. Outside production a stand-in seals with a key that is in the source, and what it sealed is refused once the vault has its keys.
  • Clerk checks which front end a session was issued to, and a Better Auth sign-in link is spent only from your own site.
  • Tables. Adds api_keys; removes guide_progress and the type column of saved_views. Run bun run gen, then bun run db:push or your migration.

docs/upgrading.md has the steps and the full list of renamed names.

Verification

  • bun run verify passes on PGlite: 809 unit and 555 integration tests, with types, lint and formatting.
  • bun run check:package passes: it builds and packs the packages, makes a new Spool from them and runs it.
  • The integration tests passed on Postgres and on Prisma (553 pass, 3 skipped on each) after the modules work. Those two runs were not repeated after the copy changes and the AES vault, which touch no store code.

Not covered

  • Nothing has run against a live CipherStash workspace, a live Clerk instance, or live Google and Microsoft accounts.
  • The link in an email to a front end's own unsubscribe page, and starting an account connection from a front end on a different site, have no test.
  • Only some operations describe their answer in the OpenAPI document; the rest are in the TypeScript types.
  • Fields marked "encrypted" in the config are still stored as plaintext.
  • The built-in modules are gated where they are; their code has not moved out of the framework's core folders.

🤖 Generated with Claude Code

Ask Polylane for an impact assessment of this pull request:

Assess with Polylane

calvinbrewer and others added 6 commits December 4, 2026 12:24
A Spool can run as the CRM's server with no interface, behind a front end
of your own. Everything the CRM does for whoever asks is an operation,
defined once and reached by the interface's server functions, the HTTP API
and the server's own code alike.

- httpApi and headlessServer: every operation over HTTP, with no web framework
- a typed client, and src/crm.types.ts generated from the config
- API keys, opt-in, sealed by the vault and ending after 90 days by default
- Clerk without TanStack Start, and Better Auth with a bearer session
- create-spools --headless
- docs for headless mode across the README and the docs site

BREAKING CHANGE: the AES vault (@swirls/spools/vault/aes, VAULT_KEY,
VAULT_OLD_KEYS) is removed. CipherStash is the vault, and a production
server does not start without the CS_* variables. Clerk takes a session
only from the front end at APP_URL or the ones named in authorizedParties.
See docs/upgrading.md.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
The racing tests gave the one copy that runs 150 ms of work and expected
every other copy to arrive within it. On a slow runner some arrived after,
and were given the kept answer instead of in_progress. The copy that runs
now waits for the others' answers, so the outcome does not depend on speed.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
An app already on TanStack Start can use a Spool as its backend and keep
its own pages.

- serveApi (@swirls/spools/api/http): the HTTP API as the handlers of two
  route files. The starter mounts it, so a new Spool serves /api/v1
- startClient (@swirls/spools/start/client): the typed client that asks the
  API in-process on the server and over HTTP in the browser
- createQueries (@swirls/spools/query): every operation as query and
  mutation options for TanStack Query, with nothing imported but the
  client's types; a mutation marks what was read from the Spool stale
- the route-adapters lint rule takes the framework's handlers made with
  options
- docs: "In a TanStack Start app" on the Headless page

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…pickers

The state behind a list, a record's form and a relation picker, with no
markup: useListState, useRecordForm and useRelationSearch from
@swirls/spools/react, over pure rules in crm/list-state.ts and
crm/record-state.ts that the address of a list and a form's save share.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Rename the public crm names to spool names, move email sequences,
mailbox and calendar sync, marketing and contact tracking into opt-in
modules from @swirls/spools/modules, and rewrite the site and docs
around the backend for business software you vibe code.

BREAKING CHANGE: the names that said crm say spool (spool.config.json,
defineSpool, spoolConfig, staffHandler and the rest), and a Spool has
sequences, mailbox, marketing and contact tracking only when it lists
each module in defineSpool. See docs/upgrading.md.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
A Spool chooses its vault again: cipherstash(), which a new Spool starts
with, or aes() from @swirls/spools/vault/aes, which seals with
AES-256-GCM under VAULT_KEY and needs no outside service. A production
server does not start without its vault's variables, and outside
production both use the same development stand-in.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@calvinbrewer calvinbrewer changed the title feat!: run a spool headless, with cipherstash as the one vault feat!: make spools the headless backend for business software Dec 5, 2026
A clean install no longer got @clerk/tanstack-react-start once the
starter stopped using it, so the Clerk adapter for TanStack Start did
not type-check in CI. It is a dev dependency of the framework now, and
@clerk/backend moves to ^3.36.0 so both share one copy. That version
takes a cookie as a session only when its header carries Clerk's session
category, so the test's stand-in token carries it too.

Co-Authored-By: Claude Fable 5.2 <[email protected]>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant