# keith-flow-sparrow/d2c-website architecture

> Architecture diagram of the GitHub repository keith-flow-sparrow/d2c-website, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/keith-flow-sparrow/d2c-website
- Repository: https://github.com/keith-flow-sparrow/d2c-website

## Overview

1. This repository is a client-side JavaScript layer for a Webflow-hosted D2C insurance quote experience. There is no backend code here; the architecture is a set of page-specific modules plus shared utilities that orchestrate form state, quote API calls, results rendering, and application redirects.

2. The core boundary is the quote lifecycle: `dpr-quote.js` collects user inputs, persists them, and redirects to a results page; `dpr-results.js` and `plan-card-display.js` then consume that persisted state to call GreenShield’s quote API; `plan-page.js` renders a single plan from cached results. These are separate page-entry modules, not a single SPA.

3. State is split deliberately across browser storage. `localStorage.dpr_local_data` holds non-personal quote preferences and filters, while `sessionStorage.dpr_session_data` holds personal contact data. `sessionStorage.dpr_results_data` stores the full API response plus original form data after a quote is fetched. This separation is a major architectural constraint, especially because personal data is kept out of URLs and out of localStorage.

4. The quote-form subsystem centers on prefill, synchronization, and submission. Inputs are kept in sync with URL parameters, localStorage, and sessionStorage, then written back on change. Submission triggers storage updates and a redirect URL defined by a script attribute. Webflow form integration is handled through the Superform-based utilities, so the form behaves like native Webflow content but with custom state management.

5. The results subsystem is the main runtime hub. `dpr-results.js` builds the `/quoteset` request from local storage plus attribution data, validates required fields conditionally, and renders pricing, apply buttons, and error/loading states. It also handles modal-based “update quote” behavior, meaning the page can refresh the quote without losing previously entered data unless the user cancels.

6. Quote rendering is plan-centric. API response data arrives as `PlanQuotes`, and the scripts map plan names to DOM regions marked with `dpr-results-plan`. Each plan card can show base premium, optional hospital accommodation premium, and either an “Apply Now” button or a Quebec-specific call button. The UI state toggles between loading, success, and failure, but plan ordering/filtering is still applied even when the API fails.

7. `plan-card-display.js` extends the results experience into a comparison/filtering subsystem. It can reorder, hide, or limit plans based on filter state and predefined filter scenarios driven by `InsuranceReason` and `CoverageTier`. It also supports plan comparison mode with up to three selected plans, temporarily disabling filters while comparison is active. This module dispatches a `plans-populated` event so other systems can react once plan content exists.

8. `utilities/plan-injector.js` is a cloning/injection layer that copies rendered plan cards into other page regions. It preserves interactivity by rewiring apply buttons, hospital toggles, tooltips, and Quebec visibility rules on the cloned cards. It depends on the `plans-populated` event or a global fallback flag, which makes it resilient to timing/race conditions when content loads dynamically.

9. `plan-page.js` is a read-only detail page for one plan. Instead of calling the quote API again, it reads the cached quote response from `sessionStorage.dpr_results_data`, matches the current plan name, and renders the selected plan’s pricing and controls. This page shares the same application URL redirect flow and Quebec handling as the results pages, but its data source is only the cached quote state.

10. Quebec handling is a cross-cutting rule, not a page-specific concern. Province `10` changes the UI from an application button to a call button across results, comparison, plan pages, and injected plan cards. `utilities/quebec-check.js` exposes `window.isQuebec()` and emits a `quebec-ready` event so other modules can detect the province safely even if storage or script load order is uncertain.

11. Attribution is a separate supporting subsystem. `attribution-tracker.js` captures UTM parameters, click IDs, referrer, landing page, browser language, and similar context into localStorage with a 90-day TTL. That attribution object is then included in quote API payloads, so marketing source data flows from landing page to quote creation to downstream application tracking.

