Status: accepted · Date: 2026-10-17 · Amends: ADR-0011 · Related: ADR-0002, ADR-0012
Enforcement: in pnpm test, scripts/mobile-feature-boundaries.test.mjs (rules M1–M10, M12 and M13 below) and scripts/import-cycles.test.mjs (no cycles in apps/mobile/src); packages/api/src/exports.test.ts (no ./routers/* subpath); max-lines in apps/mobile/src/oxlint.config.mts; expo export --platform ios|android --source-maps and scripts/verify-optional-client-removal.mjs for Metro resolution.
apps/mobile/src had grown into components/, hooks/ and lib/, a layer-first layout. One feature (todo, notifications, billing) was spread over three folders, ten routes read data through orpc, authClient or react-query directly, and two routes were over 280 lines. The backend (ADR-0011) and the web app moved to one folder per feature with a fixed role per file name; the native app read differently from both. The app also still imported four legacy API subpaths, ./routers/{todo,integrations,billing,notifications}.schema, that ADR-0011 kept only for it.
Decision
The same feature shape as the backend and the web, with screen for page. apps/mobile/src has four layers, and imports point down: app → features → platform + design.
| Folder | Holds |
|---|---|
src/app/ | expo-router routes only, the same 27 files. A route returns its screen; it reads useLocalSearchParams when it needs to and keeps the root layout's module-scope effects and ErrorBoundary export. |
src/features/<f>/ | one flat folder per feature, every file named <f>.<role>.ts(x). Names match the backend and web (todo, notifications, billing, integrations, app-config, organizations, settings, auth, app-shell, dashboard) plus app-lock and onboarding. |
src/platform/<area>/ | cross-cutting code without domain: rpc, auth, i18n, feedback, review, theme, runtime, errors, format, app (root providers). |
src/design/, src/locales/ | unchanged. |
| Role | File | Rule |
|---|---|---|
| Screen | <f>[.<topic>].screen.tsx | composes Screen from @/design, hooks and components; gets route params as props |
| Hooks | <f>[.<topic>].hooks.ts | state, effects, useQuery/useMutation, authClient; no JSX |
| Queries, search | <f>.queries.ts, <f>.search.ts | query options; route-param parsing |
| Component | <f>.<name>.tsx | presentation with @/design |
| Model | <f>.<topic>.ts | pure logic and stores |
| Collections | <f>.collections.ts | private: collection descriptors, live queries and intents (ADR-0024) |
| Variant | <f>.<name>.{ios,android,native,web}.ts(x) | next to its base, same stem |
Screens and components never value-import @tanstack/react-query, @/platform/rpc/orpc or @/platform/auth/auth-client; data access lives in hooks. A feature reaches another only through its hooks, queries or search file, by @/features/<g>/…, unless the edge is declared in the boundary test with its reason. Four such edges exist today, all to a model of todo, app-lock, auth or onboarding (for example, a preference toggles the biometric lock, and Home keeps the todo widget in sync).
No platform → feature edge. The private offline snapshot is a platform module, platform/offline/: scoped-snapshot.ts (pure: scope key, envelope, fence, readScoped, the OfflineWriteError and ScopeChangedError the global toast recognises), private-caches.ts (one cache folder, openPrivateSnapshot(namespace, schema), clearPrivateCaches()) and snapshot-scope.ts (the scope read from the session and the Organization transition). Sign-out and a 401 call clearPrivateCaches(), which deletes the whole folder, so the purge does not depend on a feature module having loaded — the initialization-order concern that had kept three platform → features/todo edges in the first version of this ADR. A feature brings only its zod schema (features/todo/todo.cache.ts derives it from the contract's todoListOutputSchema); the boundary test's platform → feature list is empty and only shrinks.
One barrel stays: src/design/index.ts. It is the design system's public surface, client-only, with about 50 consumers, the aggregate ADR-0002 allows. No other index.ts and no export * exist in src/. The former i18n directory import is now the named file platform/i18n/i18n.ts.
Direction is a test, not lint. apps/mobile/src/oxlint.config.mts extends the client boundary of ADR-0002. An oxlint override of no-restricted-imports replaces the inherited rule options instead of merging them, so a direction rule there would switch the boundary off for the files it matches. The rules are checked by scripts/mobile-feature-boundaries.test.mjs:
- M1 layers, and
src/app/holds exactly the route list; - M2 cross-feature edges;
- M3 platform variants;
- M4 no data access in screens and components;
- M5
import()/require()only inindex.tsand the lazy purchases SDK; - M6 no barrel;
- M7 every
require,import(),vi.mockandtypeof importstring resolves; - M8 flat, prefixed feature folders;
- M9 canonical API subpaths;
- M10 Vitest's
includecovers every test file; - M12 the TanStack DB packages are value-imported only by
features/<f>/<f>.collections.ts,platform/db/andplatform/realtime/, and the features that hold money, access, identity, Consent, settings or flags have nocollectionsfile (added 2026-11-29 with ADR-0024); - M13 a tab stack with several routes and no
indexexportsunstable_settings = { anchor }(added 2026-11-29: without one expo-router opens the route with the shortest name, andprivacytook the Profile tab fromprofile).
Cycles (M11) join the existing scripts/import-cycles.test.mjs: import/no-cycle in the mobile lint config made pnpm lint about 60 % slower (paired median +0.59 s over seven runs). The lint config adds only max-lines (a warning at first, an error since 2026-11-28, when the tree had none): 250 code lines in features, platform and design, 100 in routes.
Metro rules. A file's last segment before the extension is ios, android, native or web only when it is a variant of a base with the same stem in the same folder, so a topic is never named like a platform (notifications.push-native.ts, not notifications.native.ts). A variant moves with its base. Nothing but routes goes in src/app/. index.ts keeps its evaluation order: the crypto polyfill (native only: Hermes has none, and collection writes need random values; a browser keeps its own), the notifications push bootstrap, then expo-router/entry. No metro.config.js or babel.config.js; the tsconfig @/* path is enough.
Who may say who the device is. One rule, in platform/auth/session-authority.ts: a reply of the auth client counts only if the identity did not move since it was asked (the session store names another User, Session or Active Organization, or none; an Organization change begins or ends). Every read takes a ticket before the Expo plugin reads its cookie. The session gate drops an overtaken reply before a cookie or a session is stored, before the session store is written and before anybody is signed out, and judges it again once the Expo plugin stored it; Better Auth's own refetches pass the same gate. Only the authoritative read (refreshAuthSession: its own request, disableCookieCache, asked again when overtaken) opens a refused scope, and only in the fence generation its verification started in. A scope is refused on FORBIDDEN for a read and on SCOPE_MISMATCH for a read or a write: its rows leave, its queued writes are dropped, and after a mismatch the device asks the server at once, the first time for an identity.
The legacy API aliases are gone. The app imports @fofo/api/<feature>/contract, /<feature>/rules (a LEAF such as auth/rules), /client, /rpc-scope and /push-messages only, and packages/api exports no ./routers/* subpath. This replaces the ADR-0011 consequence "the mobile aliases stay until a mobile change moves the app to the canonical specifiers".
Why not the alternatives
- Keep
components/,hooks/,lib/. A feature could not be read or removed as a unit, and the removal scripts kept name filters oversrc/lib. - Sub-folders per feature (
features/todo/components/). Deeper paths without clearer boundaries; the role suffix already says what a file is, as in ADR-0011. - Direction rules in oxlint. They would replace the client boundary they extend (above).
- Move
src/design/intoplatform/, or splitlocales/per feature. The design system is already one clear unit, and the locale parity test reads the three catalogs whole.
Consequences
- Paths changed in one move: 130 files by
git mv, then 35 new screens, hooks and section files. The iOS and Android sourcemaps ofexpo exportlisted the same modules under the new names after the moves, and only the new files after the screen extraction. The JS bundle grew by about 11.5 KB raw and 2 KB gzip, the module wrappers of the new files (measurement). - The removal recipes (
remove-task-clients,remove-mcp,verify-optional-client-removal,optional-features.json) target the feature files;features/todoandfeatures/notificationsare removed as folders. - Structural checks run without a device:
tsc, Vitest, oxlint, the boundary and cycle tests,expo exportfor both platforms with sourcemaps andexpo config --type public. A device smoke test is still recommended before a release, outside these gates. - New mobile features follow
.agents/skills/domain-feature/references/mobile.md.