I built this sneaker store from scratch for a client. It is live at kicks-nation.com.
Kicks Nation sells sneakers and joggers in Pakistan, with cash on delivery. There are two parts: the storefront shoppers use, and a store manager the owner uses to run it.
This post covers the parts I cared about most: filters, prices, stock, orders and the tests around them.
The stack
- Next.js 16 and React 19
- PostgreSQL on Neon with Drizzle ORM
- Better Auth: email confirmation for customers, 2FA for the owner
- Cloudflare R2 for product photos
- Resend for emails
- Vercel in Singapore, next to the database
Filters live in the URL
Filters and sort are part of the address, so a filtered list can be shared or reloaded as it is.
Sizes can be combined. ?size=41,42 shows the shoes that are in stock in EU 41 or 42, in any color. Unknown numbers from an old or hand-typed link are ignored.
The browser never sends a price
This is everything checkout accepts for each line of the bag:
type OrderLine = {
productId: number;
color: string;
size: number;
quantity: number;
};
There is no price field. The server reads the price from the database inside the order transaction, including the sale price if a sale is running at that moment. The shop and the server use the same pricing rule.
Two buyers, one pair
Stock is tracked per color and size, so two people can easily want the last pair of the same size. Inside the transaction, that row is locked before the stock is checked (simplified here):
const [row] = await tx
.select({ variantId: variant.id, stock: variant.stock })
.from(variant)
// joins and filters for product, color and size
.for("update", { of: variant }); // SELECT ... FOR UPDATE
A second checkout for the same pair waits until the first one commits or rolls back, then sees the new stock. Bag lines are sorted first, so every checkout locks rows in the same order and two orders cannot deadlock each other.
The repo has a test script that sends two checkouts for one remaining pair at the same instant. It expects exactly one order, and stock at 0, never -1.
A double click is one order
The checkout form sends a random idempotency key, and that column is UNIQUE. If the same submission arrives twice, the second insert fails, its whole transaction rolls back, and the customer gets the order that already exists.
An order remembers what was sold
Each order line stores the product name and the unit price. Rename a product or change its price later, and old orders stay as they were.
The database also checks the arithmetic itself:
check(
"order_total_check",
sql`${t.total} = ${t.subtotal} + ${t.shipping} - ${t.discount}`,
),
The store manager
- Stock per color and size, and every stock change asks why
- Every color has its own photos
- Sale price or % off with an optional end time. When it ends, the regular price comes back by itself
- Delivery fees for Karachi and other cities, the free delivery limit, delivery time and returns text are settings, not code
- Owner sign-in needs 2FA
One photo detail
The admin shrinks each photo to WebP in the browser before upload. Shoppers load photos through kicks-nation.com/img/..., and Vercel fetches them from R2 and caches them. This is there because one of Cloudflare's addresses for the images domain times out on some Pakistani networks.
Tests that try to break it
A security script runs against the app. It checks the browser protection headers, then tries to:
- sign up as a customer and make itself the owner
- open the admin, or call its server actions, without being the owner
- check out with a tampered price
- open someone else's order with a guessed link
- send a request from another website (CSRF)
- flood orders, or guess passwords and discount codes quickly, which should get slowed down
What's next
Cash on delivery works today. Online card payments are the next feature coming to the store.
You can see it at kicks-nation.com.


Top comments (1)
Solid build. The part I would dig into is stock under cash on delivery: with COD an order is a promise to pay later, so stock has to come off at order time, not at payment. Two things that have saved me there:
update products set stock = stock - 1 where id = $1 and stock >= 1 returning stock, and treat zero rows as out of stock. A read-then-write leaves a window where two checkouts both see stock = 1.Also, if the UI shows "only 2 left", that number should come from the same conditional read, or the badge lies as soon as two people shop at once.