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.
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.
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
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
- 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
- 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
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
- 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
- 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
βββ 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
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
git clone <repository-url>
cd AP-INVOICE-AUTOMATION-mainnpm installpip install google-auth-oauthlib google-auth-httplib2 google-api-python-client
pip install google-generativeai pymongo forex-pythonCreate 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- Go to Google Cloud Console
- Create a new project or select existing one
- Enable Gmail API and Gemini AI API
- Create OAuth 2.0 credentials
- Download the credentials JSON file
- Update the
GOOGLE_APPLICATION_CREDENTIALSpath in your.envfile
npm run devThis 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
- Frontend: http://localhost:3006
- API Endpoints: http://localhost:3006/api/*
npm run buildnpm startnpm run db:pushnpm run check| 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 |
The system uses MongoDB with the following main collections:
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;
}>;
}GET /api/invoices- Get paginated invoice list with filtersGET /api/invoices/:invoice_num- Get specific invoice detailsPUT /api/invoices/:invoice_num- Update invoice informationDELETE /api/invoices/:invoice_num- Delete invoice
GET /api/analytics/summary- Get invoice analytics summaryGET /api/analytics/vendors- Get vendor analyticsGET /api/analytics/monthly- Get monthly invoice trends
GET /api/export/invoices- Export invoices to ExcelGET /api/export/dashboard- Export dashboard data
POST /api/auth/login- User loginPOST /api/auth/logout- User logoutGET /api/auth/me- Get current user info
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
- Session-based authentication using Express sessions
- Password hashing and validation
- Protected API routes
- CORS configuration for security
- Input validation using Zod schemas
- Email Fetching: Gmail API fetches emails with invoice subjects
- PDF Extraction: Python script processes PDF attachments
- AI Processing: Google Gemini AI extracts structured data
- Data Validation: Zod schemas validate extracted data
- Database Storage: MongoDB stores processed invoice data
- Web Interface: React frontend displays and manages data
Error: Failed to connect to MongoDBSolution: Check your MONGO_URI in the .env file and ensure MongoDB is running.
Error: Invalid credentialsSolution: Verify your Google API credentials and ensure the required APIs are enabled.
Error: EADDRINUSE: address already in use :::3006Solution: Change the port in server/index.ts or kill the process using port 3006.
ModuleNotFoundError: No module named 'google'Solution: Install Python dependencies using pip install -r requirements.txt (if available) or install manually.
- Enable MongoDB indexing for frequently queried fields
- Implement caching for analytics data
- Use pagination for large datasets
- Optimize PDF processing with background jobs
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
For support and questions:
- Create an issue in the repository
- Check the troubleshooting section above
- Review the API documentation
- Contact the development team
- 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.