fix(core): complete project audit remediation for auth, financial integrity, and performance
Summary of Changes - Backend
This PR implements comprehensive audit remediations covering financial integrity, authentication hardening, N+1 query elimination, route validation, database indexing, and static analysis cleanup.
Financial Integrity & Security (P0 & P1)
-
Enforced Wallet Balance Immutability: Removed
balancefromupdateWalletSchemaandUpdateWalletDto. Wallet balances can now only be mutated viaTransaction(Income/Expense) orTransferoperations within serializable transactions. -
Dual-Channel Token Delivery: Updated
/auth/loginand/auth/refreshendpoints to returnaccessTokenandrefreshTokendirectly in the JSON response payload alongside HTTP-only cookies to support mobile WebView / Mini App environments. -
Hardened Access Token Lifecycle: Reduced default JWT
accessExpiresInfrom24hto30mand added active user validation (isActive&deletedAt === null) inauthMiddlewarebacked by a 60-second in-memory/Redis cache.
Performance & Database Optimization (P1 & P2)
-
Eliminated N+1 Aggregate Queries:
- Added
BudgetRepository.getBatchSpendingSummariesto calculate spending across all budgets in a single database query. - Optimized
NotificationRepository.findBudgetCandidatesto batch-fetch transactions across candidate budgets.
- Added
-
Added Composite Indexes:
- Added
@@index([userId, isArchived])onWallet. - Added
@@index([status, updatedAt])onNotificationDelivery. - Deployed migration
20260819223000_add_composite_indexes.
- Added
API Validation & Code Quality (P2 & P3)
-
UUID Parameter Validation: Added
userParamsSchemaandsessionParamsSchemato validate:idon admin and session routes, preventing unhandled PrismaP2023(500) errors. -
ESLint & Compiler Hygiene: Updated
eslint.config.mjsto support_prefix for intentionally unused variables/caught errors; normalized Express 4-argument error handler signature (_next). Achieved 0 lint errors, 0 warnings.