Winner of Problem Statement 3 at CodeUtsava 9.0
Klar is an intelligent, multi-tenant SaaS platform designed to streamline accounts payable by automating the extraction and processing of invoices. Leveraging the power of Google Gemini, Klar achieves high accuracy in data extracting, normalization, and vendor identification, capable of handling high-volume document processing with ease.
- 🤖 AI-Powered Data Extraction: Uses Google Gemini to extract key fields from invoices with >95% accuracy.
- ⚡ High-Performance Async Workers: Built with Python
asyncioto handle 500+ documents/day efficiently using a dedicated worker queue system. - 🔄 Intelligent Normalization:
- Automatic currency conversion.
- Fuzzy matching for accurate vendor identification.
- ✅ Human-in-the-Loop (HITL): A dedicated workflow for manually verifying low-confidence AI predictions, ensuring execution data integrity.
- 📁 Multi-Format Support: Seamlessly processes PDFs and image-based invoices (JPG, PNG) by auto-converting them.
- 🔐 Secure & Scalable: JWT-based authentication and MongoDB for robust data storage.
- Backend: Python, FastAPI
- Database: MongoDB (Async Motor driver)
- AI/ML: Google Gemini API
- Frontend: React.js (Separate repository)
- Package Manager: uv / pip
- Frontend Repository: github.com/priyanshu-matrix/KlarFrontend
- Project Presentation: View Slide Deck
KlarBackend/
├── main.py # Application entry point & API routes
├── config.py # Configuration & Env variables (Gitignored)
├── utils/
│ ├── db.py # MongoDB connection & CRUD operations
│ ├── queueHandler.py # Async task queue & worker management
│ ├── extractor.py # Gemini AI extraction logic
│ ├── auth.py # JWT Authentication
│ └── ...
├── tests/ # Directory for storing uploaded/demo files
└── pyproject.toml # Dependencies- Python 3.12+
- MongoDB instance (Local or Atlas)
- Google Gemini API Key(s)
-
Clone the repository
git clone https://github.com/TechShreyash/KlarBackend.git cd KlarBackend -
Install Dependencies It is recommended to use
uvfor fast dependency management, butpipworks too.# Using pip pip install . # OR using uv uv sync
-
Configuration Copy the sample configuration file to create your local config:
cp sample_config.py config.py
Open
config.pyand fill in your actual values (MongoDB URL, Gemini API Keys, etc.). This file is gitignored for security.Note: You can provide multiple API keys in
GOOGLE_API_KEYS. The system will spawn one worker per key to maximize throughput. -
Run the Application
python main.py
The API will start at
http://0.0.0.0:8000.
Once the server is running, you can access the interactive API docs (Swagger UI) at:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
- Auth:
/auth/signup,/auth/login - Invoices:
POST /processInvoice: Upload PDF/Image for processing.GET /getInvoices: List all user invoices.GET /invoice_details/{task_id}: Get specific invoice data.POST /updateInvoice: Submit manual verification corrections.