Building PrismQTC: How I Built an Autonomous B2B Quote-to-Cash & Pricing Governance Platform
A deep-dive architectural post-mortem into native PostgreSQL RLS, PL/pg-SQL reactive triggers, real-time WebSocket negotiations, and split-warehouse fulfillment.

Most B2B software treats sales as a sequence of isolated, static records: a quotation generated as an un-editable PDF, followed by disconnected email chains, manual margin approvals in spreadsheets, detached warehouse inventory lookups, and un-reconciled billing runs.
When high-velocity B2B sales teams run into real-world operational turbulenceโsuch as complex multi-tier discount limits, stock dispersed across three different regional warehouses, mid-contract subscription proration, and external buyers demanding interactive negotiationโtraditional ERP setups like Odoo, Salesforce CPQ, or NetSuite generate immense operational friction.
To solve this, I designed and built PrismQTC (formerly DealFlow 360): a self-governing, multi-tenant B2B Sales Operations, Quote-to-Cash (QTC), and Deal Execution Platform.
In this comprehensive post, I am breaking down everything under the hood:
Why I rejected traditional ORMs in favor of PostgreSQL Row-Level Security (
SET LOCAL) and Column-Level Access Control (CLAC).How PL/pgSQL reactive triggers mathematically enforce discount ceilings and calculate blended risk scores.
How line items are dynamically split across regional warehouses with automatic backorders.
How bidirectional WebSockets power live customer counter-offers and quote locking.
How client-side vector PDF and Word (
.docx) engines eliminate document generation server load.The complete DevOps orchestration spanning Nginx, Redis Stack, BullMQ, Prometheus, Loki, and Grafana.
๐ Table of Contents & Full Content Modules
Every single module, architectural diagram, code block, and formula is contained directly inside the sections below:
1. High-Level System Topology & Architecture
The platform is designed around a decoupled, high-throughput micro-modular topology:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ FRONTEND LAYER โ
โ React 19 (SPA) โ TypeScript 5.8 โ Vite 6 โ
โ Tailwind CSS v4 โ Socket.IO โ Motion + Lucide โ
โ SWR Cache โ Axios Client โ jsPDF + docx โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ HTTP / WebSocket (Port 80)
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ GATEWAY & REVERSE PROXY โ
โ Nginx (Alpine) โ Routing, Assets, Caching, WS Upgrade โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโ
โผ โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ BACKEND API โ โ ASYNC WORKERS & CACHE โ
โ Node.js (ESM) + Express โ โ Redis Stack 7 (Broker/AOF) โ
โ Socket.IO Real-Time Hub โ โ BullMQ Job Queue Workers โ
โ Argon2 + Dual JWT Auth โ โ node-cron Schedule Engine โ
โ Raw pg (withTenantContext)โ โ RedisInsight Web Dashboard โ
โโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโ
โ โ
โโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ DATABASE LAYER โ
โ PostgreSQL 16 Alpine โ
โ โโ Row-Level Security (RLS) & Column Grants (CLAC) โ
โ โโ PL/pgSQL Reactive Triggers (Margin & Risk Math) โ
โ โโ Stored Procedures (Atomic Orders, Stalled Sweeps) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Metrics & Log Streams
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ OBSERVABILITY & MONITORING โ
โ Prometheus v2.52 (Metrics) โ Loki v3.0 (Log Streams) โ
โ Grafana v11.0 (Pre-Provisioned Unified Dashboards) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Complete Technology Stack Matrix
| Component | Technology | Role in PrismQTC |
|---|---|---|
| Frontend | React 19 + TS 5.8 | Concurrent rendering, deal builder |
| Build Tool | Vite 6 | Lightning-fast HMR, ESM bundles |
| Styling | Tailwind v4 + Tokens | Pure CSS tokens, zero runtime |
| Animation | Motion (motion) |
Spring physics, fluid drawers |
| Data Fetch | Axios + SWR | Optimistic cache revalidation |
| Real-Time | Socket.IO | Bidirectional room negotiation |
| Backend API | Node.js + Express | RESTful services, security guards |
| Database | PostgreSQL 16 | Primary datastore, RLS, triggers |
| Queue | BullMQ + Redis | Background jobs, rate limiting |
| Auth | Argon2 + Dual JWT | HttpOnly role-isolated cookies |
| Payments | Razorpay SDK | Cryptographic webhook capture |
| Gateway | Nginx Alpine | SSL, reverse proxy, WS upgrade |
| Telemetry | Prometheus + Loki | Scrapes /metrics, log ingestion |
| Dashboard | Grafana 11 | Unified metrics & log viewer |
2. Database Architecture & Zero-Trust Multi-Tenancy
Why I Ditched ORMs for Native PostgreSQL Drivers
Most enterprise applications implement multi-tenancy by appending WHERE tenant_id = ? to every query via an ORM middleware. A single developer omission, an un-scoped raw query, or an ORM bug can cause cross-tenant data leaks.
In PrismQTC, multi-tenancy is enforced directly by PostgreSQL using Row-Level Security (RLS) with transaction-scoped configuration settings:
BEGIN;
-- Scoped strictly to this transaction block
SET LOCAL app.current_tenant_id = 'a1b2c3d4-e5f6...';
SET LOCAL app.current_actor_type = 'staff';
SET LOCAL app.current_user_id = 'f9e8d7c6-b5a4...';
SET LOCAL app.current_role = 'sales_rep';
SET LOCAL ROLE app_role_staff;
-- The kernel guarantees no other tenant rows can be read
SELECT id, quote_number, total_amount
FROM quotations
WHERE id = $1;
COMMIT;
Why SET LOCAL is Crucial
SET LOCAL guarantees that session configuration variables vanish automatically on COMMIT or ROLLBACK. When connections return to the node-postgres pool, no cross-tenant parameters linger.
All operational tables declare:
ALTER TABLE quotations ENABLE ROW LEVEL SECURITY;
ALTER TABLE quotations FORCE ROW LEVEL SECURITY;
CREATE POLICY tenant_isolation_policy ON quotations
FOR ALL
USING (
tenant_id = current_setting('app.current_tenant_id', true)::UUID
);
Column-Level Access Control (CLAC)
RLS restricts rows, not columns. To stop external customers from seeing sensitive columns like unit_cost, total_cost, line_margin_pct, or blended_risk_score, PrismQTC establishes two database roles:
app_role_staff: Full read/write access to all table columns.app_role_customer_portal: Strict column whitelist:
GRANT SELECT (
id, tenant_id, quote_number, status,
subtotal_amount, tax_amount, total_amount,
currency, customer_notes, created_at
) ON quotations TO app_role_customer_portal;
-- Customer portal role CANNOT select unit_cost or line_margin_pct
-- Attempting to query them triggers an instant database error
Complete Schema Entity Map (18 Tables)
tenants: Multi-tenant organization boundaries, subdomains, currencies.users: Internal staff members (Admins, Sales Managers, Reps, Finance).customers: Client organizations assigned to tiers (BronzetoPlatinum).customer_portal_users: External customer contacts authenticated via magic links.product_categories: Category discount ceilings (e.g., Hardware 10%, Services 15%).products: Base catalog items, inventory levels, cost vs retail, tax rates.product_variants: Attribute variations with price deltas.price_lists&price_list_items: Tier-specific price overrides per currency.upsell_rules: Product recommendation triggers based on margin thresholds.quotation_requests&items: Inbound customer RFQs from the portal.tier_discount_ceilings: Category-level discount thresholds per customer tier.quotations"ation_lines: The core living transaction document.approval_audit_logs: Immutable ledger of manager/finance approval decisions.quotation_negotiation_threads: Real-time chat threads and counter-offers.shipments&shipment_items: Split-warehouse dispatch tracking and backorders.invoices&invoice_lines: Reconciled billing statements with delivery matching.subscriptions: Contract recurrence schedules and seat proration parameters.deal_health_alerts: Proactive anomaly flags (stalled deals, margin breaches).
3. The Pricing Governance & Blended Risk Engine
In high-volume B2B sales, reps often slash prices to hit quotas, eroding margins. PrismQTC automates pricing discipline directly inside the PostgreSQL database engine.
The Blended Risk Score Formula
The platform computes a mathematically weighted Blended Risk Score ($0 - 10$ scale) for every quotation:
\text{Blended Risk Score} = \sum_{i=1}^{n} \left( \frac{\text{Line Total}i}{\text{Quote Total}} \times \text{Risk}i \right) + \Delta{\text{Margin}} + \Delta{\text{Rep}}Where:
- \(\text{Line Discount} \le \text{Tier Ceiling} \implies \text{Risk} = 0\)
- \(\text{Line Discount} > \text{Tier Ceiling} \implies \text{Risk} = \left(\frac{\text{Discount} - \text{Ceiling}}{\text{Ceiling}}\right) \times 10\)
- \(\Delta_{\text{Margin}}\) triggers if Gross Margin drops below the company floor ($18%$).
- \(\Delta_{\text{Rep}}\) factors in the rep's trailing discount history.
Visual Risk Thresholds
- ๐ข Score $< 5.0$ (Low Risk): Complies with ceilings; instant client dispatch permitted.
- ๐ก Score \(= 5.0\) (Moderate Risk): Max ceiling reached; advisory review suggested.
- ๐ด Score $> 5.0$ (Critical Risk): Threshold breached; auto-routed to approval queue.
Reactive PL/pgSQL Trigger Engine
Calculations are executed instantly by PostgreSQL triggers:
CREATE OR REPLACE FUNCTION trg_calculate_quote_line_financials() RETURNS TRIGGER AS $$ DECLARE v_unit_cost NUMERIC(12, 2); BEGIN SELECT unit_cost INTO v_unit_cost FROM products WHERE id = NEW.product_id;NEW.line_subtotal := NEW.quantity * NEW.unit_price; NEW.line_discount_amount := NEW.line_subtotal * (NEW.applied_discount_pct / 100.0); NEW.line_total := NEW.line_subtotal - NEW.line_discount_amount; NEW.line_cost_subtotal := NEW.quantity * v_unit_cost;IF NEW.line_total > 0 THEN NEW.line_margin_pct := ((NEW.line_total - NEW.line_cost_subtotal) / NEW.line_total) * 100.0; ELSE NEW.line_margin_pct := 0.0; END IF;
RETURN NEW;END; $$ LANGUAGE plpgsql;
CREATE TRIGGER trg_quote_lines_calc BEFORE INSERT OR UPDATE ON quotation_lines FOR EACH ROW EXECUTE FUNCTION trg_calculate_quote_line_financials();
Multi-Tier Approval Chain Automation
When a quote breaches risk limits:
- Manager Tier ($>10%$ Discount): Moves to
pending_manager. - Finance Tier ($>15%$ Discount or Gross Margin $< 20%$): Moves to
pending_finance. - Every decision writes an immutable log to
approval_audit_logs.
4. Smart Split-Warehouse Fulfillment & Backorders
When inventory is dispersed across regional facilities, PrismQTC dynamically splits line items across depots:
[ PRISMQTC ORDER #PQ-9281 ]
|
+-----------+-----------+
| |
[ MAIN WAREHOUSE ] [ EAST DEPOT ]
* 85 Units In-Stock * 15 Units In-Stock
* Lowest Zone Rate * Regional Express
| |
[ SHIPMENT #01 ] [ SHIPMENT #02 ]
\ /
+----------+----------+
|
[ BACKORDER CONSOLIDATED ]
[ TRANSIT COST MINIMIZED ]
Split Shipment Execution Flow
- Evaluates inventory for each line item in real-time.
- If Warehouse A has partial stock, it creates Shipment #01 and assigns a tracking number.
- The remaining quantity routes to Warehouse B (Shipment #02) or an Automated Backorder.
- Invoices map directly to
shipment_idrecords, ensuring buyers are billed only for delivered inventory.
5. Real-Time Customer Portal & Living Contract Negotiation
PrismQTC replaces static email PDFs with a synchronized Customer Portal (/portal).
Dual-Token Authentication
- Internal staff authenticate via
/api/auth/loginand receive a staff JWT in anhttpOnlycookie. - External buyers authenticate via
/api/portal/auth/loginor magic links, receiving a scoped customer portal token.
Bidirectional WebSocket Negotiation
Powered by Socket.IO:
const socket = io({ path: '/socket.io' });
useEffect(() => {
socket.emit('join:quote_negotiation', { quoteId });
socket.on('quote:counter_offer_received', (data) => {
toast.info(`Counter-offer submitted: โน${data.newTotal}`);
mutate(); // Optimistic SWR refresh
});
socket.on('quote:locked_by_staff', () => {
setIsLocked(true);
toast.warning('Quote is under management review.');
});
return () => {
socket.emit('leave:quote_negotiation', { quoteId });
};
}, [quoteId]);
Atomic Confirmation via Stored Procedure
Accepting a proposal executes an atomic PostgreSQL stored procedure:
CREATE OR REPLACE PROCEDURE sp_customer_confirm_quotation(
p_quotation_id UUID,
p_customer_id UUID,
p_portal_user_id UUID
)
LANGUAGE plpgsql
AS $$
BEGIN
PERFORM 1 FROM quotations
WHERE id = p_quotation_id
AND customer_id = p_customer_id
AND status IN ('sent', 'under_negotiation')
FOR UPDATE;
IF NOT FOUND THEN
RAISE EXCEPTION 'Quotation cannot be confirmed in current state.';
END IF;
UPDATE quotations
SET status = 'confirmed',
confirmed_at = NOW(),
confirmed_by_portal_user_id = p_portal_user_id
WHERE id = p_quotation_id;
PERFORM fn_allocate_split_warehouse_shipments(p_quotation_id);
END;
$$;
6. Hybrid Contract Billing, Invoicing & Razorpay Settlement
Deals bundle one-off hardware, professional services, and recurring subscriptions into a single contract schedule.
Hybrid Order Proration
Subscriptions compute day-precise seat proration when licenses are added mid-billing cycle:
\text{Prorated Charge} = \frac{\text{Days Remaining in Cycle}}{\text{Total Days in Cycle}} \times (\text{Seat Count} \times \text{Seat Price})4-Stage Invoicing Stepper
[ Order Confirmed ] โโโถ [ Shipped ] โโโถ [ Invoiced ] โโโถ [ Paid ]
Razorpay Integration
- Backend creates an order via Razorpay SDK (
razorpay.orders.create). - Client mounts checkout modal with brand accents (
#ff3b30). - Backend cryptographically verifies the payment signature (
crypto.createHmac('sha256', secret)) before marking the invoice asPAID.
7. Deal Health, Telemetry & Autonomous Anomaly Detection
The Deal Health Dashboard (/dealhealth) monitors three automated anomaly sweeps:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ DEAL HEALTH RADAR โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ [STALLED] Quote #QT-4401 | 14 Days Inactive | Action โ
โ [MARGIN] Quote #QT-9920 | Rep: R. Rep (-6.2% vs Avg) โ
โ [SLIPPAGE] Depot East Shortfall on SKU: SRV-2U-PRO โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
- Stalled Deals: Flags quotations idling past expected closing dates.
- Discount Anomalies: Rolling z-score analysis flags quotes where discounts exceed a rep's 90-day baseline.
- Delivery Slippage: Detects backorders threatening customer delivery SLAs.
- Autonomous Sweeper:
governanceSweeper.jsexecutessp_flag_stalled_deals()hourly vianode-cron.
8. Frontend Engineering: React 19, Vite & Design Token System
Modern React 19 Architecture
- Zero Heavy UI Kits: Built with native Tailwind CSS v4 and a unified token system.
- SWR Caching: Real-time optimistic mutations across tables, modals, and badges.
- Role-Based Routing: Guards enforce route access by user role (
admin,sales_manager,sales_rep,finance,customer).
Global CSS Design System (frontend/src/global css/)
tokens.css: Color ramps, semantic states (--app-brand-red: #ff3b30), border radiuses.tables.css: High-density ledger styling with sticky headers and numeric alignments.cards.css: Clean, border-accented containers with subtle elevation.badges.css: High-contrast WCAG AAA compliant workflow badges.modals.css: Fluid backdrop blurs and focus traps.
The Landing Page Experience
- Kinetic Scramble CTA Buttons: Characters scramble on hover using monospace text manipulation.
- Word-by-Word Scroll Darkening:
ManifestoScrollSection.tsxdarkens words as the user scrolls. - Crosshairs & Target Glyphs: Blueprint design accents (
RedCrosshair.tsx). - Terminal ASCII Art: High-contrast system topologies rendered in pure text.
9. Zero-Server Document Engine: Vector PDF & Native Word .DOCX
PrismQTC performs 100% of document assembly client-side in the browser, saving significant server memory.
Vector PDF via jspdf & jspdf-autotable
Renders high-DPI vector PDFs directly in memory with branded headers and itemized financial tables:
export async function exportInvoicePDF(invoice: any) { const doc = new jsPDF();doc.setFillColor(15, 23, 42); doc.rect(0, 0, 210, 32, 'F');
doc.setTextColor(255, 255, 255); doc.setFontSize(18); doc.setFont('helvetica', 'bold'); doc.text('PRISMQTC', 14, 16);
autoTable(doc, { startY: 45, head: [['#', 'SKU / Item', 'Qty', 'Unit Price', 'Total']], body: invoice.lines.map((l: any, i: number) => [ i + 1, l.name, l.quantity,
โน${l.unit_price},โน${l.total}]), theme: 'grid', headStyles: { fillColor: [15, 23, 42] }, });
doc.save(Invoice_${invoice.invoice_number}.pdf); }
Native Word (.docx) via docx
Builds real Microsoft Word .docx documents with native paragraph runs, table shading, and styling, dispatched directly via file-saver.
10. DevOps, Observability & Container Topology
The entire stack is containerized with Docker and Docker Compose (docker-compose.yml):
docker compose up -d
Infrastructure Container Fleet
| Service | Image | Port | Responsibility |
|---|---|---|---|
| Nginx | nginx:alpine |
80 | Gateway & reverse proxy |
| Postgres | postgres:16 |
5432 | Primary RLS database |
| Redis | redis-stack |
6379 | Cache, queues & GUI |
| Prometheus | prometheus |
9090 | Metric scraper |
| Loki | loki:3.0 |
3100 | Log aggregator |
| Grafana | grafana:11 |
3001 | Observability dashboards |
Real-Time Observability
- Prometheus Metrics: Backend exposes
/metricsmeasuring response latencies, status codes, and connection pool saturation. - Loki Log Ingestion: Structured JSON application logging with request trace IDs.
- RedisInsight: GUI exposed on port
8001for real-time queue inspection and key-space debugging.
Distributed Rate Limiting & Brute-Force Defense
To safeguard authentication and financial endpoints across multi-tenant deployments, PrismQTC integrates distributed rate limiting:
- Redis-Backed State Store: Uses
express-rate-limitpaired withrate-limit-redis, synchronizing rate limit counters across all backend instances via Redis key prefixrl:auth:. - Targeted Sliding Window: Enforces a 15-minute window permitting up to 50 attempts per IP address (
windowMs: 15 * 60 * 1000, max: 50). - Selective POST Filtering: Selectively targets credential submissions (
skip: (req) => req.method !== 'POST'), preventing unnecessary throttling on read traffic. - Fail-Open Resilience: Configured with
passOnStoreError: true, ensuring enterprise users are never blocked during brief Redis reconnections.
Async Worker Queues, Schedulers & Transactional SMTP
- BullMQ Task Queues: Decouples heavy background operations (audit logs, alerts) from the HTTP cycle with Redis Stack as the message broker.
- Autonomous Node-Cron Sweepers: Runs scheduled background tasks hourly, calling
sp_flag_stalled_deals()to flag inactive deals and notify account owners. - Nodemailer Transactional SMTP: Automatically fires email dispatches when approvals are submitted, counter-offers arrive, or deals are confirmed.
11. Architectural Tradeoffs, Lessons Learned & What's Next
๐ก Key Lessons
- Push calculations to the database kernel: Offloading margin math and risk thresholds to PL/pgSQL triggers eliminated race conditions and made discount rules tamper-proof.
- Client-side document compilation is an enterprise superpower: Generating PDFs and DOCX files entirely in the client saved significant server memory and eliminated a major infrastructure bottleneck.
- Multi-tenancy belongs in the database, not in application logic: Using transaction-scoped PostgreSQL session variables (
SET LOCAL) provided true zero-trust isolation without the maintenance burden of manually appending tenant IDs across hundreds of queries.
๐ฎ Future Roadmap
- Autonomous AI RFP Parsing: Ingesting messy PDF RFQs directly into structured quote lines using Gemini Flash.
- Dynamic Currency Hedging: Automatic real-time foreign exchange adjustments on multi-currency quotations.
- EDI 850 / 810 Connectors: Native electronic data interchange integration for enterprise supply chain partners.
๐ Summary
PrismQTC demonstrates that high-velocity B2B sales operations don't need to suffer under the weight of slow, rigid enterprise software. By pairing PostgreSQL's native security kernel with a modern React 19 real-time client, we can build sales systems that are self-governing, mathematically sound, and a pleasure to use.
Built with React 19, TypeScript, Node.js, PostgreSQL 16, Redis Stack, and Docker.
System Topology & Architecture
The platform is designed around a decoupled, high-throughput micro-modular topology:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ FRONTEND LAYER โ
โ React 19 (SPA) โ TypeScript 5.8 โ Vite 6 โ
โ Tailwind CSS v4 โ Socket.IO โ Motion + Lucide โ
โ SWR Cache โ Axios Client โ jsPDF + docx โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ HTTP / WebSocket (Port 80)
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ GATEWAY & REVERSE PROXY โ
โ Nginx (Alpine) โ Routing, Assets, Caching, WS Upgrade โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโ
โผ โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ BACKEND API โ โ ASYNC WORKERS & CACHE โ
โ Node.js (ESM) + Express โ โ Redis Stack 7 (Broker/AOF) โ
โ Socket.IO Real-Time Hub โ โ BullMQ Job Queue Workers โ
โ Argon2 + Dual JWT Auth โ โ node-cron Schedule Engine โ
โ Raw pg (withTenantContext)โ โ RedisInsight Web Dashboard โ
โโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโ
โ โ
โโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ DATABASE LAYER โ
โ PostgreSQL 16 Alpine โ
โ โโ Row-Level Security (RLS) & Column Grants (CLAC) โ
โ โโ PL/pgSQL Reactive Triggers (Margin & Risk Math) โ
โ โโ Stored Procedures (Atomic Orders, Stalled Sweeps) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Metrics & Log Streams
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ OBSERVABILITY & MONITORING โ
โ Prometheus v2.52 (Metrics) โ Loki v3.0 (Log Streams) โ
โ Grafana v11.0 (Pre-Provisioned Unified Dashboards) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Visual Workflow Analogy: The End-to-End Deal Lifecycle
To understand how PrismQTC functions as a cohesive whole, here is the complete end-to-end operational flow from initial deal inception to cash collection and telemetry:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ PRISMQTC DEAL LIFECYCLE โ
โ End-to-End Autonomous Quote-to-Cash Workflow โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ STEP 1: DEAL CREATION & PRICING โ
โ โข Sales Rep crafts Quote or Buyer submits Portal RFQ โ
โ โข Contextual Upsell Engine suggests high-margin add-ons โ
โ โข Instant PL/pgSQL triggers calculate margins & totals โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ STEP 2: BLENDED RISK GATE & GOVERNANCE โ
โ โข Compares line discounts against Customer Tier Caps โ
โ โข Calculates Blended Risk Score (0 - 10 scale) โ
โ โโ Risk < 5.0 โโโถ Instant Customer Dispatch โ
โ โโ Risk โฅ 5.0 โโโถ Multi-Tier Approval Chain โ
โ (Sales Manager โ Finance Director) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Approved & Dispatched
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ STEP 3: LIVE PORTAL & BIDIRECTIONAL NEGOTIATION โ
โ โข Buyer logs in via Magic Link or Portal Password โ
โ โข Real-Time WebSockets sync live chat & counter-offers โ
โ โข Buyer clicks Accept โ sp_customer_confirm_quotation โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Atomic Deal Confirmation
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ STEP 4: SMART SPLIT-WAREHOUSE FULFILLMENT โ
โ โข Algorithm checks stock across 3 regional depots โ
โ โข Auto-splits order: Shipment #1 (Central) + #2 (East) โ
โ โข Auto-generates Backorder records for stock deficits โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Dispatches Verified
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ STEP 5: HYBRID RECONCILED BILLING & SETTLEMENT โ
โ โข Invoices generated strictly matching delivered stock โ
โ โข Daily proration calculated for recurring licenses โ
โ โข Buyer settles payment online via Razorpay Gateway โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Payment Verified (PAID)
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ STEP 6: EXECUTIVE TELEMETRY & AUDIT LEDGER โ
โ โข Deal Health Radar tracks margin velocity & win-rate โ
โ โข Background cron sweeper flags stalled deal anomalies โ
โ โข Immutable ledger sealed in approval_audit_logs โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ๏ธ The Mental Analogy: The Airport Flight Control System
Think of PrismQTC like an autonomous international airport:
The Flight Plan (Step 1 โ Quotation Builder): The sales rep plans the route, selecting hardware and subscription seats. The catalog automatically suggests fuel-efficient flight corridors (upsell add-ons).
Air Traffic Control Clearance (Step 2 โ Blended Risk Gate): Before takeoff, the flight plan is checked against strict airspace rules. Standard flights (discounts $< 5.0$) get immediate takeoff clearance. High-risk flights (discounts \(\ge 5.0\)) are held on the runway until approved by the Tower Supervisor (Sales Manager) and Airfield Director (Finance).
The Passenger Boarding Gate (Step 3 โ Customer Portal): The passenger (buyer) steps into the live terminal. If they request a seat upgrade or price adjustment, the ground crew and passenger negotiate in real time over radio (WebSockets). Once both agree, the boarding door seals atomically (
sp_customer_confirm_quotation).Baggage Routing Across Terminals (Step 4 โ Split-Warehouse Fulfillment): Heavy cargo is split intelligently across whichever regional cargo terminals currently have space, without stalling the passenger flight. Missing bags are automatically assigned tracking numbers as priority backorders.
Customs & Duty Settlement (Step 5 โ Invoices & Razorpay): Charges are billed strictly for cargo that has actually arrived at the gate, recurring tickets are prorated to the day, and duty is paid at the instant payment kiosk (Razorpay).
The Black Box Flight Recorder (Step 6 โ Deal Health & Telemetry): Every telemetry reading, altitude change, and approval decision is permanently etched into the flight recorder (
approval_audit_logs), while radar sweeps detect stalled aircraft before any collisions occur.
