AI-driven system for processing receipt images, classifying line items and tracking personal spending.
Spendify is a comprehensive receipt processing and classification system that combines Discord bot integration, Google Cloud AI services, and multi-agent AI pipelines to automatically categorize and analyze receipt data.
Discord Bot β Flask API β Google Document AI β ADK Classification Pipeline β Firebase
- Discord Bot β receives receipt images from users and forwards them to the API.
- Flask API β orchestrates OCR, classification and data storage, also serving a simple dashboard.
- ADK Pipeline β multi-agent system that groups and validates receipt items.
- Firebase β persists raw OCR data and summarised spending information.
USERDATA/ βββ {primary_id}/ β βββ sources/ β β βββ {source}: {identifier} β βββ metadata SESSIONS/ βββ {session_id}/ β βββ timestamp β βββ user_id β βββ source DATA/ βββ RAW_DATA/ β βββ {date}/ β βββ {session_id}: raw_ocr_data βββ RECEIPTS/ β βββ {date}/ β βββ {session_id}: extracted_entities βββ SUMMARIES/ βββ {date}/ βββ {session_id}: classified_data
Folder | Description |
---|---|
discord_bot |
Bot for collecting images from Discord users. |
flask_api |
Flask service performing OCR and classification. |
adk_pipeline |
Agent Development Kit pipeline for receipts. |
Spendify/
βββ discord_bot/ # Discord bot module
β βββ bot.py # Main Discord bot
β βββ requirements.txt # Bot dependencies
β βββ deploy-bot.md # Bot deployment guide
β βββ .env.template # Environment template
β βββ img_content/ # Bot image content
β βββ README.md # Bot documentation
βββ flask_api/ # Main API server module
β βββ main_api.py # Flask API server
β βββ gcp_docai.py # OCR processing
β βββ firebase_store.py # Data storage
β βββ gcp_adk_classification.py # ADK client
β βββ requirements.txt # API dependencies
β βββ deploy-api.md # API deployment guide
β βββ deploy.sh # Deployment script
β βββ Dockerfile # Docker configuration
β βββ firebaseConfig.json.template # Firebase config template
β βββ serviceAccountKey.json.template # Service account template
β βββ .env.template # Environment template
β βββ dashboard/ # Web dashboard
β β βββ index.html # Main dashboard
β β βββ login.html # Login page
β β βββ register.html # Registration page
β β βββ upload.html # Upload page
β β βββ chat.html # Chat interface
β β βββ already_registered.html # Registration status
β βββ uploads/ # API file uploads
β βββ README.md # API documentation
βββ adk_pipeline/ # Agent Development Kit pipeline
β βββ receipt_classifier/ # Agent pipeline
β β βββ agent.py # Root agent orchestrator
β β βββ requirements.txt # Agent dependencies
β β βββ firebase_credentials.json.template # Firebase template
β β βββ .env.template # Environment template
β β βββ __init__.py # Package initialization
β β βββ subagents/ # Individual processing agents
β β βββ classifier_init/ # Initial classification agent
β β β βββ agent.py # Categorizes line items
β β β βββ __init__.py # Agent initialization
β β βββ classification_grouper/ # Item grouping agent
β β β βββ agent.py # Groups items by category
β β β βββ tools.py # Grouping utilities
β β β βββ __init__.py # Agent initialization
β β βββ classification_reviewer/ # Validation agent
β β β βββ agent.py # Validates classifications
β β β βββ tools.py # Review utilities
β β β βββ __init__.py # Agent initialization
β β βββ classification_refiner/ # Correction agent
β β β βββ agent.py # Refines misclassifications
β β β βββ __init__.py # Agent initialization
β β βββ classification_response/ # Final response agent
β β βββ agent.py # Generates final summary
β β βββ tools.py # Response utilities
β β βββ firebase_store.py # Data persistence
β β βββ __init__.py # Agent initialization
β βββ evals/ # Evaluation data
β βββ deploy-adk.md # ADK deployment guide
β βββ deploy.sh # Deployment script
β βββ flow.png # Pipeline flow diagram
β βββ firebase_credentials.json # Firebase credentials
β βββ .env.template # Environment template
β βββ README.md # ADK documentation
βββ process.png # System process diagram
βββ README.md # Project documentation
- Install Python requirements in each module & Configure
.env
files using the provided templates. - Start the ADK Server:
cd adk_pipeline adk web
- In another terminal, run the Flask API:
cd flask_api python main_api.py
- In another terminal, run the Discord bot:
cd discord_bot python bot.py
- Access the dashboard at
http://localhost:8080/
(or your configured port).
- Accepts image uploads from Discord users
- Handles user registration and authentication
- Manages file uploads and session tracking
- Provides real-time feedback to users
- Central Flask API server
- Orchestrates the entire processing pipeline
- Handles user management and data flow
- Integrates all system components
- Extracts structured data from receipt images
- Identifies line items, totals, taxes, and merchant information
- Provides entity recognition and text extraction
- Manages all data persistence operations
- Stores user data, sessions, raw OCR data, and classifications
- Provides structured data organization across collections
- HTTP client for Google Agent Development Kit
- Handles communication with multi-agent systems
- Manages session creation and event streaming
Multi-agent system with sequential processing:
- Initial Classifier: Categorizes line items (Groceries, Fast Food, etc.)
- Grouping Agent: Groups items by category with totals
- Validation Loop:
- Reviewer: Validates classification accuracy
- Refiner: Corrects misclassifications
- Response Agent: Generates final summary and saves to Firebase
- User uploads receipt image via Discord
- Bot saves image locally and calls API
- API processes image through GCP Document AI
- OCR extracts entities (items, totals, taxes)
- Raw data stored in Firebase
- Classification pipeline triggered via ADK
- Multi-agent system processes receipt:
- Classifies items by category
- Groups and calculates totals
- Validates against receipt total
- Refines if validation fails
- Final classified data saved to Firebase
- Update the List of Classification Options.
- Modify the ADK agents under
adk_pipeline/receipt_classifier
to tweak classification behaviour or enhance them. - Adjust
firebase_store.py
if you prefer another database backend. - Update the
discord_bot/bot.py
with more integrations. - Adapt
discord_bot/bot.py
for different chat platforms. - Update the Dashboad Options
- Add a Oauth2 Login using GMAIL to be done through API (including requested through bot).
- Create a Regression Model to Predict Individual User Spending.
- Fork the repository
- Create feature branch
- Add tests for new functionality
- Update documentation
- Submit pull request