Skip to content

How we built mehandibysana.com: moving a henna store from WooCommerce to Medusa and Next.js

The headless stack behind Mehandi By Sana, and the problems we had to solve on the way: migrating years of orders, PIN-code delivery rules, Razorpay webhooks, and servers that forget their files.

By StackNothing7 min read

How we built mehandibysana.com: moving a henna store from WooCommerce to Medusa and Next.js: article title on a blue background

Mehandi By Sana is an organic, PPD-free henna studio and online store, founded in 2019. It sells henna cones and powder, takes bridal and event bookings, and ships across India from two studios, one in Srinagar and one in Bengaluru.

The store ran on WooCommerce. In November 2026 we moved it to a headless setup: a Next.js storefront in front of a MedusaJS commerce backend. This is the stack we chose and the problems we hit.

The stack

PartWhat we useWhere it runs
StorefrontNext.js 16 (App Router), React 19, TypeScript, Tailwind CSS 4, ZustandVercel
Commerce backendMedusaJS v2, with its admin dashboardRailway
DatabasePostgreSQLRailway
Queue, locks and cacheRedisRailway
Images and invoicesCloudflare R2, served from media.mehandibysana.comCloudflare
PaymentsRazorpay (UPI, cards, net banking), plus cash on delivery
EmailResend, Brevo or plain SMTP, chosen in settings
Studio alertsA Telegram bot
InvoicesPDFKit, generating numbered PDF invoices

The storefront pulls products from Medusa's Store API and renders them with incremental static regeneration. Product pages are rebuilt at most once an hour, and immediately when something calls the revalidation endpoint, so a shopper gets a static page without waiting for the backend.

The shopping bag lives in a Zustand store persisted to the browser, so adding an item updates the bag icon at once and survives a refresh.

Challenge 1: moving years of orders without losing any

The store had a long history in WooCommerce: products, customers and orders going back years. Starting with an empty database wasn't an option. Customers expect to see their old orders, and the studio needs them too.

We built two import routes that end in the same place:

  1. From a WooCommerce SQL dump. A script parses the dump into a clean intermediate format, then Medusa scripts sync products, customers and orders into Postgres.
  2. From the live WooCommerce REST API. This is useful for pulling in anything that changed after the dump was taken.

Both are written to be run more than once. Re-running an import updates records instead of duplicating them, so a later sync can top up anything that changed since the first import.

SEO was the other half of the move. The main henna cone product already appeared on Google Shopping, so its URL had to survive exactly: it's still /product/organic-henna-cones, and every product page carries full schema.org Product data.

Challenge 2: delivery rules by PIN code

Delivery in India depends heavily on where the parcel is going, and the rules here are specific to this business:

  • Srinagar pickup. Free studio pickup is offered for Kashmir PIN codes (19xxxx), but not for Jammu (18xxxx), even though both are in the same union territory.
  • Bengaluru pickup. Free studio pickup is offered for Bengaluru PIN codes (56xxxx).
  • Cash on delivery is currently offered only for Srinagar PIN codes (190*).
  • Everywhere else gets doorstep delivery with prepaid payment.

Rules are written as patterns: an exact PIN code like 190001, a prefix like 190*, or * for the rest of India. When a PIN matches more than one rule, the most specific one wins:

function getSinglePatternSpecificity(token: string): number {
  if (!token || token === "*") return 0;              // catch-all
  if (!token.endsWith("*")) return 1000 + token.length; // exact PIN code
  const prefix = token.slice(0, -1);
  return prefix.length * 100;                          // longer prefix wins
}

The checkout calls the backend with the PIN code as soon as it's entered. The answer decides the delivery charge and estimated days, whether studio pickup appears, and whether the cash-on-delivery option is shown. When COD isn't available, the option is hidden and a short notice explains why. The studio can edit the rules in the Medusa admin without a deploy.

Challenge 3: payments you can trust

Razorpay handles the payment, but the store has to be sure a payment is genuine before it creates an order. The flow:

  1. The storefront asks its own Next.js API route to create a Razorpay order. That route adds the Medusa publishable key on the server, so the key isn't exposed to the browser.
  2. After payment, Medusa verifies Razorpay's signature with HMAC-SHA256, compares it with crypto.timingSafeEqual, and only then creates the order. Prices are re-checked on the server, so a tampered cart can't change what's charged.
  3. Razorpay also sends webhooks (payment.captured, order.paid, payment.failed) to the backend as a second confirmation.

The webhook had a subtle trap. Razorpay signs the exact bytes of the request body. A framework that parses the JSON and re-serialises it can change those bytes, and then every signature check fails. The fix was to keep the raw body for that route (preserveRawBody: true in Medusa's middleware) and verify against it:

// simplified from the webhook route
const expected = crypto
  .createHmac("sha256", webhookSecret)
  .update(rawBody)
  .digest("hex");
 
if (
  Buffer.byteLength(expected) !== Buffer.byteLength(signature) ||
  !crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(signature))
) {
  return res.status(401).json({ received: false });
}

Challenge 4: why we added Redis

Medusa runs without Redis, but it warns you on start-up: it falls back to a fake Redis instance, an in-memory event bus and in-memory locks. That's fine on a laptop and risky in production, for two reasons:

  • Lost background work. Order confirmation emails, PDF invoices and Telegram alerts run as background jobs after an order is placed. In memory, any job still queued when the server restarts or redeploys is simply gone. With Redis as the event bus, queued jobs survive a restart.
  • Duplicate orders. Razorpay can deliver the same webhook more than once, and two shoppers can try to buy the last cone at the same moment. In-memory locks only protect a single process. Redis locks work across processes, so only one of the competing requests changes stock or creates the order.

Challenge 5: servers that forget their files

Early on, some store settings lived in JSON files on the server's disk: studio pickup addresses and hours, the PIN-code rules, bridal booking requests and newsletter sign-ups. Railway runs the backend in containers, and a fresh container starts with a fresh disk, so a redeploy could quietly reset the studio's settings.

All of that now lives in its own PostgreSQL tables, with the JSON files kept only as a fallback for local development. Anything that must stay on disk goes on a persistent Railway volume.

Challenge 6: a monorepo that deployed too much

The frontend and backend live in one repository. Vercel builds the storefront, and Railway builds the backend from the backend folder. But setting a root directory on Railway only decides what gets built, not what triggers a build, so every frontend-only change was redeploying the backend too.

The fix was a single Railway setting: a watch path of /backend/**. Railway resolves watch paths from the repository root even when the service has a root directory, so it's /backend/**, not /**. Frontend changes now skip the backend entirely.

Running the studio day to day

The site isn't only a shop. It's also how the studio runs its orders:

  • Telegram alerts. Every new order and booking arrives on Telegram, with the customer's details, the items, the payment status, and whether it's for pickup or delivery.
  • Dispatch from the order page. A custom widget inside the Medusa admin lets the studio choose which studio is dispatching, set the courier and tracking number, and move the order through preparing, dispatched and delivered. Each step emails the customer.
  • Invoices and checks. Every order gets a numbered PDF invoice by email. Both apps have health-check endpoints, and storefront errors go to Sentry.

What's next

The roadmap is about turning the store into a platform for both everyday customers and professional henna artists:

  • Search. Typo-tolerant product search built on Postgres.
  • Reviews with photos. Customers can show how their stain developed.
  • Couriers and WhatsApp. Shipping through courier APIs and order updates on WhatsApp.

Sources

Docs & Tooling

Welcome to the StackNothing blog

What this blog covers, who it's for, and how each article is put together: deep dives into languages and frameworks, case studies and performance write-ups.

By StackNothing 2 min read