# 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.

- **One job per module.** `packages/auth/src/index.ts` was the Better Auth configuration, its hooks, the transactional handler and the request scope factory in one file. It is now `auth-options.ts`, `auth-hooks.ts`, `auth-effects.ts` (the Audit Events, emails and storage deletes a write causes, registered on its unit of work) and `auth-handler.ts` (`createAuth`). Behavior is unchanged. See [backend conventions](/docs/development/backend-conventions#authentication-has-one-composition-root) and the [auth package](/docs/packages/auth). ([#268](https://github.com/CarlosZiegler/fofo/pull/268))
- **The root composes and exports one function.** `@fofo/auth` exports `createRequestScope`, built from `createDb` and `createAuth`, and nothing else. No module of the package imports it.
- **An explicit factory.** `createRequestScopes(open)` in `@fofo/auth/request-scope` returns the memoized `createRequestScope` of one composition root. `bindRequestScopeCreate` is gone: importing the root no longer installs a factory into another module, `createRequestScope` can 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 `createAuth` and `AuthInstance` from `@fofo/auth/auth-handler` (a new export, server-only). A test that called `bindRequestScopeCreate(stub)` writes `const createRequestScope = createRequestScopes(stub)`. `scripts/remove-mcp.mjs` and `scripts/remove-server-billing.mjs` edit `auth-options.ts` and `auth-hooks.ts`.
