Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

StockPulse

An embedded Shopify admin app that keeps merchants ahead of stockouts across every sales channel a product is listed on. It reads live inventory through the GraphQL Admin API, listens for inventory_levels/update and products/update webhooks, and raises alerts the moment a variant crosses a merchant-defined low-stock threshold — with a Channel Health signal on each row that goes beyond a flat in-stock/out-of-stock flag.

Built as a portfolio project for a Shopify internship application.

What it does

  • Dashboard — cursor-paginated table of every product variant, its live inventory quantity, an editable low-stock threshold, and a Channel Health badge (Healthy / Watch / Critical / Stale sync) that blends the current stock level, whether it's trending down toward the threshold, and how recently a webhook actually confirmed the number.
  • Alerts — every threshold breach, with quantity/threshold at the time, when it was raised, and whether it's since been resolved (stock rose back above threshold).
  • Sync Log — a running feed of every inventory and product webhook StockPulse has received, so you can watch the automation work end-to-end without needing to trust a black box.

Why "Channel Health" instead of a plain threshold flag

A single quantity-vs-threshold check tells you a product is already in trouble, but not whether the number itself can be trusted or whether it's about to be. computeChannelHealth (in app/lib/inventory-logic.ts) folds in three signals:

Signal What it catches
Threshold breach Quantity at or below the configured threshold → Critical
Sync freshness No inventory webhook observed in 24h → Stale sync (the number on screen might be wrong)
Trend Quantity falling and within 1.5x of threshold, even if not breached yet → Watch

This is the one piece of business logic in the app that's pure and fully unit tested — see app/lib/inventory-logic.test.ts.

Screenshots

Placeholders — swap these for real captures from a dev store install.

Dashboard Alerts Sync Log
Dashboard placeholder Alerts placeholder Sync log placeholder

Architecture

┌─────────────────┐        OAuth install / embedded load        ┌──────────────────┐
│  Shopify Admin   │ ───────────────────────────────────────────▶│  StockPulse       │
│  (merchant)      │◀─────────────────────────────────────────── │  Remix app        │
└─────────────────┘     App Bridge session token on every       └──────────────────┘
                          embedded request                                │
                                                                           │ GraphQL Admin API
                                                                           │ (products, variants,
                                                                           │  inventory quantity)
                                                                           ▼
┌─────────────────┐   inventory_levels/update, products/update   ┌──────────────────┐
│  Shopify         │ ───────────────────────────────────────────▶│  /webhooks/*      │
│  webhook engine  │        (HMAC-verified POST)                 │  route handlers   │
└─────────────────┘                                              └──────────────────┘
                                                                           │
                                                                           ▼
                                                                  ┌──────────────────┐
                                                                  │  Prisma / SQLite  │
                                                                  │  (Postgres in     │
                                                                  │   production)      │
                                                                  │  - Session        │
                                                                  │  - ProductThreshold│
                                                                  │  - StockAlert      │
                                                                  │  - SyncLogEntry    │
                                                                  └──────────────────┘

OAuth flow

  1. Merchant installs from the Shopify App Store (or a dev store install link). Shopify redirects to /auth/login?shop=....
  2. @shopify/shopify-app-remix's authenticate.admin handles the OAuth handshake, exchanges the authorization code for an access token, and stores the resulting session via PrismaSessionStorage (the Session table).
  3. The app is then rendered embedded in Shopify Admin via App Bridge, which attaches a session token to every subsequent request so authenticate.admin(request) can re-verify the merchant on each route load without a full re-auth.

Webhook flow

  1. shopify.app.toml declares subscriptions for inventory_levels/update and products/update pointing at /webhooks/inventory_levels/update and /webhooks/products/update.
  2. Shopify's CLI registers these with the Admin API when you run npm run dev / npm run deploy.
  3. Incoming webhook POSTs are HMAC-verified by authenticate.webhook before any handler code runs.
  4. webhooks.inventory_levels.update.tsx resolves the payload's inventory_item_id to a product/variant via GraphQL, writes a SyncLogEntry, and — if a threshold is configured for that variant and the new quantity breaches it — writes a StockAlert (or resolves an open one if stock has recovered).
  5. webhooks.products.update.tsx keeps cached titles on ProductThreshold rows in sync with renames and logs the event.

Tech stack

Setup

Prerequisites

  • Node.js 20.19+ or 22.12+
  • A Shopify Partners account
  • A development store (create one from the Partners dashboard)
  • Shopify CLI (installed as a dev dependency; invoked via npm run dev)

Install

npm install
npx prisma migrate deploy

Configure

cp .env.example .env

Run shopify app dev once and it will prompt you to log in, create (or select) an app in your Partners org, and it fills in SHOPIFY_API_KEY, SHOPIFY_APP_URL, and updates shopify.app.toml's client_id for you. You generally don't need to hand-edit .env beyond that — it exists so SHOPIFY_API_SECRET and a future DATABASE_URL never get hardcoded into source.

Run locally

npm run dev

The CLI opens a tunnel, prints an install link for your dev store, and hot-reloads on changes. Approve the OAuth scopes on install; the dashboard should load with your dev store's real products.

Run tests

npm test

Production database

Local dev uses SQLite (prisma/schema.prisma, datasource db { provider = "sqlite" }). For production, switch the provider to "postgresql", set DATABASE_URL in your deployment environment, and run npx prisma migrate deploy.

Project structure

app/
  routes/
    app._index.tsx                        # Dashboard: products, inventory, thresholds, Channel Health
    app.alerts.tsx                         # Alerts tab
    app.sync-log.tsx                       # Sync Log tab
    webhooks.inventory_levels.update.tsx   # Threshold check + alert + sync log on stock change
    webhooks.products.update.tsx           # Keeps cached titles in sync, logs the event
  lib/
    inventory-logic.ts                     # Pure threshold + Channel Health logic (unit tested)
    inventory-logic.test.ts
    shopify-queries.server.ts              # Cursor-paginated products GraphQL query
  shopify.server.ts                        # OAuth/session/webhook config
prisma/
  schema.prisma                            # Session, ProductThreshold, StockAlert, SyncLogEntry

License

MIT

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages