Skip to content

About

NUVO is architected following a layered, service-oriented design philosophy. The system is structured to ensure a clean separation of concerns across five primary layers: the mobile client, the API gateway, the business logic services, the AI inference engine (LUNA), and the data persistence layer.

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

6 Commits

Folders and files

Repository files navigation

NUVO Backend — Documentation

Backend API for NUVO, the AI expense & fintech platform powered by LUNA. This folder is the canonical reference for the service: architecture, setup, and the full API contract.

Contents

File What's in it
API.md Every endpoint, grouped by resource, with request/response JSON
api/auth.md Auth endpoints in detail
api/transactions.md Transaction CRUD, OCR scan, UPI parse, voice logging
api/budgets.md Budget settings and Spend Guard stop-loss
api/analytics.md Summaries, trends, health score, exports
api/ai.md LUNA chat, insights, goals, subscriptions
openapi.yaml OpenAPI 3.0 spec — powers the interactive Swagger UI

Interactive API docs (Swagger)

With the server running, open http://localhost:4000/api-docs for an interactive, try-it-out UI generated from openapi.yaml. The raw spec is also served at /api-docs.json if you want to import it into Postman/Insomnia.

openapi.yaml is hand-maintained (not JSDoc-generated) — when you add or change a route, update the corresponding path/schema in that file, ideally in the same commit as the route change.

Architecture at a glance

Mobile/client → Express API (src/app.ts) → Mongoose → MongoDB Atlas
                       │                        ↑
                       ├─ BullMQ (Redis) ───────┘
                       │     └─ src/jobs/*.worker.ts (OCR, anomaly, forecast, insights, notifications)
                       └─ Socket.io (src/sockets) → real-time push to the client
  • API process (npm run dev / npm start): src/server.ts boots Express + Socket.io, connects MongoDB, and serves all REST routes under /api/v1.
  • Worker process (npm run worker:dev / npm run worker:start): src/jobs/runWorkers.ts runs independently, consuming the five BullMQ queues (ocr-queue, anomaly-queue, forecast-queue, ai-insights-queue, notification-queue) plus the cron scheduler for weekly digests and daily forecast refreshes. Run both processes for the system to function end-to-end — the API enqueues jobs; only the worker process executes them.
  • Full service-by-service breakdown lives in code comments under src/services/*.ts — each file's top-of-file docblock states what's a real implementation vs. a documented stand-in for a future ML model (see "What's real vs. mocked" below).

Running locally

cp .env.example .env          # fill in values as needed — see table below
npm install
npm run dev                   # API on :4000
npm run worker:dev            # separate terminal — required for OCR/anomaly/forecast/insights to progress

Or via Docker Compose (brings up Mongo + Redis + API + worker together):

docker-compose up

Required local services

Service Purpose Default
MongoDB Primary datastore mongodb://127.0.0.1:27017/nuvo
Redis BullMQ queues, rate limiting, notification budget counters, JWT blocklist redis://127.0.0.1:6379

Key environment variables (.env)

Variable Required? Effect if unset
MONGODB_URI, REDIS_URL Yes Server won't start
JWT_PRIVATE_KEY_BASE64 / JWT_PUBLIC_KEY_BASE64 Production only Dev: an ephemeral RSA key pair is generated per process — all tokens are invalidated on every restart
GOOGLE_VISION_API_KEY No OCR falls back to a deterministic mock receipt instead of calling Google Vision
GEMINI_API_KEY No LUNA chat falls back to a rule-based reply built from live budget/category data instead of calling Gemini
CLOUDINARY_CLOUD_NAME / CLOUDINARY_API_KEY / CLOUDINARY_API_SECRET No Uploaded images are stored on local disk under ./uploads instead of Cloudinary
FCM_SERVER_KEY No Push notifications are logged, not sent
LARGE_TRANSACTION_THRESHOLD No Defaults to 5000 — expenses above this trigger a P2 push notification

What's real vs. mocked

Every AI-adjacent feature is either a genuine implementation or an explicitly pluggable adapter — nothing silently pretends to work. This matters when reading the API docs below: an endpoint's shape is stable and production-ready even where the underlying model is a stand-in.

Feature Status
Transaction categorisation Real — keyword/merchant rule engine (categorisation.service.ts)
Anomaly detection Real — z-score vs. 90-day category baseline, duplicate detection, velocity check (anomaly.service.ts)
Spend forecasting Real — moving average + linear projection (forecast.service.ts)
Subscription detection Real — recurrence pattern matching over transaction history (subscription.service.ts)
Financial Health Score Real — weighted composite per the documented formula (analytics.service.ts)
CSV export Real
OCR (receipt text extraction) Pluggable — calls Google Vision if GOOGLE_VISION_API_KEY is set, else a fixed mock receipt
LUNA chat Pluggable — calls Google Gemini if GEMINI_API_KEY is set, else a rule-based reply using the same live data
UPI screenshot parsing Approximation — OCRs the screenshot then regex-matches app/amount/ref patterns; no true visual template matching
Voice transaction NLU Approximation — regex-based amount/merchant extraction from an already-transcribed string
PDF report generation Not implemented — analytics/report/pdf returns 501
Biometric login verification Not implemented — auth/biometric/verify returns 501
Push (FCM) / email (SES) dispatch Logged only — the notification record and Socket.io event are real; the external send is a no-op until credentials are wired

Conventions used throughout the API

  • Base path: everything is under /api/v1 except /health and /api-docs.
  • Auth: Authorization: Bearer <accessToken> on every route except /auth/register, /auth/login, /auth/refresh, /auth/biometric/verify, and /auth/forgot-password. Access tokens are RS256-signed, 15-minute TTL; refresh via POST /auth/refresh.
  • Response envelope: every response is { success, data, message?, errors? }. See API.md for the exact shape and error format.
  • Pagination: cursor-free, page/limit based (GET /transactions).
  • Real-time: Socket.io emits budget:alert, transaction:ready, insights:updated, and notification:new to a per-user room (user:<userId>) — authenticate the socket handshake with the same access token (socket.handshake.auth.token).

About

NUVO is architected following a layered, service-oriented design philosophy. The system is structured to ensure a clean separation of concerns across five primary layers: the mobile client, the API gateway, the business logic services, the AI inference engine (LUNA), and the data persistence layer.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages