A full-stack web application that uses AI to automatically extract, process, and manage invoice data using OCR and machine learning technologies.
- AI-Powered OCR: DeepSeek OCR2 integration for accurate text extraction
- Intelligent Data Correction: LLM-based correction and structuring of OCR output
- Multi-Language Support: Automatic language detection and processing
- User Management: Role-based authentication (User/Admin)
- Real-time Analytics: Comprehensive dashboards with charts and insights
- Email Notifications: Automatic email alerts for processed invoices
- Camera Integration: Capture invoices directly from camera
- Editable Interface: Modify extracted data before saving
- Accuracy Tracking: Monitor OCR accuracy and processing performance
- Node.js with Express.js
- MongoDB Atlas with Mongoose ODM
- JWT Authentication
- Multer for file uploads
- Nodemailer for email notifications
- Python Integration via child_process
- React.js with React Router
- Tailwind CSS for styling
- Recharts for data visualization
- Lucide React for icons
- Axios for API calls
- React Hot Toast for notifications
- DeepSeek OCR2 for text extraction
- DeepSeek LLM for data correction
- Python scripts for AI processing
invoice/
├── backend/
│ ├── src/
│ │ ├── controllers/ # API controllers
│ │ ├── middleware/ # Auth middleware
│ │ ├── models/ # Mongoose schemas
│ │ ├── routes/ # API routes
│ │ └── utils/ # Utility functions
│ ├── uploads/ # File upload directory
│ ├── .env # Environment variables
│ └── package.json
├── frontend/
│ ├── src/
│ │ ├── components/ # React components
│ │ ├── contexts/ # React contexts
│ │ ├── pages/ # Page components
│ │ ├── services/ # API services
│ │ └── utils/ # Utility functions
│ ├── public/
│ ├── .env # Environment variables
│ └── package.json
├── python/
│ ├── deep.py # OCR processing script
│ └── llm_correct.py # LLM correction script
└── README.md
- Node.js (v14 or higher)
- Python (v3.7 or higher)
- MongoDB Atlas account
- Conda environment (recommended)
-
Clone the repository
git clone <repository-url> cd invoice
-
Set up Python Environment
conda create -n ocr python=3.8 conda activate ocr
-
Install Python Dependencies
cd python pip install -r requirements.txt -
Install Backend Dependencies
cd ../backend npm install -
Install Frontend Dependencies
cd ../frontend npm install -
Environment Setup
Backend (.env):
# MongoDB Configuration MONGODB_URI=mongodb+srv://nithyashriskcs24_db_user:<password>@cluster0.tg9qtt0.mongodb.net/invoice_management # JWT Configuration JWT_SECRET=your-super-secret-jwt-key JWT_EXPIRE=7d # Server Configuration PORT=5000 NODE_ENV=development # Email Configuration EMAIL_HOST=smtp.gmail.com EMAIL_PORT=587 EMAIL_USER=your-email@gmail.com EMAIL_PASS=your-app-password # Python Scripts Path PYTHON_PATH=python DEEP_SCRIPT_PATH=../python/deep.py LLM_CORRECT_SCRIPT_PATH=../python/llm_correct.py
Frontend (.env):
REACT_APP_API_URL=http://localhost:5000/api REACT_APP_ENV=development
-
Start the Backend Server
cd backend npm run dev -
Start the Frontend Development Server
cd frontend npm start -
Access the Application
- Frontend: http://localhost:3000
- Backend API: http://localhost:5000
- API Health Check: http://localhost:5000/api/health
POST /api/auth/signup- User registrationPOST /api/auth/login- User loginGET /api/auth/profile- Get user profilePUT /api/auth/profile- Update user profilePUT /api/auth/change-password- Change password
POST /api/invoice/upload- Upload and process invoicePUT /api/invoice/:id/save- Save edited invoiceGET /api/invoice/my- Get user's invoicesGET /api/invoice/:id- Get specific invoiceDELETE /api/invoice/:id- Delete invoiceGET /api/invoice/analytics/my- Get user analytics
GET /api/admin/users- Get all usersGET /api/admin/invoices- Get all invoicesGET /api/admin/analytics- Get system analyticsPUT /api/admin/users/:userId/status- Update user statusPUT /api/admin/users/:userId/role- Update user roleGET /api/admin/health- Get system health
- Image Upload: User uploads invoice image or captures via camera
- OCR Processing:
deep.pyextracts raw text using DeepSeek OCR2 - Data Correction:
llm_correct.pystructures and corrects OCR output - Accuracy Calculation: Compare original vs corrected data
- Data Storage: Save structured data with metadata to MongoDB
- Email Notification: Send processing summary to user
deep.py:
- Input: Image file path
- Output: Raw OCR text with metadata
- Integration: DeepSeek OCR2 API
llm_correct.py:
- Input: Raw OCR text
- Output: Structured JSON data
- Features: Field extraction, validation, language detection
User Model:
{
username: String,
email: String,
password: String,
role: String, // 'user' | 'admin'
profile: {
firstName: String,
lastName: String,
phone: String,
company: String
},
preferences: {
language: String,
emailNotifications: Boolean,
theme: String
}
}Invoice Model:
{
userId: ObjectId,
originalOCR: String,
correctedData: Object,
accuracyScore: Number,
languageDetected: String,
fileName: String,
filePath: String,
processingTime: Number,
status: String,
extractedFields: Object,
metadata: Object
}- Total invoices processed
- Average OCR accuracy
- Processing time metrics
- Vendor insights
- Spending analytics
- System-wide metrics
- User management
- Invoice volume trends
- Accuracy distribution
- Language distribution
- System health monitoring
- JWT-based authentication
- Role-based access control
- Input validation and sanitization
- File upload security
- Rate limiting
- CORS protection
- Helmet.js security headers
- Automatic notifications on invoice processing
- Processing summaries with accuracy metrics
- Configurable email templates
- Support for Gmail SMTP
- Responsive design for all devices
- Modern, clean interface with Tailwind CSS
- Interactive charts and data visualizations
- Real-time form validation
- Loading states and error handling
- Toast notifications
- Camera integration for mobile devices
-
Environment Variables:
- Set
NODE_ENV=production - Update MongoDB URI with production database
- Configure production email settings
- Set strong JWT secret
- Set
-
Build Frontend:
cd frontend npm run build -
Deploy Backend:
- Use PM2 for process management
- Configure reverse proxy (Nginx)
- Set up SSL certificates
- Configure firewall rules
# Backend Dockerfile
FROM node:16-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
EXPOSE 5000
CMD ["npm", "start"]- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
-
Python Scripts Not Found:
- Ensure conda environment is activated:
conda activate ocr - Check Python path in backend .env file
- Ensure conda environment is activated:
-
MongoDB Connection Error:
- Verify MongoDB URI and credentials
- Check network connectivity
- Ensure IP is whitelisted in MongoDB Atlas
-
Email Not Sending:
- Verify Gmail app password
- Check SMTP settings
- Ensure less secure apps are enabled
-
OCR Processing Fails:
- Check Python script permissions
- Verify image file format
- Check DeepSeek API credentials
Enable debug logging by setting:
NODE_ENV=development
DEBUG=invoice:*For support and questions:
- Create an issue in the repository
- Check the troubleshooting section
- Review the API documentation
Built with ❤️ using Node.js, React, and AI technologies