feat: category overspend early warning system (#117)#469
Open
qiridigital wants to merge 1 commit intorohitdash08:mainfrom
Open
feat: category overspend early warning system (#117)#469qiridigital wants to merge 1 commit intorohitdash08:mainfrom
qiridigital wants to merge 1 commit intorohitdash08:mainfrom
Conversation
- Add CategoryBudget model with per-category monthly spending limits - Configurable warning_threshold_pct (default 80%) - Budget CRUD: GET/POST /budgets, PATCH/DELETE /budgets/:id - GET /budgets/overspend: computes % spent vs limit per category - Warning levels: OK / MEDIUM (>=75%) / HIGH (>=90%) / CRITICAL (>=100%) - ?only_warnings=true filter to surface actionable alerts only - Sorted: CRITICAL first, then HIGH, MEDIUM, OK - Summary object with counts per level - Update schema.sql with category_budgets table and index - React BudgetOverspend page: summary pills, warning cards with progress bars, colour-coded by severity, budget management table - TypeScript API client with full types - 15 pytest tests covering CRUD, warning levels, income exclusion, auth /claim rohitdash08#117
There was a problem hiding this comment.
Pull request overview
Adds a category budget system with an overspend “early warning” report, plus a new frontend dashboard page to view/manage budgets and warnings.
Changes:
- Introduces
CategoryBudgetmodel/table and/budgetsCRUD +/budgets/overspendreporting endpoint. - Adds backend pytest coverage for budget CRUD and overspend warning behavior.
- Adds an
/overspendroute + UI page and a budgets API client.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 14 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/backend/tests/test_budgets.py | New pytest coverage for budgets + overspend report |
| packages/backend/app/routes/budgets.py | New budgets CRUD + overspend reporting endpoints |
| packages/backend/app/routes/init.py | Registers the new budgets blueprint |
| packages/backend/app/models.py | Adds CategoryBudget ORM model |
| packages/backend/app/db/schema.sql | Adds category_budgets table + index |
| app/src/pages/BudgetOverspend.tsx | New overspend dashboard page + budget management UI |
| app/src/components/layout/Navbar.tsx | Adds navigation link to /overspend |
| app/src/api/budgets.ts | Adds frontend budgets API client + types |
| app/src/App.tsx | Adds protected route for the overspend page |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| def _spent_this_month(user_id: int, category_id: int, month: str) -> float: | ||
| """Sum of EXPENSE-type transactions for (user, category, month).""" | ||
| year, mo = map(int, month.split("-")) |
Comment on lines
+168
to
+169
| month = (request.args.get("month") or _current_month()).strip() | ||
| only_warnings = request.args.get("only_warnings", "false").lower() == "true" |
Comment on lines
+181
to
+184
| results = [] | ||
| for b in budgets: | ||
| cat = Category.query.get(b.category_id) | ||
| spent = _spent_this_month(uid, b.category_id, month) |
Comment on lines
+89
to
+92
| budget_limit = float(data.get("budget_limit", 0)) | ||
| if budget_limit <= 0: | ||
| return jsonify(error="budget_limit must be positive"), 400 | ||
|
|
Comment on lines
+135
to
+137
| if "month" in data: | ||
| budget.month = data["month"] or None | ||
|
|
| "category_id": category_id, | ||
| "amount": amount, | ||
| "expense_type": expense_type, | ||
| "spent_at": date.today().isoformat(), |
| budget_limit NUMERIC(12,2) NOT NULL, | ||
| warning_threshold_pct INT NOT NULL DEFAULT 80, | ||
| created_at TIMESTAMP NOT NULL DEFAULT NOW() | ||
| ); |
Comment on lines
+78
to
+82
| Spent: <strong style={{ color: "#fff" }}>₹{w.spent.toLocaleString()}</strong> | ||
| </span> | ||
| <span> | ||
| {w.pct_used.toFixed(1)}% of ₹{w.budget_limit.toLocaleString()} | ||
| </span> |
Comment on lines
+138
to
+140
| const { default: api } = await import("../api/index"); | ||
| const r = await api.get("/categories"); | ||
| setCategories(r.data || []); |
Comment on lines
+29
to
+33
| Expense.user_id == user_id, | ||
| Expense.category_id == category_id, | ||
| Expense.expense_type != "INCOME", | ||
| func.strftime("%Y", Expense.spent_at) == str(year), | ||
| func.strftime("%m", Expense.spent_at) == f"{mo:02d}", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Category Overspend Early Warning System
closes #117 | /claim #117
Summary
Implements a production-ready category budget management system that alerts users before they exceed their spending limits, with configurable warning thresholds and real-time progress tracking.
Backend Changes
New model:
CategoryBudgetmonthfield (null = applies every month)warning_threshold_pct(default 80%) — fire warning when spending hits this %New endpoints (
/budgets):/budgets/budgets/budgets/:id/budgets/:id/budgets/overspendOverspend endpoint (
GET /budgets/overspend):?month=YYYY-MM— defaults to current month?only_warnings=true— filter out OK categoriesFrontend Changes
BudgetOverspend.tsx— Full dashboard with:api/budgets.ts— TypeScript API client with complete type definitions/overspendadded toApp.tsx+ nav link inNavbar.tsxDatabase
Tests
15 pytest tests covering:
?only_warningsfilter