~/projects/gastrol $ cat case-study.md
CASE STUDY — 05

Gastrol — Gas Cylinder E-Commerce

An online store for gas cylinders with two distinct storefronts — one for individual customers, one for businesses — built on Next.js, Payload CMS, and a type-safe tRPC API.

Full-Stack Engineer Placeholder period
Next.jsPayload CMSMongoDBtRPC
01 — The Problem

Two audiences, one product, very different rules

Selling gas cylinders online means serving two very different buyers from the same catalog: individuals who want a simple checkout, and companies who order at scale with their own pricing, accounts, and ordering rules.

Placeholder: expand on the business constraints — B2B pricing tiers, account verification, delivery logistics, or local payment requirements.

bash
$ curl /api/trpc/cart.add --data '{"sku":"propane-11kg","qty":4}'
resolving storefront → business
applying contract pricing tier B2
stock reserved: 4 × propane-11kg
cart total recalculated in 12ms
02 — The Approach

One catalog, two storefronts, a type-safe seam

Both storefronts share a single Payload-managed catalog and a tRPC API, so products, stock, and orders live in one place. The retail and business experiences diverge only where they must — pricing, account rules, and checkout flow.

tRPC makes the client/server boundary fully type-safe end to end: the Next.js frontend calls procedures with the same types the backend defines, so a schema change surfaces as a compile error, not a runtime bug.

ts
 1// pricing resolves per storefront, server-side 2export const cart = router({ 3  add: procedure 4    .input(z.object({ sku: z.string(), qty: z.number() })) 5    .mutation(async ({ input, ctx }) => { 6      const price = ctx.storefront === 'business' 7        ? await contractPrice(ctx.account, input.sku) 8        : await retailPrice(input.sku); 9      return ctx.carts.add(ctx.cartId, input, price);10    }),11});
03 — The Architecture

Next.js storefronts over a Payload + Mongo core

Payload CMS manages products, content, and orders on top of MongoDB; a tRPC API exposes catalog, cart, and checkout to both Next.js storefronts. Non-technical staff manage the whole catalog from the Payload admin.

Retail Storefront Business Storefront tRPC API Payload CMS MongoDB
04 — The Results

Two stores, one maintainable codebase

Both customer types order online from a single catalog without the codebase forking in two. Placeholder: add order volume, B2B account count, or conversion numbers.

0
storefronts: retail + business
0
shared catalog & checkout core
0%
end-to-end type-safe (tRPC)