TECHNICAL DOCUMENTATION

FreshGuard AI โ€” Developer Docs

Everything you need to know about how FreshGuard AI works under the hood โ€” data storage, webhooks, API, and CSV format.

๐Ÿ—๏ธ

Architecture Overview

FreshGuard AI is a Shopify-embedded app built with React Router v7 and @shopify/shopify-app-react-router. It uses Shopify Metaobjects as its primary datastore, meaning all your batch data lives directly on Shopify's infrastructure โ€” not on a third-party server. This gives you:

  • Zero data loss risk โ€” data is as safe as your Shopify store itself.
  • No sync lag โ€” reads and writes happen directly via Shopify's Admin GraphQL API.
  • GDPR compliance by default โ€” data deletion is handled by Shopify's mandatory privacy webhooks.

Data Flow:

Shopify order โ†’ orders/create webhook โ†’ FreshGuard FEFO engine โ†’ Metaobject update โ†’ Order tag + metafield write

๐Ÿ—‚๏ธ

Metaobject Schema

Each inventory batch is stored as a Shopify Metaobject of type $app:inventory_batch. The schema fields are:

Field KeyTypeDescriptionRequired
batch_numbersingle_line_text_fieldUnique lot/batch identifier (e.g. LOT-2026A)โœ…
expiry_datedateExpiry date in ISO format (YYYY-MM-DD)โœ…
initial_quantitynumber_integerStock quantity when the batch was first createdโœ…
current_quantitynumber_integerCurrent remaining stock (decremented by FEFO)โœ…
batch_statussingle_line_text_fieldActive | Out of stock | Expiredโœ…
location_idsingle_line_text_fieldShopify Location GID for multi-location tracking
barcodesingle_line_text_fieldStandard barcode string
gtinsingle_line_text_fieldGS1 GTIN barcode for industry compliance
invoice_numbersingle_line_text_fieldSupplier invoice or reference number
cost_per_unitnumber_decimalUnit cost for financial analytics and wastage
suppliersingle_line_text_fieldSupplier or vendor name

Batch-to-variant association is stored as a JSON array in a productVariant.metafield(namespace: "$app:inventory", key: "batches_data") field.

๐Ÿ“„

CSV Import / Export Format

Use the bulk CSV feature in the Batches tab โ†’ Import or Analytics โ†’ Export. The file must use these exact column headers:

Column NameFormat / ExampleRequired?
skuSTRING โ€” e.g. APPLE-RED-001โœ… for import
batch_numberSTRING โ€” e.g. LOT-2026Aโœ…
expiry_dateDATE โ€” YYYY-MM-DD (e.g. 2026-09-30)โœ…
initial_quantityINTEGER โ€” e.g. 500โœ…
current_quantityINTEGER โ€” e.g. 320โœ…
batch_statusActive | Out of stock | Expiredโœ…
barcodeSTRING โ€” optional barcode value
gtinSTRING โ€” GS1 GTIN (e.g. 00012345678905)
cost_per_unitDECIMAL โ€” e.g. 2.50
location_idShopify Location GID
invoice_numberSTRING โ€” e.g. INV-2024-0012
supplierSTRING โ€” e.g. FreshFoods Ltd.
๐Ÿ”—

Webhooks & Automation

FreshGuard subscribes to the following Shopify webhooks automatically upon installation:

orders/create

Triggers FEFO engine. Deducts batch quantities, tags the order with the Batch Number, and writes the consumed_batches metafield for traceability.

app/uninstalled

Triggers automatic deletion of all session data and store configuration from FreshGuard's database within 48 hours.

shop/redact (GDPR)

Triggers full erasure of all store data from FreshGuard systems, as required by Shopify's GDPR compliance.

customers/redact (GDPR)

Triggers erasure of any identifiable customer data FreshGuard may hold.

customers/data_request (GDPR)

Provides any customer data FreshGuard holds upon request.

โš™๏ธ

App Proxy API Endpoint

FreshGuard exposes a public JSON endpoint via Shopify's App Proxy at /apps/freshguard/expiry. This endpoint is callable from Liquid themes and JavaScript without authentication.

REQUEST

GET /apps/freshguard/expiry?variant_id={shopify_variant_id}

RESPONSE (200 OK)

{
  "expiry_date": "2026-09-30",
  "batch_number": "LOT-2026A",
  "days_remaining": 113,
  "is_expiring_soon": false
}
๐Ÿ’ณ

Billing & Plan Limits

Free

$0/month

  • Up to 15 tracked product variants
  • 1,000 FEFO order deductions/month
  • Unlimited batches per product
  • Multiple store locations
  • Batch History & Audit Log
  • Recall Report
  • Email notifications
  • CSV Export
  • Email support

Pro

$9.00/month

  • Unlimited tracked products
  • Unlimited order deductions
  • Financial Analytics dashboard
  • Value at Risk & Wastage reporting
  • Automated Discount Sync
  • Expiration Value Forecast
  • Automated Product Tagging
  • Storefront Expiry Display
  • Packing Slip integration
  • Priority support
  • 7-day free trial
๐Ÿ“‹

Batch History & Audit Log

Every batch event is stored as a JSON array in a shop-level metafield at namespace $app:settings, key batch_history. The array is capped at the most recent 500 events to stay within Shopify's metafield size limits.

Each event object contains: { batchNumber, action, quantityChange, orderId, timestamp, note }. Action types: batch_created, batch_deducted, batch_expired, batch_updated.

๐Ÿšจ

Recall Report & Compliance

The Recall Report cross-references the consumed_batches order metafield (written by the FEFO webhook) against all Shopify orders. Given a batch number, it returns a list of orders containing that batch, including: Order ID, Customer Name, Customer Email, Order Date, and Quantity Consumed. The result can be exported as a CSV for food safety and regulatory outreach. This feature requires FEFO order tagging to have been active when orders were placed.

โ† Feature GuidesFAQ โ†’

ยฉ 2026 Sumadroid ยท Privacy Policy ยท sumadroid.com