# godwinlouie2508/shopai architecture

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

- Interactive diagram: https://gitdiagram.com/godwinlouie2508/shopai
- Repository: https://github.com/godwinlouie2508/shopai

## Overview

ShopAI is a Streamlit shopping assistant: users provide a list by chatting or uploading an image, refine and confirm the extracted items, then search and filter retailer products, choose picks, and review a cart total. The main app coordinates session state, OCR, AI parsing, product search, and result presentation. Product search also includes relevance filtering, sorting, retailer-link lookup, and a “Why?” explanation action. The excerpts show the principal calls; the explanation implementation and parts of shopping search are unsampled, so those internal details are represented at module level.

Main entry points: [`ShopAI.py`](https://github.com/godwinlouie2508/shopai/blob/main/ShopAI.py) (Streamlit app flow), [`modules/shopping.py`](https://github.com/godwinlouie2508/shopai/blob/main/modules/shopping.py) (Product search and ranking), [`modules/ui.py`](https://github.com/godwinlouie2508/shopai/blob/main/modules/ui.py) (Page and cart UI), [`modules/utils.py`](https://github.com/godwinlouie2508/shopai/blob/main/modules/utils.py) (Image OCR)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["App experience"]
  node_app["Streamlit app flow<br/>[ShopAI.py]"]
  node_ui["Page and cart UI<br/>[ui.py]"]
  node_state["Session state<br/>[state.py]"]
end

subgraph group_intake["List intake"]
  node_image_ocr["Image OCR<br/>[utils.py]"]
  node_ai_parsing["AI list parsing<br/>[ShopAI.py]"]
end

subgraph group_discovery["Product discovery"]
  node_product_search["Product search and ranking<br/>[shopping.py]"]
  node_retailer_links["Retailer link lookup<br/>[shopping.py]"]
  node_why_explanation["Pick explanation<br/>[shopping.py]"]
end

subgraph group_services["External services"]
  node_azure_vision["Azure Vision"]
  node_openai["OpenAI"]
  node_serpapi["SerpAPI"]
end

node_user(("Shopper"))

node_user -->|"provides list"| node_app
node_app -->|"sets up"| node_ui
node_app -->|"initializes and resets"| node_state
node_app -->|"submits image"| node_image_ocr
node_image_ocr -->|"requests OCR"| node_azure_vision
node_app -->|"parses list"| node_ai_parsing
node_ai_parsing -->|"requests extraction"| node_openai
node_app -->|"requests product results"| node_product_search
node_product_search -->|"searches products"| node_serpapi
node_app -->|"gets purchase link"| node_retailer_links
node_retailer_links -->|"requests seller offers"| node_serpapi
node_app -->|"requests explanation"| node_why_explanation
node_app -->|"displays cart"| node_ui
node_ui -->|"reads selections"| node_state
node_product_search -.->|"validates retailer"| node_retailer_links
node_app -->|"presents picks"| node_user

click node_app "https://github.com/godwinlouie2508/shopai/blob/main/ShopAI.py"
click node_ui "https://github.com/godwinlouie2508/shopai/blob/main/modules/ui.py"
click node_state "https://github.com/godwinlouie2508/shopai/blob/main/modules/state.py"
click node_image_ocr "https://github.com/godwinlouie2508/shopai/blob/main/modules/utils.py"
click node_ai_parsing "https://github.com/godwinlouie2508/shopai/blob/main/ShopAI.py"
click node_product_search "https://github.com/godwinlouie2508/shopai/blob/main/modules/shopping.py"
click node_retailer_links "https://github.com/godwinlouie2508/shopai/blob/main/modules/shopping.py"
click node_why_explanation "https://github.com/godwinlouie2508/shopai/blob/main/modules/shopping.py"

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_app,node_ui,node_state toneBlue
class node_image_ocr,node_ai_parsing toneAmber
class node_product_search,node_retailer_links,node_why_explanation toneMint
class node_azure_vision,node_openai,node_serpapi toneRose
class node_user toneIndigo
```

## Components

### App experience

- [Streamlit app flow](https://github.com/godwinlouie2508/shopai/blob/main/ShopAI.py): `ShopAI.py`
- [Page and cart UI](https://github.com/godwinlouie2508/shopai/blob/main/modules/ui.py): `modules/ui.py`
- [Session state](https://github.com/godwinlouie2508/shopai/blob/main/modules/state.py): `modules/state.py`

### List intake

- [Image OCR](https://github.com/godwinlouie2508/shopai/blob/main/modules/utils.py): `modules/utils.py`
- [AI list parsing](https://github.com/godwinlouie2508/shopai/blob/main/ShopAI.py): `ShopAI.py`

### Product discovery

- [Product search and ranking](https://github.com/godwinlouie2508/shopai/blob/main/modules/shopping.py): `modules/shopping.py`
- [Retailer link lookup](https://github.com/godwinlouie2508/shopai/blob/main/modules/shopping.py): `modules/shopping.py`
- [Pick explanation](https://github.com/godwinlouie2508/shopai/blob/main/modules/shopping.py): `modules/shopping.py`

### External services

- **Azure Vision**
- **OpenAI**
- **SerpAPI**

### Other components

- **Shopper**

## Connections

- Shopper → Streamlit app flow: provides list (evidence: `ShopAI.py`)
- Streamlit app flow → Page and cart UI: sets up (evidence: `ShopAI.py`)
- Streamlit app flow → Session state: initializes and resets (evidence: `ShopAI.py`)
- Streamlit app flow → Image OCR: submits image (evidence: `ShopAI.py`)
- Image OCR → Azure Vision: requests OCR (evidence: `modules/utils.py`)
- Streamlit app flow → AI list parsing: parses list (evidence: `ShopAI.py`)
- AI list parsing → OpenAI: requests extraction (evidence: `ShopAI.py`)
- Streamlit app flow → Product search and ranking: requests product results (evidence: `ShopAI.py`)
- Product search and ranking → SerpAPI: searches products (evidence: `modules/shopping.py`)
- Streamlit app flow → Retailer link lookup: gets purchase link (evidence: `ShopAI.py`)
- Retailer link lookup → SerpAPI: requests seller offers (evidence: `modules/shopping.py`)
- Streamlit app flow → Pick explanation: requests explanation (evidence: `ShopAI.py`)
- Streamlit app flow → Page and cart UI: displays cart (evidence: `ShopAI.py`)
- Page and cart UI → Session state: reads selections (evidence: `modules/ui.py`)
- Product search and ranking → Retailer link lookup: validates retailer (evidence: `modules/shopping.py`)
- Streamlit app flow → Shopper: presents picks (evidence: `ShopAI.py`)
