Skip to content

API ​

Mintage's web app talks to the server over tRPC v11 with the superjson transformer, plus a handful of REST endpoints for files. Everything the web app can do, the API can do. This page summarises docs/API.md in the repository.

Basics ​

ServerFastify on http://localhost:4000 in development
tRPC mount/api/trpc (transformer: superjson)
Dev proxyThe web dev server (port 5173) proxies /api to 4000, so cookies are same-origin
TypesNames from packages/core/src/types.ts. Create<T> = Omit<T, 'id' | 'createdAt' | 'updatedAt'>; Patch<T> = Partial<Create<T>> & { id }
ListsPaginated lists return { items, nextCursor?, total? }; others return T[]
ErrorsTRPCError with cause: KeelError (code, message, details)

Authentication and CSRF ​

  • Sign-in sets a session cookie, keel_sid — HttpOnly, SameSite=Lax, and Secure in production.
  • Mutations must send the header x-keel-csrf: 1 and a matching Origin. Requests without them are rejected.
  • Every procedure that touches entity data takes an entityId and checks membership and role. viewer and accountant are read-only.
  • auth.login returns needsTotp: true when two-factor is on; call it again with the totp code.

Routers ​

RouterHighlights
authregister, login, logout, me, setupTotp / enableTotp / disableTotp, changePassword, updatePreferences (theme, calm mode, reduced motion, privacy blur, display currency…)
entitieslist, get, create (optionally seeding default categories), update, archive, members (invite, updateMember, removeMember), smsfMembers, upsertSmsfMember
accountsCRUD, close, reorder, balances({ entityId, asOf? }), history({ accountId, from, to, granularity })
categories · payees · tagsCRUD; categories.seedDefaults; payees.merge, payees.suggest({ raw })
transactionslist (filters, cursor, running balance for a single account), CRUD, bulkUpdate, createTransfer, quickAdd({ text }), markReviewed, unreviewedCount, attach / detach
rulesCRUD, run({ scope: 'unreviewed' | 'all' | 'range' }), suggest
recurringCRUD, upcoming({ days }), post, skip
reconciliationstart, get (candidates + difference), toggle, findDifference, complete, undo, list
budgetsCRUD, summary (lines with pace and status, safe-to-spend, needs/wants/savings), moveEnvelope, copyFromActuals
goalsCRUD, contribute, progress (percentage, projected date, new milestones)
forecastcashflow({ horizonDays, scenario? }), loan, debtPlan, superProjection, savings
securitiessearch, get, create, update, prices, upsertPrices, refreshPrices, benchmarks
tradeslist, create (with strategy or explicit allocations; returns CGT events), update, remove, whatIfSell, parcels
holdingslist, summary (value, cost, unrealised, allocation), valueSeries
corporateActionsCRUD, apply, suggest, importAnnualTaxStatement
incomeCRUD, report({ entityId, fy }) with ATO-labelled totals
taxfyList, cgtReport({ fy, lossOrder? }), setCarriedForwardLoss, harvestCandidates, discountCountdown
performanceportfolio({ period, benchmarkSecurityId? }) (TWR, XIRR, capital/income split, series), holding, allocation
importspresets, profiles, saveProfile, detect({ fileToken }), preview, commit({ batchId, includeDuplicates? }), revert, history
fxrates, upsert, refresh
reportsnetWorth, incomeExpense, categoryBreakdown, cashflow, budgetVsActual, payees, needsWants, taxDeductible, gstBas, vat, register, statement, goals, auditLog
businesscontacts, upsertContact, invoices, upsertInvoice, markPaid, ageing
engagementcheckIn, streaks, achievements, markAchievementsSeen, insights, dismissInsight, weeklyReviewData, homeSummary
watchlistsCRUD plus price alerts
adminauditLog, createBackup, backups, deleteAccountData({ confirm: 'DELETE' })

The full procedure list with input and output shapes is in docs/API.md.

REST endpoints ​

Method & pathPurpose
POST /api/uploadMultipart upload (field file) → { fileToken, fileName, sizeBytes, sha256 }. Files are kept for 24 hours.
GET /api/attachments/:idDownload an attachment (requires entity membership)
GET /api/export?report=…&format=csv|xlsx|pdf&entityId=…&from=…&to=…&fy=…Download a report
GET /api/backup/:fileTokenDownload a backup
POST /api/backup/restoreRestore from an uploaded backup (multipart)
GET /api/health{ ok: true, version }

Client setup ​

The web client lives in apps/web/src/api/client.ts:

ts
import { createTRPCClient, httpBatchLink } from '@trpc/client';
import superjson from 'superjson';
import type { AppRouter } from '@keel/api/router';

export const trpc = createTRPCClient<AppRouter>({
  links: [
    httpBatchLink({
      url: '/api/trpc',
      transformer: superjson,
      headers: { 'x-keel-csrf': '1' },
    }),
  ],
});

The app wraps this with TanStack Query via @trpc/tanstack-react-query.

Example: import a broker file ​

ts
// 1. upload the file (REST)
const form = new FormData();
form.append('file', file);
const { fileToken } = await fetch('/api/upload', {
  method: 'POST', body: form, headers: { 'x-keel-csrf': '1' },
}).then((r) => r.json());

// 2. detect, preview, commit (tRPC)
const detected = await trpc.imports.detect.query({ fileToken });   // { format, preset: 'nabtrade', kind: 'broker_trades', ... }
const preview = await trpc.imports.preview.mutate({
  entityId, fileToken, kind: 'broker_trades', accountId, preset: detected.preset,
});
const batch = await trpc.imports.commit.mutate({ batchId: preview.batchId });

// changed your mind?
await trpc.imports.revert.mutate({ batchId: batch.id });

Example: what-if sell ​

ts
const results = await trpc.trades.whatIfSell.query({
  entityId, accountId, securityId,
  units: '100', priceCents: 11000, date: '2026-03-15',
});
// one result per parcel strategy: proceeds, cost base, gross gain, discount, net gain, estimated tax, parcels used

Money is always integer cents and units are decimal strings — see Data model.

Not tax advice. Mintage provides general information only — it does not consider your personal circumstances. Check with a registered tax agent or licensed financial adviser before acting. Disclaimer