feat(system): implement system optimization, security hardening, detailed...
Overview
This pull request implements comprehensive system optimizations, security hardening, detailed health monitoring, and containerized deployment configuration to make the FinWise backend ready for production.
Key Changes
1. Architectural & Core Utilities
-
Logger Service: Added a custom level-based
LoggerServicethat outputs structured JSON in production (safely redacting sensitive parameters likepassword,token,apiKey) and pretty-printed format in development. -
Cache Service: Built a pluggable caching wrapper using
iorediswith an automated memory-safe fallback to prevent memory leaks if Redis is offline. -
Lock Service: Built a distributed lock mechanism using Redis (
SET NX PX) with a local fallback to prevent overlapping background task processing.
2. Throttling & Concurrency Guardrails
-
Rate Limiting: Re-implemented the Express
rateLimitMiddlewareto support Redis-backed rate limiting with a self-pruning memory-safe Map fallback. -
Worker Locking: Locked the background tick in
NotificationWorkerto ensure only one instance executes reminder checks at a time in scale-out container environments.
3. Caching & Performance Optimization
- System Categories Caching: Cached read-only system categories for 1 hour, bypassing the database for common app-startup list/tree requests.
- Financial Reports Caching: Cached report aggregates (overview, cash flow, categories spending, budget performance) for 5 minutes per user query.
- Cache Invalidation Triggers: Configured instant cache invalidation upon any mutations to Transactions, Wallets, Budgets, and Saving Goals.
4. System Health Monitoring
-
Detailed Health Endpoint: Replaced the basic
/healthcheck with an active diagnostics controller returning:- Server resource utilization (memory rss/heap, process uptime).
- Database availability & round-trip query latency (ms).
- Cache adapter state (Redis connection vs. Memory fallback).
-
Swagger API Docs: Updated the
/healthAPI schemas to document the detailed JSON response structure.
5. Deployment, CI/CD & Code Quality
-
Dockerfile: Defined a multi-stage production Docker build using a lightweight Node.js Alpine base, executing under a non-root
nodeuser. - Docker Compose: Configured healthy checks dependency order so that the Node application waits for PostgreSQL and Redis to be fully responsive.
-
CI pipeline: Created a GitHub Actions workflow
.github/workflows/ci.ymlverifying TypeScript compilation, Prisma schemas, and ESLint. -
ESLint Configuration: Set up a flat
eslint.config.mjsresolving all source-code formatting and type rules.
Verification Results
-
Compilation:
pnpm run buildcompiles successfully. -
Linting:
pnpm run lintexecutes cleanly with zero errors. -
Database validation:
pnpm exec prisma validatecompletes successfully. -
Health Check Probe: Proved database latency and Redis connection status:
{ "success": true, "status": "ok", "timestamp": "2026-08-06T10:18:58.937Z", "uptime": 11.58, "memory": { "rss": "72.16 MB", "heapTotal": "23.69 MB", "heapUsed": "20.54 MB" }, "database": { "status": "up", "latencyMs": 3 }, "cache": { "status": "up", "type": "redis" } }