Skip to content

feat: Smart digest with weekly financial summary (#121)#772

Open
wocaoac-cpu wants to merge 1 commit intorohitdash08:mainfrom
wocaoac-cpu:feat/smart-digest
Open

feat: Smart digest with weekly financial summary (#121)#772
wocaoac-cpu wants to merge 1 commit intorohitdash08:mainfrom
wocaoac-cpu:feat/smart-digest

Conversation

@wocaoac-cpu
Copy link
Copy Markdown

Summary

Closes #121

Implements a Smart Digest feature that generates weekly financial summaries with AI-powered insights.

New Endpoint

GET /digest/weekly?week=YYYY-Www

  • JWT-protected
  • Accepts optional ISO week parameter (defaults to current week)
  • Supports user-supplied Gemini API key via X-Gemini-Api-Key header
  • Supports custom AI persona via X-Insight-Persona header
  • Results cached in Redis (10 min TTL) for non-custom requests

Response Payload

Section Description
period ISO week metadata with start/end dates
summary Total income, expenses, net flow, week-over-week change %, upcoming bills total/count
category_breakdown Per-category expense totals with percentage shares
daily_spending Day-by-day expense trend for the week
top_transactions Top 5 largest expenses
upcoming_bills Bills due within the week
insights AI highlights, risk flags, and saving tips

AI Integration

  • Gemini (primary): Calls Gemini API with financial data to generate contextual insights
  • Heuristic (fallback): Rule-based insights when Gemini is unavailable or no API key is configured
  • Graceful degradation: Gemini failures automatically fall back to heuristic with a warnings field

Files Changed

  • packages/backend/app/services/smart_digest.py — Core aggregation logic + AI enrichment
  • packages/backend/app/routes/digest.py — Blueprint with /weekly endpoint
  • packages/backend/app/routes/__init__.py — Register digest blueprint
  • packages/backend/app/openapi.yaml — API documentation with WeeklyDigest schema
  • packages/backend/tests/test_smart_digest.py — 29 tests covering:
    • parse_week_param validation (7 tests)
    • _week_bounds ISO week calculation (2 tests)
    • Integration tests for endpoint behavior (14 tests)
    • Heuristic insights logic (6 tests)

Test Plan

  • Unit tests for week parsing and bounds calculation
  • Unit tests for heuristic insight generation (all edge cases)
  • Integration tests for endpoint structure, data accuracy, caching, auth
  • Gemini integration test (mocked) verifying key passthrough and fallback
  • Verified existing tests unaffected (same Redis dependency for integration tests)
  • Full integration test with Docker Compose (Redis + PostgreSQL)

Implement weekly financial digest endpoint (GET /digest/weekly) that
generates comprehensive summaries including:

- Income/expense totals with week-over-week change tracking
- Per-category spending breakdown with percentage shares
- Daily spending trend for the week
- Top 5 largest transactions
- Upcoming bills due within the week
- AI-powered insights via Gemini with heuristic fallback

Includes:
- services/smart_digest.py: Core aggregation and AI enrichment logic
- routes/digest.py: JWT-protected endpoint with Redis caching
- tests/test_smart_digest.py: 29 tests (unit + integration)
- OpenAPI spec updated with /digest/weekly endpoint and schema

Closes rohitdash08#121
@wocaoac-cpu wocaoac-cpu requested a review from rohitdash08 as a code owner April 4, 2026 02:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Smart digest with weekly financial summary

1 participant