Skip to content

feat(summary): Smart Weekly Digest — GET /summary/weekly (Issue #121)#616

Open
XavierAbraham wants to merge 3 commits intorohitdash08:mainfrom
XavierAbraham:feature/smart-weekly-digest-121
Open

feat(summary): Smart Weekly Digest — GET /summary/weekly (Issue #121)#616
XavierAbraham wants to merge 3 commits intorohitdash08:mainfrom
XavierAbraham:feature/smart-weekly-digest-121

Conversation

@XavierAbraham
Copy link

Summary

Closes #121 — implements the Smart Weekly Digest feature with a new GET /summary/weekly endpoint.

What's included

packages/backend/app/routes/summary.py (new)

  • GET /summary/weekly?weeks_back=N — returns a structured financial digest for the authenticated user
  • Aggregation: total expenses, income, net cash flow, transaction counts
  • Category breakdown: per-category spending sorted by amount desc
  • Daily trend: 7-day sparkline data (all days filled, zeros where no data)
  • Insights: auto-generated text comparing current vs previous week (% change, cash flow direction)
  • Clean separation of pure functions (_aggregate_week, _category_breakdown, _daily_trend, _generate_insights) for testability

packages/backend/tests/test_summary.py (new)

  • 10 unit tests across all helper functions
  • Mocked DB — no live DB required
  • Covers edge cases: empty weeks, first-week-ever, positive/negative cash flow

packages/backend/app/routes/__init__.py (updated)

  • Registered summary_bp at /summary

API Response shape

{
  "period": { "start": "2026-03-16", "end": "2026-03-22", "label": "Week of Mar 16, 2026" },
  "summary": { "total_expenses": 150.0, "total_income": 500.0, "net": 350.0, "expense_count": 5, "income_count": 2 },
  "previous_week": { "total_expenses": 120.0, ... },
  "category_breakdown": [{ "category": "Food", "amount": 80.0, "count": 3 }],
  "daily_trend": [{ "date": "2026-03-16", "amount": 0.0 }, ...],
  "insights": ["Total spending increased by 25.0% vs last week (120.00 → 150.00).", "Positive cash flow this week: +350.00."]
}

Testing

cd packages/backend
pytest tests/test_summary.py -v

Authored-by: Xavier Abraham Sandoval abrahamsandoval.as@gmail.com

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