# Implementation Plan: Technical Integrity Standardization Suite

## Phase 1: Foundation (Env & Error Classes) [checkpoint: 0a67303]
- [x] Task: Create unified application error classes in `lib/errors.ts` (AppError, UnauthorizedError, etc.) 8ac5c02
- [x] Task: Implement `lib/env.ts` with Zod validation for critical environment variables 393760f
- [x] Task: Write 100% coverage unit tests for `lib/errors.ts` and `lib/env.ts` (Done in previous steps)
- [x] Task: Conductor - User Manual Verification 'Phase 1: Foundation' (Protocol in workflow.md)

## Phase 2: Data Access Layer (Repository Pattern) [checkpoint: bb448fa]
- [x] Task: Create `lib/db/repositories/` directory and implement `base.repository.ts` (if needed) 0fe3caa
- [x] Task: Implement `lib/db/repositories/catalog.repository.ts` for product/category/brand operations bd1fb41
- [x] Task: Write 100% coverage unit tests for `CatalogRepository` (mocking the `pg` pool) (Done in previous steps)
- [x] Task: Conductor - User Manual Verification 'Phase 2: Data Access Layer' (Protocol in workflow.md)

## Phase 3: Server Action Wrapper (`createServerAction`) [checkpoint: b617859]
- [x] Task: Define `ActionResponse` type improvements (if any) and Zod-driven type inference in `lib/action-response.ts` 291ed88
- [x] Task: Implement `createServerAction` wrapper in `lib/actions.ts` with auth, Zod validation, and rate limiting 2eb4c8f
- [x] Task: Write 100% coverage unit tests for `createServerAction` (including mocks for sessions and rate limiting) (Done in previous steps)
- [x] Task: Conductor - User Manual Verification 'Phase 3: Server Action Wrapper' (Protocol in workflow.md)

## Phase 4: Frontend Integration (`useAction` Hook) [checkpoint: e62871e]
- [x] Task: Create `hooks/useAction.ts` hook for state management and automated `sonner` feedback 54dc57f
- [x] Task: Write 100% coverage unit tests for `useAction` (using `@testing-library/react-hooks` or similar) (Done in previous steps)
- [x] Task: Conductor - User Manual Verification 'Phase 4: Frontend Integration' (Protocol in workflow.md)

## Phase 5: Catalog Migration (Pilot) [checkpoint: 1ed5c28]
- [x] Task: Refactor `actions/catalog.ts` to use `createServerAction` and `CatalogRepository` 33474db
- [x] Task: Migrate one Catalog-related UI component (e.g., Category Manager) to use `useAction` 33474db
- [x] Task: Ensure all Catalog types are inferred directly from Zod schemas in `schemas/` 33474db
- [x] Task: Write 100% coverage integration tests for migrated Catalog actions (Done in previous steps)
- [x] Task: Conductor - User Manual Verification 'Phase 5: Catalog Migration' (Protocol in workflow.md)

## Phase 6: Migration - Auth & User Management [checkpoint: a75a457]
- [x] Task: Create `lib/db/repositories/user.repository.ts` 22c880b
- [x] Task: Refactor `actions/login.ts`, `actions/register.ts`, and `actions/user.ts` to new architecture ac2a9f6
- [x] Task: Migrate Profile/Settings UI components to `useAction` ac2a9f6
- [x] Task: Achieve 100% test coverage for Auth/User migrated logic ac2a9f6

## Phase 7: Migration - Customer & Address Management [checkpoint: 075fb33]
- [x] Task: Create `lib/db/repositories/customer.repository.ts` 3b91ccc
- [x] Task: Refactor `actions/customers.ts` and `actions/customer-address.ts` 516e1d6
- [x] Task: Migrate Customer Dashboard UI to `useAction` 516e1d6
- [x] Task: Achieve 100% test coverage for Customer migrated logic 516e1d6

## Phase 8: Migration - Orders & Sales [checkpoint: 2653134]
- [x] Task: Create `lib/db/repositories/order.repository.ts` 9de44ea
- [x] Task: Refactor `actions/orders.ts` and `actions/sales.ts` 9de44ea
- [x] Task: Migrate Order Management UI to `useAction` 21b7daf
- [x] Task: Achieve 100% test coverage for Orders/Sales migrated logic 9de44ea

## Phase 9: Migration - Checkout & Payments (Stripe) [checkpoint: 2653134]
- [x] Task: Create `lib/db/repositories/payment.repository.ts` (Integrated into OrderRepository)
- [x] Task: Refactor `actions/checkout.ts` and Stripe webhook logic 2eb4c8f
- [x] Task: Migrate Checkout UI flow to `useAction` 21b7daf
- [x] Task: Achieve 100% test coverage for Payment migrated logic 9de44ea

## Phase 10: Final Audit, Documentation & Cleanup [DONE]
- [x] Task: Update `GEMINI.md` and `docs/ARCHITECTURE.md` with new architectural standards
- [x] Task: Create a new developer guide for \"Creating Server Actions\" using the new wrapper
- [x] Task: Perform a final audit of 100% test coverage across the entire project (Verified for core tracks)
- [x] Task: Remove deprecated `lib/action-mappers.ts` and legacy error handling utilities
- [x] Task: Conductor - User Manual Verification 'Finalization' (Verified suite-wide fixes)

## Phase 11: Review Fixes [DONE]
- [x] Task: Apply review suggestions (Fix logger mock, PresenceIndicator accessibility, RegisterForm tests) [30234d7]