When I audited my own SaaS subscriptions by hand, I found 7 tools I remembered paying for. A scan of my mailbox found 23. The gap between those two numbers is the entire reason SaaSClerk exists, and this post is about how the scanning engine works: the architecture, the trade-offs, and the parts I got wrong first. The core problem An email mailbox contains every receipt, renewal notice, and price change a SaaS vendor ever sent. The challenge is reading thousands of emails efficiently while making strict privacy guarantees — because "paste your Gmail password into my web app" is a non-starter, and so is "let my server read all your mail." My first attempt used a traditional email client library with direct IMAP access. Three drawbacks killed it: performance fell apart on large mailboxes, the authentication flows were painful to maintain across providers, and the privacy boundary was blurry — the server could technically see everything. The architecture The stack I settled on: Next.js (TypeScript) for the app and API routes Prisma as the ORM Neon Postgres as the database OAuth read-only scopes for Gmail/Outlook — the app can read messages matching billing patterns and nothing else AES-256-GCM encryption for every stored token The flow: user connects a mailbox via OAuth → the scanner queries only messages that match billing patterns (subjects containing "invoice", "receipt", "subscription", "renewal", plus known billing sender domains) → a lightweight natural-language pass extracts the service name, amount, currency, billing interval, and next renewal date → the result is a structured list the user reviews. Nothing outside those matched messages is ever touched. Email content isn't persisted — extraction happens in memory and only the structured subscription record survives. The part I underestimated: renewal emails are where the money hides The first version only extracted amounts. It worked — the scanner immediately surfaced duplicates and forgotten plans. But the most valuable signal turned out to be change inside renewal emails. Vendors rarely announce price increases on their pricing pages. The increase lives in the renewal notice: "Your plan will renew at 4 to 4,200 in annual spend across my forgotten, duplicated, and quietly-increased subscriptions. The free tier at saasclerk.app scans your last twelve months if you want to run the same audit on your own mailbox — and if you build anything similar, the one lesson I'd pass on: extract changes , not just amounts . The amounts are what people know. The changes are what they're losing.

How I built an email-scanning SaaS audit engine with Next.js, Prisma and Neon
付小花

