Skip to main content

API and Server Actions

Cashlytics primarily uses Next.js Server Actions as the application API layer.

Implementation Model

  • Mutations and queries are implemented in src/actions/*.
  • AI chat is exposed via an API route in src/app/api/chat/route.ts.
  • Responses use a consistent success/error shape.

Core Action Domains

  • Accounts
  • Expenses, daily expenses, subscriptions, and attachments
  • Income
  • Transfers
  • Categories
  • Dashboard and analytics
  • Forecasts
  • Search and AI conversations
  • Documents
  • CSV import staging, reconciliation, conflict decisions, and confirmation
  • User settings
  • Exchange rates
  • Push subscriptions and upcoming payment cron

API Routes

RoutePurposeNotes
POST /api/chatAI assistant chat and tool orchestrationRequires OPENAI_API_KEY; authenticated and rate-limited
POST /api/receipt-scanReceipt image extractionRequires OPENAI_API_KEY; JPG/PNG, 5 MB limit
GET /api/documentsList user documentsAuthenticated
POST /api/documentsUpload a documentAuthenticated; PDF/PNG/JPG/JPEG, 5 MB limit
GET /api/documents/[id]Fetch one documentAuthenticated/user-scoped behavior should be preserved when changing this route
DELETE /api/documents/[id]Delete one documentUsed by document library workflows
GET /api/exchange-ratesReturn EUR-based exchange ratesRefreshes stale cache and falls back when upstream rates are unavailable
GET /api/push/vapid-public-keyReturn browser push public keyRequires VAPID configuration for useful output
POST /api/push/subscribeSave push subscriptionAuthenticated
DELETE /api/push/subscribeRemove push subscriptionAuthenticated
GET /api/cron/upcoming-paymentsSend upcoming payment remindersRequires Authorization: Bearer <CRON_SECRET>

Import Actions

CSV import is implemented in src/actions/import-actions.ts and supporting services under src/lib/import. The flow stages rows first, runs deterministic and AI reconciliation, records conflict decisions, and only writes income/expense records during final confirmation.

Typical Action Contract

type ApiResponse<T> =
| { success: true; data: T }
| { success: false; error: string };

Revalidation Strategy

After successful writes, affected paths are revalidated so dashboard and list views stay consistent.

  • cashlytics/docs/api/README.md
  • cashlytics/docs/api/expenses.md
  • cashlytics/docs/api/incomes.md
  • cashlytics/docs/api/accounts.md
  • cashlytics/docs/api/transfers.md

For AI scope, restrictions, and approval rules, see AI Capabilities and Guardrails.