Multi-Vendor E-Commerce Platform (BACKEND System)

A scalable multi-vendor marketplace featuring 15 microservices, escrow-based payment protection, tenant isolation, and admin governance system with dual-approval workflows.

microservices
nestjs
typescript
postgresql
multi-tenant
e-commerce
escrow
payment-gateway
docker
keycloak
oauth2
row-level-security
redis
nginx
dispute-resolution
compliance
audit-logging
saas
marketplace
api-gateway

Note: Some repositories are private to protect proprietary logic. Full source code access can be shared with recruiters on request.

Technical Documentation

πŸ›’ Multi-Vendor E-Commerce Platform

Enterprise-Grade, Escrow-Protected Multi-Tenant Marketplace

A production-ready multi-tenant e-commerce platform built with modern microservices architecture. Features complete buyer protection through escrow, dispute resolution, and compliance workflows.


🎯 What This Platform Solves

ProblemSolution
Buyer doesn't trust unknown sellersEscrow holds payment until delivery confirmed
Sellers fear chargebacksDispute resolution with evidence-based decisions
Platform liabilityComplete audit trail + legal hold support
Multi-vendor complexityTenant isolation at database level (RLS)
Payment fraudGateway abstraction with webhook verification

πŸ—οΈ Architecture Overview

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                              NGINX GATEWAY                               β”‚
β”‚                    (Rate Limiting, Load Balancing, SSL)                  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                    β”‚
        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
        β”‚                           β”‚                           β”‚
        β–Ό                           β–Ό                           β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   IDENTITY    β”‚         β”‚   COMMERCE    β”‚         β”‚   FINANCIAL   β”‚
β”‚               β”‚         β”‚               β”‚         β”‚               β”‚
β”‚ β€’ Tenant Svc  β”‚         β”‚ β€’ Product Svc β”‚         β”‚ β€’ Payment Svc β”‚
β”‚ β€’ User Svc    β”‚         β”‚ β€’ Cart Svc    β”‚         β”‚ β€’ Escrow Svc  β”‚
β”‚ β€’ Admin Svc   β”‚         β”‚ β€’ Order Svc   β”‚         β”‚ β€’ Payout Svc  β”‚
β”‚ β€’ Keycloak    β”‚         β”‚ β€’ Inventory   β”‚         β”‚ β€’ Compliance  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
        β”‚                           β”‚                           β”‚
        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                    β”‚
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚               β”‚               β”‚
                    β–Ό               β–Ό               β–Ό
            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
            β”‚PostgreSQL β”‚   β”‚   Redis   β”‚   β”‚ Keycloak  β”‚
            β”‚  (RLS)    β”‚   β”‚  (Cache)  β”‚   β”‚  (OAuth)  β”‚
            β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ”„ Data Flow

Product Discovery Flow

User Request
     β”‚
     β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  NGINX Gateway  β”‚ ── Rate limit check
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Product Service β”‚ ── Check Redis cache
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
    β”Œβ”€β”€β”€β”€β”΄β”€β”€β”€β”€β”
    β”‚         β”‚
    β–Ό         β–Ό
 CACHE     DATABASE
  HIT        MISS
    β”‚         β”‚
    β”‚    β”Œβ”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”
    β”‚    β”‚PostgreSQLβ”‚ ── RLS applies tenant filter
    β”‚    β”‚  Query   β”‚
    β”‚    β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜
    β”‚         β”‚
    β”‚    β”Œβ”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”
    β”‚    β”‚  Cache  β”‚ ── Store in Redis
    β”‚    β”‚ Update  β”‚
    β”‚    β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜
    β”‚         β”‚
    β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜
         β”‚
         β–Ό
   JSON Response
   to Client

Order Creation Flow

                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚   Cart Service  β”‚
                    β”‚  (Validate Cart)β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                             β”‚
                             β–Ό
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚Inventory Serviceβ”‚
                    β”‚ (Reserve Stock) β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                             β”‚
                             β–Ό
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚  Order Service  β”‚
                    β”‚ (Create Order)  β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                             β”‚
                             β–Ό
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚ Pricing Service β”‚
                    β”‚(Calculate Final)β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                             β”‚
                             β–Ό
              Order Created (Status: PENDING)

