WorkBrandWala Retail – Market-Aware Cross-Border Commerce Platform7 min

Cross-Border Commerce · Active Production · Proprietary

BrandWala Retail – Market-Aware Cross-Border Commerce Platform

Lead Full-Stack & Systems Engineer2025 — 2026

React 19Firebase FirestoreTanStack QueryPython Web ScrapingTailwindCSSTypeScript

Architected a market-aware cross-border commerce platform achieving sub-second catalog renders and -60% Firestore read costs across 40+ K-Beauty brands by designing React 19 market-scoped routing, TanStack Query cache invalidation, automated Python ETL pipelines, and a 5-layer real-time commission engine.

Role
Lead Full-Stack & Systems Engineer
Timeline
2025 — 2026
Class
Proprietary

Overview

Architected and deployed BrandWala Retail [X], an enterprise cross-border K-Beauty commerce platform serving Bangladeshi resellers and wholesale importers. Built a high-performance React 19 SPA backed by Firebase Firestore Lite and TanStack Query v5 [Y] — automating UK wholesale catalog ingestion via Python scrapers for 40+ brands, orchestrating a 5-layer real-time commission engine with delivery adjustments, and implementing quota-optimized cursor pagination and derived Customer Order Book projections [Z].

Decisions

Bangladeshi K-Beauty resellers faced a disconnected workflow: manually scraping UK supplier websites, hand-calculating multi-tier commissions with delivery charges and COD deductions, taking orders over WhatsApp without customer purchase history, and facing Firestore quota spikes from un-optimized query patterns.

Challenge

Automating UK Wholesale Catalog Ingestion

Decision

Built dedicated Python scrapers with session/CSRF authentication for kobareseller.com and WooCommerce REST API adapters, integrating automatic regex brand tagging for 40+ K-Beauty labels.

Outcome

Catalog refreshes on demand via automated scripts without manual data entry.

Challenge

Market-Aware Multi-Vendor Routing

Decision

Structured routing under /#/m/{marketSlug}/{vendorSlug}/(products|cart|orders) with React Router 7 and domain feature isolation under web/src/features/{market}.

Outcome

Clean separation of global modules (auth, users, markets) from market-specific business rules.

Challenge

Complex 5-Layer Commission Calculation

Decision

Centralized calculation logic in domain modules (orderCommission.js / uiCommission.js), capturing base commissions, custom sell markups, delivery adjustments, COD fees, packing charges, and invoice deductions in an immutable ui_calculation order snapshot.

Outcome

Complete transparency for resellers at checkout and frictionless financial reconciliation.

Challenge

Firestore Read Quota Optimization

Decision

Implemented 250ms debounced searching, cursor-based pagination, bounded page limits, no-op write guards on quantity updates, and chunked status queries (submitted, placed, cancelled).

Outcome

Reduced Firestore read operations by over 60% while maintaining instantaneous UI responsiveness.

Challenge

Customer Order Book Intelligence

Decision

Built a derived customer_order_book projection supporting dual-mode operation (projection mode with legacy fallback) with lazy-loaded row expansions.

Outcome

Instant KPI dashboard (effective quantities, order totals, commission rollups) without scanning the entire orders collection.

Before → after

Cross-Border Resellers, Wholesale Importers & K-Beauty Retail Operations

Before

Manual Price Copying & Catalog Drift

Resellers spent hours manually browsing UK wholesale websites and copying GBP prices into spreadsheets, causing stockouts and stale exchange rates.

After

Automated Python Scraping & Ingestion Pipelines

Engineered automated ETL scrapers for kobareseller.com (session/CSRF auth) and WooCommerce APIs, automatically upserting categorized catalog items.

Before

Disputed Multi-Tier Commission Calculations

Calculating custom price markups, delivery charge adjustments, COD percentages, and packing fees by hand led to payout reconciliation errors.

After

Deterministic 5-Layer UI Commission Engine

Built a centralized mathematical calculation engine that computes live breakdowns at checkout and persists immutable snapshots on orders.

Before

Firestore Quota Inflation & High Read Costs

Unbounded Firestore queries on large order catalogs rapidly consumed free quotas and caused UI slowdowns during search.

After

Quota-Optimized Querying & Derived Projections

Implemented debounced searches, cursor pagination, status-filtered batch reads, and derived Customer Order Book collections.

Stack

FrontendReact 19 + Vite 7TypeScriptTailwindCSS + Radix / ShadCN UITanStack React Query v5React Router 7 (HashRouter Market Scopes)Lucide React

BackendFirebase AuthenticationCloud Firestore (Lite SDK)Firestore Security Rules (Role-Based ACL)Python 3 ETL Web Scrapers (Session/CSRF & WooCommerce REST)

DatabaseCloud Firestore (Market-Scoped Collections & Derived Projections)PostgreSQL Schema (Target Migration Engine & Indexed Views)

DevOpsFirebase HostingZero-Read Maintenance GateAutomated Scrape & Deploy PipelinesGit & GitHub

Security

  • Granular Firestore Security Rules with role-based access control (superadmin, admin, ops, sales, customer, investor).
  • Market-level data isolation restricting user queries to assigned markets.
  • Immutable relation fields (creator_user_id, ordered_by_user_id, customer_key) persisted on order documents.
  • Zero-read static maintenance mode toggle (web/public/maintenance.json) bypassing local development.
  • Relational PostgreSQL migration artifacts (schema, indexes, views) prepared for SQL backend cutover.

Roadmap

  • Dual-write runtime pipeline for Firestore to PostgreSQL live synchronization.
  • Courier webhook integration for automated courier tracking and status updates.
  • Automated reconciliation pipeline comparing Firestore documents with PostgreSQL records.
  • Multi-currency dynamic FX rate engine for real-time GBP to BDT conversion adjustments.

Executive Summary

BrandWala Retail (BW Retail) is a production-grade, market-aware cross-border commerce platform designed for cross-border consumer goods verticals — with its flagship deployment powering the K-Beauty (Korean Beauty) retail market.

The platform bridges international wholesale suppliers in the United Kingdom (Kobareseller, Koba International) with local resellers, retailers, and direct consumers in Bangladesh. Engineered with React 19, Vite 7, Tailwind CSS, TanStack React Query, and Firebase Firestore Lite, BW Retail automates the complete lifecycle: automated catalog scraping, market-scoped routing, dynamic 5-layer commission accounting, and quota-optimized customer intelligence.

flowchart TB
    subgraph Sourcing ["UK Wholesale Sourcing"]
        SCRAPE["Python ETL Scrapers<br/>Session/CSRF & WooCommerce APIs"] --> BRANDS["40+ K-Beauty Brands<br/>Auto-Tagging Engine"]
    end

    subgraph Data ["Firebase Cloud Firestore"]
        BRANDS --> PROD["markets/{market_id}/products"]
        PROD --> CART["carts/{email}/items"]
        CART --> ORDERS["markets/{market_id}/orders"]
        ORDERS --> PROJ["customer_order_book<br/>(Derived Projection)"]
        ORDERS --> ACCT["kbeauty_accounting_entries"]
    end

    subgraph Client ["React 19 Frontend SPA"]
        ROUTER["Market-Scoped Router<br/>/#/m/{marketSlug}/{vendorSlug}/*"]
        QUERY["TanStack Query v5<br/>Cache & Cursor Pagination"]
        UI["Radix / ShadCN Primitives<br/>Tailwind CSS"]
        CALC["5-Layer Commission Engine<br/>(ui_calculation snapshot)"]
    end

    Data <--> QUERY
    QUERY --> ROUTER --> UI
    UI --> CALC

The Cross-Border Problem

Operating cross-border commerce between the UK and Bangladesh creates unique architectural and operational challenges:

flowchart TD
    subgraph Legacy ["Legacy Manual Operations"]
        A["Browse UK wholesale sites manually"] --> B["Manually copy GBP prices to sheets"]
        B --> C["Hand-calculate COD %, packing, and margin"]
        C --> D["Take orders via WhatsApp chats"]
        D --> E["No repeat customer history or risk scoring"]
        E --> F["Firestore read costs explode from un-indexed scans"]
    end
Operational Challenge Architectural Solution in BW Retail
Stale Sourcing Prices Automated Python ETL ingestion pipelines fetching from session-authenticated supplier portals and WooCommerce APIs.
Multi-Tier Profit Sharing Deterministic 5-layer commission calculation engine snapshotting pricing, COD fees, and delivery charges on every order.
Firestore Read Quota Spikes Debounced search (250ms), cursor pagination, chunked status queries, and derived Customer Order Book projections.
Multi-Market Expansion Modular domain architecture separating global auth/users from market features (web/src/features/kbeauty).
Database Scalability Prepared PostgreSQL relational schema, indexed views, and migration scripts for seamless Firestore-to-SQL cutover.

