The Problem & Challenge
E-commerce retail faces severe operational challenges: stock-hoarding by unpaid orders and bots locking up inventory, unreviewed return requests leading to customer dissatisfaction, payment gateway webhook race conditions, and vulnerabilities in administrative access that could compromise customer financial transactions and stock accuracy.
The Engineering Solution
I engineered a unified Turborepo monorepo with automated background job queues using @nestjs/bullmq and Redis to deterministically govern order timeouts (auto-cancelling unpaid orders and restocking within 15 mins for PromptPay). Additionally, I implemented a Dual-Token authentication architecture featuring Refresh Token Rotation with token reuse detection, one-time token admin invitation onboarding, a pro-rated net price calculation engine for partial refunds, and Omise payment webhook idempotency.
Technical System Architecture
Turborepo Monorepo structure managing Next.js Storefront, React Admin Portal, NestJS Store API, NestJS Admin API, and shared Prisma/Zod validation packages.
BullMQ & Redis 7 background worker cluster managing delayed jobs for unpaid order auto-cancellation, 48-hour return review timeouts, and 5-day delivery auto-completion.
Dual-Token Authentication (15-min Access Token + 7-day Refresh Token) with cryptographic Token Family Rotation, replay attack revocation, and Redis-backed session invalidation.
Zero-Knowledge Admin Onboarding via Redis-backed One-Time Setup Tokens (48h TTL) sent through automated email invitations without hardcoded initial passwords.
E-Commerce Core Engines: Pre-Order reservation quotas, Coupon abuse-prevention engine, pro-rated net cost refund ledger, and weight-based shipping matrix.
PostgreSQL 16 relational database with Prisma ORM, implementing comprehensive audit trails (StockMovement and AdminAuditLog) for 100% operational traceability.
Key System Highlights
Automated Order Lifecycles
BullMQ & Redis delayed workers handle auto-cancellation, restocking, and return timeouts deterministically.
Dual-Token Authentication
15-min JWTs + 7-day Refresh Tokens with cryptographic rotation, replay attack detection, and instant multi-device revocation.
Turborepo Modular Monorepo
Decoupled Next.js storefront, React admin back-office, and separate NestJS APIs sharing Prisma and Zod packages.
Pro-Rated Refund Ledger
Automated item-level net cost breakdown ensuring precise partial refunds and immutable transaction audit trails.
