Skip to content

KrishnaNarkhede/AP-INVOICE-AUTOMATION

Repository files navigation

AP Invoice Automation System

A comprehensive invoice management and automation system built with React, TypeScript, Node.js, and MongoDB. This system provides automated PDF invoice processing, AI-powered data extraction, and a modern web interface for managing accounts payable workflows.

πŸ“– About

The AP Invoice Automation System is designed to revolutionize how businesses handle their accounts payable processes. By leveraging cutting-edge AI technology and modern web development practices, this system automates the tedious task of invoice data extraction and management.

🎯 Problem Statement

Traditional invoice processing is time-consuming, error-prone, and requires significant manual effort. Businesses often struggle with:

  • Manual data entry from PDF invoices
  • Inconsistent data formats across vendors
  • Time delays in invoice approval workflows
  • Difficulty in tracking and analyzing payment patterns
  • Risk of human errors in financial data processing

πŸ’‘ Our Solution

We've built an intelligent system that:

  • Automatically extracts invoice data using Google Gemini AI
  • Integrates seamlessly with Gmail for real-time invoice processing
  • Provides instant insights through comprehensive analytics dashboards
  • Ensures data accuracy with advanced validation and error handling
  • Streamlines workflows with user-friendly interfaces and automation

πŸ† Key Benefits

  • 90% reduction in manual data entry time
  • Improved accuracy through AI-powered extraction
  • Real-time processing of incoming invoices
  • Enhanced visibility into payment patterns and vendor relationships
  • Scalable architecture that grows with your business needs

πŸŽ“ Use Cases

  • Small Businesses: Streamline invoice processing without dedicated AP staff
  • Medium Enterprises: Scale operations efficiently with automated workflows
  • Large Corporations: Standardize processes across multiple departments
  • Accounting Firms: Provide value-added services to clients
  • Freelancers: Manage client invoices and payments professionally

πŸ”¬ Technology Innovation

This project showcases the integration of multiple cutting-edge technologies:

  • AI/ML: Google Gemini AI for intelligent document processing
  • Cloud Integration: Gmail API for seamless email processing
  • Modern Web Stack: React + TypeScript for robust frontend development
  • Database Design: MongoDB with optimized schemas for financial data
  • Real-time Processing: WebSocket support for live updates

πŸš€ Features

Core Functionality

  • Automated PDF Processing: Extract invoice data from PDF attachments using Google Gemini AI
  • Gmail Integration: Automatically fetch and process invoices from Gmail
  • Invoice Management: Complete CRUD operations for invoice data
  • Vendor Management: Track and manage vendor relationships
  • Analytics Dashboard: Comprehensive reporting and insights
  • Export Capabilities: Export data to Excel format
  • Real-time Updates: WebSocket support for live data updates

Technical Features

  • Modern UI: Built with React, TypeScript, and Tailwind CSS
  • Responsive Design: Mobile-first approach with shadcn/ui components
  • Type Safety: Full TypeScript implementation with Zod validation
  • Database: MongoDB with Drizzle ORM for data management
  • Authentication: Session-based user authentication
  • File Processing: Python-based PDF processing with Google APIs

πŸ—οΈ Architecture

β”œβ”€β”€ client/                 # React frontend application
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/     # Reusable UI components
β”‚   β”‚   β”œβ”€β”€ pages/         # Application pages
β”‚   β”‚   β”œβ”€β”€ hooks/         # Custom React hooks
β”‚   β”‚   └── lib/           # Utility functions
β”œβ”€β”€ server/                 # Node.js backend server
β”‚   β”œβ”€β”€ routes.ts          # API route definitions
β”‚   β”œβ”€β”€ storage.ts         # Database operations
β”‚   β”œβ”€β”€ pdf_processor.py   # Python PDF processing
β”‚   └── vite.ts            # Vite development server
β”œβ”€β”€ shared/                 # Shared schemas and types
└── migrations/             # Database migration files

πŸ“‹ Prerequisites

Before running this project, ensure you have the following installed:

  • Node.js (v18 or higher)
  • Python (v3.8 or higher)
  • npm or yarn package manager
  • MongoDB database (local or cloud)
  • Google Cloud Platform account with:
    • Gmail API enabled
    • Gemini AI API access
    • OAuth 2.0 credentials

πŸ”§ Environment Setup

1. Clone the Repository

git clone <repository-url>
cd AP-INVOICE-AUTOMATION-main

2. Install Dependencies

Frontend Dependencies

npm install

Python Dependencies

pip install google-auth-oauthlib google-auth-httplib2 google-api-python-client
pip install google-generativeai pymongo forex-python

3. Environment Variables

Create a .env file in the root directory:

# Database Configuration
MONGO_URI=mongodb+srv://username:password@cluster.mongodb.net/
DATABASE_URL=postgresql://username:password@localhost:5432/database

# Google APIs
GOOGLE_APPLICATION_CREDENTIALS=path/to/credentials.json
GEMINI_API_KEY=your_gemini_api_key

# Server Configuration
NODE_ENV=development
PORT=3006

# Session Secret
SESSION_SECRET=your_session_secret_here

4. Google API Setup

  1. Go to Google Cloud Console
  2. Create a new project or select existing one
  3. Enable Gmail API and Gemini AI API
  4. Create OAuth 2.0 credentials
  5. Download the credentials JSON file
  6. Update the GOOGLE_APPLICATION_CREDENTIALS path in your .env file

πŸš€ Running the Project

Development Mode

Start the Development Server

npm run dev

This command will:

  • Start the Node.js backend server on port 3006
  • Launch the Vite development server for the React frontend
  • Enable hot module replacement for development

Access the Application

Production Mode

Build the Application

npm run build

Start Production Server

npm start

Database Operations

Push Database Schema

npm run db:push

Type Checking

npm run check

πŸ“± Available Scripts

Command Description
npm run dev Start development server with hot reload
npm run build Build production bundle
npm start Start production server
npm run check Run TypeScript type checking
npm run db:push Push database schema changes

πŸ—„οΈ Database Schema

The system uses MongoDB with the following main collections:

Invoice Structure

interface Invoice {
  _id?: string;
  invoice_header: {
    organization_code: number;
    invoice_num: string;
    invoice_date: string;
    vendor_name: string;
    vendor_site_code: string;
    invoice_amount: number;
    currency_code: string;
    payment_term: string;
    invoice_type: string;
    pdf_link?: string;
    pdf_base64?: string;
  };
  invoice_lines: Array<{
    line_number: number;
    line_type: string;
    description: string;
    quantity: number;
    unit_price: number;
    line_amount: number;
  }>;
}

πŸ”Œ API Endpoints

Invoice Management

  • GET /api/invoices - Get paginated invoice list with filters
  • GET /api/invoices/:invoice_num - Get specific invoice details
  • PUT /api/invoices/:invoice_num - Update invoice information
  • DELETE /api/invoices/:invoice_num - Delete invoice

Analytics

  • GET /api/analytics/summary - Get invoice analytics summary
  • GET /api/analytics/vendors - Get vendor analytics
  • GET /api/analytics/monthly - Get monthly invoice trends

Export

  • GET /api/export/invoices - Export invoices to Excel
  • GET /api/export/dashboard - Export dashboard data

Authentication

  • POST /api/auth/login - User login
  • POST /api/auth/logout - User logout
  • GET /api/auth/me - Get current user info

🎨 UI Components

The application uses a comprehensive set of UI components built with:

  • shadcn/ui: Modern, accessible component library
  • Tailwind CSS: Utility-first CSS framework
  • Radix UI: Unstyled, accessible component primitives
  • Framer Motion: Animation library
  • React Hook Form: Form handling and validation
  • Zod: Schema validation

πŸ” Authentication & Security

  • Session-based authentication using Express sessions
  • Password hashing and validation
  • Protected API routes
  • CORS configuration for security
  • Input validation using Zod schemas

πŸ“Š Data Processing Pipeline

  1. Email Fetching: Gmail API fetches emails with invoice subjects
  2. PDF Extraction: Python script processes PDF attachments
  3. AI Processing: Google Gemini AI extracts structured data
  4. Data Validation: Zod schemas validate extracted data
  5. Database Storage: MongoDB stores processed invoice data
  6. Web Interface: React frontend displays and manages data

🚨 Troubleshooting

Common Issues

MongoDB Connection Error

Error: Failed to connect to MongoDB

Solution: Check your MONGO_URI in the .env file and ensure MongoDB is running.

Google API Authentication Error

Error: Invalid credentials

Solution: Verify your Google API credentials and ensure the required APIs are enabled.

Port Already in Use

Error: EADDRINUSE: address already in use :::3006

Solution: Change the port in server/index.ts or kill the process using port 3006.

Python Dependencies Missing

ModuleNotFoundError: No module named 'google'

Solution: Install Python dependencies using pip install -r requirements.txt (if available) or install manually.

Performance Optimization

  • Enable MongoDB indexing for frequently queried fields
  • Implement caching for analytics data
  • Use pagination for large datasets
  • Optimize PDF processing with background jobs

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ†˜ Support

For support and questions:

  • Create an issue in the repository
  • Check the troubleshooting section above
  • Review the API documentation
  • Contact the development team

πŸ”„ Updates and Maintenance

  • Regularly update dependencies for security patches
  • Monitor Google API quotas and limits
  • Backup MongoDB data regularly
  • Keep Python packages updated for PDF processing

Note: This system integrates with external services (Gmail, Google Gemini AI) and requires proper API credentials and quotas to function correctly. Ensure you have sufficient API limits for production use.

About

AI-powered invoice automation system that extracts data from PDFs using Google Gemini AI, integrates with Gmail, and provides a modern web interface for accounts payable management.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors