Skip to main content

Command Palette

Search for a command to run...

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.

Updated
โ€ข18 min readโ€ขView as Markdown
Building PrismQTC: How I Built an Autonomous B2B Quote-to-Cash & Pricing Governance Platform
A
Software Engineer focused on building production-ready applications. Passionate about crafting modern interfaces with Framer Motion and also integrating and building robust APIs with Node.js, managing database architectures, and integrating AI endpoints to power real-world applications.

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:

  1. app_role_staff: Full read/write access to all table columns.
  2. 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 (Bronze to Platinum).
  • 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 & quotation_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:

  1. Manager Tier ($>10%$ Discount): Moves to pending_manager.
  2. Finance Tier ($>15%$ Discount or Gross Margin $< 20%$): Moves to pending_finance.
  3. 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

  1. Evaluates inventory for each line item in real-time.
  2. If Warehouse A has partial stock, it creates Shipment #01 and assigns a tracking number.
  3. The remaining quantity routes to Warehouse B (Shipment #02) or an Automated Backorder.
  4. Invoices map directly to shipment_id records, 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/login and receive a staff JWT in an httpOnly cookie.
  • External buyers authenticate via /api/portal/auth/login or 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

  1. Backend creates an order via Razorpay SDK (razorpay.orders.create).
  2. Client mounts checkout modal with brand accents (#ff3b30).
  3. Backend cryptographically verifies the payment signature (crypto.createHmac('sha256', secret)) before marking the invoice as PAID.

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      โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  1. Stalled Deals: Flags quotations idling past expected closing dates.
  2. Discount Anomalies: Rolling z-score analysis flags quotes where discounts exceed a rep's 90-day baseline.
  3. Delivery Slippage: Detects backorders threatening customer delivery SLAs.
  4. Autonomous Sweeper: governanceSweeper.js executes sp_flag_stalled_deals() hourly via node-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.tsx darkens 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 /metrics measuring response latencies, status codes, and connection pool saturation.
  • Loki Log Ingestion: Structured JSON application logging with request trace IDs.
  • RedisInsight: GUI exposed on port 8001 for 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-limit paired with rate-limit-redis, synchronizing rate limit counters across all backend instances via Redis key prefix rl: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

  1. 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.
  2. 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.
  3. 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:

  1. 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).

  2. 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).

  3. 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).

  4. 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.

  5. 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).

  6. 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.

Stack & Scale

Part 1 of 1

Threading together complex backend logic and modern frontend design. This series explores the complete lifecycle of real-world web projectsโ€”documenting architectural decisions, database modeling, DevOps pipelines, and the pursuit of perfect UI/UX.