How riitkagarwal/hackinmotion-ricr-him-1182 works
Purpose and entry points
SpenSight is a personal-finance expense analyzer: authenticated users add or import transactions, receive automated categories, budget comparisons, analytics, health scoring, and text-based financial insights. The browser entry pages are Frontend/login.html, Frontend/dashboard.html, and Frontend/insights.html. The Node/Express API starts at backend/server.js.
Client application
The frontend is a static Vanilla JS application, not a separate SPA build. Page scripts authenticate through the API, retain/use JWT credentials, request dashboard and insight data, and render charts/UI. Shared API access is centralized in Frontend/js/api.js; dashboard and insight orchestration reside in Frontend/js/dashboard.js and Frontend/js/insights.js. Styling/design-system concerns are in Frontend/css/style.css.
HTTP API and tenant boundary
Express routes divide the API by domain—authentication, transactions, accounts/categories, budgets, analytics, health, insights, and AI. Route modules dispatch to controllers, while JWT middleware protects user-scoped endpoints and enforces tenant isolation before database access. Principal paths: backend/routes/authRoutes.js, backend/routes/transactionRoutes.js, backend/middleware/authMiddleware.js, backend/controllers/transactionController.js.
Transaction ingestion pipeline
Transactions enter either as manual API submissions or CSV uploads. Upload middleware accepts multipart files; CSV processing is designed as an asynchronous BullMQ job path backed by Redis. The worker parses records, categorizes them, and persists results rather than requiring synchronous bulk processing. Key boundaries: upload/API (backend/middleware/uploadMiddleware.js, backend/controllers/transactionController.js), queue (backend/queues/csvQueue.js), and worker/import service (backend/workers/csvWorker.js, backend/services/csvImportService.js, backend/utils/csvParser.js).
Classification and financial computation
A local deterministic categorization engine normalizes transaction descriptions and maps merchants/keywords to categories, avoiding external AI providers for transaction data. Analytics and insight services aggregate persisted user transactions into category, trend, spike, budget, and recommendation data; the health controller exposes the composite 0–100 score. Core paths: backend/services/categorizationService.js, backend/services/analyticsService.js, backend/services/insightsService.js, backend/controllers/healthController.js. The separate assistant-facing logic is in backend/services/aiEngine.js behind backend/routes/aiRoutes.js.
Persistence, cache, and infrastructure
PostgreSQL is the source of truth, with normalized users, categories, transactions, and budgets; its schema and initialization flow are backend/schema.sql, backend/config/db.js, and backend/scripts/initDb.js. Redis supports both caching and BullMQ queueing through backend/config/redis.js and backend/services/cacheService.js. Runtime is Node.js 18+ with Express; deployment/container topology is represented by backend/Dockerfile and docker-compose.yml. Production infrastructure is intended for Neon PostgreSQL, Redis, and Render; secrets, CORS origins, and connection settings are environment-driven.
Main entry points: transactionController.js Transaction controller · api.js Shared API client & JWT use · csvQueue.js CSV import queue · server.js Express server
Components 19
Static browser client
- Login, dashboard & insights pages
- Shared API client & JWT use
Frontend/js/api.js - Dashboard orchestration
Frontend/js/dashboard.js - Insights orchestration
Frontend/js/insights.js
Node / Express API
- Express server
backend/server.js - Domain routes · Authentication, transactions, accounts, budgets, analytics, health, insights, and AI endpoints.
- JWT tenant guard · Protects user-scoped endpoints before database access.
backend/middleware/authMiddleware.js - Transaction controller · Handles manual transaction submissions and CSV upload requests.
backend/controllers/transactionController.js - Health score endpoint · Exposes the composite 0–100 financial health score.
backend/controllers/healthController.js - Multipart upload middleware
backend/middleware/uploadMiddleware.js
Async processing & finance logic
- CSV import queue
backend/queues/csvQueue.js - CSV import worker · Processes imports asynchronously.
backend/workers/csvWorker.js - CSV import service & parser · Parses records, categorizes them, and persists transactions.
- Deterministic categorization · Normalizes descriptions and maps merchant keywords locally.
backend/services/categorizationService.js - Analytics & insights services · Builds category, trend, spike, budget, and recommendation data.
- Assistant AI engine · Separate assistant-facing logic.
backend/services/aiEngine.js
Data infrastructure
- PostgreSQL · Normalized users, categories, transactions, and budgets.
- Redis · Supports cached responses and BullMQ.
- Container deployment · Node API runs with PostgreSQL and Redis infrastructure.
Connections 26
- Login, dashboard & insights pages → Shared API client & JWT use: loads and calls
- Dashboard orchestration → Shared API client & JWT use: requests dashboard data
- Insights orchestration → Shared API client & JWT use: requests insight data
- Shared API client & JWT use → Express server: JWT API requests
- Express server → Domain routes: mounts
- Domain routes → JWT tenant guard: protects scoped endpoints
- JWT tenant guard → Transaction controller: authorized requests
- Domain routes → Health score endpoint: health endpoint
- Domain routes → Assistant AI engine: AI endpoint
- Transaction controller → Multipart upload middleware: CSV submissions
- Multipart upload middleware → CSV import queue: enqueues import
- CSV import queue → CSV import worker: jobs
- CSV import worker → CSV import service & parser: processes
- CSV import service & parser → Deterministic categorization: classifies records
- Transaction controller → Deterministic categorization: categorizes manual entries
- Deterministic categorization → PostgreSQL: uses categories and persists results
- CSV import service & parser → PostgreSQL: persists imported transactions
- Transaction controller → PostgreSQL: persists transactions
- Analytics & insights services → PostgreSQL: aggregates user finances
- Health score endpoint → Analytics & insights services: computes score from
- Domain routes → Analytics & insights services: analytics and insights endpoints
- CSV import queue → Redis: BullMQ backend
- Analytics & insights services → Redis: cached results
- Container deployment → Express server: runs API
- Container deployment → PostgreSQL: provisions
- Container deployment → Redis: provisions