Title:
Refactor: Remove remaining backward-compatible shims and finalize DI migration (Batch 7)
Description:
Complete the final cleanup step of the DI migration plan by removing the remaining backward-compatible shims (top-level default exports that call factories) and consolidating use-case wiring in the central DI container (src/di/container.tsx / src/di/useCases.ts). This task finishes Batch 7 (cleanup final) of the migration and ensures the codebase consistently uses the DI factories and the centralized container rather than module-level shims.
Scope:
The refactor touches application-layer use-case modules and their UI/application consumers. Files/modules to review and migrate (representative list; please adjust as you discover additional shim exports during the work):
- src/modules/clipboard/application/usecases/clipboardUseCases.ts (clipboardUseCases)
- src/modules/diet/macro-profile/application/service/macroProfileCrudService.ts
- src/modules/diet/macro-profile/application/usecases/macroProfileUseCases.ts
- src/modules/diet/day-diet/application/usecases/dayUseCases.ts
- src/modules/diet/day-diet/application/usecases/createBlankDay.ts
- src/modules/diet/day-diet/application/usecases/dayEditOrchestrator.ts
- src/modules/diet/food/application/usecases/foodCrud.ts
- src/modules/diet/recipe/application/usecases/recipeCrud.ts
- src/modules/diet/item/application/recipeItemUseCases.ts
- src/modules/diet/macro-nutrients/application/macroOverflow.ts
- src/modules/diet/macro-target/application/macroTargetUseCases.ts
- src/modules/diet/meal/application/meal.ts (mealUseCases)
- (verify others listed in DI-migration-plan.md under "Remaining shims")
Note: the set above is intended as the canonical starting checklist; the engineer performing the work must run a project-wide search for export const <name> = create<...> shims and include any additional matches in the Scope section of the issue.
Motivation:
- Remove duplicate / ambiguous module-level defaults so there is a single standardized DI entrypoint for the UI and application layers.
- Improve testability and reduce hidden import-time side-effects / circular imports.
- Finalize the migration to a factory + container DI pattern, improving maintainability and clarity for future work.
Proposed Plan / Tasks (incremental, low-risk):
- Discovery:
- Search the repo for existing shims (pattern:
export const <name> = create<...>(...)).
- Produce an up-to-date list of shim modules and their consumers.
- Pick a low-risk shim to start (recommendation: modules with few UI imports and no transitive UI components — avoid those that import UI components at module-level).
- For each shim (one-by-one):
- Add the use-case to
src/di/useCases.ts (create a memo/root instance as needed).
- Add a type to
src/di/container.tsx if required.
- Update all consumers to use
useCases.<xxx>() (or useContainer() where appropriate).
- Run full checks:
pnpm run check / npm run copilot:check.
- Remove the shim export and run checks again.
- Commit a single, focused change (one shim per commit) with Conventional Commit style.
- If any circular import appears (example: clipboard → UI modal → item view → macroOverflow → dayUseCases), stop and:
- Isolate the circular import chain.
- Refactor the minimum module in the chain to remove top-level UI imports (move heavy UI imports into functions or defer them; accept a temporary shim if necessary).
- Re-run the incremental flow.
- Update
DI-migration-plan.md marking the shim as removed and documenting any refactors made to break circular dependencies.
- Repeat until all shims are removed and the repository passes lint/type/tests.
Acceptance Criteria:
Notes / Known Blockers
- Some shims (for example
clipboardUseCases) may transitively import UI components that themselves reference domain use-cases (macroOverflow → dayUseCases). These create circular import chains and must be handled by minimal targeted refactors (e.g. moving UI-only imports into functions, deferring modal wiring, or extracting small helper interfaces).
- Prefer Option C (incremental) workflow: one shim at a time, keep the repo green after each change, and commit each migration separately.
References
- DI migration plan: DI-migration-plan.md
- Current container & central wiring: src/di/container.tsx, src/di/useCases.ts
Title:
Refactor: Remove remaining backward-compatible shims and finalize DI migration (Batch 7)
Description:
Complete the final cleanup step of the DI migration plan by removing the remaining backward-compatible shims (top-level default exports that call factories) and consolidating use-case wiring in the central DI container (
src/di/container.tsx/src/di/useCases.ts). This task finishes Batch 7 (cleanup final) of the migration and ensures the codebase consistently uses the DI factories and the centralized container rather than module-level shims.Scope:
The refactor touches application-layer use-case modules and their UI/application consumers. Files/modules to review and migrate (representative list; please adjust as you discover additional shim exports during the work):
Note: the set above is intended as the canonical starting checklist; the engineer performing the work must run a project-wide search for
export const <name> = create<...>shims and include any additional matches in the Scope section of the issue.Motivation:
Proposed Plan / Tasks (incremental, low-risk):
export const <name> = create<...>(...)).src/di/useCases.ts(create a memo/root instance as needed).src/di/container.tsxif required.useCases.<xxx>()(oruseContainer()where appropriate).pnpm run check/npm run copilot:check.DI-migration-plan.mdmarking the shim as removed and documenting any refactors made to break circular dependencies.Acceptance Criteria:
src/di/useCases.ts/useContainer()), and no consumer imports the removed shim directly.npm run copilot:check(lint + type-check + tests).DI-migration-plan.mdis updated to mark Batch 7 as complete and documents any refactors performed to break circular dependencies.Notes / Known Blockers
clipboardUseCases) may transitively import UI components that themselves reference domain use-cases (macroOverflow → dayUseCases). These create circular import chains and must be handled by minimal targeted refactors (e.g. moving UI-only imports into functions, deferring modal wiring, or extracting small helper interfaces).References