Skip to content

AdityaMedidala/invoice-app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

11 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Invoice Management System

AI-Powered Invoice Data Extraction and Management System

πŸ“‹ Overview

An intelligent invoice management system that automates the extraction, processing, and management of invoice data from various file formats using AI. Built for Swipe's internship assignment.

✨ Features

Core Functionality

  • πŸ€– AI-Powered Extraction: Uses Google Document AI + Gemini LLM
  • πŸ“„ Multi-Format Support: PDF, Images (JPG, PNG), Excel, CSV
  • πŸ“Š Three-Tab Dashboard: Invoices, Products, Customers
  • πŸ”„ Real-Time Sync: Redux-powered cross-tab updates
  • βœ… Smart Validation: Missing field detection and consistency checks
  • πŸ“¦ Batch Processing: Upload multiple files simultaneously

Advanced Features

  • πŸ’° Tax-aware calculations with automatic totals
  • 🏦 Bank detail extraction
  • πŸ“ Amount in words conversion
  • πŸ“ˆ Customer purchase history tracking
  • πŸ”’ Product quantity aggregation
  • ✏️ Inline editing with cascade updates
  • 🎨 Status indicators (OK, Incomplete, Mismatch)

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   React     │────────▢│   FastAPI    β”‚
β”‚  Frontend   β”‚         β”‚   Backend    β”‚
β”‚  (TypeScript)│◀────────│  (Python)    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
      β”‚                        β”‚
      β”‚                        β”œβ”€β”€β”€β”€β”€β–Ά Google Document AI
      β”‚                        β”‚
      β”œβ”€ Redux Store           β”œβ”€β”€β”€β”€β”€β–Ά Google Gemini LLM
      β”‚                        β”‚
      β”œβ”€ Mantine UI            └─────▢ Pandas (Excel)
      β”‚
      └─ React Dropzone

πŸš€ Tech Stack

Frontend

  • Framework: React 18 with TypeScript
  • State Management: Redux Toolkit
  • UI Library: Mantine UI v7
  • Tables: Mantine React Table
  • File Upload: React Dropzone

Backend

  • Framework: FastAPI (Python 3.12)
  • OCR: Google Document AI
  • LLM: Google Gemini 2.5 Flash
  • Data Processing: Pandas
  • Server: Uvicorn

πŸ“¦ Installation

Prerequisites

  • Node.js 18+
  • Python 3.12+
  • Google Cloud account with Document AI enabled
  • Gemini API key

Frontend Setup

# Clone repository
git clone https://github.com/YOUR_USERNAME/swipe-invoice-system.git
cd swipe-invoice-system/frontend

# Install dependencies
npm install

# Start development server
npm start

Backend Setup

cd backend

# Create virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

# Set up environment variables
cp .env.example .env
# Edit .env and add your API keys

# Add Google Cloud credentials
# Place service-account-key.json in backend directory

# Start server
python main.py

The backend will run on http://localhost:8000
The frontend will run on http://localhost:3000

πŸ”‘ Configuration

Backend .env file:

GEMINI_API_KEY=your_gemini_api_key_here
PROJECT_ID=your_google_cloud_project_id
LOCATION=us
PROCESSOR_ID=your_document_ai_processor_id

Google Cloud Setup:

  1. Create a Google Cloud project
  2. Enable Document AI API
  3. Create a Document AI processor (Invoice Parser)
  4. Create a service account and download JSON key
  5. Save as service-account-key.json in backend directory

Gemini API:

  1. Get API key from Google AI Studio
  2. Add to .env file

πŸ“– Usage

1. Upload Files

  • Drag and drop files onto the upload area
  • Or click to browse and select files
  • Supports: PDF, JPG, PNG, XLSX, XLS, CSV

2. View Extracted Data

  • Invoices Tab: View all invoices with details
  • Products Tab: See aggregated product data
  • Customers Tab: Track customer purchase history

3. Edit Data

  • Click the edit icon (pencil) in any table
  • Make changes inline
  • Changes automatically sync across all tabs

4. Validate Data

  • Red text indicates missing required fields
  • Status badges show data completeness
  • Expand invoice rows for detailed breakdown

πŸ“ Project Structure

swipe-invoice-system/
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”‚   β”œβ”€β”€ Dashboard.tsx
β”‚   β”‚   β”‚   └── UploadArea.tsx
β”‚   β”‚   β”œβ”€β”€ features/
β”‚   β”‚   β”‚   └── data/
β”‚   β”‚   β”‚       └── dataSlice.ts
β”‚   β”‚   β”œβ”€β”€ store/
β”‚   β”‚   β”‚   └── store.ts
β”‚   β”‚   └── types/
β”‚   β”‚       └── types.ts
β”‚   └── package.json
β”‚
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ main.py          # FastAPI application
β”‚   β”œβ”€β”€ docai.py         # Document AI integration
β”‚   β”œβ”€β”€ llm.py           # Gemini LLM extraction
β”‚   β”œβ”€β”€ validator.py     # Data validation
β”‚   └── requirements.txt
β”‚
└── README.md

πŸ”„ Data Flow

  1. Upload β†’ User drops files in upload area
  2. Route β†’ Backend routes files by type (PDF/Image β†’ DocAI, Excel β†’ Pandas)
  3. Extract β†’ AI extracts structured data using Gemini prompts
  4. Validate β†’ Validator checks completeness and consistency
  5. Store β†’ Redux dispatches action to update state
  6. Sync β†’ All tabs automatically update with new data
  7. Edit β†’ User can edit data with cascade updates across tabs

🎯 Key Algorithms

Product Aggregation

// Products are matched by name across invoices
// Quantities are summed, prices updated if newer data available
if (existing) {
  existing.quantity += item.quantity;
  if (price > 0) existing.unitPrice = price;
}

Customer Tracking

// Customer totals calculated by summing all their invoices
cust.totalPurchaseAmount = invoices
  .filter(inv => inv.customerName === cust.name)
  .reduce((sum, inv) => sum + inv.totalAmount, 0);

Consistency Validation

// Invoice is consistent if calculated total matches stated total
const calculated = items.reduce((sum, i) => sum + i.amount, 0) + taxTotal;
const variance = Math.abs(statedTotal - calculated);
isConsistent = variance < 1.0;

πŸ› Known Limitations

  • OCR accuracy depends on image quality
  • Excel format must have standard column headers
  • Phone number formatting assumes Indian format
  • Service charges (shipping, making) are filtered from products

πŸš€ Deployment

Frontend (Vercel)

cd frontend
npm run build
vercel --prod

Backend (Railway/Render)

cd backend
# Add Procfile: web: python main.py
# Deploy to Railway or Render

πŸ‘¨β€πŸ’» Author

Medidala Aditya

About

AI-powered invoice extraction and management system using Google Document AI and Gemini, built with React, Redux, and a FastAPI backend.

Resources

Stars

Watchers

Forks

Contributors