# nickysemenza/ingredient-parser architecture

> Architecture diagram of the GitHub repository nickysemenza/ingredient-parser, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nickysemenza/ingredient-parser
- Repository: https://github.com/nickysemenza/ingredient-parser

## Overview

##### Project Type and Purpose
- This is a Rust‐centric monorepo containing:
– Core libraries for fetching and parsing recipe data.
– Multiple consumer apps: CLI (`food_cli`), TUI/desktop UI (`food_ui`), a Trunk‐based web app (`food_web`), and a React+WASM demo (`demo-site`).
- Purpose: scrape recipe pages (`recipe-scraper`, `recipe_scraper_fetcher`), parse ingredient lines (`ingredient-parser`), and expose functionality via CLIs, UIs, and web frontends (including WASM builds).

##### File Structure
- Top-level crates (each a Cargo workspace member):
– `ingredient-parser/` – core parsing library + unit testing.
– `recipe-scraper/` & `recipe_scraper_fetcher/` – HTML/JSON-LD scraper + HTTP utilities.
– `ingredient-wasm/` – builds `ingredient-parser` to WebAssembly for browser use.
– `food_cli/`, `food_ui/` – command-line and desktop UI frontends linking core libs.
– `food_web/` – Rust/WASM web app served via Trunk.
- Standalone frontend:
– `demo-site/` – React+TypeScript + Vite, consuming `ingredient-wasm` via `wasmContext`.

##### README for Additional Insights
- The main README points to `ingredient-parser/readme.md` for detailed API docs.
- CI/CD workflows target Rust tests (`.github/workflows/rust.yml`) and demo-site deployment.

##### Main Components & Interactions
a. Core Library Layer
- **recipe_scraper_fetcher**: HTTP client utilities (fetch raw HTML).
- **recipe-scraper**: parse scraped HTML + JSON-LD into structured recipe objects.
- **ingredient-parser**: tokenize and parse ingredient‐line strings into structured data.
b. WASM Bridge
- **ingredient-wasm**: compiles `ingredient-parser` to WebAssembly + JS glue.
c. Application Layer
- **food_cli**: CLI entrypoint; uses scraper + parser to fetch & display recipes.
- **food_ui**: possibly a TUI or desktop UI; links the same core libs.
- **food_web**: Rust/WebAssembly SPA built with Trunk; serves interactive recipe viewer in browser.
- **demo-site**: React app that imports `ingredient-wasm` via ES modules; demo UI for browser usage.
d. External Systems
- Recipe websites (NYTimes, SeriousEats, etc.) – HTTP endpoints.
- Browser environment (for web frontends).

