# engels-hub/pizza-calc architecture

> Architecture diagram of the GitHub repository engels-hub/pizza-calc, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/engels-hub/pizza-calc
- Repository: https://github.com/engels-hub/pizza-calc

## Overview

Picu kalkulators is a Latvian pizza-order calculator for groups, comparing Picu darbnīca and LuLū menus and prices. Visitors set group size and appetite, browse and filter pizzas, add whole or half-and-half pizzas, and see coverage and discounted totals; saved choices can be restored from a cookie or shared through URL state. Menus are documented as live-scraped, cached for six hours, and backed by a bundled snapshot on failure. The graph follows documented and indexed relationships; unsampled implementation details are not inferred.

Main entry points: [`src/app/page.tsx`](https://github.com/engels-hub/pizza-calc/blob/main/src/app/page.tsx) (Calculator page), [`src/lib/store.ts`](https://github.com/engels-hub/pizza-calc/blob/main/src/lib/store.ts) (Order state), [`src/components/planner/Planner.tsx`](https://github.com/engels-hub/pizza-calc/blob/main/src/components/planner/Planner.tsx) (Order planner), [`src/components/menu/MenuBrowser.tsx`](https://github.com/engels-hub/pizza-calc/blob/main/src/components/menu/MenuBrowser.tsx) (Menu browser)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["Calculator experience"]
  node_page["Calculator page<br/>[page.tsx]"]
  node_planner["Order planner<br/>[Planner.tsx]"]
  node_recommend["Recommendation"]
  node_menu_ui["Menu browser<br/>[MenuBrowser.tsx]"]
  node_pizza_row["Pizza selection<br/>[PizzaRow.tsx]"]
  node_cart["Cart and coverage<br/>[Cart.tsx]"]
  node_coverage["Coverage indicator<br/>[Coverage.tsx]"]
  node_deals["Promo controls<br/>[DealsList.tsx]"]
end

subgraph group_menu["Menu and sourcing"]
  node_menu_data["Menu loader<br/>[menu.ts]"]
  node_darbnica["Darbnīca scraper<br/>[darbnica.ts]"]
  node_lulu["LuLū scraper<br/>[lulu.ts]"]
  node_http["HTTP fetch<br/>[http.ts]"]
end

subgraph group_logic["Ordering logic"]
  node_calculator["Area calculations<br/>[calc.ts]"]
  node_filter["Menu filtering<br/>[filter.ts]"]
  node_ingredients["Ingredient matching<br/>[ingredients.ts]"]
  node_discounts["Discount engine<br/>[discounts.ts]"]
  node_halves["Half-pizza pricing<br/>[halves.ts]"]
  node_totals["Totals hook<br/>[useTotals.ts]"]
end

subgraph group_state["State and presentation"]
  node_prefs["Saved preferences<br/>[prefs.ts]"]
  node_store_provider["Request store provider<br/>[StoreProvider.tsx]"]
  node_store["Order state<br/>[store.ts]"]
  node_pizza3d["3D pizza stack<br/>[StackStage.tsx]"]
  node_meshes["Ingredient meshes"]
end

node_visitor(("Visitor"))
node_pizzerias["Pizzeria websites"]

node_visitor -->|"opens"| node_page
node_page -->|"loads menus"| node_menu_data
node_page -->|"restores order"| node_prefs
node_page -->|"initializes state"| node_store_provider
node_page -->|"renders"| node_planner
node_page -->|"renders"| node_cart
node_page -->|"renders"| node_menu_ui
node_menu_data -.->|"scrapes menu"| node_darbnica
node_menu_data -.->|"scrapes menu"| node_lulu
node_darbnica -.->|"fetches menu"| node_pizzerias
node_lulu -.->|"fetches menu"| node_pizzerias
node_darbnica -->|"uses fetch"| node_http
node_lulu -->|"uses fetch"| node_http
node_menu_ui -->|"filters menu"| node_filter
node_filter -->|"matches ingredients"| node_ingredients
node_menu_ui -->|"renders choices"| node_pizza_row
node_pizza_row -->|"adds selections"| node_store
node_pizza_row -->|"builds half pizza"| node_halves
node_planner -.->|"updates rules"| node_store
node_planner -.->|"shows estimate"| node_recommend
node_recommend -->|"calculates need"| node_calculator
node_coverage -->|"reads target"| node_recommend
node_coverage -->|"measures coverage"| node_calculator
node_cart -->|"renders stack"| node_pizza3d
node_pizza3d -->|"uses ingredient meshes"| node_meshes
node_deals -->|"toggles promos"| node_discounts
node_deals -->|"updates discounts"| node_store
node_totals -->|"computes totals"| node_discounts
node_totals -->|"reads order"| node_store
node_store_provider -->|"creates store"| node_store
node_store_provider -->|"loads preferences"| node_prefs
node_prefs -->|"restores halves"| node_halves

click node_page "https://github.com/engels-hub/pizza-calc/blob/main/src/app/page.tsx"
click node_planner "https://github.com/engels-hub/pizza-calc/blob/main/src/components/planner/Planner.tsx"
click node_recommend "https://github.com/engels-hub/pizza-calc/blob/main/src/hooks/useRecommendation.ts"
click node_menu_ui "https://github.com/engels-hub/pizza-calc/blob/main/src/components/menu/MenuBrowser.tsx"
click node_pizza_row "https://github.com/engels-hub/pizza-calc/blob/main/src/components/menu/PizzaRow.tsx"
click node_cart "https://github.com/engels-hub/pizza-calc/blob/main/src/components/cart/Cart.tsx"
click node_coverage "https://github.com/engels-hub/pizza-calc/blob/main/src/components/cart/Coverage.tsx"
click node_deals "https://github.com/engels-hub/pizza-calc/blob/main/src/components/deals/DealsList.tsx"
click node_menu_data "https://github.com/engels-hub/pizza-calc/blob/main/src/lib/menu.ts"
click node_darbnica "https://github.com/engels-hub/pizza-calc/blob/main/src/lib/scrapers/darbnica.ts"
click node_lulu "https://github.com/engels-hub/pizza-calc/blob/main/src/lib/scrapers/lulu.ts"
click node_http "https://github.com/engels-hub/pizza-calc/blob/main/src/lib/scrapers/http.ts"
click node_calculator "https://github.com/engels-hub/pizza-calc/blob/main/src/lib/calc.ts"
click node_filter "https://github.com/engels-hub/pizza-calc/blob/main/src/lib/filter.ts"
click node_ingredients "https://github.com/engels-hub/pizza-calc/blob/main/src/lib/ingredients.ts"
click node_discounts "https://github.com/engels-hub/pizza-calc/blob/main/src/lib/discounts.ts"
click node_halves "https://github.com/engels-hub/pizza-calc/blob/main/src/lib/halves.ts"
click node_totals "https://github.com/engels-hub/pizza-calc/blob/main/src/hooks/useTotals.ts"
click node_prefs "https://github.com/engels-hub/pizza-calc/blob/main/src/lib/prefs.ts"
click node_store_provider "https://github.com/engels-hub/pizza-calc/blob/main/src/components/layout/StoreProvider.tsx"
click node_store "https://github.com/engels-hub/pizza-calc/blob/main/src/lib/store.ts"
click node_pizza3d "https://github.com/engels-hub/pizza-calc/blob/main/src/components/pizza3d/StackStage.tsx"
click node_meshes "https://github.com/engels-hub/pizza-calc/blob/main/src/components/pizza3d/ingredientMeshes.ts"

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_page,node_planner,node_recommend,node_menu_ui,node_pizza_row,node_cart,node_coverage,node_deals toneBlue
class node_menu_data,node_darbnica,node_lulu,node_http toneAmber
class node_calculator,node_filter,node_ingredients,node_discounts,node_halves,node_totals toneMint
class node_prefs,node_store_provider,node_store,node_pizza3d,node_meshes toneRose
class node_visitor,node_pizzerias toneIndigo
```

## Components

### Calculator experience

- [Calculator page](https://github.com/engels-hub/pizza-calc/blob/main/src/app/page.tsx): `src/app/page.tsx`
- [Order planner](https://github.com/engels-hub/pizza-calc/blob/main/src/components/planner/Planner.tsx): `src/components/planner/Planner.tsx`
- [Recommendation](https://github.com/engels-hub/pizza-calc/blob/main/src/hooks/useRecommendation.ts): `src/hooks/useRecommendation.ts`
- [Menu browser](https://github.com/engels-hub/pizza-calc/blob/main/src/components/menu/MenuBrowser.tsx): `src/components/menu/MenuBrowser.tsx`
- [Pizza selection](https://github.com/engels-hub/pizza-calc/blob/main/src/components/menu/PizzaRow.tsx): `src/components/menu/PizzaRow.tsx`
- [Cart and coverage](https://github.com/engels-hub/pizza-calc/blob/main/src/components/cart/Cart.tsx): `src/components/cart/Cart.tsx`
- [Coverage indicator](https://github.com/engels-hub/pizza-calc/blob/main/src/components/cart/Coverage.tsx): `src/components/cart/Coverage.tsx`
- [Promo controls](https://github.com/engels-hub/pizza-calc/blob/main/src/components/deals/DealsList.tsx): `src/components/deals/DealsList.tsx`

### Menu and sourcing

- [Menu loader](https://github.com/engels-hub/pizza-calc/blob/main/src/lib/menu.ts): `src/lib/menu.ts`
- [Darbnīca scraper](https://github.com/engels-hub/pizza-calc/blob/main/src/lib/scrapers/darbnica.ts): `src/lib/scrapers/darbnica.ts`
- [LuLū scraper](https://github.com/engels-hub/pizza-calc/blob/main/src/lib/scrapers/lulu.ts): `src/lib/scrapers/lulu.ts`
- [HTTP fetch](https://github.com/engels-hub/pizza-calc/blob/main/src/lib/scrapers/http.ts): `src/lib/scrapers/http.ts`

### Ordering logic

- [Area calculations](https://github.com/engels-hub/pizza-calc/blob/main/src/lib/calc.ts): `src/lib/calc.ts`
- [Menu filtering](https://github.com/engels-hub/pizza-calc/blob/main/src/lib/filter.ts): `src/lib/filter.ts`
- [Ingredient matching](https://github.com/engels-hub/pizza-calc/blob/main/src/lib/ingredients.ts): `src/lib/ingredients.ts`
- [Discount engine](https://github.com/engels-hub/pizza-calc/blob/main/src/lib/discounts.ts): `src/lib/discounts.ts`
- [Half-pizza pricing](https://github.com/engels-hub/pizza-calc/blob/main/src/lib/halves.ts): `src/lib/halves.ts`
- [Totals hook](https://github.com/engels-hub/pizza-calc/blob/main/src/hooks/useTotals.ts): `src/hooks/useTotals.ts`

### State and presentation

- [Saved preferences](https://github.com/engels-hub/pizza-calc/blob/main/src/lib/prefs.ts): `src/lib/prefs.ts`
- [Request store provider](https://github.com/engels-hub/pizza-calc/blob/main/src/components/layout/StoreProvider.tsx): `src/components/layout/StoreProvider.tsx`
- [Order state](https://github.com/engels-hub/pizza-calc/blob/main/src/lib/store.ts): `src/lib/store.ts`
- [3D pizza stack](https://github.com/engels-hub/pizza-calc/blob/main/src/components/pizza3d/StackStage.tsx): `src/components/pizza3d/StackStage.tsx`
- [Ingredient meshes](https://github.com/engels-hub/pizza-calc/blob/main/src/components/pizza3d/ingredientMeshes.ts): `src/components/pizza3d/ingredientMeshes.ts`

### Other components

- **Visitor**
- **Pizzeria websites**

## Connections

- Visitor → Calculator page: opens (evidence: `src/app/page.tsx`)
- Calculator page → Menu loader: loads menus (evidence: `src/app/page.tsx`)
- Calculator page → Saved preferences: restores order (evidence: `src/app/page.tsx`)
- Calculator page → Request store provider: initializes state (evidence: `src/app/page.tsx`)
- Calculator page → Order planner: renders (evidence: `src/app/page.tsx`)
- Calculator page → Cart and coverage: renders (evidence: `src/app/page.tsx`)
- Calculator page → Menu browser: renders (evidence: `src/app/page.tsx`)
- Menu loader → Darbnīca scraper: scrapes menu (evidence: `README.md`)
- Menu loader → LuLū scraper: scrapes menu (evidence: `README.md`)
- Darbnīca scraper → Pizzeria websites: fetches menu (evidence: `README.md`)
- LuLū scraper → Pizzeria websites: fetches menu (evidence: `README.md`)
- Darbnīca scraper → HTTP fetch: uses fetch (evidence: `src/lib/scrapers/darbnica.ts`)
- LuLū scraper → HTTP fetch: uses fetch (evidence: `src/lib/scrapers/lulu.ts`)
- Menu browser → Menu filtering: filters menu (evidence: `src/components/menu/MenuBrowser.tsx`)
- Menu filtering → Ingredient matching: matches ingredients (evidence: `src/lib/filter.ts`)
- Menu browser → Pizza selection: renders choices (evidence: `src/components/menu/MenuBrowser.tsx`)
- Pizza selection → Order state: adds selections (evidence: `src/components/menu/PizzaRow.tsx`)
- Pizza selection → Half-pizza pricing: builds half pizza (evidence: `src/components/menu/PizzaRow.tsx`)
- Order planner → Order state: updates rules
- Order planner → Recommendation: shows estimate
- Recommendation → Area calculations: calculates need (evidence: `src/hooks/useRecommendation.ts`)
- Coverage indicator → Recommendation: reads target (evidence: `src/components/cart/Coverage.tsx`)
- Coverage indicator → Area calculations: measures coverage (evidence: `src/components/cart/Coverage.tsx`)
- Cart and coverage → 3D pizza stack: renders stack (evidence: `src/components/cart/Cart.tsx`)
- 3D pizza stack → Ingredient meshes: uses ingredient meshes
- Promo controls → Discount engine: toggles promos (evidence: `src/components/deals/DealsList.tsx`)
- Promo controls → Order state: updates discounts (evidence: `src/components/deals/DealsList.tsx`)
- Totals hook → Discount engine: computes totals (evidence: `src/hooks/useTotals.ts`)
- Totals hook → Order state: reads order (evidence: `src/hooks/useTotals.ts`)
- Request store provider → Order state: creates store (evidence: `src/components/layout/StoreProvider.tsx`)
- Request store provider → Saved preferences: loads preferences (evidence: `src/components/layout/StoreProvider.tsx`)
- Saved preferences → Half-pizza pricing: restores halves (evidence: `src/lib/prefs.ts`)
