-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Refactor Template
Title:
Refactor(di): Remove all DI backward-compatibility shims and complete migration plan
Description:
Over the past weeks several migration batches moved module factories and use-cases into the DI container while leaving short-lived backward-compatibility "shims" (legacy named exports, helper re-exports, and runtime indirection) in place. Those shims increase runtime indirection, hide module boundaries, and create testing and maintenance friction. This refactor finishes the DI migration by removing all remaining shims, consolidating factories and exports in the DI container, and updating consumers and tests to use the container/factories directly.
This issue codifies a step-by-step migration plan, lists all affected modules/files discovered in the last 50 commits, and defines acceptance criteria to safely remove the shims and keep CI/tests passing.
Scope:
Affected modules and files (collected from the last 50 commits — review each for leftover shims and migration impact):
- src/di/container.tsx
- src/di/useCases.ts
- DI-migration-plan.md
- src/modules/diet/day-diet/application/usecases/createBlankDay.ts
- src/modules/diet/day-diet/application/usecases/dayUseCases.ts
- src/modules/diet/day-diet/application/usecases/dayEditOrchestrator.ts
- src/modules/diet/day-diet/application/usecases/useCopyDayOperations.ts
- src/modules/diet/day-diet/tests/application/createBlankDay.test.ts
- src/modules/diet/day-diet/tests/application/dayEditOrchestrator.test.ts
- src/modules/diet/macro-profile/application/usecases/macroProfileState.ts
- src/modules/diet/macro-profile/application/usecases/macroProfileUseCases.ts
- src/modules/diet/macro-profile/application/service/macroProfileCrudService.ts
- src/modules/diet/macro-target/application/macroTargetUseCases.ts
- src/modules/diet/macro-nutrients/application/macroOverflow.ts
- src/modules/diet/meal/application/meal.ts
- src/modules/diet/food/application/usecases/foodCrud.ts
- src/modules/diet/food/infrastructure/api/infrastructure/supabase/supabaseFoodRepository.ts
- src/modules/diet/recipe/application/usecases/recipeCrud.ts
- src/modules/measure/application/usecases/measureCrud.ts
- src/modules/measure/application/usecases/measureState.ts
- src/modules/observability/application/telemetry.ts
- src/modules/profile/application/profile.ts
- src/modules/recent-food/application/usecases/recentFoodCrud.ts
- src/modules/recent-food/infrastructure/recentFoodRepository.ts
- src/modules/search/application/usecases/cachedSearchCrud.ts
- src/modules/template-search/application/usecases/templateSearchState.ts
- src/modules/toast/application/toastManager.ts
- src/modules/user/application/usecases/userUseCases.ts
- src/modules/weight/application/chart/weightChartUseCases.ts
- src/modules/weight/application/weight/usecases/weightUseCases.ts
- src/modules/clipboard/application/usecases/clipboardUseCases.ts
- src/modules/clipboard/README.md
- src/sections/clipboard/components/ClipboardPanel.tsx
- src/sections/clipboard/components/ClipboardToggleButton.tsx
- src/sections/common/components/ClipboardActionButtons.tsx
- src/sections/ean/components/EANSearch.tsx
- src/sections/item/components/ItemView/ItemEdit/ItemChildrenEditor.tsx
- src/sections/item/components/ItemView/ItemEdit/ItemEditModal.tsx
- src/sections/item/components/ItemView/ItemEdit/ItemEditBody.tsx
- src/sections/item/components/ItemView/ItemViewMacros.tsx
- src/sections/meal/components/MealEditView.tsx
- src/sections/recipe/components/RecipeEditView.tsx
- src/sections/search/components/TemplateSearchModal.tsx
- src/sections/day-diet/components/DayMeals.tsx
- src/sections/weight/components/WeightChartTooltip.tsx
- src/sections/weight/components/WeightEvolution.tsx
- src/sections/weight/components/WeightView.tsx
- src/sections/profile/components/MacroEvolution.tsx
- src/sections/profile/components/MacroProfile.tsx
- src/sections/profile/measure/components/BodyMeasureChart.tsx
- .github/copilot-instructions.md
(Note: Some files above were already migrated in batches; this list is exhaustive for the last 50 commits and helps verify no leftover shims remain.)
Motivation:
- Remove runtime indirection and legacy compatibility layers that hide true module boundaries.
- Improve maintainability and testability by making DI explicit and centralized.
- Reduce bundle/hydration surprises by avoiding implicit exports and runtime shims.
- Align codebase with repository rules (no barrel files, explicit DI wiring) and finalized migration plan.
Migration Plan (step-by-step):
-
Inventory and classify shims
- For each file listed in Scope, open and categorize the shim type: legacy named export, re-export helper, runtime proxy, or test-only shim.
- Produce a small matrix: file → shim type → migration risk (low/medium/high).
-
Prepare atomic migration batches
- Group related shims into small batches (by domain/module) to limit blast radius (e.g., weight, day-diet, food, recent-food, clipboard).
- Each batch must include: migration branch, unit test updates, and smoke test checklist.
-
Replace shim usage with DI container factories
- Update all consumers to import and use the DI container or exported factory directly (avoid dynamic/implicit re-exports).
- Where a factory API is missing, add a typed factory in the DI container and export a well-documented symbol (with JSDoc) from the module.
-
Update tests
- Replace imports that relied on shims with container factories or test factories/mocks.
- Add small integration tests ensuring the container wiring produces the expected instances.
-
Remove shim files/exports
- After consumers and tests are updated and CI passes, remove shim exports and legacy named exports.
- Run a codebase grep for any remaining references to the legacy symbol and resolve them.
-
CI and incremental verification
- For each batch: run unit tests, lint, and
npm run copilot:check(project's check script per repo guidance). - Merge when CI passes and smoke tests are green.
- For each batch: run unit tests, lint, and
-
Final cleanup
- Update
DI-migration-plan.mdto mark completed batches. - Ensure documentation (.github/copilot-instructions.md, JSDoc) and export surfaces are consistent.
- Search for disallowed patterns: barrel files (index.ts re-exports), runtime global mutations, and hidden proxies.
- Update
-
Post-merge validation
- Run full test suite and spot checks across major flows (day diet, weight chart, food search).
- Optionally run a small e2e test scenario for key user journeys.
Risk & Mitigation:
- Breaking public APIs inadvertently: mitigate by doing small batches and updating tests first.
- Circular imports when centralizing DI: fix by converting to factory functions and explicit dependency parameters.
- Missing export surface for re-used internals: add well-documented factories and keep internal helpers private.
Acceptance Criteria:
- All legacy DI shims listed in the Scope have been removed or archived and their consumers updated.
- DI container (
src/di/*) provides factories for every previously shimmed use-case. - All unit and integration tests pass locally and on CI for each migration batch.
-
DI-migration-plan.mdis updated to reflect completed batches and remaining work. - No runtime indirection patterns or barrel files were introduced (confirm with repo grep and code review).
- A short migration checklist and recommended review checklist are added to
DI-migration-plan.md.
Additional Context:
- Analysis of the last 50 commits shows staged batch migrations (Batch 2..7) progressively replacing shims with factories and migrating consumers. This issue consolidates remaining work and defines the final plan to remove the last compatibility layers.
- Suggested reviewers: owners of
di/*and module leads fordiet,weight,measure,recent-food,clipboard.