Skip to content

Refactor: Remove remaining backward-compatible shims and finalize DI migration (Batch 7) #1451

@marcuscastelo

Description

@marcuscastelo

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):

  1. Discovery:
    • Search the repo for existing shims (pattern: export const <name> = create<...>(...)).
    • Produce an up-to-date list of shim modules and their consumers.
  2. 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).
  3. 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.
  4. 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.
  5. Update DI-migration-plan.md marking the shim as removed and documenting any refactors made to break circular dependencies.
  6. Repeat until all shims are removed and the repository passes lint/type/tests.

Acceptance Criteria:

  • All backward-compatible shims listed in the Scope are removed from their modules.
  • All former consumers were migrated to use the centralized DI container (src/di/useCases.ts / useContainer()), and no consumer imports the removed shim directly.
  • The repo passes the full verification command: npm run copilot:check (lint + type-check + tests).
  • DI-migration-plan.md is updated to mark Batch 7 as complete and documents any refactors performed to break circular dependencies.
  • Commits are small and focused (one shim removal per commit) and use Conventional Commit messages.
  • If any shim cannot be removed due to a non-trivial circular dependency, open a short follow-up issue describing the minimal refactor required and mark that shim as “blocked” in the plan.

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

Metadata

Metadata

Assignees

Labels

refactorCode refactoring required

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions