Logo
Smart Invoice Automation dashboard showing processed invoices

Smart Invoice Automation

azureaiserverlessnext.js.nettypescriptc#document-processingcosmos-db

An AI-powered serverless invoice processing platform that automatically extracts key data from uploaded invoices and intelligently classifies them by expense category. Built with Azure AI services (Form Recognizer and OpenAI), .NET Azure Functions, Next.js, and Cosmos DB, the system processes PDF and image files in 3-5 seconds with 95%+ accuracy.

Key Features

  • Intelligent Data Extraction - Automatically extracts vendor information, invoice numbers, dates, amounts, currency, and line items using Azure Form Recognizer's pretrained model
  • AI-Powered Classification - Uses Azure OpenAI to categorize invoices into business expense categories (IT Services, Marketing, Office Supplies, etc.) with confidence scores and reasoning
  • Drag-and-Drop Upload - Simple, intuitive interface supporting PDF, PNG, and JPG formats
  • Real-Time Processing - Complete processing pipeline executes in 3-5 seconds per invoice
  • Structured Storage - Invoice data stored in Cosmos DB with original files preserved in Azure Blob Storage
  • Processing Dashboard - View, search, and filter all processed invoices with detailed view capabilities
  • Cost-Optimized Architecture - Serverless design with auto-scaling and pay-per-use pricing (less than $5/month for demo usage)

Tech Stack

Azure .NET C# Azure Functions Next.js TypeScript React Tailwind CSS Cosmos DB Blob Storage OpenAI

Backend:

  • .NET Azure Functions (Isolated Worker Process)
  • Azure Form Recognizer (Document Intelligence)
  • Azure OpenAI Service
  • Azure Blob Storage with SAS token security
  • Azure Cosmos DB (Serverless mode)

Frontend:

  • Next.js with App Router
  • React
  • TypeScript for type safety
  • Tailwind CSS for responsive design

Architecture Highlights

The platform implements a fully serverless, multi-tier architecture:

Processing Pipeline:

  1. User uploads invoice (PDF/PNG/JPG) via drag-and-drop interface
  2. File stored in Azure Blob Storage with organized folder structure
  3. Azure Function orchestrates the processing workflow
  4. Form Recognizer extracts structured data (vendor, amounts, dates, line items)
  5. Azure OpenAI classifies the invoice into expense categories with reasoning
  6. Results saved to Cosmos DB, original file preserved in Blob Storage
  7. Dashboard displays processed invoices with full metadata

Key Technical Decisions:

  • Serverless Architecture: Zero infrastructure management, auto-scaling, pay-per-use pricing
  • Isolated Worker Process: Modern .NET Functions model with better DI and middleware support
  • Polling Strategy: Synchronous user experience despite async AI service processing
  • SAS Tokens: Secure, time-limited Blob Storage access for AI services
  • Service Layer Pattern: Clean separation of concerns with dedicated services for each Azure resource
  • Type Safety: TypeScript frontend + C# backend for compile-time error detection

Problem Solved

Manual invoice data entry is tedious, time-consuming, and error-prone. Businesses receive invoices in various formats via email, and someone must manually extract vendor information, amounts, dates, and categorize expenses for accounting purposes.

This platform demonstrates how AI can automate this workflow while maintaining high accuracy (95%+) and providing transparent, auditable decision-making through the language model's reasoning capabilities.

Implementation Challenges

Async AI Processing: Form Recognizer uses async polling, but users expect quick responses. Solution: Implemented polling with exponential backoff in the Azure Function to maintain synchronous user experience while processing completes in 3-5 seconds.

Diverse Invoice Formats: Invoices vary wildly in layout and structure. Solution: Leveraged Form Recognizer's pretrained model trained on thousands of global invoice formats, achieving 95%+ accuracy out of the box.

Consistent Classification: Categorizing expenses without predefined rules is challenging. Solution: Engineered language model prompts to act as an "expert accountant" with structured JSON output including category, confidence score, and reasoning for transparency.

Cost Management: AI services can be expensive at scale. Solution: Used serverless pricing models, Cosmos DB serverless mode, leveraged free tiers, and implemented efficient prompts to keep demo costs under $5/month.

Secure AI Access: Form Recognizer needs file access without exposing blobs publicly. Solution: Generated time-limited SAS tokens for secure, temporary access during processing.

What I Learned

  • Serverless Architecture Patterns: Building truly stateless, auto-scaling applications with cold start optimization and cost-conscious design
  • Prompt Engineering: Crafting production-grade prompts for consistent AI behavior with structured outputs and reasoning requirements
  • Azure AI Integration: Working with multiple AI services, handling async operations, interpreting confidence scores, and implementing error handling
  • .NET Isolated Functions: Modern Azure Functions development with improved DI and middleware support
  • Next.js App Router: Server Components, streaming, and the mental model shift from Pages Router
  • Type Safety Benefits: Catching errors at compile time across the entire stack with TypeScript and C#

Future Enhancements

  • Batch processing via Azure Queue Storage
  • Duplicate detection using content hashing
  • Export to CSV, Excel, or accounting software APIs
  • Multi-step approval workflows
  • Custom Form Recognizer model training for company-specific formats
  • Analytics dashboard for spending insights and trends
  • Receipt processing (in addition to invoices)
  • Multi-language support
  • Azure AD B2C authentication and RBAC

Read the detailed build process →