12. UI behavior is rounded out by shared utilities. `utilities/tooltip-system.js` manages both simple and accordion tooltips and re-initializes them after dynamic plan rendering. `utilities/script-loader.js` chooses staging vs production script URLs based on host environment, and `utilities/superform-auto-next.js` supports form navigation. These are infrastructure helpers rather than business logic, but they matter because they keep the Webflow pages modular and environment-aware.

13. The external service boundary is consistent across the repository: `POST /quoteset` retrieves pricing and plan options, and `GET /applicationUrl/{confirmationNumber}` resolves the final enrollment URL. Before redirecting, the client decorates the application URL with GTM auto-linking so analytics continuity survives cross-domain navigation.

14. The `.archive` directory contains older quote and plan-page implementations used as reference, not primary runtime code. For architecture diagrams, the active system is the set of top-level scripts plus `utilities/`; the archive is historical only.

Main entry points: [`dpr-results.js`](https://github.com/keith-flow-sparrow/d2c-website/blob/main/dpr-results.js) (Results page), [`plan-card-display.js`](https://github.com/keith-flow-sparrow/d2c-website/blob/main/plan-card-display.js) (Plan cards), [`dpr-quote.js`](https://github.com/keith-flow-sparrow/d2c-website/blob/main/dpr-quote.js) (Quote form), [`utilities/plan-injector.js`](https://github.com/keith-flow-sparrow/d2c-website/blob/main/utilities/plan-injector.js) (Plan injector)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_pages["Page scripts"]
  node_dpr_quote["Quote form<br/>page-entry<br/>[dpr-quote.js]"]
  node_dpr_results["Results page<br/>page-entry<br/>[dpr-results.js]"]
  node_plan_card_display["Plan cards<br/>results-ui"]
  node_plan_page["Plan detail<br/>page-entry<br/>[plan-page.js]"]
end

subgraph group_utils["Utilities"]
  node_plan_injector["Plan injector<br/>dom-clone<br/>[plan-injector.js]"]
  node_quebec_check["Quebec check<br/>province-rule<br/>[quebec-check.js]"]
  node_tooltip_system["Tooltips<br/>ui-helper<br/>[tooltip-system.js]"]
  node_script_loader["Script loader<br/>env-loader<br/>[script-loader.js]"]
  node_script_loader_min["Loader min<br/>env-loader"]
  node_superform_auto_next["Auto-next<br/>form-helper"]
end

subgraph group_support["Support modules"]
  node_contact_js["Contact form<br/>form-module<br/>[contact.js]"]
  node_pip_js["PIP flow<br/>form-module<br/>[pip.js]"]
  node_attribution_tracker["Attribution<br/>tracking"]
end

subgraph group_archive["Archive"]
  node_quote_v5_5["Legacy quote<br/>archived-page<br/>[get-quote-v5_5.js]"]
  node_plan_page_v1["Legacy plan<br/>archived-page<br/>[plan-page-v1.js]"]
end

node_dpr_quote -->|"captures source"| node_attribution_tracker
node_dpr_quote -->|"form steps"| node_superform_auto_next
node_dpr_quote -->|"loads env scripts"| node_script_loader
node_dpr_quote -->|"redirects to"| node_dpr_results
node_dpr_results -->|"adds attribution"| node_attribution_tracker
node_dpr_results -->|"province rule"| node_quebec_check
node_dpr_results -->|"rebinds ui"| node_tooltip_system
node_dpr_results -->|"renders plans"| node_plan_card_display
node_dpr_results -->|"injects cards"| node_plan_injector
node_plan_card_display -->|"apply mode"| node_quebec_check
node_plan_card_display -->|"tooltip refresh"| node_tooltip_system
node_plan_card_display -->|"populates clones"| node_plan_injector
node_plan_card_display -->|"plans-populated"| node_dpr_results
node_plan_page -->|"apply mode"| node_quebec_check
node_plan_page -->|"reads cache"| node_dpr_results
node_plan_injector -->|"mirrors rules"| node_quebec_check
node_plan_injector -->|"rewires tooltips"| node_tooltip_system
node_contact_js -->|"form helper"| node_superform_auto_next
node_pip_js -->|"form helper"| node_superform_auto_next
node_quote_v5_5 -.->|"legacy pair"| node_plan_page_v1

click node_dpr_quote "https://github.com/keith-flow-sparrow/d2c-website/blob/main/dpr-quote.js"
click node_dpr_results "https://github.com/keith-flow-sparrow/d2c-website/blob/main/dpr-results.js"
click node_plan_card_display "https://github.com/keith-flow-sparrow/d2c-website/blob/main/plan-card-display.js"
click node_plan_page "https://github.com/keith-flow-sparrow/d2c-website/blob/main/plan-page.js"
click node_contact_js "https://github.com/keith-flow-sparrow/d2c-website/blob/main/contact.js"
click node_pip_js "https://github.com/keith-flow-sparrow/d2c-website/blob/main/pip.js"
click node_attribution_tracker "https://github.com/keith-flow-sparrow/d2c-website/blob/main/attribution-tracker.js"
click node_plan_injector "https://github.com/keith-flow-sparrow/d2c-website/blob/main/utilities/plan-injector.js"
click node_quebec_check "https://github.com/keith-flow-sparrow/d2c-website/blob/main/utilities/quebec-check.js"
click node_tooltip_system "https://github.com/keith-flow-sparrow/d2c-website/blob/main/utilities/tooltip-system.js"
click node_script_loader "https://github.com/keith-flow-sparrow/d2c-website/blob/main/utilities/script-loader.js"
click node_script_loader_min "https://github.com/keith-flow-sparrow/d2c-website/blob/main/utilities/script-loader-min.js"
click node_superform_auto_next "https://github.com/keith-flow-sparrow/d2c-website/blob/main/utilities/superform-auto-next.js"
click node_quote_v5_5 "https://github.com/keith-flow-sparrow/d2c-website/blob/main/.archive/get-quote-v5_5.js"
click node_plan_page_v1 "https://github.com/keith-flow-sparrow/d2c-website/blob/main/.archive/plan-page-v1.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_dpr_quote,node_dpr_results,node_plan_card_display,node_plan_page toneBlue
class node_plan_injector,node_quebec_check,node_tooltip_system,node_script_loader,node_script_loader_min,node_superform_auto_next toneAmber
class node_contact_js,node_pip_js,node_attribution_tracker toneMint
class node_quote_v5_5,node_plan_page_v1 toneRose
```

## Components

### Page scripts

Active page-entry modules that drive quote capture, results, and plan detail rendering.

- [Quote form](https://github.com/keith-flow-sparrow/d2c-website/blob/main/dpr-quote.js): page-entry · Collects quote inputs, keeps browser state synchronized, and redirects to results. · `dpr-quote.js`
- [Results page](https://github.com/keith-flow-sparrow/d2c-website/blob/main/dpr-results.js): page-entry · Builds quote requests, renders pricing and states, and handles update-quote flows. · `dpr-results.js`
- [Plan cards](https://github.com/keith-flow-sparrow/d2c-website/blob/main/plan-card-display.js): results-ui · Renders, filters, reorders, and compares plan cards in the results experience. · `plan-card-display.js`
- [Plan detail](https://github.com/keith-flow-sparrow/d2c-website/blob/main/plan-page.js): page-entry · Reads cached quote results and renders a single plan on a read-only detail page. · `plan-page.js`

### Utilities

Shared infrastructure and cross-cutting browser helpers.

- [Plan injector](https://github.com/keith-flow-sparrow/d2c-website/blob/main/utilities/plan-injector.js): dom-clone · Clones rendered plan cards into other page regions and rewires their interactions. · `utilities/plan-injector.js`
- [Quebec check](https://github.com/keith-flow-sparrow/d2c-website/blob/main/utilities/quebec-check.js): province-rule · Detects Quebec province state and broadcasts readiness for dependent modules. · `utilities/quebec-check.js`
- [Tooltips](https://github.com/keith-flow-sparrow/d2c-website/blob/main/utilities/tooltip-system.js): ui-helper · Initializes and re-initializes tooltip behavior after dynamic content updates. · `utilities/tooltip-system.js`
- [Script loader](https://github.com/keith-flow-sparrow/d2c-website/blob/main/utilities/script-loader.js): env-loader · Selects environment-specific script URLs for staging and production hosts. · `utilities/script-loader.js`
- [Loader min](https://github.com/keith-flow-sparrow/d2c-website/blob/main/utilities/script-loader-min.js): env-loader · Minified script-loader variant used for deployment or legacy inclusion. · `utilities/script-loader-min.js`
- [Auto-next](https://github.com/keith-flow-sparrow/d2c-website/blob/main/utilities/superform-auto-next.js): form-helper · Supports Webflow/Superform-style multi-step form navigation. · `utilities/superform-auto-next.js`

### Support modules

Supporting logic for attribution, contact handling, and legacy page references.

- [Contact form](https://github.com/keith-flow-sparrow/d2c-website/blob/main/contact.js): form-module · Handles contact-related form behavior and state integration. · `contact.js`
- [PIP flow](https://github.com/keith-flow-sparrow/d2c-website/blob/main/pip.js): form-module · Supplementary page or form logic for a separate insurance flow. · `pip.js`
- [Attribution](https://github.com/keith-flow-sparrow/d2c-website/blob/main/attribution-tracker.js): tracking · Captures and persists marketing attribution data for later quote and application requests. · `attribution-tracker.js`

### Archive

Historical implementations kept for reference, not primary runtime code.

- [Legacy quote](https://github.com/keith-flow-sparrow/d2c-website/blob/main/.archive/get-quote-v5_5.js): archived-page · Archived quote implementation kept as historical reference. · `.archive/get-quote-v5_5.js`
- [Legacy plan](https://github.com/keith-flow-sparrow/d2c-website/blob/main/.archive/plan-page-v1.js): archived-page · Archived plan detail implementation kept as historical reference. · `.archive/plan-page-v1.js`

## Connections

- Quote form → Attribution: captures source · Stores attribution context alongside quote input state.
- Quote form → Auto-next: form steps · Uses shared form navigation helpers for the quote experience.
- Quote form → Script loader: loads env scripts · Relies on environment-aware script loading for page behavior.
- Quote form → Results page: redirects to · Sends completed quote inputs to the results page.
- Results page → Attribution: adds attribution · Includes marketing context in the quote API payload.
- Results page → Quebec check: province rule · Branches UI and enrollment behavior based on Quebec status.
- Results page → Tooltips: rebinds ui · Re-initializes tooltips after plan content is rendered.
- Results page → Plan cards: renders plans · Delegates plan ordering, filtering, and comparison display.
- Results page → Plan injector: injects cards · Exposes rendered plan cards for cloning into other regions.
- Plan cards → Quebec check: apply mode · Switches plan actions between apply and call behavior for Quebec.
- Plan cards → Tooltips: tooltip refresh · Relies on tooltip reinitialization after plan population.
- Plan cards → Plan injector: populates clones · Emits rendered content that can be cloned elsewhere on the site.
- Plan cards → Results page: plans-populated · Signals that plan content is ready for downstream consumers.
- Plan detail → Quebec check: apply mode · Uses the same province-based action swap as the results pages.
- Plan detail → Results page: reads cache · Consumes cached quote response written by the results flow.
- Plan injector → Quebec check: mirrors rules · Preserves province-specific visibility and action rules on cloned cards.
- Plan injector → Tooltips: rewires tooltips · Keeps tooltips functional after DOM cloning.
- Contact form → Auto-next: form helper · Uses shared navigation behavior for Webflow-style forms.
- PIP flow → Auto-next: form helper · Uses shared navigation behavior for another quote-related form flow.
- Legacy quote → Legacy plan: legacy pair · Archived quote and plan page implementations from an earlier architecture.
