Back to Case Studies

Storfront E-Commerce Platform

Storfront E-commerce / Retail
7+
Promotion Types
100%
Type-Safe
REST
API Architecture

Situation

E-commerce platforms either offer rigid templates or require extensive development. Merchants needed a flexible backend that could power custom storefronts while handling complex promotions, inventory, and multi-tenant isolation out of the box.

Task

Build a headless e-commerce API with multi-tenant architecture, a powerful rules-based promotion engine, cart/order management, and JWT authentication—designed to power any frontend.

Action

Developed a TypeScript monorepo using Express 5 for the REST API, Drizzle ORM with PostgreSQL 17 for type-safe data access, and Redis for session/cart caching. Implemented a sophisticated promotion engine supporting percentage, fixed amount, BOGO, bundles, tiered discounts, and free shipping rules.

Result

Delivered a production-ready headless e-commerce backend. The promotion engine supports 7+ discount types with composable conditions. The API handles guest and authenticated carts, order management, and multi-store isolation with tenant-scoped queries.

Technologies Used

Express 5 TypeScript Drizzle ORM PostgreSQL 17 Redis JWT Auth

The Challenge

Building an e-commerce backend from scratch is complex. Promotions alone require handling percentages, fixed amounts, buy-one-get-one, bundles, tiered pricing, and more—each with its own conditions and stacking rules. Storfront needed enterprise-grade capabilities without enterprise complexity.

Our Approach

We built Storfront as a headless API-first platform:

  1. Monorepo Structure — Turborepo with shared configs, ESLint rules, and TypeScript definitions
  2. Type-Safe Stack — Express 5 + TypeScript + Drizzle ORM for end-to-end type safety
  3. Service Layer Pattern — Routes handle HTTP, services contain business logic with Zod validation
  4. Multi-Tenant by Design — All queries scoped to storeId preventing data leakage

Promotion Engine

The rules-based promotion system supports:

TypeDescription
Percentage10% off entire order
Fixed Amount$5 off orders over $50
Buy X Get YBuy 2, get 1 free
BundleDiscount when buying specific items together
TieredIncreasing discounts at quantity thresholds
Free ShippingWaive shipping on qualifying orders
BOGOBuy one, get one at 50% off

Each promotion has composable conditions (min cart value, specific products, customer segments) and stacking rules.

Technical Highlights

  • Drizzle ORM — Type-safe SQL with automatic migrations
  • Cart System — Supports both authenticated customers and guest sessions
  • JWT Auth — Short-lived access tokens (15m) with refresh token rotation (7d)
  • Docker Compose — PostgreSQL, Redis, and Adminer for local development
  • Vitest — Fast, ESM-native unit testing

API Structure

/api/v1/auth                    # Login, register, refresh
/api/v1/stores/:storeId/products    # Product catalog
/api/v1/stores/:storeId/cart        # Cart operations
/api/v1/stores/:storeId/orders      # Order management
/api/v1/stores/:storeId/promotions  # Promotion CRUD

The Results

Storfront provides a solid foundation for any e-commerce frontend:

  • 7+ promotion types with composable conditions
  • 100% type-safe from database to API response
  • Multi-tenant ready with proper data isolation
  • Developer-friendly — Clear patterns, comprehensive tests

Ready to Write Your Success Story?

Let's discuss how we can help solve your technical challenges.

Let's Talk