Design overview
HomeProblem statement
Accounts Payable teams manually enter invoice data, which is slow and error-prone. Artificial intelligence can automate extraction, but incorrect data creates financial risk. The product must reduce manual work without compromising trust.
Product scope
- Invoice uploads — PDF and image files, up to 4MB (the real ceiling Vercel enforces on Serverless Function request bodies in production, confirmed by testing — not an arbitrary number).
- Automatic extraction — extract key invoice fields using artificial intelligence.
- Confidence scoring — flag fields that may need review.
- Inline correction — review and correct flagged fields.
Product decisions & rationale
- Upload-only: invoices usually arrive as documents, so manual entry is unnecessary for day-to-day use. Backlog migration is a future consideration.
- Confidence model: combines model uncertainty, deterministic format/math checks, and model-reported ambiguity. Each field is scored 1, 0.5, or 0.
- Document-type check: prevents incorrect documents from being treated as valid invoices.
- Flagged-field correction: lets users fix uncertain data without leaving the workflow.
Confidence model
- Document-level confidence: first checks whether the uploaded file is actually an invoice.
- Field-level confidence: each extracted field receives a score of 1, 0.5, or 0.
- Multiple signals: scores combine model uncertainty, deterministic format/math checks, and model-reported ambiguity.
- Needs review: low-confidence fields are flagged for user verification instead of requiring users to re-check everything.
Architecture & technical design
Client
Browser
Vercel deployment
Application framework — Next.js 16 (App Router)
Client component
Pages / UI
JSON
Server
API routes
AI / extraction
Vercel AI SDK
Data
PostgreSQL (Neon)
File storage
Vercel Blob
- Frontend: Next.js 16 App Router, React, TypeScript, and Tailwind CSS.
- API: Next.js API routes handle uploads, extraction, confidence scoring, and data operations.
- AI: Vercel AI SDK with Gemini extracts structured invoice data using a shared Zod schema.
- Database: Neon PostgreSQL stores invoice fields, line items, and confidence data through Drizzle ORM.
- Storage: Vercel Blob stores the original invoice PDFs and images.
- Validation: Zod validates the structured AI output before it is stored.
- Deployment: the entire application runs on Vercel, keeping the initial architecture simple.
- Development: Claude Code, with a design-language skill and a systematic-refactoring skill.
Alternative approaches considered
- MongoDB → PostgreSQL: typed columns and indexes are a better fit for structured invoice data.
- React + Express → Next.js: one application avoids unnecessary service and deployment overhead.
- Gemini SDK → Vercel AI SDK: structured output and shared schemas make extraction safer and provider changes easier.
- Second extraction pass → Single pass: avoids doubling cost and latency for limited additional value.
- Separate OCR → Direct Gemini: removes an unnecessary processing step.
- Manual entry → Upload-only: keeps the product focused on eliminating manual invoice entry.
Scale, rollout & future decisions
- Authentication: required before handling real company data.
- Tracking: measure flags, corrections, and confidence to improve the product.
- Async processing: move extraction to a queue as usage grows.
- Duplicate detection: prevent duplicate invoice uploads.
- Batch uploads: support multiple invoices at once.
- Initial rollout: start with one Accounts Payable team and validate before expanding.