# 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) - [x] Extract router into `src/router/index.js` with named routes - [x] Add route meta `requiresAuth` and a global auth guard - [x] Remove auth-redirect from `App.vue` (handled by guard instead) - [x] 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) - [x] Add `src/api/http.js` wrapper for JSON fetch with error handling and env-based base URL - [x] Add `src/api/mappers/mealMapper.js` to normalize Meal data (dates) - [x] Add `src/api/meals.js` and migrate MealPlan API calls (get upcoming, mark consumed, delete) - [x] Create `src/api/recipes.js` and migrate recipe endpoints - [x] Create `src/api/shopping.js` and migrate shopping endpoints - [x] Create `src/api/auth.js` and migrate auth endpoints Outcome: Feature modules call cohesive services; logic for mapping/normalization is isolated and testable. ### Phase 3 — Composables (UI-Facing Logic) - [x] Add `src/composables/useAuth.js` (user ref, ensureAuth) - [x] Add `src/composables/useMeals.js` (fetch and mutate meals) - [x] Refactor pages to use composables and `