# fotopaulooficial/gmc-prices architecture

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

- Interactive diagram: https://gitdiagram.com/fotopaulooficial/gmc-prices
- Repository: https://github.com/fotopaulooficial/gmc-prices

## Overview

Preços x Mercado retrieves Google Merchant benchmark data and presents it for filtering, comparison, and selection. The user sets a discount and reviews an approval summary; selected products are converted into Tray product lines and exported as CSV or XLSX. The server-side export path re-fetches selected rows from Merchant data rather than trusting browser-supplied prices. The README also documents optional Basic Auth and the Tray import template. UI-to-XLSX routing is documented as a capability, but the sampled UI excerpt does not show that request, so the edge is marked unverified.

Main entry points: [`lib/tray.ts`](https://github.com/fotopaulooficial/gmc-prices/blob/main/lib/tray.ts) (Tray line conversion), [`app/precos-app.tsx`](https://github.com/fotopaulooficial/gmc-prices/blob/main/app/precos-app.tsx) (Filter and approval UI), [`app/page.tsx`](https://github.com/fotopaulooficial/gmc-prices/blob/main/app/page.tsx) (Catalog page), [`lib/tray-export.ts`](https://github.com/fotopaulooficial/gmc-prices/blob/main/lib/tray-export.ts) (Validate export selection)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_presentation["Catalog interface"]
  node_page["Catalog page<br/>[page.tsx]"]
  node_catalog_ui["Filter and approval UI<br/>[precos-app.tsx]"]
  node_layout["Page layout<br/>[layout.tsx]"]
end

subgraph group_merchant["Market data"]
  node_merchant_data["Price report and cache<br/>[merchant.ts]"]
end

subgraph group_tray["Tray export"]
  node_selection_loader["Validate export selection<br/>[tray-export.ts]"]
  node_tray_lines["Tray line conversion<br/>[tray.ts]"]
  node_csv_api["CSV export endpoint<br/>[route.ts]"]
  node_xlsx_api["XLSX export endpoint<br/>[route.ts]"]
  node_xlsx_builder["XLSX builder<br/>[tray-xlsx.ts]"]
  node_template["Tray import template<br/>[modelo.xlsx]"]
end

subgraph group_access["Access control"]
  node_auth_middleware["Optional Basic Auth<br/>[middleware.ts]"]
end

node_shopper(("Catalog user"))
node_merchant_api{{"Google Merchant API"}}
node_tray_import{{"Tray importer"}}

node_shopper -->|"opens catalog"| node_page
node_page -->|"loads prices"| node_merchant_data
node_page -->|"renders"| node_catalog_ui
node_merchant_data -->|"queries report"| node_merchant_api
node_catalog_ui -->|"builds selection lines"| node_tray_lines
node_catalog_ui -.->|"requests CSV"| node_csv_api
node_catalog_ui -.->|"requests XLSX"| node_xlsx_api
node_csv_api -->|"loads selection"| node_selection_loader
node_xlsx_api -->|"loads selection"| node_selection_loader
node_selection_loader -->|"reloads rows"| node_merchant_data
node_selection_loader -->|"builds export lines"| node_tray_lines
node_csv_api -->|"formats CSV"| node_tray_lines
node_xlsx_api -->|"builds workbook"| node_xlsx_builder
node_xlsx_builder -->|"formats lines"| node_tray_lines
node_tray_lines -->|"matches columns"| node_template
node_shopper -->|"sends credentials"| node_auth_middleware
node_layout -->|"wraps page"| node_page
node_shopper -->|"imports export"| node_tray_import

click node_page "https://github.com/fotopaulooficial/gmc-prices/blob/main/app/page.tsx"
click node_catalog_ui "https://github.com/fotopaulooficial/gmc-prices/blob/main/app/precos-app.tsx"
click node_layout "https://github.com/fotopaulooficial/gmc-prices/blob/main/app/layout.tsx"
click node_merchant_data "https://github.com/fotopaulooficial/gmc-prices/blob/main/lib/merchant.ts"
click node_selection_loader "https://github.com/fotopaulooficial/gmc-prices/blob/main/lib/tray-export.ts"
click node_tray_lines "https://github.com/fotopaulooficial/gmc-prices/blob/main/lib/tray.ts"
click node_csv_api "https://github.com/fotopaulooficial/gmc-prices/blob/main/app/api/precos.csv/route.ts"
click node_xlsx_api "https://github.com/fotopaulooficial/gmc-prices/blob/main/app/api/precos.xlsx/route.ts"
click node_xlsx_builder "https://github.com/fotopaulooficial/gmc-prices/blob/main/lib/tray-xlsx.ts"
click node_template "https://github.com/fotopaulooficial/gmc-prices/blob/main/app/csv-template/modelo.xlsx"
click node_auth_middleware "https://github.com/fotopaulooficial/gmc-prices/blob/main/middleware.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_catalog_ui,node_layout,node_shopper toneBlue
class node_merchant_data toneAmber
class node_selection_loader,node_tray_lines,node_csv_api,node_xlsx_api,node_xlsx_builder,node_template,node_merchant_api toneMint
class node_auth_middleware toneRose
class node_tray_import toneIndigo
```

## Components

### Catalog interface

- [Catalog page](https://github.com/fotopaulooficial/gmc-prices/blob/main/app/page.tsx): `app/page.tsx`
- [Filter and approval UI](https://github.com/fotopaulooficial/gmc-prices/blob/main/app/precos-app.tsx): `app/precos-app.tsx`
- [Page layout](https://github.com/fotopaulooficial/gmc-prices/blob/main/app/layout.tsx): `app/layout.tsx`

### Market data

- [Price report and cache](https://github.com/fotopaulooficial/gmc-prices/blob/main/lib/merchant.ts): `lib/merchant.ts`

### Tray export

- [Validate export selection](https://github.com/fotopaulooficial/gmc-prices/blob/main/lib/tray-export.ts): `lib/tray-export.ts`
- [Tray line conversion](https://github.com/fotopaulooficial/gmc-prices/blob/main/lib/tray.ts): `lib/tray.ts`
- [CSV export endpoint](https://github.com/fotopaulooficial/gmc-prices/blob/main/app/api/precos.csv/route.ts): `app/api/precos.csv/route.ts`
- [XLSX export endpoint](https://github.com/fotopaulooficial/gmc-prices/blob/main/app/api/precos.xlsx/route.ts): `app/api/precos.xlsx/route.ts`
- [XLSX builder](https://github.com/fotopaulooficial/gmc-prices/blob/main/lib/tray-xlsx.ts): `lib/tray-xlsx.ts`
- [Tray import template](https://github.com/fotopaulooficial/gmc-prices/blob/main/app/csv-template/modelo.xlsx): `app/csv-template/modelo.xlsx`

### Access control

- [Optional Basic Auth](https://github.com/fotopaulooficial/gmc-prices/blob/main/middleware.ts): `middleware.ts`

### Other components

- **Catalog user**
- **Google Merchant API**
- **Tray importer**

## Connections

- Catalog user → Catalog page: opens catalog (evidence: `app/page.tsx`)
- Catalog page → Price report and cache: loads prices (evidence: `app/page.tsx`)
- Catalog page → Filter and approval UI: renders (evidence: `app/page.tsx`)
- Price report and cache → Google Merchant API: queries report (evidence: `lib/merchant.ts`)
- Filter and approval UI → Tray line conversion: builds selection lines (evidence: `app/precos-app.tsx`)
- Filter and approval UI → CSV export endpoint: requests CSV
- Filter and approval UI → XLSX export endpoint: requests XLSX
- CSV export endpoint → Validate export selection: loads selection (evidence: `app/api/precos.csv/route.ts`)
- XLSX export endpoint → Validate export selection: loads selection (evidence: `app/api/precos.xlsx/route.ts`)
- Validate export selection → Price report and cache: reloads rows (evidence: `lib/tray-export.ts`)
- Validate export selection → Tray line conversion: builds export lines (evidence: `lib/tray-export.ts`)
- CSV export endpoint → Tray line conversion: formats CSV (evidence: `app/api/precos.csv/route.ts`)
- XLSX export endpoint → XLSX builder: builds workbook (evidence: `app/api/precos.xlsx/route.ts`)
- XLSX builder → Tray line conversion: formats lines (evidence: `lib/tray-xlsx.ts`)
- Tray line conversion → Tray import template: matches columns (evidence: `lib/tray.ts`)
- Catalog user → Optional Basic Auth: sends credentials (evidence: `middleware.ts`)
- Page layout → Catalog page: wraps page (evidence: `app/layout.tsx`)
- Catalog user → Tray importer: imports export (evidence: `README.md`)
