- One job per module.
packages/auth/src/index.tswas the Better Auth configuration, its hooks, the transactional handler and the request scope factory in one file. It is nowauth-options.ts,auth-hooks.ts,auth-effects.ts(the Audit Events, emails and storage deletes a write causes, registered on its unit of work) andauth-handler.ts(createAuth). Behavior is unchanged. See backend conventions and the auth package. (#268) - The root composes and exports one function.
@fofo/authexportscreateRequestScope, built fromcreateDbandcreateAuth, and nothing else. No module of the package imports it. - An explicit factory.
createRequestScopes(open)in@fofo/auth/request-scopereturns the memoizedcreateRequestScopeof one composition root.bindRequestScopeCreateis gone: importing the root no longer installs a factory into another module,createRequestScopecan no longer throw "request scope factory is not bound", and a test builds its own scopes instead of binding a stub that later tests share. - The file-size baseline shrinks. The largest backend file left the list of files over 400 lines; seven remain.
- For template users. Import
createAuthandAuthInstancefrom@fofo/auth/auth-handler(a new export, server-only). A test that calledbindRequestScopeCreate(stub)writesconst createRequestScope = createRequestScopes(stub).scripts/remove-mcp.mjsandscripts/remove-server-billing.mjseditauth-options.tsandauth-hooks.ts.
Authentication has one composition root
The 830-line packages/auth entry is split into options, hooks, effects and handler. The package root only composes them, and a request scope takes an explicit factory instead of one bound when a module is imported.
Edit on GitHubDocumentation is in English.