I spent the last few months building a complete B2B wholesale operating system from scratch. Here's a deep dive into the architecture and challenges I solved.
The Problem
Most small wholesale suppliers still manage orders over WhatsApp, email, and spreadsheets. There's no affordable tool built specifically for them. I set out to build one.
Tech Stack
- Next.js 14 (App Router)
- Supabase (PostgreSQL + Row Level Security + Auth)
- Stripe Connect (buyers pay merchants directly)
- Tailwind CSS + Framer Motion
- Resend (transactional emails)
- Vercel (deployment)
Architecture Decisions
1. Multi-Tenancy with Row Level Security
Each merchant gets their own store. Instead of separate databases, I used Supabase RLS to isolate data at the row level. This means every query is automatically scoped to the user's store — no middleware needed.
2. Stripe Connect for Marketplace Payments
Buyers pay merchants directly through Stripe Connect. The platform takes a 2% fee per transaction. Each merchant onboards through Stripe's hosted flow — no API keys needed from their side.
3. Pricing Engine
B2B pricing is complex. I built a pricing engine that handles:
- MOQ (Minimum Order Quantity) — products can require a minimum purchase
- Tier pricing — buy 10+ for $8, buy 100+ for $6
- Trade codes — VIP customers get custom discounts
- Per-customer price lists — override pricing for specific buyers
4. Webhook System
For ERP/CRM integrations, I built a webhook system with:
- HMAC-SHA256 signed payloads
- Automatic retry (3 attempts with backoff)
- Delivery logs with status tracking
5. Role-Based Team Access
Not every team member needs full admin access:
- Owner — full control
- Manager — orders + products
- Fulfillment — shipping only
- Read-only — view dashboard
What I Learned
- Supabase RLS is powerful but tricky — one wrong policy and you either leak data or block everything
- Stripe Connect onboarding has edge cases — handle account deauthorization gracefully
- B2B UX is different from B2C — buyers want efficiency (list view, CSV upload, quick reorder), not pretty product galleries
Result
The platform includes:
- Buyer-facing storefront with cart, search, categories
- Full admin dashboard (products, orders, quotes, buyers, team, billing)
- Stripe payments + bank wire option
- REST API + webhooks
- Custom domain support
- Email notifications
I packaged the entire codebase as a starter kit for developers who want to build similar B2B platforms: B2B Wholesale OS on Gumroad
Happy to answer any questions about the architecture!
Top comments (0)