# ramawaterfilter/auto-line-item-zero architecture

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

- Interactive diagram: https://gitdiagram.com/ramawaterfilter/auto-line-item-zero
- Repository: https://github.com/ramawaterfilter/auto-line-item-zero

## Overview

Auto Remove Line Item is a multi-store Shopify app for selecting orders in an inclusive date range, previewing eligible orders, and setting configured variant quantities to zero. Its standalone Worker serves the merchant UI and API, then queues discovery and order processing. Processing requires a BEFORE Sheets audit write, commits the Shopify edit, persists the result, and writes AFTER for reconciliation. The graph follows documented capabilities and visible call ownership; D1/Queue wiring and some subsystem details are documented in the README but not fully shown in source excerpts.

Main entry points: [`src/api.ts`](https://github.com/ramawaterfilter/auto-line-item-zero/blob/main/src/api.ts) (Authenticated API), [`src/processor.ts`](https://github.com/ramawaterfilter/auto-line-item-zero/blob/main/src/processor.ts) (Discovery and processing), [`src/index.ts`](https://github.com/ramawaterfilter/auto-line-item-zero/blob/main/src/index.ts) (Worker router), [`src/auth.ts`](https://github.com/ramawaterfilter/auto-line-item-zero/blob/main/src/auth.ts) (OAuth and sessions)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["Merchant experience"]
  node_worker["Worker router<br/>[index.ts]"]
  node_appui["Admin interface<br/>[ui.ts]"]
  node_client["Browser client<br/>[ui-client.ts]"]
  node_styles["UI styles<br/>[ui-styles.ts]"]
  node_api["Authenticated API<br/>[api.ts]"]
end

subgraph group_identity["Identity and safety"]
  node_oauth["OAuth and sessions<br/>[auth.ts]"]
  node_crypto["Token cryptography<br/>[crypto.ts]"]
  node_safety["Audit safety gate<br/>[safety.ts]"]
end

subgraph group_jobs["Job processing"]
  node_core["Date and job rules<br/>[core.ts]"]
  node_processor["Discovery and processing<br/>[processor.ts]"]
  node_queue["Cloudflare Queue"]
  node_d1[("D1 job state")]
end

subgraph group_integrations["External systems"]
  node_shopify["Shopify Admin API<br/>[shopify.ts]"]
  node_sheets["Audit writer<br/>[sheets.ts]"]
  node_google[("Google Sheets")]
end

node_merchant(("Shopify merchant"))

node_merchant -->|"uses app"| node_worker
node_worker -->|"serves pages"| node_appui
node_appui -->|"embeds script"| node_client
node_appui -->|"embeds styles"| node_styles
node_client -->|"calls endpoints"| node_api
node_worker -->|"routes requests"| node_api
node_worker -->|"routes auth"| node_oauth
node_oauth -->|"signs and encrypts"| node_crypto
node_api -->|"authenticates staff"| node_oauth
node_api -->|"validates dates"| node_core
node_api -->|"refreshes jobs"| node_processor
node_api -->|"validates audit sheet"| node_sheets
node_api -->|"stores jobs"| node_d1
node_api -.->|"enqueues work"| node_queue
node_worker -->|"dispatches messages"| node_processor
node_processor -->|"reads and writes state"| node_d1
node_processor -->|"gets access token"| node_oauth
node_processor -->|"discovers and edits"| node_shopify
node_processor -.->|"gates mutations"| node_safety
node_processor -.->|"writes audit rows"| node_sheets
node_sheets -->|"encodes credentials"| node_crypto
node_sheets -->|"writes audit tabs"| node_google
node_shopify -->|"uses error types"| node_core
node_oauth -.->|"exchanges tokens"| node_shopify
node_oauth -.->|"stores installations"| node_d1
node_worker -.->|"removes uninstalled shop"| node_d1

click node_worker "https://github.com/ramawaterfilter/auto-line-item-zero/blob/main/src/index.ts"
click node_appui "https://github.com/ramawaterfilter/auto-line-item-zero/blob/main/src/ui.ts"
click node_client "https://github.com/ramawaterfilter/auto-line-item-zero/blob/main/src/ui-client.ts"
click node_styles "https://github.com/ramawaterfilter/auto-line-item-zero/blob/main/src/ui-styles.ts"
click node_api "https://github.com/ramawaterfilter/auto-line-item-zero/blob/main/src/api.ts"
click node_oauth "https://github.com/ramawaterfilter/auto-line-item-zero/blob/main/src/auth.ts"
click node_crypto "https://github.com/ramawaterfilter/auto-line-item-zero/blob/main/src/crypto.ts"
click node_safety "https://github.com/ramawaterfilter/auto-line-item-zero/blob/main/src/safety.ts"
click node_core "https://github.com/ramawaterfilter/auto-line-item-zero/blob/main/src/core.ts"
click node_processor "https://github.com/ramawaterfilter/auto-line-item-zero/blob/main/src/processor.ts"
click node_shopify "https://github.com/ramawaterfilter/auto-line-item-zero/blob/main/src/shopify.ts"
click node_sheets "https://github.com/ramawaterfilter/auto-line-item-zero/blob/main/src/sheets.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_worker,node_appui,node_client,node_styles,node_api toneBlue
class node_oauth,node_crypto,node_safety toneAmber
class node_core,node_processor,node_queue,node_d1 toneMint
class node_shopify,node_sheets,node_google toneRose
class node_merchant toneIndigo
```

## Components

### Merchant experience

- [Worker router](https://github.com/ramawaterfilter/auto-line-item-zero/blob/main/src/index.ts): `src/index.ts`
- [Admin interface](https://github.com/ramawaterfilter/auto-line-item-zero/blob/main/src/ui.ts): `src/ui.ts`
- [Browser client](https://github.com/ramawaterfilter/auto-line-item-zero/blob/main/src/ui-client.ts): `src/ui-client.ts`
- [UI styles](https://github.com/ramawaterfilter/auto-line-item-zero/blob/main/src/ui-styles.ts): `src/ui-styles.ts`
- [Authenticated API](https://github.com/ramawaterfilter/auto-line-item-zero/blob/main/src/api.ts): `src/api.ts`

### Identity and safety

- [OAuth and sessions](https://github.com/ramawaterfilter/auto-line-item-zero/blob/main/src/auth.ts): `src/auth.ts`
- [Token cryptography](https://github.com/ramawaterfilter/auto-line-item-zero/blob/main/src/crypto.ts): `src/crypto.ts`
- [Audit safety gate](https://github.com/ramawaterfilter/auto-line-item-zero/blob/main/src/safety.ts): `src/safety.ts`

### Job processing

- [Date and job rules](https://github.com/ramawaterfilter/auto-line-item-zero/blob/main/src/core.ts): `src/core.ts`
- [Discovery and processing](https://github.com/ramawaterfilter/auto-line-item-zero/blob/main/src/processor.ts): `src/processor.ts`
- **Cloudflare Queue**
- **D1 job state**

### External systems

- [Shopify Admin API](https://github.com/ramawaterfilter/auto-line-item-zero/blob/main/src/shopify.ts): `src/shopify.ts`
- [Audit writer](https://github.com/ramawaterfilter/auto-line-item-zero/blob/main/src/sheets.ts): `src/sheets.ts`
- **Google Sheets**

### Other components

- **Shopify merchant**

## Connections

- Shopify merchant → Worker router: uses app (evidence: `README.md`)
- Worker router → Admin interface: serves pages (evidence: `src/index.ts`)
- Admin interface → Browser client: embeds script (evidence: `src/ui.ts`)
- Admin interface → UI styles: embeds styles (evidence: `src/ui.ts`)
- Browser client → Authenticated API: calls endpoints (evidence: `README.md`)
- Worker router → Authenticated API: routes requests (evidence: `src/index.ts`)
- Worker router → OAuth and sessions: routes auth (evidence: `src/index.ts`)
- OAuth and sessions → Token cryptography: signs and encrypts (evidence: `src/auth.ts`)
- Authenticated API → OAuth and sessions: authenticates staff (evidence: `src/api.ts`)
- Authenticated API → Date and job rules: validates dates (evidence: `src/api.ts`)
- Authenticated API → Discovery and processing: refreshes jobs (evidence: `src/api.ts`)
- Authenticated API → Audit writer: validates audit sheet (evidence: `src/api.ts`)
- Authenticated API → D1 job state: stores jobs (evidence: `README.md`)
- Authenticated API → Cloudflare Queue: enqueues work (evidence: `README.md`)
- Worker router → Discovery and processing: dispatches messages (evidence: `src/index.ts`)
- Discovery and processing → D1 job state: reads and writes state (evidence: `README.md`)
- Discovery and processing → OAuth and sessions: gets access token (evidence: `src/processor.ts`)
- Discovery and processing → Shopify Admin API: discovers and edits (evidence: `src/processor.ts`)
- Discovery and processing → Audit safety gate: gates mutations (evidence: `src/processor.ts`)
- Discovery and processing → Audit writer: writes audit rows (evidence: `README.md`)
- Audit writer → Token cryptography: encodes credentials (evidence: `src/sheets.ts`)
- Audit writer → Google Sheets: writes audit tabs (evidence: `README.md`)
- Shopify Admin API → Date and job rules: uses error types (evidence: `src/shopify.ts`)
- OAuth and sessions → Shopify Admin API: exchanges tokens (evidence: `README.md`)
- OAuth and sessions → D1 job state: stores installations (evidence: `README.md`)
- Worker router → D1 job state: removes uninstalled shop (evidence: `README.md`)
