Appearance
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
| Server | Fastify on http://localhost:4000 in development |
| tRPC mount | /api/trpc (transformer: superjson) |
| Dev proxy | The web dev server (port 5173) proxies /api to 4000, so cookies are same-origin |
| Types | Names from packages/core/src/types.ts. Create<T> = Omit<T, 'id' | 'createdAt' | 'updatedAt'>; Patch<T> = Partial<Create<T>> & { id } |
| Lists | Paginated lists return { items, nextCursor?, total? }; others return T[] |
| Errors | TRPCError with cause: KeelError (code, message, details) |
Authentication and CSRF
- Sign-in sets a session cookie,
keel_sid—HttpOnly,SameSite=Lax, andSecurein production. - Mutations must send the header
x-keel-csrf: 1and a matchingOrigin. Requests without them are rejected. - Every procedure that touches entity data takes an
entityIdand checks membership and role.viewerandaccountantare read-only. auth.loginreturnsneedsTotp: truewhen two-factor is on; call it again with thetotpcode.
Routers
| Router | Highlights |
|---|---|
auth | register, login, logout, me, setupTotp / enableTotp / disableTotp, changePassword, updatePreferences (theme, calm mode, reduced motion, privacy blur, display currency…) |
entities | list, get, create (optionally seeding default categories), update, archive, members (invite, updateMember, removeMember), smsfMembers, upsertSmsfMember |
accounts | CRUD, close, reorder, balances({ entityId, asOf? }), history({ accountId, from, to, granularity }) |
categories · payees · tags | CRUD; categories.seedDefaults; payees.merge, payees.suggest({ raw }) |
transactions | list (filters, cursor, running balance for a single account), CRUD, bulkUpdate, createTransfer, quickAdd({ text }), markReviewed, unreviewedCount, attach / detach |
rules | CRUD, run({ scope: 'unreviewed' | 'all' | 'range' }), suggest |
recurring | CRUD, upcoming({ days }), post, skip |
reconciliation | start, get (candidates + difference), toggle, findDifference, complete, undo, list |
budgets | CRUD, summary (lines with pace and status, safe-to-spend, needs/wants/savings), moveEnvelope, copyFromActuals |
goals | CRUD, contribute, progress (percentage, projected date, new milestones) |
forecast | cashflow({ horizonDays, scenario? }), loan, debtPlan, superProjection, savings |
securities | search, get, create, update, prices, upsertPrices, refreshPrices, benchmarks |
trades | list, create (with strategy or explicit allocations; returns CGT events), update, remove, whatIfSell, parcels |
holdings | list, summary (value, cost, unrealised, allocation), valueSeries |
corporateActions | CRUD, apply, suggest, importAnnualTaxStatement |
income | CRUD, report({ entityId, fy }) with ATO-labelled totals |
tax | fyList, cgtReport({ fy, lossOrder? }), setCarriedForwardLoss, harvestCandidates, discountCountdown |
performance | portfolio({ period, benchmarkSecurityId? }) (TWR, XIRR, capital/income split, series), holding, allocation |
imports | presets, profiles, saveProfile, detect({ fileToken }), preview, commit({ batchId, includeDuplicates? }), revert, history |
fx | rates, upsert, refresh |
reports | netWorth, incomeExpense, categoryBreakdown, cashflow, budgetVsActual, payees, needsWants, taxDeductible, gstBas, vat, register, statement, goals, auditLog |
business | contacts, upsertContact, invoices, upsertInvoice, markPaid, ageing |
engagement | checkIn, streaks, achievements, markAchievementsSeen, insights, dismissInsight, weeklyReviewData, homeSummary |
watchlists | CRUD plus price alerts |
admin | auditLog, createBackup, backups, deleteAccountData({ confirm: 'DELETE' }) |
The full procedure list with input and output shapes is in docs/API.md.
REST endpoints
| Method & path | Purpose |
|---|---|
POST /api/upload | Multipart upload (field file) → { fileToken, fileName, sizeBytes, sha256 }. Files are kept for 24 hours. |
GET /api/attachments/:id | Download an attachment (requires entity membership) |
GET /api/export?report=…&format=csv|xlsx|pdf&entityId=…&from=…&to=…&fy=… | Download a report |
GET /api/backup/:fileToken | Download a backup |
POST /api/backup/restore | Restore 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 usedMoney is always integer cents and units are decimal strings — see Data model.