All case studies

Marhaba SweetsClient Work4 min read

Taking a traditional sweets shop online: a Next.js store with made-to-order stock, safe checkout and WhatsApp order alerts

An online store for a family sweets and bakery shop: real products, made-to-order limits, Safepay and cash on delivery, and order alerts the shop can't miss.

Role
Full-stack developer
Timeline
May 2026 – ongoing
Stack
Next.jsReactPostgreSQLPrismaTailwind CSSSafepay
Marhaba Sweets home page: mithai and cake rusk from Railbazar Chowk, Jhang
2 ways
To pay: Safepay or cash on delivery
3 channels
New-order alerts: email, admin, WhatsApp
24/7
Ordering, beyond shop hours

Context

Marhaba Sweets & Bakers is a family sweets and bakery shop at Railbazar Chowk, Jhang, Punjab, making mithai and cake rusk since 1960. Like most traditional mithai shops, it sold over the counter and by phone: customers called or sent a WhatsApp message, and the shop wrote orders down by hand.

The goal was a proper online store that fits how a sweets shop actually works: many products are made fresh each day rather than kept in stock, gift boxes matter around Eid and weddings, and plenty of customers still prefer to pay cash when the order arrives.

The problem

A busy sweets shop needed to take orders online without overselling fresh, made-to-order products, losing orders in a chat thread, or charging customers a different price than they saw.

Constraints

  • Most sweets are made to order each day, so ordinary stock counts don't fit.
  • Customers pay both online (Safepay) and in cash on delivery, and both must follow the same order flow.
  • Shop staff aren't technical: new orders have to reach them by email, in the admin panel and on WhatsApp.
  • Mobile-first: most customers browse and order from a phone.
  • Customer accounts and payments had to be secure from day one.

Architecture

01 · Storefront

  • Products + gift boxes
  • Cart (Zustand)
  • Checkout
  • Price list

02 · Next.js API

  • Auth (HTTP-only cookies)
  • Orders + workflow
  • Stock + daily limits
  • Coupons

03 · Data

  • PostgreSQL
  • Prisma
  • Cloudinary images

04 · Shop + payments

  • Admin panel
  • Email + WhatsApp alerts
  • Safepay
  • Cash on delivery
One Next.js app serves the store, the admin panel and the API; Prisma talks to PostgreSQL, images live on Cloudinary and payments go through Safepay.

The approach

  1. 01

    Model the shop as it really works

    Products can have counted stock or be made to order with a per-day limit, come in sizes, and be grouped into gift boxes. The catalogue holds the shop's real products only, and the homepage sections are managed from the admin.

  2. 02

    A checkout that can't go wrong quietly

    Delivery pricing is shared by the cart, checkout and order API, every order carries an idempotency key so a double tap can't create two, and new orders wait as pending until the shop confirms them.

  3. 03

    Make sure the shop sees every order

    New orders trigger an email, an alert in the admin panel and an optional WhatsApp message, with a button to send a test order email so the shop can check alerts are working.

  4. 04

    Local SEO from the start

    Titles and pages are written for people searching for sweets in Jhang, with a public price list page, a sitemap, and the shop's real Google rating instead of made-up review numbers.

Deep dives

Stock for sweets that are made fresh every day

A box of gulab jamun isn't sitting on a shelf; it's made that morning, and the kitchen can only make so many. So each product either has a counted stock that goes down with each order, or is made to order with an optional daily limit.

The day runs midnight to midnight Pakistan time, and cancelled orders don't count toward the limit. When a customer asks for more than is available, they get a clear reason: sold out for today, or only a few left.

js
const PK_OFFSET_MS = 5 * 60 * 60 * 1000 // Pakistan time, no DST

export function startOfShopDay(now = new Date()) {
  const pk = new Date(now.getTime() + PK_OFFSET_MS)
  pk.setUTCHours(0, 0, 0, 0)
  return new Date(pk.getTime() - PK_OFFSET_MS)
}

