feat(be): implement 5 advanced financial engineering modules
Overview
This pull request delivers 5 end-to-end full-stack advanced financial features for FinWise Mini App, introducing algorithmic financial forecasting, discrete-event simulation, statistical anomaly detection, automated subscription tracking, and a deterministic natural language query engine.
All features are fully integrated across the stack with Type-Safe Backend Services, Mathematical Engines, Automated Tests, Claymorphism UI Components, TanStack Query Hooks, and Bilingual Localization (VI/EN).
Upgrades Breakdown
1. Cash Flow Runway & Budget Forecaster (/forecast)
-
Backend:
- Exponential decay weighting for daily burn rate ($\lambda = 0.04$).
- Mathematical runway projection: $\text{Runway} = \frac{\text{Current Balance}}{\text{Weighted Burn Rate}}$.
- Data sufficiency validation based on sample variance & count.
- Active budget exhaustion date prediction and daily spending cap recommendations.
-
Frontend:
- Interactive forecast horizon switcher (
14,30,60,90days). - Runway gauge card with finite countdown or positive cash flow indicator.
- Risk badges (
LOW,MEDIUM,HIGH,CRITICAL) with localized date formatting. - Claymorphism loading skeleton & error retry handling.
- Interactive forecast horizon switcher (
2. What-if Financial Simulation Sandbox (/simulations)
-
Backend:
- Discrete-event simulation over a 1–24 month horizon.
- Support for custom recurring & one-time perturbations (income & expense shifts).
- First-month deficit detection & saving goal collision evaluation.
- Built-in scenario presets (New Job, Major Purchase, Inflation Surge, Aggressive Saving).
-
Frontend:
- 1-click preset loader and interactive month duration slider.
- Custom cash flow adjustment builder with real-time currency formatting.
- Comparative trajectory breakdown (Baseline vs. Simulated) and goal delay alerts.
3. Multi-dimensional Anomaly Detection (/anomalies)
-
Backend:
- Modified Z-Score using Median Absolute Deviation (MAD): $$M_i = \frac{0.6745 \cdot |x_i - \tilde{x}|}{\text{MAD}}$$
- Multi-factor evaluation: Velocity bursts ($\ge 3$ txns / 20 min), off-peak transactions (02:00–05:00 UTC+7), and wallet balance ratio triggers.
- Integration with
NotificationServicefor real-time alerts.
-
Frontend:
- Pre-purchase interactive transaction evaluator.
- Flagged history cards with severity badges (
CRITICAL,HIGH,ELEVATED) and tagged reason codes.
4. Auto Subscription Discovery (/subscriptions)
-
Backend:
- Merchant token normalization and string cleaning.
- Periodic regularity autocorrelation scoring ($R \ge 0.75$).
- Price drift detection ($>3%$ increase between billing cycles).
- 1-click conversion endpoint creating active tracked
Reminderentries.
-
Frontend:
- Discovered subscription cards with frequency badges (
Monthly,Weekly,Yearly). - Amber warning banners for detected subscription price hikes.
- 1-click "Add to Reminders" conversion action flow.
- Discovered subscription cards with frequency badges (
5. Hybrid NL to Deterministic DSL Query Engine (/query)
-
Backend:
- Vietnamese natural language tokenizer and slot extractor.
- Compiler generating type-safe Abstract Syntax Trees (AST).
- Parameterized database aggregation executor (preventing raw SQL injection risks).
-
Frontend:
- Natural language input bar with quick prompt chips.
- AST filter inspector tags.
- Verifiable summary card, category breakdown groups, and detailed matching transaction list.