πŸ‘€ User Flows

Buyer Journey

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                          BUYER FLOW                                   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

  Browse      Add to       Checkout      Payment       Receive       Review
  Products    Cart         Order         (Escrow)      Delivery      Product
     β”‚          β”‚            β”‚              β”‚             β”‚             β”‚
     β–Ό          β–Ό            β–Ό              β–Ό             β–Ό             β–Ό
  β”Œβ”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”       β”Œβ”€β”€β”€β”€β”€β”       β”Œβ”€β”€β”€β”€β”€β”       β”Œβ”€β”€β”€β”€β”€β”
  β”‚ GET β”‚   β”‚ ADD β”‚      β”‚CREATEβ”‚      β”‚ PAY β”‚       β”‚CONFIRMβ”‚     β”‚ POST β”‚
  β”‚/prodβ”‚   β”‚/cartβ”‚      β”‚/orderβ”‚      β”‚     β”‚       β”‚DELIVERYβ”‚    β”‚/reviewβ”‚
  β””β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”˜       β””β”€β”€β”¬β”€β”€β”˜       β””β”€β”€β”€β”¬β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”˜
                                          β”‚              β”‚
                                          β–Ό              β–Ό
                                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                                    β”‚  ESCROW  β”‚   β”‚  ESCROW  β”‚
                                    β”‚  CREDIT  β”‚   β”‚  RELEASE β”‚
                                    β”‚ (Frozen) β”‚   β”‚ (Payout) β”‚
                                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

  DISPUTE PATH (if issue):
  
  Receive Issue β†’ Open Dispute β†’ Submit Evidence β†’ Admin Review β†’ Resolution
       β”‚               β”‚               β”‚               β”‚              β”‚
       β–Ό               β–Ό               β–Ό               β–Ό              β–Ό
  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”
  β”‚ Problem β”‚    β”‚ ESCROW   β”‚    β”‚ Evidence β”‚    β”‚ Admin   β”‚    β”‚ Refund β”‚
  β”‚Detected β”‚    β”‚ FROZEN   β”‚    β”‚ Upload   β”‚    β”‚ Decides β”‚    β”‚   OR   β”‚
  β”‚         β”‚    β”‚          β”‚    β”‚          β”‚    β”‚         β”‚    β”‚Release β”‚
  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Seller (Tenant) Journey

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                         SELLER FLOW                                   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

  Onboard      Setup        List         Receive      Ship         Get
  Tenant       Store        Products     Order        Order        Paid
     β”‚           β”‚            β”‚            β”‚            β”‚            β”‚
     β–Ό           β–Ό            β–Ό            β–Ό            β–Ό            β–Ό
  β”Œβ”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”
  β”‚REGISβ”‚    β”‚CONFIGβ”‚     β”‚ ADD β”‚      β”‚ VIEW β”‚     β”‚CREATEβ”‚     β”‚PAYOUTβ”‚
  β”‚TER  β”‚    β”‚STORE β”‚     β”‚PRODSβ”‚      β”‚ORDERSβ”‚     β”‚SHIPMTβ”‚     β”‚      β”‚
  β””β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”¬β”€β”€β”˜
                                                                    β”‚
                                                         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                                                         β”‚                     β”‚
                                                         β–Ό                     β–Ό
                                                  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                                                  β”‚  ELIGIBLE  β”‚       β”‚  BLOCKED   β”‚
                                                  β”‚            β”‚       β”‚            β”‚
                                                  β”‚ β€’ Deliveredβ”‚       β”‚ β€’ Dispute  β”‚
                                                  β”‚ β€’ 14 days  β”‚       β”‚ β€’ Legal    β”‚
                                                  β”‚ β€’ No disputeβ”‚      β”‚ β€’ Penalty  β”‚
                                                  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Admin Journey

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                         ADMIN FLOW                                    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚       ADMIN DASHBOARD       β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                  β”‚
        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
        β”‚                         β”‚                         β”‚
        β–Ό                         β–Ό                         β–Ό
  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
  β”‚   TRUST   β”‚            β”‚  FINANCE  β”‚            β”‚COMPLIANCE β”‚
  β”‚   ADMIN   β”‚            β”‚   ADMIN   β”‚            β”‚   ADMIN   β”‚
  β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜            β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜            β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜
        β”‚                        β”‚                        β”‚
        β–Ό                        β–Ό                        β–Ό
  β€’ Tenant Management      β€’ Payout Approval       β€’ Legal Holds
  β€’ Suspend/Warn           β€’ Escrow Review         β€’ Data Exports
  β€’ Support Escalation     β€’ Refund Override       β€’ Audit Review
        β”‚                        β”‚                        β”‚
        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                 β”‚
                                 β–Ό
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚    DUAL APPROVAL SYSTEM     β”‚
                    β”‚                             β”‚
                    β”‚  Sensitive actions require  β”‚
                    β”‚  approval from 2 admins     β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ’³ Payment Flow

