# 07 — Implementation plan

Build the Next.js app against existing vectors. Do not re-ingest `data/verticals` or `data/knowledge` unless playbooks change (`npm run ingest:knowledge`).

## Phase A — Shell

- Next.js app, layout, `/mortgage` three panes with mock profile.
- `POST /api/mortgage/case` + cookie.
- Zod `ApplicantProfile`.

**Exit:** Empty chat UI + empty profile + stepper on step 0.

## Phase B — Mortgage-only interview (steps 0–2, 5)

- Load `data/knowledge/mortgage` + `data/verticals/mortgage`.
- `POST /api/mortgage/chat` → retrieve → gpt-4o-mini → patch profile.
- `gates.ts` for steps 0, 1, 2, 5.

**Exit:** Customer can fill loan_balance, term, coverage_on_whom; profile pane updates live.

## Phase C — Full process steps 3–4

- Switch stores at step 3 (BMI) and 4 (health).
- Compute `bmi_computed`.
- Disease modules list with R/S from dataset HTML.
- Emergency stop handling.

**Exit:** Stepper can reach step 5 with build + at least knockout questions asked.

## Phase D — Soft UW + later steps

- Stub `DecisionResult` from BMI class + impairment flags.
- Step 6 stub DecisionResult; steps 7–8 shortlist + handoff. No in-app steps 9–11.

**Exit:** Customer sees illustrative offer family and “not a bind.”

## Phase E — Polish

- Citations expander.
- Persistence of cases.
- Tests: gate logic, merge patch, retrieve k.

## Acceptance tests

1. Message “I rent” → path stops; no fake loan_balance.
2. “About 240k left, 28 years, both on the loan” → profile shows those fields; step ≥ 2.
3. Profile groups match dataset names (Mortgage, Demographics, BMI, Tobacco, Diseases, Household, Income).
4. Stepper labels match process HTML steps **0–8** only; profile/progress toggles collapse independently.
5. At step 2, assistant does not ask cancer history.
6. GPT-4o-mini key stays server-side.
7. `data/verticals/*` unchanged by running the web app.

## Order of files to implement first

1. `lib/mortgage/schema.ts` + `gates.ts`
2. `lib/rag/retrieve.ts` reading existing JSON stores
3. `app/api/mortgage/chat/route.ts`
4. `components/ProfilePane.tsx` + `ProcessStepper.tsx`
5. Chat UI wired to the API