##### Architectural Patterns & Design Principles
- **Layering**: clear separation between core domain libraries and UIs.
- **Modularity**: each crate has a single responsibility.
- **Cross-compilation**: core parsing logic reused in native CLI/UI and WASM.
- **Monorepo Workspace**: shared CI, versioning, and dependency management (Cargo workspace).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Systems
    subgraph "External Systems"
        RecipeSites["Recipe Websites"]:::external
        Browser["Browser"]:::external
    end

    %% Applications Layer
    subgraph "Applications"
        food_cli["food_cli\n(Rust binary)"]:::app
        food_ui["food_ui\n(Rust binary)"]:::app
        food_web["food_web\n(Rust + Trunk + WASM)"]:::app
        demo_site["demo-site\n(React + TypeScript + Vite)"]:::app
    end

    %% WASM Bridge
    subgraph "WASM Bridge"
        ingredient_wasm["ingredient-wasm"]:::bridge
    end

    %% Core Libraries
    subgraph "Core Libraries"
        recipe_scraper_fetcher["recipe_scraper_fetcher"]:::core
        recipe_scraper["recipe-scraper"]:::core
        ingredient_parser["ingredient-parser"]:::core
    end

    %% Data Flows
    RecipeSites -->|HTTP fetch| recipe_scraper_fetcher
    recipe_scraper_fetcher -->|raw HTML| recipe_scraper
    recipe_scraper -->|structured recipe| food_cli
    recipe_scraper -->|structured recipe| food_ui
    recipe_scraper -->|structured recipe| food_web
    ingredient_parser -->|parsing| food_cli
    ingredient_parser -->|parsing| food_ui
    ingredient_parser -->|parsing| food_web
    ingredient_parser -->|parsing| ingredient_wasm
    ingredient_wasm -->|WASM+JS import| demo_site
    Browser -->|user interaction| food_web
    Browser -->|user interaction| demo_site

    %% Click Events - recipe_scraper_fetcher
    click recipe_scraper_fetcher "https://github.com/nickysemenza/ingredient-parser/blob/main/recipe_scraper_fetcher/src/lib.rs"
    click recipe_scraper_fetcher "https://github.com/nickysemenza/ingredient-parser/blob/main/recipe_scraper_fetcher/src/http_utils.rs"

    %% Click Events - recipe-scraper
    click recipe_scraper "https://github.com/nickysemenza/ingredient-parser/blob/main/recipe-scraper/src/lib.rs"
    click recipe_scraper "https://github.com/nickysemenza/ingredient-parser/blob/main/recipe-scraper/src/html.rs"
    click recipe_scraper "https://github.com/nickysemenza/ingredient-parser/blob/main/recipe-scraper/src/ld_json.rs"
    click recipe_scraper "https://github.com/nickysemenza/ingredient-parser/blob/main/recipe-scraper/src/ld_schema.rs"
    click recipe_scraper "https://github.com/nickysemenza/ingredient-parser/blob/main/recipe-scraper/src/chefsteps.rs"
    click recipe_scraper "https://github.com/nickysemenza/ingredient-parser/tree/main/recipe-scraper/test_data/"
    click recipe_scraper "https://github.com/nickysemenza/ingredient-parser/blob/main/recipe-scraper/tests/integration.rs"

    %% Click Events - ingredient-parser
    click ingredient_parser "https://github.com/nickysemenza/ingredient-parser/blob/main/ingredient-parser/src/lib.rs"
    click ingredient_parser "https://github.com/nickysemenza/ingredient-parser/blob/main/ingredient-parser/src/fraction.rs"
    click ingredient_parser "https://github.com/nickysemenza/ingredient-parser/blob/main/ingredient-parser/src/ingredient.rs"
    click ingredient_parser "https://github.com/nickysemenza/ingredient-parser/blob/main/ingredient-parser/src/rich_text.rs"
    click ingredient_parser "https://github.com/nickysemenza/ingredient-parser/tree/main/ingredient-parser/src/unit/"
    click ingredient_parser "https://github.com/nickysemenza/ingredient-parser/blob/main/ingredient-parser/src/util.rs"
    click ingredient_parser "https://github.com/nickysemenza/ingredient-parser/blob/main/ingredient-parser/readme.md"

    %% Click Events - ingredient-wasm
    click ingredient_wasm "https://github.com/nickysemenza/ingredient-parser/blob/main/ingredient-wasm/src/lib.rs"
    click ingredient_wasm "https://github.com/nickysemenza/ingredient-parser/blob/main/ingredient-wasm/tests/web.rs"
    click ingredient_wasm "https://github.com/nickysemenza/ingredient-parser/blob/main/ingredient-wasm/Cargo.toml"

    %% Click Events - food_cli
    click food_cli "https://github.com/nickysemenza/ingredient-parser/blob/main/food_cli/src/main.rs"
    click food_cli "https://github.com/nickysemenza/ingredient-parser/blob/main/food_cli/Cargo.toml"

    %% Click Events - food_ui
    click food_ui "https://github.com/nickysemenza/ingredient-parser/blob/main/food_ui/src/main.rs"
    click food_ui "https://github.com/nickysemenza/ingredient-parser/blob/main/food_ui/src/lib.rs"
    click food_ui "https://github.com/nickysemenza/ingredient-parser/blob/main/food_ui/Cargo.toml"

    %% Click Events - food_web
    click food_web "https://github.com/nickysemenza/ingredient-parser/blob/main/food_web/src/main.rs"
    click food_web "https://github.com/nickysemenza/ingredient-parser/blob/main/food_web/src/lib.rs"
    click food_web "https://github.com/nickysemenza/ingredient-parser/blob/main/food_web/src/app.rs"
    click food_web "https://github.com/nickysemenza/ingredient-parser/blob/main/food_web/Trunk.toml"
    click food_web "https://github.com/nickysemenza/ingredient-parser/blob/main/food_web/index.html"
    click food_web "https://github.com/nickysemenza/ingredient-parser/tree/main/food_web/assets/"
    click food_web "https://github.com/nickysemenza/ingredient-parser/blob/main/food_web/Cargo.toml"

    %% Click Events - demo-site
    click demo_site "https://github.com/nickysemenza/ingredient-parser/blob/main/demo-site/src/main.tsx"
    click demo_site "https://github.com/nickysemenza/ingredient-parser/blob/main/demo-site/src/wasmContext.tsx"
    click demo_site "https://github.com/nickysemenza/ingredient-parser/blob/main/demo-site/src/App.tsx"
    click demo_site "https://github.com/nickysemenza/ingredient-parser/blob/main/demo-site/src/Demo.tsx"
    click demo_site "https://github.com/nickysemenza/ingredient-parser/blob/main/demo-site/package.json"
    click demo_site "https://github.com/nickysemenza/ingredient-parser/blob/main/demo-site/vite.config.ts"

    %% Styles
    classDef core fill:#B3E5FC,stroke:#0288D1,stroke-width:2px
    classDef bridge fill:#C5E1A5,stroke:#558B2F,stroke-width:2px
    classDef app fill:#AED581,stroke:#33691E,stroke-width:2px
    classDef external fill:#EEEEEE,stroke:#666666,stroke-width:1px,stroke-dasharray: 2 2
```
