Stop 15 · MERN Projects & Interview PrepProjects · 1/3

E-commerce Store with Razorpay

Part of the MERN Stack Roadmap

In short

An online store is the classic MERN capstone because it touches everything: catalogue, search, cart, auth, payments, orders and an admin panel. Build it well and you can talk about it in every interview.

Build a complete store with product listing, search and filters, a cart, checkout with Razorpay test mode, order history and an admin panel for products and orders.

The jaadu runs a cosy saree shop, folding a bright silk saree into a shopping bag at the counter while colourful shelves line the walls behind.

Think of it like this

Running a small saree shop

Your shop has a display window (catalogue), shelves you can browse by colour and price (filters), a basket (cart), a billing counter with UPI (Razorpay), a bill book (orders) and a back office where you add new stock (admin panel). Each part of the store maps to a part of your app.

Watch it happen

Feature map

Store
Shopper side
Catalogue, search, filters
Cart and checkout
Order history
Admin side
Product CRUD, images
Order status updates

1/5Two kinds of users with different screens and permissions.

The big ideas

What you need to know

Data model

User, Product (price, stock, images, category), Order (items snapshot with price at purchase, total, status, payment ids).

Money on the server

Recalculate totals from database prices, verify Razorpay signatures and handle the payment.captured webhook.

Stock safety

Decrease stock only after payment is confirmed, with a conditional update like stock: { $gte: qty } so it never goes negative.

Roles everywhere

requireRole("admin") on every admin route, and an AdminRoute in React. Test that a normal user gets 403.

How it works

Build in milestones

  1. 1

    Catalogue

    Product model, seed script, list and detail pages with filters and pagination.

  2. 2

    Auth and cart

    Login and signup with cookies, cart with Redux Toolkit or Zustand.

  3. 3

    Checkout

    Address form, Razorpay test mode order and verify, order confirmation page.

  4. 4

    Admin

    Product CRUD with image upload and an orders table with status changes.

  5. 5

    Ship it

    Tests for checkout and admin permissions, deploy, README with a demo login.

See it in code

Walk through the code

js
1// After the Razorpay signature is verified2async function fulfilOrder(order) {3  const session = await mongoose.startSession();4  try {5    await session.withTransaction(async () => {6      for (const item of order.items) {7        const result = await Product.updateOne(8          { _id: item.product, stock: { $gte: item.qty } },9          { $inc: { stock: -item.qty } },10          { session }11        );12        if (result.modifiedCount === 0) {13          throw new Error("Out of stock: " + item.name);14        }15      }16      order.status = "paid";17      await order.save({ session });18    });19  } finally {20    await session.endSession();21  }22}

1/5Start a session and run the work inside withTransaction, which also retries on transient errors.

Reduce stock for every item and mark the order paid, all or nothing. Needs a replica set, which Atlas provides.

Save yourself the pain

Common mistakes

Oops

Storing only the product id in the order and reading the price later.

Do this instead

Snapshot name and price into the order items. Prices change, but past orders must not.

Oops

Reducing stock when the item is added to the cart.

Do this instead

Reduce it after payment is confirmed. Carts are abandoned all the time.

Oops

Letting the admin panel rely only on hidden buttons.

Do this instead

Protect every admin API route with a role check. Hidden buttons are not security.

Your mission

Build the store

~900 min

Quick check

Why snapshot the price into each order item instead of only storing the product id?

Go deeper

  1. 1Use roles so only admins can manage products and orders.
  2. 2Verify payments on the server and update stock in a transaction.
  3. 3Deploy it and add test card details to the README.

More projects at this stop

Stuck on this topic? Ask an Insider

Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.

Download
InsideEdge