3.1 KiB
3.1 KiB
Refactor Strategy
This document outlines a pragmatic, step-by-step refactor plan to improve structure, readability, and maintainability. Each step includes a clear outcome and a checkbox to track progress.
Last updated: 2025-10-18
Goals
- Separate concerns (routing, HTTP/API, mapping/normalization, UI logic)
- Improve readability and testability
- Establish light-weight standards (naming, lint/format) without blocking development
- Keep changes incremental and safe
Phases and Steps
Phase 1 — Routing and Auth (Foundational)
- Extract router into
src/router/index.jswith named routes - Add route meta
requiresAuthand a global auth guard - Remove auth-redirect from
App.vue(handled by guard instead) - Convert top-level nav to use route names consistently (optional)
Outcome: Routing logic is centralized and testable; pages redirect consistently based on auth.
Phase 2 — API Layer Split (Incremental)
- Add
src/api/http.jswrapper for JSON fetch with error handling and env-based base URL - Add
src/api/mappers/mealMapper.jsto normalize Meal data (dates) - Add
src/api/meals.jsand migrate MealPlan API calls (get upcoming, mark consumed, delete) - Create
src/api/recipes.jsand migrate recipe endpoints - Create
src/api/shopping.jsand migrate shopping endpoints - Create
src/api/auth.jsand migrate auth endpoints
Outcome: Feature modules call cohesive services; logic for mapping/normalization is isolated and testable.
Phase 3 — Composables (UI-Facing Logic)
- Add
src/composables/useAuth.js(user ref, ensureAuth) - Add
src/composables/useMeals.js(fetch and mutate meals) - Refactor pages to use composables and
<script setup>where appropriate
Outcome: Components get smaller and easier to read; business logic is reusable.
Phase 4 — Tooling and Standards
- Add Prettier config and .editorconfig; wire Prettier with ESLint
- Upgrade ESLint (if/when convenient) and align with Vue 3 rules
- Ensure Volar is used (dev environment) for Vue 3 type intelligence
- Optional next: add lint-staged + husky for
pre-commitformatting
- Optional next: add lint-staged + husky for
Outcome: Stable formatting and consistent linting across contributors.
Phase 5 — Tests (Targeted)
- Add a unit test runner (Vitest or Jest)
- Test mappers (dates/reference wiring)
- Test
units.jsconversions and totals
Outcome: Confidence in refactors and easier onboarding.
Environment
- Prefer
VUE_APP_API_BASEfor backend base URL (fallback to/apifor dev). Optionally set a devServer proxy invue.config.js.
Progress Log
- 2025-10-18:
- Extracted router with names and auth guard
- Removed
App.vueauth redirect - Added
api/http.js,api/mappers/mealMapper.js,api/meals.js - Updated
MealPlanPage.vueto use meals API - Added
api/mappers/recipeMapper.js,api/recipes.js; updated recipes components - Added
api/mappers/shoppingListMapper.js,api/shopping.js; updated shopping components - Added
api/auth.jsandapi/persons.js; router uses auth API - Added
composables/useAuth.jsand used inMyShoppingPage.vue - Added Prettier and EditorConfig