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:
- Monorepo Structure — Turborepo with shared configs, ESLint rules, and TypeScript definitions
- Type-Safe Stack — Express 5 + TypeScript + Drizzle ORM for end-to-end type safety
- Service Layer Pattern — Routes handle HTTP, services contain business logic with Zod validation
- Multi-Tenant by Design — All queries scoped to
storeIdpreventing data leakage
Promotion Engine
The rules-based promotion system supports:
| Type | Description |
|---|---|
| Percentage | 10% off entire order |
| Fixed Amount | $5 off orders over $50 |
| Buy X Get Y | Buy 2, get 1 free |
| Bundle | Discount when buying specific items together |
| Tiered | Increasing discounts at quantity thresholds |
| Free Shipping | Waive shipping on qualifying orders |
| BOGO | Buy 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