Complete Payment Lifecycle

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                           PAYMENT FLOW                                       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

PHASE 1: CHECKOUT
═══════════════════════════════════════════════════════════════════════════════

  Buyer                    Platform                    Gateway
    β”‚                         β”‚                           β”‚
    β”‚   ──── Checkout ────►   β”‚                           β”‚
    β”‚                         β”‚   ── Create Payment ──►   β”‚
    β”‚                         β”‚   ◄── Payment URL ────    β”‚
    β”‚   ◄── Redirect ─────    β”‚                           β”‚
    β”‚                         β”‚                           β”‚
    β”‚   ───────────────────── Complete Payment ──────────►│
    β”‚                         β”‚                           β”‚


PHASE 2: ESCROW CREDIT
═══════════════════════════════════════════════════════════════════════════════

  Gateway                  Platform                    Escrow
    β”‚                         β”‚                           β”‚
    β”‚   ── Webhook: PAID ──►  β”‚                           β”‚
    β”‚                         β”‚                           β”‚
    β”‚                         β”‚   ── Credit Escrow ───►   β”‚
    β”‚                         β”‚   (Tenant's Account)      β”‚
    β”‚                         β”‚                           β”‚
    β”‚                         β”‚   ◄── Balance Updated ─   β”‚
    β”‚                         β”‚       (HELD, not available)β”‚


PHASE 3: FULFILLMENT
═══════════════════════════════════════════════════════════════════════════════

  Seller                   Platform                    Buyer
    β”‚                         β”‚                           β”‚
    β”‚   ── Create Shipment ─► β”‚                           β”‚
    β”‚                         β”‚   ── Tracking Update ──►  β”‚
    β”‚                         β”‚                           β”‚
    β”‚   ── Mark Delivered ──► β”‚                           β”‚
    β”‚                         β”‚   ── Delivery Confirm ──► β”‚
    β”‚                         β”‚                           β”‚
    β”‚                         β”‚   ◄── Confirm Receipt ─   β”‚
    β”‚                         β”‚       (or auto after 14d) β”‚


PHASE 4: PAYOUT (HAPPY PATH)
═══════════════════════════════════════════════════════════════════════════════

  Time Passes              Platform                    Seller
    β”‚                         β”‚                           β”‚
    β”‚ ── 14 day window ──►    β”‚                           β”‚
    β”‚                         β”‚                           β”‚
    β”‚                  β”Œβ”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”                    β”‚
    β”‚                  β”‚   CHECK:    β”‚                    β”‚
    β”‚                  β”‚ β€’ Delivered β”‚                    β”‚
    β”‚                  β”‚ β€’ No disputeβ”‚                    β”‚
    β”‚                  β”‚ β€’ No hold   β”‚                    β”‚
    β”‚                  β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜                    β”‚
    β”‚                         β”‚                           β”‚
    β”‚                  β”Œβ”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”                    β”‚
    β”‚                  β”‚   RELEASE   β”‚   ── Platform Fee ──► (5%)
    β”‚                  β”‚   ESCROW    β”‚   ── Seller Share ──► (95%)
    β”‚                  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                    β”‚


PHASE 4: PAYOUT (DISPUTE PATH)
═══════════════════════════════════════════════════════════════════════════════

  Buyer                    Platform                    Seller
    β”‚                         β”‚                           β”‚
    β”‚   ── Open Dispute ──►   β”‚                           β”‚
    β”‚                         β”‚                           β”‚
    β”‚                  β”Œβ”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”                    β”‚
    β”‚                  β”‚   ESCROW    β”‚                    β”‚
    β”‚                  β”‚   FROZEN    β”‚                    β”‚
    β”‚                  β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜                    β”‚
    β”‚                         β”‚                           β”‚
    β”‚   ── Evidence ───────►  β”‚  ◄───── Evidence ─────    β”‚
    β”‚                         β”‚                           β”‚
    β”‚                  β”Œβ”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”                    β”‚
    β”‚                  β”‚   ADMIN     β”‚                    β”‚
    β”‚                  β”‚   REVIEW    β”‚                    β”‚
    β”‚                  β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜                    β”‚
    β”‚                         β”‚                           β”‚
    β”‚              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                β”‚
    β”‚              β”‚                     β”‚                β”‚
    β”‚              β–Ό                     β–Ό                β”‚
    β”‚       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”          β”‚
    β”‚       β”‚BUYER WINS β”‚         β”‚SELLER WINSβ”‚          β”‚
    β”‚       β”‚           β”‚         β”‚           β”‚          β”‚
    β”‚       β”‚ Refund to β”‚         β”‚ Release   β”‚          β”‚
    β”‚       β”‚ Buyer     β”‚         β”‚ to Seller β”‚          β”‚
    β”‚       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜          β”‚

Payment States

                              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                              β”‚ PENDING β”‚
                              β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜
                                   β”‚
                         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                         β”‚                   β”‚
                         β–Ό                   β–Ό
                   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                   β”‚   PAID   β”‚        β”‚  FAILED  β”‚
                   β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                        β”‚
                        β–Ό
                   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                   β”‚ IN ESCROWβ”‚ ◄──── Funds held
                   β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜
                        β”‚
          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
          β”‚             β”‚             β”‚
          β–Ό             β–Ό             β–Ό
    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
    β”‚ RELEASED β”‚  β”‚  FROZEN  β”‚  β”‚ REFUNDED β”‚
    β”‚          β”‚  β”‚(Dispute) β”‚  β”‚          β”‚
    β”‚ To Sellerβ”‚  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜  β”‚ To Buyer β”‚
    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜       β”‚        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                       β”‚
               β”Œβ”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”
               β”‚               β”‚
               β–Ό               β–Ό
         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
         β”‚ RELEASED β”‚    β”‚ REFUNDED β”‚
         β”‚(Seller Won)   β”‚(Buyer Won)β”‚
         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ”§ Technology Choices & Rationale

Core Stack

TechnologyPurposeWhy This Choice
Node.js + NestJSMicroservicesTypeScript support, dependency injection, modular architecture, excellent for APIs
PostgreSQLPrimary DatabaseACID compliance for financial data, Row-Level Security (RLS) for tenant isolation, JSON support
RedisCache + SessionsSub-millisecond latency, pub/sub for real-time updates, session storage
KeycloakIdentity ProviderEnterprise-grade OAuth2/OIDC, multi-realm for tenant isolation, battle-tested security
NGINXAPI GatewayRate limiting, load balancing, SSL termination, request routing
DockerContainerizationConsistent environments, easy scaling, microservices deployment

Why PostgreSQL with RLS?

-- Every query automatically filters by tenant
CREATE POLICY tenant_isolation ON products
    USING (tenant_id = current_setting('app.tenant_id')::uuid);

-- Result: Tenant A can NEVER see Tenant B's data
-- No application-level bugs can leak data across tenants

Why Escrow Pattern?

Traditional PaymentEscrow Pattern
Money goes directly to sellerMoney held by platform
Buyer has no protectionBuyer protected until delivery
Disputes are messyClear dispute resolution
Chargebacks hurt sellerPlatform absorbs chargeback risk

Why Microservices?

MONOLITH PROBLEMS                    MICROSERVICES SOLUTION
─────────────────                    ──────────────────────
Single point of failure         β†’    Fault isolation
Hard to scale specific parts    β†’    Scale only what's needed
Tightly coupled changes         β†’    Independent deployments
One language/framework          β†’    Best tool for each job

✨ Features

πŸͺ Multi-Tenant Commerce

FeatureDescription
Tenant IsolationDatabase-level isolation using PostgreSQL RLS
Custom BrandingEach tenant can customize their storefront
Flexible PricingTenant-specific pricing rules, discounts, promotions
Inventory ManagementStock tracking with reservation system
Category ManagementHierarchical categories per tenant

πŸ’° Financial Safety

FeatureDescription
Escrow ProtectionAll payments held until delivery confirmed
Platform FeeConfigurable platform commission (default 5%)
Payout EligibilityAutomated checks before fund release
Dispute ResolutionEvidence-based, admin-mediated disputes
Legal HoldsFreeze funds for legal/compliance needs

πŸ”’ Security & Compliance

FeatureDescription
OAuth2/OIDCKeycloak for enterprise authentication
Role-Based Access5 distinct admin roles with separated duties
Dual ApprovalSensitive actions require 2 admins
Immutable AuditTamper-proof audit logs with checksums
Data ExportGDPR-compliant data export with watermarking

πŸ“¦ Order Management

FeatureDescription
Cart SystemPersistent carts with guest support
Order LifecycleComplete state machine from checkout to delivery
Shipping IntegrationTracking, webhooks, delivery confirmation
Returns ManagementReturn requests, approval workflow, restocking
NotificationsEmail/SMS notifications at each stage

πŸ›‘οΈ Dispute System

FeatureDescription
Dispute TypesNon-delivery, damaged, fraud, chargeback
Evidence UploadBoth parties can submit evidence
Auto-ResolutionAutomatic buyer win for non-delivery
Abuse PreventionBuyer flagging, tenant penalties
Partial RefundsSupport for partial resolutions

πŸ“Š Service Map

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                            SERVICE ARCHITECTURE                             β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

PORT    SERVICE              RESPONSIBILITY
────    ───────              ──────────────
3001    tenant-service       Tenant registration, configuration, branding
3002    user-service         User accounts, profiles, authentication
3003    admin-service        Platform administration, tenant management
3004    product-service      Product catalog, categories, search
3005    review-service       Product reviews, ratings, moderation
3006    cart-service         Shopping cart, wishlist, guest carts
3007    inventory-service    Stock management, reservations
3008    pricing-service      Pricing rules, discounts, promotions
3009    order-service        Order creation, lifecycle, status
3010    payment-service      Payment gateway integration, webhooks
3011    escrow-service       Escrow accounts, transactions, payouts
3012    shipping-service     Shipment tracking, delivery confirmation
3013    return-service       Returns workflow, refunds, restocking
3014    dispute-service      Dispute resolution, escrow freezing
3015    compliance-service   Legal holds, exports, dual approval, audit

INFRASTRUCTURE
──────────────
5432    PostgreSQL           Primary database with RLS
6379    Redis                Caching, sessions, pub/sub
8080    NGINX                API gateway, load balancer
8081    Keycloak             OAuth2/OIDC identity provider

πŸ—„οΈ Database Design

Multi-Tenant Isolation Strategy

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    TENANT ISOLATION LAYERS                       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

LAYER 1: APPLICATION
    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
    β”‚ JWT token contains tenant_id          β”‚
    β”‚ Middleware extracts and validates     β”‚
    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

LAYER 2: DATABASE CONNECTION
    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
    β”‚ SET app.tenant_id = 'uuid'            β”‚
    β”‚ Applied at connection level           β”‚
    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

LAYER 3: ROW-LEVEL SECURITY
    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
    β”‚ POLICY: WHERE tenant_id = current_setting('app.tenant_id')
    β”‚ Applied automatically to every query  β”‚
    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

RESULT: Even SQL injection cannot access other tenant's data

Core Tables

IDENTITY                 COMMERCE                 FINANCIAL
────────                 ────────                 ─────────
tenants                  products                 escrow_accounts
users                    categories               escrow_transactions
admin_users             product_variants          payouts
                        cart_items                payment_records
                        orders                    
                        order_items               COMPLIANCE
                        shipments                 ────────────
                        returns                   legal_holds
                        disputes                  approval_requests
                        reviews                   unified_audit_log
                                                  risk_signals

πŸ” Security Model

Authentication Flow

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    AUTHENTICATION FLOW                           β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

  Client                 Platform                 Keycloak
    β”‚                       β”‚                        β”‚
    β”‚ ── Login Request ──►  β”‚                        β”‚
    β”‚                       β”‚ ── OAuth2 Auth ──────► β”‚
    β”‚                       β”‚ ◄── Access Token ───── β”‚
    β”‚ ◄── JWT Token ──────  β”‚                        β”‚
    β”‚                       β”‚                        β”‚
    β”‚ ── API Request ─────► β”‚                        β”‚
    β”‚    (with JWT)         β”‚                        β”‚
    β”‚                       β”‚ ── Validate Token ───► β”‚
    β”‚                       β”‚ ◄── Token Valid ────── β”‚
    β”‚                       β”‚                        β”‚
    β”‚ ◄── Response ───────  β”‚                        β”‚

Authorization Matrix

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ ACTION           β”‚ SUPER    β”‚ TRUST    β”‚ FINANCE  β”‚ SUPPORT  β”‚COMPLIANCEβ”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Terminate Tenant β”‚ βœ“ Init   β”‚ βœ“ Init   β”‚    βœ—     β”‚    βœ—     β”‚ βœ“ Approveβ”‚
β”‚ Approve Payout   β”‚ βœ“ Both   β”‚    βœ—     β”‚ βœ“ Init   β”‚    βœ—     β”‚ βœ“ Approveβ”‚
β”‚ Resolve Dispute  β”‚ βœ“        β”‚    βœ—     β”‚    βœ—     β”‚ βœ“        β”‚    βœ—     β”‚
β”‚ Place Legal Hold β”‚ βœ“        β”‚    βœ—     β”‚    βœ—     β”‚    βœ—     β”‚ βœ“        β”‚
β”‚ Export Data      β”‚ βœ“ Approveβ”‚    βœ—     β”‚    βœ—     β”‚    βœ—     β”‚ βœ“ Init   β”‚
β”‚ Change Admin Roleβ”‚ βœ“ Both   β”‚    βœ—     β”‚    βœ—     β”‚    βœ—     β”‚    βœ—     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Init = Can initiate action
Approve = Can approve action
Both = Can do either

πŸ“ Project Structure

ecomm-platform/
β”œβ”€β”€ services/
β”‚   β”œβ”€β”€ tenant-service/          # Tenant management
β”‚   β”œβ”€β”€ user-service/            # User accounts
β”‚   β”œβ”€β”€ admin-service/           # Platform administration
β”‚   β”œβ”€β”€ product-service/         # Product catalog
β”‚   β”œβ”€β”€ review-service/          # Reviews & ratings
β”‚   β”œβ”€β”€ cart-service/            # Shopping cart
β”‚   β”œβ”€β”€ inventory-service/       # Stock management
β”‚   β”œβ”€β”€ pricing-service/         # Pricing rules
β”‚   β”œβ”€β”€ order-service/           # Order management
β”‚   β”œβ”€β”€ payment-service/         # Payment processing
β”‚   β”œβ”€β”€ escrow-service/          # Escrow management
β”‚   β”œβ”€β”€ shipping-service/        # Shipment tracking
β”‚   β”œβ”€β”€ return-service/          # Returns workflow
β”‚   β”œβ”€β”€ dispute-service/         # Dispute resolution
β”‚   └── compliance-service/      # Governance & compliance
β”‚
β”œβ”€β”€ docker/
β”‚   β”œβ”€β”€ postgres/
β”‚   β”‚   β”œβ”€β”€ init.sql             # Base schema
β”‚   β”‚   β”œβ”€β”€ phase4-inventory.sql # Commerce schema
β”‚   β”‚   β”œβ”€β”€ phase5-orders-payments.sql
β”‚   β”‚   β”œβ”€β”€ phase6-shipping-returns.sql
β”‚   β”‚   └── phase7-admin-governance.sql
β”‚   β”œβ”€β”€ nginx/
β”‚   β”‚   └── nginx.conf           # Gateway configuration
β”‚   └── keycloak/
β”‚
β”œβ”€β”€ docs/
β”‚   β”œβ”€β”€ PHASE4-CART-INVENTORY-PRICING.md
β”‚   β”œβ”€β”€ PHASE5-ORDERS-PAYMENTS-ESCROW.md
β”‚   β”œβ”€β”€ PHASE6-SHIPPING-RETURNS-DISPUTES.md
β”‚   β”œβ”€β”€ PHASE7-ADMIN-GOVERNANCE.md
β”‚   └── DISPUTE-RESOLUTION-RULES.md
β”‚
β”œβ”€β”€ docker-compose.yml
└── README.md

🎯 Key Design Decisions

1. Database-Level Tenant Isolation

Decision: Use PostgreSQL Row-Level Security instead of separate databases.

Rationale:

  • Single database is easier to maintain and backup
  • RLS provides guaranteed isolation even against SQL injection
  • Scales better than multi-database approach
  • Cross-tenant reporting possible for platform admins

2. Escrow-First Payment Model

Decision: Never let payment go directly to seller.

Rationale:

  • Buyer protection is non-negotiable for marketplace trust
  • Platform has leverage for dispute resolution
  • Reduces chargeback impact on sellers
  • Legal clarity on fund ownership

3. Immutable Audit Logs

Decision: Audit logs cannot be modified or deleted, even by admins.

Rationale:

  • Legal defensibility in disputes
  • Regulatory compliance (especially for financial data)
  • Internal fraud prevention
  • Database triggers enforce immutability

4. Dual Approval for Sensitive Actions

Decision: High-risk admin actions require approval from a second admin.

Rationale:

  • Prevents single-point fraud
  • Reduces impact of compromised accounts
  • Creates accountability trail
  • Industry standard for financial platforms

5. Microservices with Clear Boundaries

Decision: One service per domain, not per entity.

Rationale:

  • Reduces inter-service chatter
  • Clear ownership and deployment
  • Can scale independently
  • Easier to reason about

πŸ“ˆ Scalability Considerations

Current Architecture Scales To:

MetricCapacity
Concurrent Users10,000+
Products per Tenant1,000,000+
Orders per Day100,000+
Tenants10,000+

Scaling Strategies Built-In:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    HORIZONTAL SCALING                            β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

STATELESS SERVICES
    └── Any service can be replicated behind NGINX load balancer

DATABASE SCALING
    └── Read replicas for heavy-read services (Product, Cart)
    └── Connection pooling via PgBouncer

CACHE STRATEGY
    └── Redis cluster for session and cache distribution
    └── Cache-aside pattern with TTL

MESSAGE QUEUE (FUTURE)
    └── RabbitMQ/Kafka for async processing
    └── Event-driven architecture ready

πŸ† Quality Attributes

AttributeImplementation
ReliabilityHealth checks, graceful degradation, retry logic
SecurityOAuth2, RLS, rate limiting, audit logging
ScalabilityMicroservices, stateless design, caching
MaintainabilityTypeScript, modular structure, documentation
ObservabilityCorrelation IDs, structured logging, health endpoints
ComplianceGDPR exports, legal holds, immutable audit

πŸ“š Additional Documentation

DocumentDescription
Phase 4: Cart, Inventory & PricingCommerce layer details
Phase 5: Orders, Payments & EscrowFinancial layer details
Phase 6: Shipping, Returns & DisputesFulfillment layer details
Phase 7: Admin GovernanceCompliance layer details
Dispute Resolution RulesDispute handling policies

πŸ‘€ Author

Kunal

This platform demonstrates expertise in:

  • Enterprise microservices architecture
  • Financial system design (escrow, payouts)
  • Multi-tenant SaaS architecture
  • Security & compliance systems
  • Modern DevOps practices

Built with ❀️ for the modern marketplace economy