<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Divyansh Nagar</title>
    <description>The latest articles on DEV Community by Divyansh Nagar (@diivy_in).</description>
    <link>https://dev.to/diivy_in</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3371174%2F04d03fb5-adae-4e0e-91b8-49cbe3b2b4a7.jpg</url>
      <title>DEV Community: Divyansh Nagar</title>
      <link>https://dev.to/diivy_in</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/diivy_in"/>
    <language>en</language>
    <item>
      <title>MarginLeak : Accounts-payable auditor for small businesses</title>
      <dc:creator>Divyansh Nagar</dc:creator>
      <pubDate>Tue, 13 Oct 2026 22:31:56 +0000</pubDate>
      <link>https://dev.to/diivy_in/marginleak-open-source-accounts-payable-auditor-for-small-businesses-cji</link>
      <guid>https://dev.to/diivy_in/marginleak-open-source-accounts-payable-auditor-for-small-businesses-cji</guid>
      <description>&lt;p&gt;&lt;em&gt;This is a submission for the &lt;a href="https://dev.to/challenges/hacktoberfest-week2-2026-10-12"&gt;Hacktoberfest Open-Source AI Challenge Week 2: Side Hustle&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;




&lt;h1&gt;
  
  
  MarginLeak: Autonomous Accounts-Payable AI Auditor &amp;amp; Margin Recovery System
&lt;/h1&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Catch hidden overcharges, quantity discrepancies, and silent price creep before paying supplier invoices.&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Built as an evidence-backed, production-grade accounts-payable auditor for small businesses, e-commerce sellers, and recurring B2B buyers.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  What I Built
&lt;/h2&gt;

&lt;p&gt;MarginLeak is an open-source, production-ready accounts-payable AI auditor and margin recovery platform designed for small e-commerce sellers, independent retail distributors, and recurring B2B buyers.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Problem: Unnoticed Profit Bleed
&lt;/h3&gt;

&lt;p&gt;In high-velocity commerce, small and medium businesses purchase inventory from dozens of distinct suppliers and process hundreds of raw invoice lines every month. Because accounting teams and solo founders lack the time to manually cross-check every single line item against purchase orders and historical rates, &lt;strong&gt;accounts-payable leakage silently drains 2% to 8% of net business margins&lt;/strong&gt;:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Silent Unit Price Creep&lt;/strong&gt;: A supplier quietly hikes a unit price from &lt;code&gt;$14.50&lt;/code&gt; to &lt;code&gt;$16.20&lt;/code&gt; (+11.7%). Across a standard 300-unit shipment, that is &lt;strong&gt;$510.00 directly lost from net profit&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Quantity Over-Billing&lt;/strong&gt;: An invoice bills for 150 units when the approved Purchase Order (PO) only authorized 100 units. That represents &lt;strong&gt;hundreds of dollars of unauthorized inventory exposure&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Duplicate Line Items &amp;amp; Invoices&lt;/strong&gt;: The same line item is billed twice across overlapping invoices, or an entire invoice is resubmitted under a slightly altered invoice number.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Semantic Description Chaos&lt;/strong&gt;: Traditional spreadsheet &lt;code&gt;VLOOKUP&lt;/code&gt; or SQL joins fail completely because supplier descriptions never match purchase order catalog names (&lt;em&gt;"Type C Multi-Port Hub 7P"&lt;/em&gt; vs. &lt;em&gt;"7-in-1 USB-C Dock Space Gray"&lt;/em&gt;).&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  The Solution: Audit-Grade Autonomous Reconciliation
&lt;/h3&gt;

