Labsco
keyurgit45 logo

Expense Tracker

from keyurgit45

Automated expense management with a Supabase backend and hierarchical category support.

πŸ”₯πŸ”₯βœ“ VerifiedFreeQuick setup

Expense Tracker Backend

AI-powered expense tracking system with natural language interface, intelligent categorization, and real-time sync.

Architecture

The system uses a two-server architecture:

  1. MCP Server: Core expense tracking tools exposed via Model Context Protocol
  2. Gemini AI Server: FastAPI server providing chat interface with authentication

Features

  • πŸ€– Natural language expense management via Gemini AI
  • 🧠 Intelligent categorization using embeddings and similarity search
  • πŸ” JWT authentication with Supabase
  • πŸ“Š Hierarchical categories for organization
  • 🏷️ Predefined tag system
  • πŸ“ˆ Real-time data sync
  • πŸ”„ Learning system that improves over time

API Endpoints

Chat Interface

  • POST /chat - Send natural language commands
  • POST /auth/refresh - Refresh JWT token

MCP Tools (via chat)

  • Create expenses from natural language
  • Auto-categorize transactions
  • Get spending summaries
  • Analyze subscriptions
  • View recent transactions

Flutter Client

refer https://github.com/keyurgit45/expense-tracker-client

Testing

# Run all tests with mocks
ENVIRONMENT=test pytest tests/ -v

# Run specific components
ENVIRONMENT=test pytest tests/test_mcp_tools.py -v
ENVIRONMENT=test pytest tests/test_categorization.py -v

Project Structure

backend/
β”œβ”€β”€ app/
β”‚   β”œβ”€β”€ core/              # Business logic
β”‚   β”œβ”€β”€ servers/
β”‚   β”‚   β”œβ”€β”€ gemini/       # AI chat server
β”‚   β”‚   └── mcp/          # MCP tool server
β”‚   └── shared/           # Shared configs
β”œβ”€β”€ scripts/              # Utilities
└── tests/               # Test suite

AI Categorization

The system uses a hybrid approach:

  1. Generates embeddings for transactions using Sentence Transformers
  2. Finds similar past transactions using pgvector
  3. Uses weighted voting to predict categories
  4. Falls back to rule-based matching
  5. Learns from user confirmations

Development

  • API docs: http://localhost:8000/docs
  • Frontend integration: Configure CORS in Gemini server
  • MCP tools can be tested directly via chat interface