Technical Architecture

1. Market-Aware & Vendor-Scoped Routing

The application enforces strict URL hierarchy and domain isolation using React Router:

  • Products Catalog: /#/m/{marketSlug}/{vendorSlug}/products
  • Shopping Cart: /#/m/{marketSlug}/{vendorSlug}/cart
  • Order Management: /#/m/{marketSlug}/{vendorSlug}/orders
  • Customer Purchase Book: /#/m/{marketSlug}/{vendorSlug}/customers

Global services (authentication, session state, market navigation) remain completely decoupled from market domain logic, allowing new retail verticals to plug into the platform without modifying core infrastructure.

flowchart LR
    URL["Route: /#/m/kbeauty/retail-1/orders"] --> GUARD["Market & Role Guards"]
    GUARD --> FEATURE["features/kbeauty/pages/OrdersPage.jsx"]
    FEATURE --> QUERY["useOrdersQuery (TanStack Query)"]
    QUERY --> FIRESTORE["Firestore: markets/kbeauty/orders"]

2. The 5-Layer Commission Engine

Every order computes net commissions deterministically through domain calculation pipelines (orderCommission.js & uiCommission.js), storing an immutable ui_calculation map directly on the order document:

flowchart TD
    subgraph Items ["Item Layer"]
        BASE["Base Wholesale Price (GBP)"]
        CUSTOM["Custom Reseller Sell Price (BDT)"]
        COMM["Base Product Commission"]
        EXTRA["Extra Profit = (Sell Price − Base Price) × Qty"]
    end

    subgraph Adjustments ["Order Deductions & Charges"]
        DEL["Delivery Adjustment (District / Thana)"]
        COD["COD Charge (Total × COD Rate %)"]
        PACK["Packing Flat Fee"]
        INV["Invoice Flat Fee"]
        FREE["Free Delivery Subsidy / Deduction"]
    end

    subgraph Output ["Settlement"]
        NET["Net Reseller Commission<br/>= Products Commission + Delivery Adjustment<br/>− COD Amount − Packing − Invoice − Free Delivery Deduction"]
    end

    BASE & CUSTOM & COMM --> EXTRA
    EXTRA & DEL & COD & PACK & INV & FREE --> NET

3. Quota Optimization & Derived Projections

To eliminate N+1 query fanout and high read costs on Firebase Firestore, BW Retail implements a comprehensive query optimization suite:

  1. Debounced Query Execution: 250ms debounce on search bars preventing per-keystroke document reads.
  2. Cursor-Based Pagination: Paginated document cursors with strict limit bounds.
  3. No-Op Write Guards: Quantity update handlers compare dirty state before dispatching writes.
  4. Derived Customer Order Book: A dedicated customer_order_book projection collection enabling instant KPI aggregation (effective quantities, order counts, gross spend) with lazy-loaded row expansions.
flowchart TD
    CRM["Customer Book Page"] --> CHECK{"Projection Exists?"}
    CHECK -- Yes --> PROJ["Projection Mode<br/>Read customer_order_book (1 read/customer)"]
    CHECK -- No --> FALLBACK["Legacy Fallback<br/>Aggregate active orders"]
    PROJ --> ROW["User Clicks Customer Row"]
    ROW --> LAZY["Lazy-Fetch Orders & Items on Demand"]

4. SQL & PostgreSQL Migration Readiness

To prepare the platform for enterprise relational throughput, a complete PostgreSQL migration architecture was designed:

  • Core Relational Schemas: sql/postgres/001_core_schema.sql
  • Performance Indexes: sql/postgres/002_indexes.sql
  • Customer Order Book SQL Views: sql/postgres/003_customer_order_book_view.sql

Personal Engineering Contributions

  • React 19 Frontend Architecture: Designed the market-aware component hierarchy, Radix/ShadCN UI design system, and TanStack Query state orchestration.
  • Python Automated Sourcing ETL: Developed web scrapers with session auth and CSRF management for UK wholesale platforms, implementing automated regex brand detection for 40+ brands.
  • Deterministic Commission Accounting: Authored the full 5-layer commission calculation engine, ensuring zero discrepancies across order creation, status changes, and quantity saves.
  • Firestore Cost Optimization: Reduced Firestore read volume by over 60% through debounced search pipelines, cursor pagination, and derived projection collections.
  • SQL Migration Strategy: Architected PostgreSQL database schemas, indexes, and SQL analytical views for long-term database scalability.

Case closed

More work.