&lt;p&gt;MarginLeak transforms manual invoice verification into an automated, evidence-backed workflow. When a user uploads a supplier invoice PDF and an authorized purchase-order spreadsheet, MarginLeak:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Performs Fuzzy Semantic Matching&lt;/strong&gt;: Matches invoice lines to purchase-order lines even when abbreviations, naming conventions, and pack sizes differ.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Checks Historical Supplier Pricing&lt;/strong&gt;: Identifies unexplained price drift against historical supplier median baselines.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Calculates Cent-Precision Exposure&lt;/strong&gt;: Computes financial risk using strict Python &lt;code&gt;decimal.Decimal&lt;/code&gt; arithmetic (zero floating-point error).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Anchors Visual Document Evidence&lt;/strong&gt;: Cites the exact invoice page number, raw text block, and bounding-box coordinates for instant verification.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Estimates Dispute Recovery Likelihood&lt;/strong&gt;: Uses &lt;strong&gt;TabPFN 2.0&lt;/strong&gt; Bayesian tabular modeling to score supplier overbilling risk and calculate the empirical win-rate for disputed charges.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Generates One-Click Dispute Letters&lt;/strong&gt;: Automatically drafts a polite, itemized, and legally grounded supplier credit-memo request with instant clipboard copy and &lt;code&gt;mailto:&lt;/code&gt; pre-filling.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Business &amp;amp; Commercial Model (Side Hustle Potential)
&lt;/h3&gt;

&lt;p&gt;MarginLeak is engineered as a high-margin, low-overhead B2B SaaS:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Target Audience&lt;/strong&gt;: 30M+ SMBs, Amazon/Shopify sellers, and wholesale distributors spending $10k–$250k/month on vendor inventory.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;ROI&lt;/strong&gt;: Catching just &lt;strong&gt;one&lt;/strong&gt; $300 pricing error per month delivers a 10x ROI on a standard $29/month subscription.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cost Structure&lt;/strong&gt;: Running open-weight fine-tuned models on Render with Docker yields marginal compute costs of less than &lt;strong&gt;$0.40 per 1,000 processed invoice lines&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Demo
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;🌐 &lt;strong&gt;Live Hosted Application&lt;/strong&gt;: &lt;a href="https://marginleak.onrender.com/" rel="noopener noreferrer"&gt;https://marginleak.onrender.com/&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The deployed application features full Supabase email/password authentication with private, tenant-isolated workspaces and PostgreSQL persistence on Render.&lt;/p&gt;

&lt;h3&gt;
  
  
  ⚡ Instant One-Click Demo Walkthrough
&lt;/h3&gt;

&lt;p&gt;Judges and evaluators can test the entire audit pipeline immediately without uploading external files:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Open the live application at &lt;a href="https://marginleak.onrender.com/" rel="noopener noreferrer"&gt;https://marginleak.onrender.com/&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Sign in or click &lt;strong&gt;"Load Demo Scenario"&lt;/strong&gt; in the top navigation bar.&lt;/li&gt;
&lt;li&gt;The dashboard instantly stages an authentic multi-item purchase order and supplier invoice containing four real-world discrepancies:

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Unit Price Variance&lt;/strong&gt;: Item billed at &lt;code&gt;$18.50&lt;/code&gt; vs PO contracted price of &lt;code&gt;$16.00&lt;/code&gt; (+$187.50 exposure).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Quantity Overage&lt;/strong&gt;: Invoiced for 75 units against 50 authorized units (+$400.00 unauthorized inventory).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Historical Price Drift&lt;/strong&gt;: Unit price 14% higher than the historical supplier median.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Duplicate Invoiced Line&lt;/strong&gt;: An accidental second billing of the same component on line 4.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Interact with the review workflow: Inspect the exact visual PDF coordinates, review the TabPFN supplier risk badge, and click &lt;strong&gt;"Generate Dispute Letter"&lt;/strong&gt; to inspect the auto-generated credit memo.&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  Code
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;💻 &lt;strong&gt;GitHub Repository&lt;/strong&gt;: &lt;a href="https://github.com/inddivyansh/MarginLeak" rel="noopener noreferrer"&gt;https://github.com/inddivyansh/MarginLeak&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;📜 &lt;strong&gt;Open-Source License&lt;/strong&gt;: &lt;a href="https://github.com/inddivyansh/MarginLeak/blob/main/LICENSE" rel="noopener noreferrer"&gt;MIT License&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Key Architecture Modules:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;FastAPI Core &amp;amp; Routing&lt;/strong&gt;: &lt;a&gt;backend/app/main.py&lt;/a&gt; and &lt;a&gt;backend/app/api/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Deterministic Reconciliation Engine&lt;/strong&gt;: &lt;a&gt;backend/app/engine/reconciliation.py&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fuzzy Product Matching&lt;/strong&gt;: &lt;a&gt;backend/app/engine/matcher.py&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;TabPFN Supplier Risk Intelligence&lt;/strong&gt;: &lt;a&gt;backend/app/engine/supplier_risk.py&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tinker Normalization Client&lt;/strong&gt;: &lt;a&gt;backend/app/ai/tinker_client.py&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tinker LoRA Fine-Tuning Pipeline&lt;/strong&gt;: &lt;a&gt;tinker_experiment/train_tinker_lora.py&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Held-Out Benchmark Harness&lt;/strong&gt;: &lt;a&gt;tinker_experiment/run_benchmark.py&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;React 19 Dashboard&lt;/strong&gt;: &lt;a&gt;frontend/src/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Multi-Tenant Security &amp;amp; Auth&lt;/strong&gt;: &lt;a&gt;backend/app/auth.py&lt;/a&gt; and &lt;a&gt;frontend/src/components/AuthGate.tsx&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Production Infrastructure&lt;/strong&gt;: &lt;a&gt;Dockerfile&lt;/a&gt; and &lt;a&gt;render.yaml&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  How I Built It
&lt;/h2&gt;

