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 Solution
I engineered a unified Turborepo monorepo with automated background job queues using @nestjs/bullmq and Redis to manage order lifecycle 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 Token Family Rotation, replay attack revocation, and Redis-backed session invalidation.
Secure Admin Onboarding via Redis-backed One-Time Setup Tokens (48h TTL) sent through automated email invitations without hardcoded initial passwords.
Pre-Order reservation quotas, Coupon abuse-prevention engine, pro-rated net cost refund ledger, and weight-based shipping matrix.
PostgreSQL relational database with Prisma ORM, implementing comprehensive audit trails (StockMovement and AdminAuditLog) for full operational traceability.
Key System Highlights
Automated Order Lifecycles
BullMQ & Redis delayed workers handle auto-cancellation, restocking, and return timeouts automatically.
Dual-Token Authentication
15-min JWTs + 7-day Refresh Tokens with token 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.
