Skip to content

feat: Add expense tracking #73

@QueryPlanner

Description

@QueryPlanner

Priority: Medium

Level of Effort: Large (5-8 days)

Summary

Add expense tracking capability following the same pattern as calorie and workout tracking. Users can log expenses with categories, amounts, and notes; the agent can provide summaries and spending insights.

Scope

  • New module: src/blacki/expenses/
  • Storage: PostgresExpenseStorage (table: expenses, extends PostgresStorage base)
  • Data model:
    • amount (Decimal, required — supports precision for currency)
    • category (str, required — e.g., "food", "transport", "entertainment", "utilities", "shopping")
    • description (str, optional)
    • currency (str, default "INR", configurable)
    • spent_at (datetime UTC, auto-set to current time if not provided)
    • spent_date (date local, for daily aggregation)
  • Tools:
    1. log_expense — record an expense with amount, category, and optional description
    2. get_expense_summary — daily summary or multi-day range with category breakdown and total
    3. edit_expense — update an existing expense entry
    4. delete_expense — remove an expense entry
    5. set_expense_budget — set a daily/weekly/monthly budget goal (stored in preferences)
    6. list_expenses — list recent expenses with optional date range and category filter
    7. get_spending_insights — compare spending to budget, highlight top categories, identify trends
  • Preferences: Budget goal stored in PostgresPreferencesStorage under keys like expense_budget_monthly, expense_budget_weekly
  • Date support: Use existing dateparser integration from src/blacki/utils/dates.py for natural language dates
  • Pattern: Follow existing storage + tools patterns from calories/ and workouts/

Sources

  • Calorie storage: src/blacki/calories/storage.py (model pattern)
  • Calorie tools: src/blacki/calories/tools.py (tool pattern, summary aggregation)
  • Workout storage: src/blacki/workouts/storage.py
  • Storage base class: src/blacki/storage/base.py
  • Preferences storage: src/blacki/utils/preferences.py
  • Date utilities: src/blacki/utils/dates.py
  • Tool registry: src/blacki/registry.py
  • DI container: src/blacki/container.py
  • Agent prompt: src/blacki/prompt.py
  • AGENTS.md tool design principles

Passing Criteria

  • uv run ruff check passes with no errors
  • uv run ruff format passes with no changes needed
  • uv run mypy . passes with no errors
  • uv run pytest tests/expenses/ --cov=src/blacki/expenses passes with 100% coverage on expenses module
  • uv run pytest full suite passes
  • log_expense correctly stores expense entry scoped to user_id with all fields
  • get_expense_summary returns correct daily totals and category breakdowns
  • get_expense_summary supports multi-day ranges with aggregation
  • edit_expense updates fields correctly and returns updated record
  • delete_expense removes the record and returns confirmation
  • set_expense_budget persists budget preference and returns confirmation
  • get_spending_insights compares spending to budget and highlights top categories
  • list_expenses supports filtering by date range and category
  • Storage is properly initialized via AppContainer and registry.py
  • All tools support natural language dates via existing dateparser integration

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions