Records the fold and corrects two long-carried errors: there is no admin MCP surface (the '11 MCP consumers' figure predated the Phase-0 addons extraction) and systemNotices/conditions.ts was never a consumer. The memories/admin edge is documented in the right direction for the first time. journeyService and oauthService now head the frontier.
17 KiB
Recommended order
Wave 1 — pilots (establish the template on easy wins)
- tagService (26 lines, zero deps, only consumers: TagsModule + 1 MCP tool) — the ideal first migration. Small enough that the whole pattern fits in one PR: move the SQL into TagsService with injected DatabaseService, retire the legacy file, convert its tests to overrideProvider(DATABASE_CONNECTION).
- categoryService (31 lines, same shape) — immediate repeat to confirm the template.
- todoService (120 lines, classic CRUD with transactions + broadcast) — first "full-shaped" domain: prepared statements, db.transaction, WebSocket broadcast, 3 MCP tools. After this one, the recipe is settled for everything else.
The pilots deliberately include MCP consumers, because they force the one open design decision early: MCP tools run outside the Nest container, so either the migrated module keeps thin function exports delegating to a shared instance, or the MCP layer gets a handle to the Nest app (app.get(TodoService)). Better to settle that on a 26-line service than on authService.
Wave 2 — cross-cutting leverage (parallel to wave 3, high payoff)
- permissions (149 lines, zero deps, 17 Nest consumers) → an injectable PermissionsService (done 2026-07 — every module wrapper, the airtrail-import controller and PluginHostDepsFactory now inject it; the cache stays module-scoped so the DI singleton and permissions.bridge — kept for mcp/_shared.ts + adminService/backupService — share one invalidation; the authService and collectionsService consumers fell away with their own folds). Every module wrapper already calls checkPermission; this converts the single most-imported seam in one move.
- auditLog (171 lines, 13 Nest consumers) → AuditService (done 2026-07 — writeAudit is the injectable; getClientIp and the log*/LOG_LEVEL logger stay plain modules in nest/audit/ (client-ip.ts, audit-log.logger.ts with its frozen-at-import level + mkdir as a documented parity exception); audit.bridge covers mcp/index, oauthProvider and the legacy airtrail/immich/oauth services).
- tripAccess (9 lines) — don't migrate, delete: it's a wrapper around canAccessTrip, which DatabaseService now exposes. Absorb its 11 call sites opportunistically.
Wave 3 — domain services with existing modules, low fan-in
- dayNoteService (done 2026-07), tripInviteService (done 2026-07), assignmentService (done 2026-07), shareService (done 2026-07), settingsService (done 2026-07), fileService (done 2026-07), collabService (done 2026-07), packingService (done 2026-07) — each maps 1:1 to a Nest module that's already a thin delegate; none is imported by more than one other legacy service.
Wave 4 — the coupled cluster (order matters here)
- dayService → budgetService → reservationService in that order: reservations depend on both (budget-item linking, day resolution), so migrating the dependencies first lets ReservationsService inject the finished versions instead of
importing legacy functions. — Correction (migration-graph.md, borne out by the migration): the claimed ordering constraint doesn't exist at the service layer. reservationService (done 2026-07) imported neither budgetService nor
dayService; the budget/day coupling lives in the Nest wrapper's budget-sync seam and the MCP registrars, which keep their legacy imports until those domains migrate. Reservations went first as the frontier residue fold; dayService
(done 2026-07 — the 592-line service folded into the wrapper
DaysService, the accommodations seam innest/reservations/now injects it, and the hand-rolled reorder/insert transactions becamedb.transaction()) followed; budgetService followed (done 2026-07 — the 755-line money core folded into the wrapperBudgetService(settlement maths, FX freeze/rebase, items/members/payers CRUD; the raw settlement writes becameinsertSettlement/applySettlementUpdateso the MCP paths keep skipping the freeze); the 11-tool mcp registrar + 3 budget resources moved to the decorator-drivenbudget.mcp.ts; TripsService/ReservationsService/BookingImportService now injectBudgetService; a 4-exportbudget.bridge.tsserves tripService, userCleanupService and the legacy trips/transports registrars;exchange-rates.bridge.tswas deleted with its last consumers; and the controller adoptedbudget.dto.tsover the shared schemas, clearing all nine budget allow-list entries — tripService is now unblocked). - tripService (done 2026-07 — the 1121-line hub folded into the wrapper
TripsService: generateDays, the updateTrip date-shift transaction, members/guests (#973/#1362), the ICS export, copyTripById and getTripSummary; its six bridge imports became injected services (CollabService/VacayService joined the constructor); the 10-tool trips registrar + 3 trip resources + the trip-summary prompt moved to the decorator-driventrips.mcp.ts(first@Prompt; the static-token deprecation notice rides theregistry.attachctx) and the 3 share-link tools toshare.mcp.tson thecanShareTripspredicate; FeedsService and the plugin RPC host injectTripsService; a 3-exporttrips.bridge.tsserves the legacy prompts registrar and budget.mcp.ts's owner/member seam; todo/share/collab/vacay bridges deleted with their last consumers; the controller adoptedtrips.dto.ts, clearing all seven trip allow-list entries). placeService followed (done 2026-07 — the 1029-line place core folded into the wrapperPlacesServicewith its pure half inplaces.helpers.ts; the 10-tool registrar + the trip-places resource moved to the decorator-drivenplaces.mcp.ts(search_placeinjectsMapsService); TripsService/DaysMcp/BookingImportService/the plugin RPC host all inject it, so the domain needs no bridge at all; the siblingplaceEnrichmentfold absorbed the lastmaps.bridgeconsumer and deleted that bridge too, and the DTO ratchet cleared all sevenPlacesControllerallow-list entries). transitItineraryService followed (done 2026-08 — the last step-4 link and the first pure-helpers relocation with no service fold: the 287-line module is 100% pure (no SQL, no DB, no broadcasts), so the schemas + endpoint/metadata builders moved byte-identical tonest/transit/transit-itinerary.helpers.ts(the schemas must stay module-level plain exports —transit.mcp.tsconsumes them inside@Tooldecorators, which evaluate before the container exists), its sole consumertransit.mcp.tswas a one-import repoint, and a new 21-caseTRANSIT-ITIN-*characterization suite pins the previously untested superRefine error strings and builder output — step 4 is complete). notificationService followed (done 2026-08 — the notifications fan-in, step 3 of the dependency-honest order, deferred while step 4 ran: thesend()dispatcher and theinAppNotifications.tsstore folded together into the existing wrapperNotificationsServiceover DatabaseService + RealtimeService; the prefs matrix, smtp/webhook/ntfy transports, channel registry andinAppNotificationActionsstay plain infra modules (their registry⇄prefs cycle included); a 1-exportnotifications.bridge.ts(send) covers scheduler's two cronrequires, legacy adminService + memories/{unified,synology}, and the six deliberately-lazy fire-and-forgetimport()sends in migrated Nest services (path-only repoints);AdminControllerand the plugin RPC host (24th constructor dep) inject instead; the 5-tool registrar + thenotifications-in-appresource moved to the decorator-drivennotifications.mcp.ts; the DTO ratchet cleared all fiveNotificationsControllerallow-list entries (testNtfyRequestSchemagained.nullable()server/token — the client sends null to mean "use the saved value") — adminService is now unblocked and heads the frontier).
Wave 5 — the heavyweights, last
- adminService (done 2026-08 — the last Wave-5 god file: the "11 MCP consumers" figure below was stale,
src/mcp/tools/admin.tshas never existed in the repo's history and the plugin host never imported the domain either, so recipe steps 3 and 4 were both no-ops. Ahead of the fold the 11 packing-template functions moved toPackingService, which already owned all three template tables — resolving theadmin-2residual with no bridge, sincepacking.mcp.tsalready injects that service. The 851-line module then folded into the wrapperAdminServiceoverDatabaseService+ injected Settings/Addons/Passkey/Packing/Auth/Permissions/Notifications (the auth, notifications and permissions bridge imports all became injections;PERMISSION_ACTIONSstayed a plain const and themcp/sessionManagerdeep import kept its anti-cycle comment), with the pure + module-scoped half —compareVersions,utcSuffix, the import-timeisDockerprobe and the 5-minute version cache — moving toadmin.helpers.ts; the cache stays module-scoped so the bridge instance and the container singleton share one GitHub fetch. A 1-exportadmin.bridge.ts(checkAndNotifyVersion) servesscheduler.ts's cron, the only out-of-container consumer. The DTO ratchet cleared all twentyAdminControllerallow-list entries, the largest single block, and the module e2e went DI-native (6 cases → 15 over real SQL) — journeyService and oauthService now head the frontier), journeyService/atlasService (done 2026-08 — pulled forward as a zero-dependency frontier member opening the Wave-5 auth chain: the 1612-line core split places-style — the DB half (stats aggregation with its two divergent return shapes, visited countries/regions with the #1490 tombstones + cascade, bucket-list CRUD) folded into the wrapperAtlasServiceoverDatabaseServicealone, while the ~750-line pure-geo half (admin0/admin1 boundary stores with the #1576 streaming builders, poly/box indexes, Nominatim geocoding with its shared throttle, the geocode/region caches incl. the import-time unref'd cleanup interval, thegeocodingInFlightdedup set) moved verbatim to the plain modulenest/atlas/atlas-geo.tsso the multi-MB caches stay process-global across the container + bridge instances; the 10-tool registrarmcp/tools/atlas.tsplus all four atlas resources inmcp/resources.tsmoved to the decorator-drivenatlas.mcp.ts(thewhen:atlas-addon gate is parity here — legacy tools/resources gated, REST deliberately doesn't;resources.test.tsretired with its last two cases, moved to the atlas suites); the plugin RPC host swapped its 9 atlas imports for the injected service (23rd constructor dep — journeys is the factory's last legacy domain import); a minimal 2-exportatlas.bridge.tsserved legacyauthService.getTravelStats(the zero-bridge streak ends at five; the bridge died on schedule with the 2026-08 auth fold); the DTO ratchet cleared all threeAtlasControllerallow-list entries)/vacayService (done 2026-07 — pulled forward as a zero-dependency frontier member, see migration-graph.md)/collectionsService (done 2026-08 — pulled forward as a frontier-ready member: the 1024-line saved-places core folded into the wrapperCollectionsServiceover DatabaseService + PermissionsService + RealtimeService (thecheckPermissionbridge import andbroadcastToUserwebsocket import became injections; thesendInvitelazy notificationServiceimport()stays, collab precedent;deleteOldCollectionCoverre-anchored one directory deeper); the 25-tool registrarmcp/tools/collections.tsmoved to the decorator-drivencollections.mcp.ts— with NOwhen:addon gate, preserving the legacy registrar's addon-gate asymmetry — plus a new 23-casetools-collectionscharacterization suite (the registrar was previously untested); the plugin RPC host swapped its 7 collections imports for the injected service (22nd constructor dep); no bridge file anywhere; the DTO ratchet cleared both collections allow-list entries (reorder,delete-many))/mapsService (done 2026-07 — pulled forward as step 4 of the dependency-honest order: the 1429-line geo core folded into the wrapperMapsService, pure helpers tomaps.helpers.ts, the 3 geo MCP tools to the decorator-drivenmaps.mcp.ts(weather/airport tools stay in the legacy registrar), BookingImportService injects it, and a 3-exportmaps.bridge.tsserves placeEnrichment + the places registrar — transitService → placeService now unblocked)/transitService (done 2026-07 — pulled forward as step 5 of the dependency-honest order: the first fully SQL-free domain fold — the 333-line Transitous/MOTIS proxy became a dep-freeTransitService(noDatabaseService); purederiveTransitStats+ mode whitelist + itinerary types moved totransit.helpers.tsso the downstreamtransitItineraryServiceneeded no bridge; the whole 3-tool registrar moved to the decorator-driventransit.mcp.ts, its days/reservations bridge imports becoming injectedDaysService/ReservationsService— zero bridge files; placeService → transitItineraryService followed, both done 2026-07/08), and the auth stack: authService (done 2026-08 — the 1497-line head of the auth → admin → oauth chain folded into the wrapperAuthServiceover DatabaseService + injected PermissionsService/AtlasService (retiringatlas.bridge.tson schedule); the pure crypto half (backup-code hash/match/generate,stripUserForClient, key masking, the import-timeDUMMY_PASSWORD_HASHtiming equaliser +avatarDirmkdir, both documented parity exceptions) moved to the plain moduleauth.helpers.ts;mfaSetupPending+ the per-email reset throttle (with its unref'd cleanup interval) stay module-scoped so the bridge and container instances share them; no MCP registrar existed and the plugin host never imported it, so neither surface changed — but the 15 in-container*.mcp.tsisDemoUserguards now injectAuthService(15 modules import AuthModule), withatlas.mcp.tsalone on the new 8-exportauth.bridge.tsbecause the AuthModule→AtlasModule edge would otherwise close a cycle (places.mcp precedent); the bridge also servesmcp/index.tstoken verification, the journey/notifications/transports registrars, and the still-legacy adminService/passkeyService; tests moved with IDs preserved (authService.test.ts → auth.helpers.test.ts, authServiceDb.test.ts → auth.service.test.ts + AUTH-BR-001…007 bridge cases), auth.e2e went DI-native (real bcrypt, real audit rows), oidc.e2e switched its dead path-mock for an instance spy). oidcService followed (done 2026-08 — the first frontier cash-in of the auth fold: the 508-line SSO module folded into the wrapperOidcServiceover DatabaseService + injected AuthService (theresolveAuthTogglesauth.bridgeimport became the injection); no MCP surface, no plugin-host import, and no bridge at all — nothing outside the container consumes the domain, so the state/auth-code maps, their sweep intervals, and the discovery/JWKS caches became instance state withonModuleDestroyclearing the timers;uuid/bcryptjslazy requires, theinvite_exhaustedsentinel transaction and every SQL string relocated verbatim; tests moved with OIDC-SVC IDs preserved, oidc.e2e and the integration suite switched their path mocks forvi.spyOn(app.get(OidcService), …)instance spies). passkeyService followed (done 2026-08 — the last frontier member of that pair: the 364-line WebAuthn module folded into a newPasskeyServiceinnest/auth/over DatabaseService + injected AuthService (the threeauth.bridgeimports resolved to the injection + plainauth.helpers/avatarUrlimports;resolveWebauthnConfigstays a plain helper import); no MCP surface, no plugin-host import, no bridge and no module state — the challenge store is DB-backed — so both in-container consumers just swapped to the injection (PasskeyController, andAdminService.resetUserPasskeysviaexports: [PasskeyService]+ an AdminModule→AuthModule import); the previously untested service gained a fresh PASSKEY-SVC-001…030 characterization suite with@simplewebauthn/servermocked at the verdict boundary), leaving oauthService — still an unblocked repoint-consumer of the bridge — plus adminService next in the chain. backupService also stays late: it owns closeDb/reinitialize lifecycle, which is deliberately outside the DI wrapper.
Two special cases to keep in mind: airportService is lazily required by db/database.ts at boot (the flight-endpoint backfill) — whenever it migrates, that call should move into Nest's bootstrap instead, or you recreate the circular
import; and notifications/notificationService were imported by 6+ other services, so they had to migrate before their dependents — cashed in 2026-08: the fan-in fold above landed exactly that way, send shimmed 1:1 through notifications.bridge.ts for the remaining legacy dependents (adminService, memories) until their own folds.
The through-line: each finished migration lets that domain's tests drop vi.mock('db/database') for overrideProvider(DATABASE_CONNECTION), so the mock seam shrinks wave by wave and disappears with the auth stack. Want me to start on tagService as the pilot?