A demo clothing store with a storefront, a versioned REST API and an admin panel, built around the parts of e-commerce that usually break: stock under concurrent checkouts, payment webhooks, and account security.
Sandang is a portfolio project, not a real shop. Customers browse 25 products across 5 categories, check out, and pay through the Midtrans sandbox with test cards, bank transfers, or QRIS. Admins ship orders, issue partial refunds, and edit products and stock per size.
Built with Next.js route handlers, PostgreSQL, and Prisma. The API exposes 33 route handlers under /api/v1, each declared with its access level and Zod schemas for query, body, and params. Vitest covers the API and server modules against a real database, and Playwright runs the storefront end to end, including a full sandbox card purchase.
- category
- Full-stack e-commerce, payments and REST API
- year
- 2026
- role
- Full-stack developer
- tech stack
Stock that cannot oversell
Two customers buying the last jacket at the same moment is a race condition, so every stock change happens inside a database transaction.
Reserve on order, deduct on payment
Placing an order reserves stock for each size. A confirmed payment turns the reservation into a deduction, and a cancelled or expired order releases it back to the shelf.
Row-level locks in a fixed order
Stock updates lock the affected variant rows with SELECT … FOR UPDATE inside a PostgreSQL transaction. Rows are always locked sorted by ID, so two checkouts touching the same sizes cannot deadlock each other.
Unpaid orders settle themselves
A daily Vercel cron job, authorized by a shared secret, cancels overdue unpaid orders and returns their stock, clears expired sessions and rate-limit rows, and resets the public demo data.
Payments: trust the signature, not the browser
Midtrans reports payments through webhooks, so the notification endpoint treats every request as untrusted input.
Signature check
Each notification's SHA-512 signature is recomputed with the server key and compared in constant time before anything is applied. Rejected notifications are still stored for review.
Forward-only status
A payment can only move forward, from pending to paid to partially refunded to refunded. Late or repeated notifications cannot undo a payment.
Amount and duplicate guards
If the reported amount does not match the order, or a second payment arrives for an order that is already paid, the payment is flagged for an admin instead of being applied silently.
Refunds through the gateway
Admins issue full or partial refunds from the order page, capped at the amount that is still refundable.
Security by default
Argon2id passwords
Passwords are hashed with Argon2id. Logins for unknown emails still run a full verification, so response time does not reveal which accounts exist.
Rate limits stored in PostgreSQL
Login, registration, password reset, newsletter sign-up, and order placement each have limits per email, visitor, or customer, such as 5 login attempts per email every 15 minutes.
Origin check on every write
State-changing API requests must carry the app's own Origin header, which blocks cross-site request forgery.
Nonce-based Content Security Policy
Every page gets a fresh script nonce with strict-dynamic, framing is denied, and only the Midtrans origin may load its payment window.
A restricted demo admin
The public demo admin can ship and refund sandbox orders but cannot delete anything, upload photos, or see subscribers, and other customers' names, emails, and phone numbers are masked.
Architecture rules enforced by lint
Custom ESLint rules turn the project's boundaries into errors, so they hold even when the code changes.
Server-only boundary
Every file in src/server must start by importing server-only, so database and payment code can never be bundled for the browser.
Secrets stay on the server
Secret environment variables can only be read inside src/server, and the environment is validated with Zod at startup.
One way to change data
Server Actions are disallowed. Every write goes through the versioned API, where access, origin, and validation checks live.
Admin panel
Orders are grouped by what needs doing next: to ship, awaiting payment, shipped, cancelled, and refunded. Each order shows its payments, refunds, and delivery address, with ship and refund actions beside the summary. Order confirmation, shipping, and password reset emails are recorded in an outbox the admin can read.
Products, sizes, and stock
Each product has sizes with their own price and stock, shown as available over total so reserved items are visible at a glance. Products in the same style group appear as colours of one garment in the storefront.
The boring parts, done carefully
A storefront is the visible part of e-commerce, but the work that protects a shop is underneath: stock that stays correct under concurrent checkouts, payments that only count once they are verified, and accounts that resist guessing. Sandang treats those as the main features, with tests that run on every push through a pre-push hook.
key engineering insights
- Model stock as reservations and deductions inside transactions, not as a single number updated by the browser flow.
- Treat payment webhooks as untrusted input: verify the signature, check the amount, and only allow forward status changes.
- Turn architecture decisions into lint rules so boundaries like server-only code hold as the project grows.