Skip to content

AI-powered expense optimization platform (AIG200 - Capstone Project) integrating Discord uploads, Vertex AI OCR, and a multi-agent ADK pipeline for automated receipt classification, explainable results, and predictive analytics.

Notifications You must be signed in to change notification settings

jcp-tech/Spendify

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

96 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Spendify

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.


πŸ—οΈ Architecture

Discord Bot β†’ Flask API β†’ Google Document AI β†’ ADK Classification Pipeline β†’ Firebase

Process Flow

  1. Discord Bot – receives receipt images from users and forwards them to the API.
  2. Flask API – orchestrates OCR, classification and data storage, also serving a simple dashboard.
  3. ADK Pipeline – multi-agent system that groups and validates receipt items.
  4. 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
    

πŸ“ Repository Structure

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.

Project Structure

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

πŸš€ Quick Start

  1. Install Python requirements in each module & Configure .env files using the provided templates.
  2. Start the ADK Server:
    cd adk_pipeline
    adk web
  3. In another terminal, run the Flask API:
    cd flask_api
    python main_api.py
  4. In another terminal, run the Discord bot:
    cd discord_bot
    python bot.py
  5. Access the dashboard at http://localhost:8080/ (or your configured port).

System Components

1. Entry Points

Discord Bot (bot.py)

  • Accepts image uploads from Discord users
  • Handles user registration and authentication
  • Manages file uploads and session tracking
  • Provides real-time feedback to users

Main API (main_api.py)

  • Central Flask API server
  • Orchestrates the entire processing pipeline
  • Handles user management and data flow
  • Integrates all system components

2. Data Processing

GCP Document AI (gcp_docai.py)

  • Extracts structured data from receipt images
  • Identifies line items, totals, taxes, and merchant information
  • Provides entity recognition and text extraction

Firebase Storage (firebase_store.py)

  • Manages all data persistence operations
  • Stores user data, sessions, raw OCR data, and classifications
  • Provides structured data organization across collections

3. AI Classification Pipeline

ADK Client (gcp_adk_classification.py)

  • HTTP client for Google Agent Development Kit
  • Handles communication with multi-agent systems
  • Manages session creation and event streaming

Receipt Classifier Agents (adk_pipeline/receipt_classifier/)

Multi-agent system with sequential processing:

  1. Initial Classifier: Categorizes line items (Groceries, Fast Food, etc.)
  2. Grouping Agent: Groups items by category with totals
  3. Validation Loop:
    • Reviewer: Validates classification accuracy
    • Refiner: Corrects misclassifications
  4. Response Agent: Generates final summary and saves to Firebase

Data Flow

  1. User uploads receipt image via Discord
  2. Bot saves image locally and calls API
  3. API processes image through GCP Document AI
  4. OCR extracts entities (items, totals, taxes)
  5. Raw data stored in Firebase
  6. Classification pipeline triggered via ADK
  7. Multi-agent system processes receipt:
    • Classifies items by category
    • Groups and calculates totals
    • Validates against receipt total
    • Refines if validation fails
  8. Final classified data saved to Firebase

πŸ”§ Extending Spendify

  • 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.

Contributing

  1. Fork the repository
  2. Create feature branch
  3. Add tests for new functionality
  4. Update documentation
  5. Submit pull request

About

AI-powered expense optimization platform (AIG200 - Capstone Project) integrating Discord uploads, Vertex AI OCR, and a multi-agent ADK pipeline for automated receipt classification, explainable results, and predictive analytics.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •