RESONANCE

A full-stack headphone storefront built with React, Express and MariaDB, with accounts, a server-side cart and a checkout that pays through Stripe in test mode.

Adrian

· Visit Project

Try the store or explore its source code:

Check out with Continue with the demo, which needs no email or password, and pay with Stripe's test card 4242 4242 4242 4242. No real money is ever taken, and demo accounts are cleared every night.

The RESONANCE home page with the headline Less noise. More feeling. above graphite over-ear headphones

A storefront where the hard parts are real

RESONANCE is a headphone store with over-ear and in-ear models, product pages with image views, zoom and short product films, and an account page with every order. Accounts, the bag and checkout all run against a real API and database, and payments go through Stripe in test mode.

I wanted to build a shop where the parts that usually get faked in a portfolio project actually work: signing in, keeping a cart in sync and taking a payment without losing stock or money along the way.

The over-ear collection page with a gallery of headphone models

How it is built

The frontend is React 19 with MUI and TanStack Query, built with Vite. The API is Node.js and Express, split into routes, services and Sequelize models, with versioned migrations for MariaDB. Both deploy together to Vercel, where Express runs as a serverless function on the same origin as the site, so the session cookie just works.

A few decisions carry most of the weight:

  • Prices are stored in öre as integers, so totals never suffer from rounding.
  • Sessions are opaque tokens in an httpOnly cookie, and only a digest is stored. Routes act on the signed-in user and never accept a user id.
  • Guests keep their bag in the browser, and it merges into the server cart when they sign in.
  • Repeated wrong passwords pause sign-in for 15 minutes, without letting someone guessing elsewhere lock out the owner.
The Atlas product page with its finishes and an Add to bag button

A checkout that never sells the last pair twice

The checkout is where a store can lose money, stock or trust. Two visitors can buy the last pair at the same moment, a double click can send the same order twice, and the visitor can leave Stripe's page halfway through.

Placing an order runs in one database transaction. It locks the bag, then each product, checks stock, reserves it and writes a pending order whose lines freeze the current prices. Products are always locked in id order, so two bags with the same models in opposite order cannot deadlock. This excerpt comes from reserveOrder:

// Locking in id order keeps parallel orders from deadlocking.
const products = await Product.findAll({
  where: { id: rows.map((row) => row.product_id) },
  order: [['id', 'ASC']],
  lock: transaction.LOCK.UPDATE,
  transaction,
});

Only after that transaction commits does the API open a Stripe Checkout page, so no payment call ever runs inside a database transaction. A repeated request for an unchanged bag finds its open order and the same payment page, so nothing is bought twice.

Only Stripe can mark an order paid

The return from Stripe arrives through the visitor's browser and could be forged. Stripe's webhook is signed with a secret only Stripe and the API share, so it is the only thing that marks an order paid:

const event = payments.readEvent(req.body, req.get('stripe-signature'));
const session = event.data.object;
const orderId = Number(session.metadata?.order_id);
switch (event.type) {
  case 'checkout.session.completed':
  case 'checkout.session.async_payment_succeeded':
    if (session.payment_status === 'paid') await markPaid(orderId, session.id);
    break;
  case 'checkout.session.expired':
  case 'checkout.session.async_payment_failed':
    await cancelOrder(orderId, session.id);
    break;
}

Marking an order paid checks that it is still pending and belongs to that Stripe session, so late or repeated events change nothing. A payment page that expires cancels its order and returns the stock.

An earlier version emptied the bag as soon as the order was placed, so a visitor who went back from Stripe found nothing there. Now the bag stays until the payment goes through, with Continue to payment and Cancel payment on the bag and the order page. If the visitor changes the bag while a payment is open, the old payment page is closed first, so they can never pay for a bag that no longer exists.

The bag with one Atlas and two Prism headphones

Tested at every level

Database tests run against MariaDB in CI. They send five checkouts for the same bag at once and get one order, let two buyers race for the last item, and check that two opposite bags do not deadlock. Component tests cover the bag and the order page, and Playwright tests browse, sign in and pay end to end against a local stand-in for Stripe that sends signed webhooks, so CI needs no network or keys.

Every measured page scores 97 to 100 for performance in Lighthouse, with images served in several widths and product films that only load when they come on screen.

Next, I would send an order confirmation by email once the webhook marks it paid, and add an admin view of pending and cancelled orders.

Contact

Questions or need more details? Ping me on LinkedIn or any of my other social media links.