Invoice-IQ is a comprehensive full-stack application designed to revolutionize invoice management for businesses. It provides robust tools for managing sellers, products, and deliveries, with a standout feature of Optical Character Recognition (OCR) to automate data extraction from invoice images. The platform also offers insightful analytics to help users understand their delivery trends and operational efficiency.
This project aims to reduce manual data entry, minimize errors, and provide a centralized system for tracking and analyzing product deliveries from various sellers.
- User Authentication & Authorization: Secure user registration, login, and session management using JWT.
- Seller Management:
- Create, view, update, and delete seller profiles.
- Associate products with specific sellers.
- Product Management:
- Define and manage a catalog of products with units.
- Support for product aliases to improve OCR matching accuracy.
- Link products to specific sellers.
- Delivery Management:
- Manual Delivery Entry: Easily record product deliveries with quantity, price, and date.
- OCR-Powered Invoice Processing: Upload invoice images (e.g., PNG, JPEG) to automatically extract product details.
- Intelligent Product Matching: Automatically match OCR-extracted product names to your existing product catalog, leveraging normalization and aliases.
- Detailed delivery history tracking.
- Analytics & Reporting:
- Visualize delivery trends over time.
- Track product movement and seller performance.
- Generate reports for informed decision-making.
- Intuitive User Interface: A modern, responsive frontend built with Next.js and Shadcn UI for a seamless user experience.
Invoice-IQ is built as a monorepo, separating the backend API from the frontend client.
- Language: TypeScript
- Framework: Node.js with Express.js
- Database: MongoDB (managed with Mongoose ODM)
- Authentication: JSON Web Tokens (JWT)
- OCR:
node-tesseract-ocrfor image text extraction - Hashing:
crypto-es - Utilities:
dotenv,cors,cookie-parser - Development:
nodemon,ts-node
- Framework: Next.js (React)
- Language: TypeScript
- Styling: Tailwind CSS with Shadcn UI components
- Data Visualization: Chart.js with
react-chartjs-2 - State Management: React hooks
- Theming:
next-themes - Icons:
lucide-react
The project follows a monorepo structure, dividing the application into two main services: backend and frontend.
Invoice-IQ/
├── backend/ # Node.js/Express API
│ ├── ConnectDB.ts # MongoDB connection
│ ├── Controller/ # Business logic for API endpoints
│ ├── Models/ # Mongoose schemas for data models
│ ├── Router/ # API route definitions
│ ├── middleware/ # Express middleware (e.g., authentication)
│ ├── utils/ # Helper functions (hashing, tokens, OCR transformation)
│ └── index.ts # Main backend server entry point
└── frontend/ # Next.js React application
├── public/ # Static assets
├── src/
│ ├── app/ # Next.js pages and routes
│ ├── components/ # Reusable UI components (Shadcn UI)
│ ├── hooks/ # Custom React hooks
│ ├── lib/ # Utility functions, API clients
│ └── types/ # TypeScript type definitions
└── next.config.ts # Next.js configuration
- Request Reception: Express.js receives API requests.
- Middleware Processing:
authMiddlewareverifies JWT tokens for protected routes. - Routing: Requests are directed to appropriate routers (
Auth.Router,Delivery.Router, etc.). - Controller Logic: Controllers handle business logic, interacting with Mongoose models for database operations.
- OCR Integration: For invoice processing,
Delivery.Controllerutilizesnode-tesseract-ocrto extract text from images andpromptForTransforming.tsfor intelligent data parsing. - Response: JSON responses are sent back to the client.
- User Interaction: Users interact with the Next.js application in their browser.
- API Calls: React components make asynchronous requests to the backend API.
- Data Display: Fetched data is rendered using React components, often styled with Tailwind CSS and Shadcn UI.
- Data Visualization:
Chart.jsis used to display analytics data.
Follow these instructions to set up and run Invoice-IQ on your local machine.
Before you begin, ensure you have the following installed:
- Node.js: Version 18.x or higher.
- npm or Yarn: Package manager (npm comes with Node.js).
- MongoDB: A running MongoDB instance (local or cloud-hosted).
- Install MongoDB Community Edition
- Alternatively, use a cloud service like MongoDB Atlas.
- Tesseract OCR Engine: Required for the backend's OCR functionality.
- Linux (Debian/Ubuntu):
sudo apt update sudo apt install tesseract-ocr
- macOS (Homebrew):
brew install tesseract
- Windows: Download the installer from Tesseract OCR GitHub. Ensure it's added to your system's PATH.
- Linux (Debian/Ubuntu):
-
Clone the repository:
git clone https://github.com/GURUDAS-DEV/Invoice-IQ.git cd Invoice-IQ -
Backend Setup:
Navigate to the
backenddirectory and install dependencies:cd backend npm install # or yarn install
-
Frontend Setup:
Navigate to the
frontenddirectory and install dependencies:cd ../frontend npm install # or yarn install
Create a .env file in the backend/ directory and populate it with your environment variables:
PORT=9000
MONGO_URI="mongodb://localhost:27017/invoiceiq" # Your MongoDB connection string
JWT_SECRET="YOUR_SUPER_SECRET_KEY_HERE" # Generate a strong, random string
TESSERACT_BINARY_PATH="/usr/local/bin/tesseract" # Optional: Specify if tesseract is not in your system PATHNote: For JWT_SECRET, use a complex, unique string. For TESSERACT_BINARY_PATH, provide the full path to your Tesseract executable if it's not automatically discoverable by node-tesseract-ocr.
Create a .env.local file in the frontend/ directory:
NEXT_PUBLIC_BACKEND_URL="http://localhost:9000/api" # Ensure this matches your backend's URL and port-
Start the Backend Server:
From the
backend/directory:npm run dev
The backend server will start on
http://localhost:9000(or thePORTyou configured). You should see a message likeServer is running on port 9000. -
Start the Frontend Development Server:
From the
frontend/directory:npm run dev
The frontend application will start on
http://localhost:3000. -
Access the Application:
Open your web browser and navigate to
http://localhost:3000.- Register a new user or log in with existing credentials.
- Explore the dashboard to manage sellers, products, and record deliveries.
- Try uploading an invoice image to test the OCR functionality.
- Ensure all dependencies are installed for both
backendandfrontend. - The
npm run devscript for the backend usesnodemonandts-nodefor automatic restarts on code changes. - The
npm run devscript for the frontend leverages Next.js's hot module reloading.
Currently, no dedicated test suites are configured in the package.json files. For comprehensive testing, you would typically integrate:
- Backend: Unit/integration tests using frameworks like Jest or Mocha/Chai.
- Frontend: Component and end-to-end tests using React Testing Library, Jest, and Cypress.
- Adhere to TypeScript best practices.
- Frontend uses ESLint for code quality and consistency. Ensure your IDE is configured to use ESLint.
- Use clear, descriptive variable and function names.
- Comment complex logic where necessary.
- Backend: Use Node.js debugger tools or integrate with your IDE's debugger (e.g., VS Code's built-in debugger).
console.logstatements are also useful for quick checks. - Frontend: Utilize your browser's developer tools (Console, Network, Components tabs) for debugging React components and API interactions.
While specific deployment scripts are not included, here are general guidelines for deploying Invoice-IQ:
Both the backend (Node.js) and frontend (Next.js) are excellent candidates for Dockerization.
- Create
Dockerfiles for bothbackendandfrontend. - Use
docker-compose.ymlto orchestrate the services, including MongoDB.
- Backend (Node.js/Express):
- PaaS: Heroku, Google Cloud Run, AWS App Runner, DigitalOcean App Platform.
- IaaS: Deploy to a virtual machine on AWS EC2, Google Compute Engine, or DigitalOcean Droplets.
- Frontend (Next.js):
- Vercel: The recommended platform for Next.js applications, offering seamless deployment.
- Netlify: Another popular choice for static sites and serverless functions.
- Static Hosting: Build the Next.js application (
npm run build) and serve theout/directory from any web server (Nginx, Apache, AWS S3 + CloudFront).
- Database Indexing: Ensure appropriate indexes are created in MongoDB for frequently queried fields (e.g.,
userId,sellerId,normalizedName). - Image Processing: OCR can be resource-intensive. Consider optimizing image sizes or offloading processing to a dedicated service for high-volume scenarios.
- Caching: Implement caching mechanisms for frequently accessed data.
The Invoice-IQ backend provides a RESTful API. All endpoints are prefixed with /api.
POST /api/auth/register: Register a new user.- Request Body:
{ "username": "...", "email": "...", "password": "..." }
- Request Body:
POST /api/auth/login: Authenticate user and set a JWT cookie.- Request Body:
{ "email": "...", "password": "..." }
- Request Body:
POST /api/auth/logout: Invalidate the current user's session.GET /api/auth/me: Get details of the authenticated user.- Requires: Authentication (JWT cookie).
POST /api/sellerManagement/create: Create a new seller.- Request Body:
{ "name": "...", "mobile": "...", "address": "..." } - Requires: Authentication.
- Request Body:
GET /api/sellerManagement/all: Retrieve all sellers for the authenticated user.- Requires: Authentication.
GET /api/sellerManagement/:id: Get a specific seller by ID.- Requires: Authentication.
PUT /api/sellerManagement/:id: Update an existing seller.- Request Body:
{ "name"?: "...", "mobile"?: "...", "address"?: "..." } - Requires: Authentication.
- Request Body:
DELETE /api/sellerManagement/:id: Delete a seller.- Requires: Authentication.
POST /api/product/create: Create a new product.- Request Body:
{ "sellerId": "...", "name": "...", "unit": "..." } - Requires: Authentication.
- Request Body:
GET /api/product/all: Retrieve all products for the authenticated user.- Requires: Authentication.
GET /api/product/:id: Get a specific product by ID.- Requires: Authentication.
PUT /api/product/:id: Update an existing product.- Request Body:
{ "name"?: "...", "unit"?: "...", "allies"?: [{ "name": "..." }] } - Requires: Authentication.
- Request Body:
DELETE /api/product/:id: Delete a product.- Requires: Authentication.
POST /api/delivery/manual: Add a delivery manually.- Request Body:
{ "sellerId": "60c72b2f9b1d8c001c8e4d1a", // Optional, if product is already linked to seller "productId": "60c72b2f9b1d8c001c8e4d1b", "unit": "kg", "quantity": 10.5, "price": 120.75, "date": "2023-10-26" } - Requires: Authentication.
- Request Body:
POST /api/delivery/ocr: Add a delivery by uploading an invoice image for OCR processing.- Request Body:
{ "sellerId": "60c72b2f9b1d8c001c8e4d1a", // Optional, if known "invoiceImageBase64": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA..." // Base64 encoded image } - Requires: Authentication.
- Request Body:
GET /api/delivery/form-data: Get data required for manual delivery forms (lists of sellers and products).- Requires: Authentication.
POST /api/delivery/product/manual: Create a product manually for a specific seller (used within delivery context).- Request Body:
{ "sellerId": "...", "name": "...", "unit": "..." } - Requires: Authentication.
- Request Body:
GET /api/analytics/summary: Get a summary of delivery data.- Requires: Authentication.
GET /api/analytics/sales-by-product: Get delivery data grouped by product.- Requires: Authentication.
GET /api/analytics/sales-by-seller: Get delivery data grouped by seller.- Requires: Authentication.
We welcome contributions to Invoice-IQ! If you're interested in improving the project, please follow these guidelines:
- Fork the repository.
- Create a new branch for your feature or bug fix (
git checkout -b feature/your-feature-name). - Make your changes, ensuring they adhere to the project's code style.
- Write clear, concise commit messages.
- Test your changes thoroughly.
- Submit a pull request to the
mainbranch of this repository.
Please ensure your pull requests are well-documented and explain the changes you've made.
- Backend not starting:
- Check your
.envfile inbackend/for correctPORT,MONGO_URI, andJWT_SECRET. - Ensure MongoDB is running and accessible.
- Check the console for any error messages from
nodemonorts-node.
- Check your
- Frontend not connecting to backend:
- Verify
NEXT_PUBLIC_BACKEND_URLinfrontend/.env.localmatches the backend's address. - Ensure the backend server is running.
- Check browser developer console for network errors (CORS issues, failed requests).
- Verify
- OCR not working:
- Ensure Tesseract OCR engine is correctly installed and its binary path is correctly configured in
backend/.env(if not in system PATH). - Check the backend logs for Tesseract-related errors.
- Ensure the uploaded image is clear and readable.
- Ensure Tesseract OCR engine is correctly installed and its binary path is correctly configured in
- CORS errors:
- Verify
allowedOriginsinbackend/index.tsincludes the URL where your frontend is running (e.g.,http://localhost:3000).
- Verify
If you encounter any other issues, please open an issue on the GitHub repository.
- Implement user roles and permissions.
- Add support for more invoice formats and complex layouts.
- Integrate with payment gateways for invoice processing.
- Advanced analytics and custom report generation.
- Notification system for delivery updates.
- Dockerize the application for easier deployment.
This project is licensed under the ISC License. See the LICENSE file for details.
- GURUDAS-DEV: Project maintainer and primary developer.
- Contributors:
- [Your Name/GitHub Handle Here] - For contributions to [specific feature/fix].
- Thanks to the developers of Node.js, Express.js, Next.js, MongoDB, Tesseract, and all the open-source libraries used in this project.