export async function limitsFor(db, product) {
  const stockLeft = product.madeToOrder ? Infinity : product.stockQty
  const dailyLeft = product.dailyLimit == null
    ? Infinity
    : Math.max(0, product.dailyLimit - (await orderedToday(db, product.id)))
  return { stockLeft, dailyLeft, left: Math.min(stockLeft, dailyLeft) }
}
From lib/stock.js: counted stock and today's remaining allowance, whichever is lower.

An order workflow the shop can trust

Every order moves through a fixed set of steps: pending, awaiting payment for online orders, confirmed, preparing, out for delivery, delivered. Any other jump is rejected, so an order can't skip from pending to delivered by mistake.

Customers can cancel only before the kitchen starts. After that, or for orders already paid online, they contact the shop and the admin cancels, and the panel shows that a refund is due.

js
const VALID_TRANSITIONS = {
  PENDING: ['CONFIRMED', 'CANCELLED', 'AWAITING_PAYMENT'],
  AWAITING_PAYMENT: ['CONFIRMED', 'CANCELLED'],
  CONFIRMED: ['PREPARING', 'CANCELLED'],
  PREPARING: ['OUT_FOR_DELIVERY', 'CANCELLED'],
  OUT_FOR_DELIVERY: ['DELIVERED', 'CANCELLED'],
  DELIVERED: [],
  CANCELLED: [],
}

export const canTransition = (from, to) =>
  (VALID_TRANSITIONS[from] ?? []).includes(to)

// Customers may cancel only before the kitchen starts.
export const canCancel = (status) => ['PENDING', 'CONFIRMED'].includes(status)
From lib/orderWorkflow.js: the allowed status changes.

Hardening checkout and accounts before real orders

Before taking real orders, a dedicated hardening pass fixed the things that hurt a shop most. Sign-in tokens moved out of the browser's local storage into HTTP-only, secure cookies, so a script on the page can't steal them.

Coupons moved from hard-coded logic into the database, and every order now carries an idempotency key. If a customer on a slow connection taps “Place order” twice, the second request returns the first order instead of creating a duplicate. Indexes were added on every column the store filters by.

js
if (idempotencyKey) {
  const existing = await prisma.order.findUnique({
    where: { idempotencyKey },
  })
  if (existing) return NextResponse.json({ order: existing })
}

const order = await prisma.order.create({
  data: { userId, items, deliveryFee, total, idempotencyKey, status: 'PENDING' },
})
Simplified from app/api/orders/route.js: a repeated request returns the existing order.

Key decisions

One Next.js app for store, admin and API
A single deploy is simpler for a small business to run and move between hosts. It already runs on Vercel, Netlify or Docker with no code changes.
Orders wait as pending until the shop confirms
Fresh food depends on the kitchen's day. Letting the shop confirm each order avoids promising what it can't make.
One pricing module shared by cart, checkout and API
The price a customer sees is always the price they're charged: free delivery from Rs 3,000 is decided in one place.
Real facts only
Placeholder claims and invented ratings were replaced with the shop's real details and its actual Google rating. Trust matters more than a nicer number.

Results

Marhaba Sweets now takes orders online around the clock, with stock limits the kitchen can keep, payment by Safepay or cash on delivery, and alerts that make sure no order is missed.

Customers can browse the real menu, check prices and order gift boxes from their phone at any time, instead of calling during shop hours.

The shop sees every new order straight away, confirms it before the kitchen starts, and moves it through preparation and delivery in the admin panel.

Lessons

  • 01Model the business, not a generic store. “Made to order with a daily limit” mattered more than any theme.
  • 02Small shops need alerts they can't miss more than they need dashboards.
  • 03Harden checkout and authentication before launch; fixing them after real orders is far more expensive.

FAQ

Can you build an online store for a bakery or sweets shop?

Yes. I build stores in Next.js that handle made-to-order products, daily limits, gift boxes, online payment and cash on delivery.

Which payment options work in Pakistan?

This store uses Safepay for online card payments plus cash on delivery. Other gateways like PayFast, JazzCash or Easypaisa can be added.

How does the shop find out about new orders?

By email, an alert in the admin panel and an optional WhatsApp message, so orders aren't missed during busy hours.

Have a similar problem?

Book a call and let's talk about your project.

More case studies