H1Trips → Offer → Order — Micro Execution Map (Condensed)
H2Overview
Break Phase 1 into atomic, testable goals. Each goal = one working unit, no cross-dependency drift.
H2Core Flow (reference)
Trip Draft → Trip (DB) → LineItems → Offer → Order → Projection
H1🧩 MICRO GOALS (ORDERED)
H2G1 — Trip Draft Identity (UI → stable id)
Goal:
- Ensure every Trip draft has a persistent
id
Done when:
tripData.idalways exists before any save
H2G2 — Trip Draft → DB Sync (idempotent)
Goal:
- Persist Trip from Document silently
Files:
trips/actions/commitTripFromDocument.ts
Done when:
- DB row updates on every edit
- No duplicates (upsert works)
H2G3 — Trip DB ID Back-Propagation
Goal:
- Store DB id inside draft (
_dbId)
Done when:
trip._dbIdexists after first sync- Used by downstream actions
H2G4 — Pricing Snapshot Integrity
Goal:
- Ensure
trip.pricingis always serializable + complete
Done when:
- pricing JSON survives reload
- no undefined fields
H2G5 — LineItems Generation (Document-bound)
Goal:
- Convert pricing → LineItems (document scope)
Done when:
- LineItems appear under document
- correct
sourceType: "trip"
H2G6 — LineItems Determinism
Goal:
- Prevent duplication on re-generation
Done when:
- overwrite pattern works
- no stacking duplicates
H2G7 — Trip ↔ LineItems Traceability
Goal:
- Every LineItem references trip
Done when:
sourceId = trip.idmeta.tripIdexists
H2G8 — Offer Entity Creation
Goal:
- Create Offer container from Trip
Files:
offers/actions/createOfferFromTrip.ts
Done when:
- Offer exists with:
tripIddocumentId
H2G9 — LineItems → Offer Snapshot
Goal:
- Clone LineItems from Document → Offer
Done when:
- Offer has its own LineItems
- Document remains unchanged
H2G10 — Offer Creation Flow (atomic)
Goal:
- Combine G8 + G9 into single action
Files:
createOfferFromTripFlow.ts
Done when:
- One call → full Offer ready
H2G11 — UI Trigger (Trip → Offer)
Goal:
- Button inside TripBuilder
Done when:
- Click → Offer created
- No reload needed
H2G12 — Offer Read Model (no logic)
Goal:
- Render Offer purely from LineItems
Done when:
- totals derived in render only
- no stored totals required
H2G13 — Offer Idempotency (optional)
Goal:
- Prevent duplicate offers per draft (optional rule)
Done when:
- either:
- always new Offer
- OR reuse existing
H2G14 — Document ← Trip Backfill
Goal:
- Populate document sections from Trip
Files:
populateTripDocument.ts
Done when:
- Trip data visible in document fields
H2G15 — Trip ↔ Document Sync Direction
Goal:
- Define clear authority
Rule:
- Document = UI
- Trip = structured snapshot
Done when:
- no circular overwrite bugs
H2G16 — Order Entity Creation
Goal:
- Create Order from Offer
Files:
orders/actions/createOrderFromOffer.ts
Done when:
- Order row created
- linked to Offer
H2G17 — Order Snapshot (CRITICAL)
Goal:
- Copy LineItems → OrderLineItems
Done when:
- Order survives Offer edits
H2G18 — Offer Lock on Order
Goal:
- Freeze Offer after order
Done when:
status = "ordered"
H2G19 — Offer Totals (derived)
Goal:
- Compute totals only when needed
Done when:
- no totals stored as truth
H2G20 — Checkout Trigger (UI)
Goal:
- Button to create Order
Done when:
- redirect →
/orders/[id]
H2G21 — Order → PDF
Goal:
- Render Order snapshot
Done when:
- PDF matches Order exactly
H2G22 — Document Export Boundary
Goal:
- Stable printable root
Done when:
- all exports use same DOM root
H2G23 — Pricing Engine Centralization
Goal:
- One pricing engine used everywhere
Done when:
- Trip + Experience share logic
H2G24 — Experience → LineItems
Goal:
- Same pipeline as Trip
Done when:
- interchangeable in Offer
H2G25 — Mixed Offer Support
Goal:
- Allow Trip + Experience in one Offer
Done when:
- LineItems coexist safely
H2G26 — Offer Regeneration (safe)
Goal:
- Re-sync Trip into Offer without breaking Experience items
Done when:
- selective overwrite works
H2G27 — Full Offer Regeneration (nuclear)
Goal:
- Replace all LineItems from Document
Done when:
- Offer fully mirrors Document
H2G28 — Space Publication Hook
Goal:
- Publish Offer / Document as Space
Done when:
- page generated from snapshot
H2G29 — Channel Readiness (prep)
Goal:
- Ensure Offer can be exported
Done when:
- LineItems complete
- metadata ready
H2G30 — Error Safety Layer
Goal:
- Guard all actions
Done when:
- no silent failures
- clear thrown errors
H1✅ EXECUTION STRATEGY
H2Work Loop
- Pick ONE goal
- Implement
- Test manually
- Confirm DB state
- Move next
H2Priority Order (NOW)
- G2 → G3 → G5 → G8 → G9 → G10 → G11
- G12 → G16 → G17 → G18
- G21 → G22
- Then expand (Experience / Space)
H2Verification Checklist
- Trip persists without duplication
- LineItems reflect pricing exactly
- Offer clones LineItems correctly
- Order locks snapshot
- PDF matches Order
- No totals stored outside LineItems
- No Prisma outside actions
H2Notes / Improvements (non-blocking)
- unify
_dbIdnaming →tripId - add
versionto Offer later - add
status transitionsenum - optional audit log for LineItems mutations