# zmomz/1688 architecture

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

- Interactive diagram: https://gitdiagram.com/zmomz/1688
- Repository: https://github.com/zmomz/1688

## Overview

This repository is a 1688 product-search scraper with both a command-line workflow and a chat-based web interface. Users submit product requests; the web app can translate them into search terms with Ollama, then searches 1688 through a logged-in Chrome session, optionally enriches products from detail pages, and saves results as JSON or CSV. The CLI exposes search, optional detail scraping, login, and export. Edges reflect excerpted calls or README-equivalent source-index references; unsampled behavior is not inferred.

Main entry points: [`app.py`](https://github.com/zmomz/1688/blob/main/app.py) (Web workflow), [`main.py`](https://github.com/zmomz/1688/blob/main/main.py) (CLI workflow), [`scraper_search.py`](https://github.com/zmomz/1688/blob/main/scraper_search.py) (Search scraping), [`scraper_detail.py`](https://github.com/zmomz/1688/blob/main/scraper_detail.py) (Detail enrichment)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interfaces["User interfaces"]
  node_chat_ui["Chat interface<br/>[chat.js]"]
  node_web_page["Search page<br/>[index.html]"]
end

subgraph group_orchestration["Workflow orchestration"]
  node_web_app["Web workflow<br/>[app.py]"]
  node_cli["CLI workflow<br/>[main.py]"]
end

subgraph group_browser["Browser and scraping"]
  node_session_manager["Browser session<br/>[session_manager.py]"]
  node_auth["Chrome login and CDP<br/>[auth.py]"]
  node_search_scraper["Search scraping<br/>[scraper_search.py]"]
  node_detail_scraper["Detail enrichment<br/>[scraper_detail.py]"]
end

subgraph group_product_data["Product data and export"]
  node_product_model["Product model<br/>[models.py]"]
  node_export["JSON and CSV export<br/>[storage.py]"]
end

subgraph group_language["Language assistance"]
  node_ollama_client["Request translation<br/>[ollama_client.py]"]
end

node_user(("User"))
node_ollama_service(("Ollama"))
node_chrome(("Chrome browser"))
node_marketplace(("1688 marketplace"))

node_user -->|"submits request"| node_chat_ui
node_chat_ui -->|"sends WebSocket"| node_web_app
node_web_app -->|"renders page"| node_web_page
node_web_app -->|"translates request"| node_ollama_client
node_ollama_client -->|"calls API"| node_ollama_service
node_web_app -->|"acquires session"| node_session_manager
node_session_manager -->|"connects to Chrome"| node_auth
node_auth -->|"connects via CDP"| node_chrome
node_web_app -->|"scrapes terms"| node_search_scraper
node_cli -->|"logs in or connects"| node_auth
node_cli -->|"scrapes keyword"| node_search_scraper
node_search_scraper -->|"reads search results"| node_marketplace
node_cli -->|"requests enrichment"| node_detail_scraper
node_detail_scraper -->|"reads product details"| node_marketplace
node_search_scraper -->|"creates products"| node_product_model
node_detail_scraper -->|"enriches products"| node_product_model
node_web_app -->|"saves results"| node_export
node_cli -->|"saves results"| node_export
node_export -->|"serializes products"| node_product_model

click node_chat_ui "https://github.com/zmomz/1688/blob/main/static/chat.js"
click node_web_page "https://github.com/zmomz/1688/blob/main/templates/index.html"
click node_web_app "https://github.com/zmomz/1688/blob/main/app.py"
click node_cli "https://github.com/zmomz/1688/blob/main/main.py"
click node_ollama_client "https://github.com/zmomz/1688/blob/main/ollama_client.py"
click node_session_manager "https://github.com/zmomz/1688/blob/main/session_manager.py"
click node_auth "https://github.com/zmomz/1688/blob/main/auth.py"
click node_search_scraper "https://github.com/zmomz/1688/blob/main/scraper_search.py"
click node_detail_scraper "https://github.com/zmomz/1688/blob/main/scraper_detail.py"
click node_product_model "https://github.com/zmomz/1688/blob/main/models.py"
click node_export "https://github.com/zmomz/1688/blob/main/storage.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_chat_ui,node_web_page,node_user,node_chrome toneBlue
class node_web_app,node_cli toneAmber
class node_session_manager,node_auth,node_search_scraper,node_detail_scraper toneMint
class node_product_model,node_export toneRose
class node_ollama_client,node_ollama_service,node_marketplace toneIndigo
```

## Components

### User interfaces

- [Chat interface](https://github.com/zmomz/1688/blob/main/static/chat.js): `static/chat.js`
- [Search page](https://github.com/zmomz/1688/blob/main/templates/index.html): `templates/index.html`

### Workflow orchestration

- [Web workflow](https://github.com/zmomz/1688/blob/main/app.py): `app.py`
- [CLI workflow](https://github.com/zmomz/1688/blob/main/main.py): `main.py`

### Browser and scraping

- [Browser session](https://github.com/zmomz/1688/blob/main/session_manager.py): `session_manager.py`
- [Chrome login and CDP](https://github.com/zmomz/1688/blob/main/auth.py): `auth.py`
- [Search scraping](https://github.com/zmomz/1688/blob/main/scraper_search.py): `scraper_search.py`
- [Detail enrichment](https://github.com/zmomz/1688/blob/main/scraper_detail.py): `scraper_detail.py`

### Product data and export

- [Product model](https://github.com/zmomz/1688/blob/main/models.py): `models.py`
- [JSON and CSV export](https://github.com/zmomz/1688/blob/main/storage.py): `storage.py`

### Language assistance

- [Request translation](https://github.com/zmomz/1688/blob/main/ollama_client.py): `ollama_client.py`

### Other components

- **User**
- **Ollama**
- **Chrome browser**
- **1688 marketplace**

## Connections

- User → Chat interface: submits request (evidence: `static/chat.js`)
- Chat interface → Web workflow: sends WebSocket (evidence: `static/chat.js`)
- Web workflow → Search page: renders page (evidence: `app.py`)
- Web workflow → Request translation: translates request (evidence: `app.py`)
- Request translation → Ollama: calls API (evidence: `ollama_client.py`)
- Web workflow → Browser session: acquires session (evidence: `app.py`)
- Browser session → Chrome login and CDP: connects to Chrome (evidence: `session_manager.py`)
- Chrome login and CDP → Chrome browser: connects via CDP (evidence: `auth.py`)
- Web workflow → Search scraping: scrapes terms (evidence: `app.py`)
- CLI workflow → Chrome login and CDP: logs in or connects (evidence: `main.py`)
- CLI workflow → Search scraping: scrapes keyword (evidence: `main.py`)
- Search scraping → 1688 marketplace: reads search results (evidence: `scraper_search.py`)
- CLI workflow → Detail enrichment: requests enrichment (evidence: `main.py`)
- Detail enrichment → 1688 marketplace: reads product details (evidence: `scraper_detail.py`)
- Search scraping → Product model: creates products (evidence: `scraper_search.py`)
- Detail enrichment → Product model: enriches products (evidence: `scraper_detail.py`)
- Web workflow → JSON and CSV export: saves results (evidence: `app.py`)
- CLI workflow → JSON and CSV export: saves results (evidence: `main.py`)
- JSON and CSV export → Product model: serializes products (evidence: `storage.py`)
