# Implementation Plan - System Stabilization & Standardization

## Phase 1: Discovery & Audit
- [x] Task: **Codebase Pattern Analysis**
    - [x] Audit `actions/` for `createServerAction` usage vs. raw exports.
    - [x] Audit `components/` for direct DB access violations.
    - [x] Audit `lib/` for error handling consistency.
- [x] Task: **Documentation Inventory**
    - [x] Compare `docs/` content with `conductor/` to identify overlap and obsolescence.
    - [x] Identify "Source of Truth" conflicts.
- [x] Task: **TDD Gap Analysis**
    - [x] Run test coverage report for the entire project.
    - [x] Generate a detailed report listing all files with missing tests or low coverage (< 100%).
- [~] Task: Conductor - User Manual Verification 'Discovery & Audit' (Protocol in workflow.md)

## Phase 2: Documentation Standardization (Rewrite & Migration)
- [x] Task: **Migrate & Archive `docs/`**
    - [x] Move relevant architectural decisions from `docs/` to `conductor/`.
    - [x] Move developer guides to `conductor/workflow.md` or `conductor/dev-guide.md`.
    - [x] Archive the old `docs/` folder to avoid confusion.
- [x] Task: **Rewrite `conductor/tech-stack.md`**
    - [x] Update to reflect the *actual* implemented technologies and versions.
    - [x] Document the standardized patterns (e.g., "Must use Zod", "Must use Server Actions").
- [x] Task: **Rewrite `conductor/workflow.md`**
    - [x] Explicitly document the "Strict TDD" requirement.
    - [x] Define the standard for "Done" (**100% coverage** on touched files).
    - [x] **Future-Proofing:** Add "TDD Protocols" section detailing how to write testable code and maintain the suite.
- [x] Task: Conductor - User Manual Verification 'Documentation Standardization' (Protocol in workflow.md)

## Phase 3: Code Standardization (Critical Path: Actions & Data Access)
- [x] Task: **Standardize Server Actions (`actions/`)**
    - [x] Select a high-impact Action file (e.g., `actions/cart.ts` or `actions/products.ts`) that violates the standard.
    - [x] **Red Phase:** Write failing tests for the existing functionality (if missing).
    - [x] **Green Phase:** Refactor to use `createServerAction` wrapper and Repository pattern.
    - [x] **Refactor Phase:** Ensure strict typing and error handling.
    - [x] **Verify:** Ensure **100% coverage** for the refactored file.
- [x] Task: **Standardize Data Access**
    - [x] Ensure the refactored Action uses a Repository (in `lib/db/repositories/`) instead of direct Prisma calls.
- [x] Task: Conductor - User Manual Verification 'Code Standardization' (Protocol in workflow.md)

## Phase 4: Final Verification & Reporting
- [x] Task: **Final TDD Report**
    - [x] Compile the final "Missing TDD Report" (gaps remaining after this track).
- [x] Task: **CI Verification**
    - [x] Run full test suite to ensure no regressions.
    - [x] Verify build passes.
- [x] Task: **Create Pull Request**
    - [x] add to the sync-main-updates branch Pull Request on GitHub with a comprehensive comment/description including the TDD report and track reference.
- [x] Task: Conductor - User Manual Verification 'Final Verification' (Protocol in workflow.md)

## Phase: Review Fixes
- [x] Task: Apply review suggestions a8e3f85