&lt;p&gt;MarginLeak is built on an architectural golden rule for financial software: &lt;strong&gt;The Strict Separation of Model Semantics and Deterministic Arithmetic.&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Core Architectural Principle&lt;/strong&gt;: &lt;em&gt;The AI model must never calculate money.&lt;/em&gt; Open-weight models interpret messy supplier descriptions and extract canonical attributes; ordinary deterministic Python code calculates every dollar amount and verifies totals.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  1. Document Extraction &amp;amp; Fuzzy Alignment
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;PyMuPDF (&lt;code&gt;pymupdf&lt;/code&gt;)&lt;/strong&gt;: Ingests supplier PDF invoices without OCR latency, extracting selectable text blocks, line coordinates, and page indices for precise bounding-box citations.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pandas &amp;amp; OpenPyXL&lt;/strong&gt;: Parses purchase order spreadsheets with auto-detection of column headers (&lt;code&gt;sku&lt;/code&gt;, &lt;code&gt;description&lt;/code&gt;, &lt;code&gt;qty&lt;/code&gt;, &lt;code&gt;unit_price&lt;/code&gt;, &lt;code&gt;uom&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;RapidFuzz Engine&lt;/strong&gt;: Leverages token-sort ratios, SKU alignment, and attribute extraction to resolve variations like &lt;em&gt;"Type C Multi-Port Hub 7P"&lt;/em&gt; vs &lt;em&gt;"7-in-1 USB-C Dock Space Gray"&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Continuous Learning Memory&lt;/strong&gt;: Human reviewer corrections are persisted per tenant as supplier aliases, automatically teaching the system vendor naming conventions over time.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2. Open-Weight Fine-Tuning with Thinking Machines Tinker
&lt;/h3&gt;

&lt;p&gt;To map unstructured vendor descriptions into structured canonical items without hallucinations, MarginLeak implements a complete fine-tuning pipeline for &lt;strong&gt;&lt;code&gt;Qwen/Qwen3-8B&lt;/code&gt;&lt;/strong&gt; using &lt;strong&gt;Thinking Machines' Tinker API&lt;/strong&gt; with Low-Rank Adaptation (LoRA rank 16, alpha 32).&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The Normalization Task&lt;/strong&gt;: Standardizes chaotic descriptions into structured JSON containing canonical title, brand, pack size (&lt;code&gt;100&lt;/code&gt;), pack unit (&lt;code&gt;box&lt;/code&gt;), size (&lt;code&gt;large&lt;/code&gt;), and specific attributes (&lt;code&gt;blue&lt;/code&gt;, &lt;code&gt;nitrile&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Real SDK Training Loop&lt;/strong&gt;: &lt;a&gt;train_tinker_lora.py&lt;/a&gt; calls &lt;code&gt;create_lora_training_client&lt;/code&gt;, executes real forward/backward passes, performs AdamW optimizer updates, and exports sampler checkpoint metadata.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Empirical Training Trajectory&lt;/strong&gt;: Demonstrates a &lt;strong&gt;17.8% loss reduction&lt;/strong&gt; across training epochs (dropping from &lt;code&gt;2892.88&lt;/code&gt; to &lt;code&gt;2379.41&lt;/code&gt;), confirming consistent convergence.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Held-Out Benchmark Harness&lt;/strong&gt;: &lt;a&gt;run_benchmark.py&lt;/a&gt; evaluates extraction accuracy, pack-quantity precision, and token similarity on a 30-case held-out dataset.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Deterministic Offline Fallback&lt;/strong&gt;: Features a rule-based fallback normalizer ensuring 100% system availability even when offline or without API keys.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3. TabPFN Bayesian Supplier Risk Intelligence
&lt;/h3&gt;

&lt;p&gt;MarginLeak integrates &lt;strong&gt;TabPFN 2.0&lt;/strong&gt; (prior-data fitted networks for tabular data). When analyzing historical supplier records:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Evaluates vendor invoice frequency, discrepancy rates, average overcharge margins, and dispute resolution outcomes.&lt;/li&gt;
&lt;li&gt;Emits an empirical &lt;strong&gt;Overbilling Risk Score&lt;/strong&gt; (&lt;code&gt;low&lt;/code&gt;, &lt;code&gt;moderate&lt;/code&gt;, &lt;code&gt;elevated&lt;/code&gt;) and calculates an estimated &lt;strong&gt;Dispute Win Probability&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Falls back to statistical median estimation when historical records are sparse.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  4. Deterministic Financial Precision
&lt;/h3&gt;

&lt;p&gt;Every monetary calculation is handled in Python using &lt;code&gt;decimal.Decimal&lt;/code&gt; with transparent mathematical proofs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Price Variance&lt;/strong&gt;: &lt;code&gt;(Invoice Unit Price - PO Unit Price) × Invoiced Quantity&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Quantity Overage&lt;/strong&gt;: &lt;code&gt;(Invoiced Quantity - PO Quantity) × PO Unit Price&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Historical Drift&lt;/strong&gt;: Compared against the tenant's historical median price for that specific supplier and item.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  5. Multi-Tenant Enterprise Security
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Dual-Mode JWT Verification&lt;/strong&gt;: Dynamically inspects token headers to support modern Supabase asymmetric &lt;strong&gt;&lt;code&gt;ES256&lt;/code&gt; Elliptic Curve tokens&lt;/strong&gt; via Supabase Auth API verification (&lt;code&gt;/auth/v1/user&lt;/code&gt;), while retaining fast local &lt;strong&gt;&lt;code&gt;HS256&lt;/code&gt; HMAC verification&lt;/strong&gt; when symmetric secrets are configured.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;In-Memory TTL Token Caching&lt;/strong&gt;: &lt;code&gt;_verified_token_cache&lt;/code&gt; eliminates redundant network latency during high-frequency API polling.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Row-Level Tenancy&lt;/strong&gt;: All models are foreign-keyed to &lt;code&gt;workspace_id&lt;/code&gt;. Cross-tenant record inspection returns strict &lt;code&gt;404 Not Found&lt;/code&gt; errors.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Upload Sandboxing&lt;/strong&gt;: Uploads use generated UUID keys; directory traversal attacks (&lt;code&gt;../&lt;/code&gt;) are blocked before disk access.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  6. Technology Stack Matrix
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Frontend&lt;/strong&gt;: React 19, TypeScript, Vite, Vanilla CSS design system (dark mode, glassmorphism, responsive cards, micro-animations).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Backend API&lt;/strong&gt;: FastAPI, Uvicorn, SQLAlchemy 2.0, Pydantic v2, Pydantic-Settings.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Database&lt;/strong&gt;: PostgreSQL (Production on Render), SQLite (Local development).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;AI &amp;amp; Tabular ML&lt;/strong&gt;: Thinking Machines Tinker LoRA (&lt;code&gt;Qwen/Qwen3-8B&lt;/code&gt;), TabPFN 2.0.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Testing &amp;amp; QA&lt;/strong&gt;: Pytest (11 unit and integration security tests passing), TypeScript compiler (&lt;code&gt;tsc -b&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;DevOps&lt;/strong&gt;: Docker multi-stage build, Render Blueprint (&lt;code&gt;render.yaml&lt;/code&gt;).&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Why Does Open Innovation Matter?
&lt;/h2&gt;

&lt;p&gt;Accounts-payable auditing should not be a walled-garden monopoly controlled by multi-million-dollar legacy ERP providers. When accounting software operates as an opaque black box:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Trade Secret Confidentiality &amp;amp; Financial Privacy&lt;/strong&gt;: Supplier pricing discount agreements, vendor negotiation rates, and wholesale item costs are strictly confidential trade secrets. Businesses cannot legally or commercially stream proprietary supplier invoices into closed commercial LLM servers. Open-weight models can be hosted entirely inside a private VPC or private cloud instance, ensuring zero data leakage.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Domain-Specific Adaptation Over Generalist Chatbots&lt;/strong&gt;: Off-the-shelf closed models frequently hallucinate or fail on industrial abbreviations (&lt;em&gt;"CRG-055 HY BLK TONER"&lt;/em&gt;, &lt;em&gt;"7P Type C Dock w/ 100W PD"&lt;/em&gt;). Fine-tuning an open-weight model with LoRA on Thinking Machines' Tinker adapts normalization to specific supplier vocabulary without paying massive token fees.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Inspectability &amp;amp; Audit Compliance&lt;/strong&gt;: In financial auditing, "trust me" is unacceptable. An open implementation makes the workflow fully inspectable: owners and accountants can see how a product was matched, how an amount was calculated, and which exact source text supported the finding.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Zero Marginal Vendor Tax&lt;/strong&gt;: Closed APIs change pricing and deprecate model versions unexpectedly. An open-weight model deployed on open infrastructure gives predictable, fixed marginal costs, making a lean SaaS sustainable from day one.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The most important design choice is not to ask the model to calculate money. Open innovation provides the language interpretation layer, while ordinary deterministic code remains responsible for the numbers and the audit trail.&lt;/p&gt;




&lt;h2&gt;
  
  
  My Agent Session
&lt;/h2&gt;

&lt;p&gt;This entire application—from backend architecture and Tinker fine-tuning scripts to Supabase authentication debugging, Docker packaging, and UI components—was developed collaboratively with AI agent assistance and recorded via &lt;a href="https://devrelay.com/" rel="noopener noreferrer"&gt;DevRelay&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The verified interactive session has been submitted to DEV and can be inspected in full:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🔗 &lt;strong&gt;DEV Agent Session&lt;/strong&gt;: &lt;a href="https://dev.to/agent_sessions/vscode-marginleak-session-fjttbm"&gt;https://dev.to/agent_sessions/vscode-marginleak-session-fjttbm&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;🆔 &lt;strong&gt;Session Slug&lt;/strong&gt;: &lt;code&gt;vscode-marginleak-session-fjttbm&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;📊 &lt;strong&gt;Scope&lt;/strong&gt;: 26 curated, high-value engineering messages (13 deep architectural and ML milestones)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Interactive Liquid Tag Embeds
&lt;/h3&gt;

&lt;p&gt;The session can be embedded in any DEV community article using DEV's native Liquid tags:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight liquid"&gt;&lt;code&gt;&lt;span class="cp"&gt;{%&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;agent_session&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;vscode-marginleak-session-fjttbm&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="cp"&gt;%}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or embedded by curated milestone slices:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;TabPFN Anomaly Scoring &amp;amp; Dispute UI&lt;/strong&gt;: &lt;code&gt;{% agent_session vscode-marginleak-session-fjttbm 0..2 %}&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Render Multi-Stage Docker Packaging&lt;/strong&gt;: &lt;code&gt;{% agent_session vscode-marginleak-session-fjttbm 3..6 %}&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tinker LoRA Fine-Tuning SDK&lt;/strong&gt;: &lt;code&gt;{% agent_session vscode-marginleak-session-fjttbm 7..12 %}&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Supabase Auth &amp;amp; Workspace Tenancy&lt;/strong&gt;: &lt;code&gt;{% agent_session vscode-marginleak-session-fjttbm 13..16 %}&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Model Loss &amp;amp; Convergence Trajectory&lt;/strong&gt;: &lt;code&gt;{% agent_session vscode-marginleak-session-fjttbm 17..20 %}&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Origin Redirection &amp;amp; DevRelay Registration&lt;/strong&gt;: &lt;code&gt;{% agent_session vscode-marginleak-session-fjttbm 21..25 %}&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  My First User
&lt;/h2&gt;

&lt;p&gt;During development, MarginLeak was pilot-tested using authentic historical order records from a &lt;strong&gt;family-owned hardware and electrical supplies shop&lt;/strong&gt; processing roughly 200 invoice lines monthly across 8 recurring suppliers.&lt;/p&gt;

&lt;h3&gt;
  
  
  Real-World Validation &amp;amp; Key Takeaways:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Pack Unit Confusion is the #1 Cause of Leaks&lt;/strong&gt;: Suppliers frequently bill by the &lt;em&gt;"inner carton"&lt;/em&gt; (e.g., pack of 12) while purchase orders record individual units. MarginLeak's canonical attribute normalization immediately flagged two separate box-versus-unit pricing mismatches that had previously slipped past manual human review, &lt;strong&gt;recovering over $140 in margin on a single batch&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Bookkeepers Demand Proof, Not Assertions&lt;/strong&gt;: When bookkeepers were shown an AI estimate, they hesitated; when shown the &lt;strong&gt;exact page snippet, bounding box, and arithmetic formula&lt;/strong&gt;, they felt 100% confident approving the finding.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The Power of One-Click Dispute Letters&lt;/strong&gt;: Generating the dispute email draft in the UI reduced the friction of disputing vendor overcharges from 15 minutes of manual writing to under 5 seconds.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Prize Categories
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Hacktoberfest Open-Source AI Challenge Week 2: Side Hustle (Primary Track)
&lt;/h3&gt;

&lt;p&gt;MarginLeak is designed from the ground up as a viable, high-leverage commercial B2B SaaS. It features full multi-tenant authentication, private workspace isolation, evidence-backed reconciliation, automated dispute letter generation, and an interactive hosted demo on Render. With a $29/mo pricing tier and marginal compute costs under $0.40/1,000 lines, MarginLeak is ready for customer onboarding.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Best Use of Thinking Machines Tinker ($200)
&lt;/h3&gt;

&lt;p&gt;MarginLeak implements a complete open-weight LoRA fine-tuning workflow with the Tinker SDK, targeting &lt;code&gt;Qwen/Qwen3-8B&lt;/code&gt; for canonical line-item normalization. The repository contains genuine forward/backward passes, AdamW optimizer updates, a documented &lt;strong&gt;17.8% loss reduction trajectory&lt;/strong&gt;, checkpoint export in &lt;a&gt;train_tinker_lora.py&lt;/a&gt;, and a 30-case held-out benchmark runner in &lt;a&gt;run_benchmark.py&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Best Use of Render ($200)
&lt;/h3&gt;

&lt;p&gt;MarginLeak is packaged with a multi-stage &lt;a&gt;Dockerfile&lt;/a&gt; (Node 20 Alpine builder + Python 3.12 slim runtime) and deployed using Infrastructure-as-Code via &lt;a&gt;render.yaml&lt;/a&gt;. Render manages the web service, static React distribution, persistent PostgreSQL database, and automated &lt;code&gt;/health&lt;/code&gt; checks.&lt;/p&gt;




&lt;h2&gt;
  
  
  Additional Information
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Architecture Flowchart
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;┌─────────────────────────────────────────────────────────────────────────────┐
│                            MARGINLEAK ARCHITECTURE                          │
├─────────────────────────────────────────────────────────────────────────────┤
│                                                                             │
│  [Invoice PDF] ──&amp;gt; PyMuPDF Extractor ──&amp;gt; Raw Line Items + Bounding Boxes    │
│  [PO Spreadsheet] ─&amp;gt; Pandas / OpenPyXL ─&amp;gt; Authorized PO Line Items          │
│                                │                                            │
│                                ▼                                            │
│   ┌─────────────────────────────────────────────────────────────────────┐   │
│   │               CANONICAL NORMALIZATION &amp;amp; MATCHING                    │   │
│   │  • Thinking Machines Tinker LoRA (Qwen3-8B): Canonical attributes   │   │
│   │  • Deterministic Fallback Normalizer: Rule-based regex tokenization │   │
│   │  • RapidFuzz Matcher: Token-sort ratio, SKU alignment, confidence   │   │
│   └─────────────────────────────────────────────────────────────────────┘   │
│                                │                                            │
│                                ▼                                            │
│   ┌─────────────────────────────────────────────────────────────────────┐   │
│   │            DETERMINISTIC FINANCIAL RECONCILIATION ENGINE            │   │
│   │  • Exact Python decimal.Decimal precision (zero floating-point err) │   │
│   │  • Price Variance: (Invoice Price - PO Price) × Invoiced Qty        │   │
│   │  • Quantity Variance: (Invoiced Qty - PO Qty) × PO Unit Price       │   │
│   │  • Duplicate Line Detection &amp;amp; Historical Median Price Tracking      │   │
│   └─────────────────────────────────────────────────────────────────────┘   │
│                                │                                            │
│                                ▼                                            │
│   ┌─────────────────────────────────────────────────────────────────────┐   │
│   │         TABPFN SUPPLIER RISK &amp;amp; DISPUTE RECOVERY INTELLIGENCE         │   │
│   │  • TabPFN 2.0 Bayesian Tabular Classifier: Supplier Overbilling Risk│   │
│   │  • Dispute Recovery Probability: Historical win rate estimation     │   │
│   └─────────────────────────────────────────────────────────────────────┘   │
│                                │                                            │
│                                ▼                                            │
│   ┌─────────────────────────────────────────────────────────────────────┐   │
│   │                      OUTPUT &amp;amp; REMEDIATION LAYER                     │   │
│   │  • Interactive Audit Dashboard (React 19 + TypeScript + Vite)       │   │
│   │  • PDF Source Snippet &amp;amp; Page Citation                               │   │
│   │  • One-Click Credit-Memo Dispute Generator (Formatted text + mailto)│   │
│   │  • Human-in-the-Loop Feedback: Confirmed corrections saved as aliases│  │
│   └─────────────────────────────────────────────────────────────────────┘   │
└─────────────────────────────────────────────────────────────────────────────┘
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Roadmap &amp;amp; Commercial Expansion
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;[ ] &lt;strong&gt;Multi-Currency Live FX&lt;/strong&gt;: Automated conversion for cross-border supplier invoices using historical European Central Bank (ECB) rates.&lt;/li&gt;
&lt;li&gt;[ ] &lt;strong&gt;Direct Accounting Integrations&lt;/strong&gt;: Sync confirmed audit adjustments directly into QuickBooks Online and Xero via OAuth.&lt;/li&gt;
&lt;li&gt;[ ] &lt;strong&gt;Automated Inbox Ingestion&lt;/strong&gt;: Webhook listeners to monitor a designated &lt;code&gt;invoices@company.com&lt;/code&gt; inbox for continuous hands-free reconciliation.&lt;/li&gt;
&lt;li&gt;[ ] &lt;strong&gt;Multi-Model Benchmark Expansion&lt;/strong&gt;: Publish full benchmark matrices comparing Tinker LoRA vs Base Qwen3-8B vs Claude/GPT APIs across 500+ real-world invoice formats.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;MarginLeak is proudly 100% open-source under the MIT License. Check out the &lt;a href="https://github.com/inddivyansh/MarginLeak" rel="noopener noreferrer"&gt;code on GitHub&lt;/a&gt; and try the &lt;a href="https://marginleak.onrender.com/" rel="noopener noreferrer"&gt;live demo&lt;/a&gt;!&lt;/em&gt;&lt;/p&gt;

</description>
      <category>devchallenge</category>
      <category>hf26challenge</category>
      <category>ai</category>
      <category>marginleak</category>
    </item>
  </channel>
</rss>
