Skip to content

ADR-0003: the in-memory tuple store refuses production

The createTupleStore that init --authz rebac writes (packages/cli/templates/init/platform/auth/relationships/create-tuple-store.ts.tpl) answers the in-memory InMemoryRelationTupleStore in development and test only, and throws in any other environment. Its message names what to bind instead: OpenFgaRelationTupleStore of @ddd-ts-kit/openfga, or a table of the database held to relationTupleStoreContract. InMemoryRelationTupleStore itself is unchanged and stays free for tests. This is the rule DevelopmentHeaderAuthenticator already follows. The entry of the change is changes/rebac-tuple-store-refuses-production.md.

An unset NODE_ENV stops the start. loadConfig (packages/cli/templates/init/platform/config/load-config.ts.tpl) reports NODE_ENV must be set under --authz rebac, as it reports NODE_ENV must be development or test under --authn none for the development header: a component that runs in development and test only makes the variable required, so production is never reached by default. The comment of that check says to drop it once createTupleStore binds a store that persists. createTupleStore itself still reads process.env['NODE_ENV'] ?? 'development', because the scripts that compose the application without starting it, scripts/openapi.ts among them, run with no NODE_ENV and never serve a request. The entry of that change is changes/rebac-memory-store-needs-node-env.md.

The tuples of the in-memory store live in the process. A revocation reaches that instance alone, a second instance never sees it, and a restart forgets every grant. In production that is not a degraded mode, it is an access control that does not hold. A project that starts in that state should not run.

Refusing in createTupleStore puts the refusal where the choice is made, and its message says what to do. A generated spec proves it.

The refusal of an unset NODE_ENV sits in loadConfig, where the development header already has its own, and not in createTupleStore: the store is built when its module loads, and a refusal there would also stop the contract scripts, which load it with no NODE_ENV. loadConfig runs at the start of the application, the worker and the scripts that open the database, which read .env.

  • A project on ReBAC that runs in production binds a real store in createTupleStore, or its start refuses. ddd-ts-kit init --force brings the refusal and its spec.
  • A project on ReBAC sets NODE_ENV wherever it starts: .env holds NODE_ENV=development for npm run dev, the Dockerfile sets production, the test runners set test. npm start on a machine with no NODE_ENV refuses.
  • The check stays after a persistent store is bound until someone removes it, as its comment asks.

A start that refuses an unset NODE_ENV for every stack would replace the two checks of loadConfig by one. A persistent store generated by default would make the refusal of createTupleStore and the check needless.