Ahmed Abdelaziz

Custom Ecommerce Backend API for a Clothing BrandDesign Docs

Functional Requirements

What customers and administrators can do, by role — 23 requirements including financial reports.

Last updated September 2026

Overview

These are the functional requirements in plain language — what customers and administrators can do, split by role.

How to read

Must = shipped and verified by tests. Should = shipped. Planned = designed but not implemented.


Customer Requirements

IDRequirementStatus
FR-01Register with email + phone; verify email via hashed token link (24h TTL)Must
FR-02Log in from multiple devices; view active sessions; revoke any or allMust
FR-03Recover password via email link or 6-digit OTP (15 min TTL, attempt-limited); reset revokes all sessionsMust
FR-04Manage profile: name, password change, email change (link, 24h TTL), phone change (6-digit OTP, 10 min TTL), soft-delete own accountMust
FR-05Manage an address book (CRUD with default shipping/billing flags, ownership-scoped) used at checkout (address is snapshot into shipments)Must
FR-06Browse products with filtering, search, sorting, pagination; browse categories; list products per category — customer visibility = non-deleted product with ≥1 ACTIVE variantMust
FR-07View a product's variants — pick size/color/barcode/dimensions with live availability and computed final_price; see ordered images per product and per variant with exactly-one-primary invariantMust
FR-08Maintain a single lazily-created server-side cart: add variants (merge-on-duplicate), update quantities, remove lines, clear — all four mutations advisory-locked alongside checkoutMust
FR-09Check out in one transaction: owned address, optional coupon (uppercased), shipping rules, guarded stock reservation, mock payment (PaymentGateway interface), immutable order_items + shipments snapshots, cart clear — under pg_advisory_xact_lockMust
FR-10Apply coupons honoring validity window, global limit, per-user limit, minimum order value, and max-discount cap — quota restored on pre-fulfillment cancel, kept on post-fulfillment refundMust
FR-11View order history and order detail with immutable snapshots of prices, discounts, SKUs, and variant attributes; filtered by status, sorted by placement dateMust
FR-12Write one live review per product (with images), edit or delete it; list own reviews — purchase-gate implemented behind REVIEWS_REQUIRE_PURCHASE (off)Should
FR-13Upload review/product images directly to ImageKit with server-signed short-lived HMAC params; URLs re-validated for host/folder/extensionShould

Administrator Requirements

IDRequirementStatus
FR-14Full catalog CRUD: products, nested variants, product/variant images with primary-flag managementMust
FR-15Manage categories and assign/unassign productsMust
FR-16Manage inventory per variant: adjust quantity_on_hand/reorder_level, create manual reservations, commit/release stock via the FSMMust
FR-17Transition orders through an explicit allowedTransitions FSM (pending → confirmed → processing → shipped → delivered → cancelled/returned → refunded) with automatic side effects (shipment row, stock commit/release, payment status, coupon quota) under SELECT … FOR UPDATEMust
FR-18Moderate reviews; manage coupons with coupon_usages inspection and historyMust
FR-19Manage users: list, suspend/activate; role changes (customer ↔ admin) require SUPER_ADMIN; last SUPER_ADMIN protectedMust
FR-20Manage admin accounts (/admin/admins — SUPER_ADMIN only) and transfer SUPER_ADMIN via CLIMust
FR-21View stats dashboard (/admin/stats), analytics — overview, coupons, and P&L expenses ledger (/admin/analytics) — and the append-only audit log (/admin/audit), all SUPER_ADMIN unless notedShould
FR-22Download financial PDFs — P&L Statement, Expenses, Revenue by `monthquarter
FR-23Issue and audit signed ImageKit upload params (/uploads/imagekit-auth + /admin/products/uploads/imagekit-auth)Should

Behavior That Matters

  • Checkout is all-or-nothing — stock validation, price/Decimal computation, coupon redemption (global/per-user limits + max-discount cap), order + order_items/shipments snapshot creation, payment recording, and cart deletion succeed together or not at all under one advisory lock.
  • Overselling is impossible — reservation uses guarded UPDATE … WHERE available >= qty, not check-then-write; cart mutations are also advisory-locked so races degrade to clean 404s.
  • Order history never lies — later catalog/address edits can't rewrite order_items (price/SKU/attributes) or shipments (address copy).
  • Every privileged mutation is audited — actor, action, entity, request body (redacted), prev/diff, IP, UA — append-only audit_logs.

Out of Scope (Current Version)

  • Real payment gateway (Paymob integration is designed as tracked tasks; MockPaymentGateway only today).
  • SMS delivery — the interface exists, sending is stubbed.
  • Review purchase verification — implemented behind REVIEWS_REQUIRE_PURCHASE, currently off.
  • Multi-origin CORS support.

Why it matters

Every gap is a documented decision with a task number — not an undocumented surprise.