Bullion Exchange
Multi-tenant SaaS platform displaying live gold and silver market rates.
Project Overview
- ❯Dynamic subdomain architecture (e.g., shopname.bullion.sumitgogia.in)
- ❯Cloudflare Wildcard DNS and custom Caddy Reverse Proxy for auto Let's Encrypt SSL
- ❯Next.js frontend (Port 8011) uses proxy.ts to extract tenant slug for UI context
- ❯NestJS backend (Port 8012) queries MySQL via Prisma based on tenant slug
Architecture
Documentation and notes for Architecture.
The Bullion Exchange platform operates on a robust, scalable multi-tenant architecture. Designed to support infinite shop subdomains dynamically, the system cleanly separates the presentation layer, business logic, and database state for maximum security and performance.
1 Request Interception
Cloudflare Wildcard DNS routes all subdomain requests to a central Caddy reverse proxy, which instantly secures the connection using Let's Encrypt.
2 Tenant Resolution
The Next.js frontend uses custom proxy middleware to extract the tenant slug directly from the URL to fetch appropriate UI context.
3 API Execution
NestJS isolates data per tenant by aggressively filtering Prisma queries using the resolved shop ID, ensuring strict cross-tenant data boundaries.
Complete System Request Flow
Database Schema
Documentation and notes for Database Schema.
Our data foundation is built on MySQL and accessed safely via the Prisma ORM. At the heart of the schema is the SHOP entity, which represents an individual tenant on the platform. All major operational tables maintain a foreign key relationship to enforce strict tenant-level data isolation.
ADMIN & SHOP
Global administrators provision new shops with strict validUntil expiry dates. The SHOP table stores margins, configurations, and branding.
BUYER
End-customers mapped specifically to a single shop, complete with individually managed trading limits and balances.
ORDER (Fulfillment)
Tenant-isolated table tracking every trade booked (By Amount or Quantity), its locked rate, and its fulfillment status (Pending/Delivered).
PRODUCT & UPDATES
The actual commodities linked to Angel Broking live feeds, and a micro-blogging system for shop-wide market updates.
User Flow
Documentation and notes for User Flow.
The Bullion Exchange is designed to facilitate a smooth, frictionless pipeline from the moment an admin provisions a new tenant, to the exact second an end-customer books a live commodity trade.
Shop owners are empowered with immediate control over their margins and banking details. Once configured, their customers experience a bespoke trading environment locked to the shop's unique pricing rules. The system seamlessly handles all limit deductions, order placement, and transaction finalization securely in the background.
Caddy Configuration
Documentation and notes for Caddy Configuration.
Handling SSL certificates manually for every new tenant is unscalable. We deployed Caddy as our edge proxy because of its native ACME integration. Caddy communicates directly with the Cloudflare API via DNS challenges to automatically provision Let's Encrypt wildcard certificates.
Beyond SSL termination, Caddy acts as an intelligent Layer 7 router. It inspects the incoming request paths and silently proxies traffic to different internal ports: pushing standard web traffic to Next.js (Port 8011), while redirecting API and WebSocket traffic directly to the NestJS backend (Port 8012).