Most teams assume adding an AI assistant to a personal-finance app requires moving user ledgers to a server database, executing tools in the cloud, and maintaining a dedicated backend for auth, streaming, quotas, and billing.
For a local-first iPhone app, that assumption breaks on contact. The moment you copy a couple’s expenses, incomes, and savings pots to a server just so a language model can answer questions about them, you throw away the privacy guarantee people chose the app for. Worse, you still burn weeks building device auth, spend caps, streaming parsers, and eval harnesses before the assistant answers a single real question.
In Justa 1.2, I shipped Justina, an in-app household finance assistant, by splitting the problem the other way around: every tool runs on the iPhone against the local SwiftData store, and the entire server side is a tenant document pushed to my open-source ai-platform.
Keep the ledger and the math on the iPhone
Justina never reads a server database because Justa does not have one. The household ledger lives in SwiftData on the iPhone (optionally synced peer-to-peer through a shared Files folder). When a user asks Justina a question, the app sends the message, the household’s currency, locale, and member first names, and the tool definitions to the runtime. When the model wants data, it emits a tool call—and the iPhone executes it locally, then sends only that tool result back for the next turn.
The client exposes seven tools under contract v3 (contracts/ask-justa/v3/tools.json), all routed through CompanionTools over the same IntentLedger and calculators that power Home, widgets, and Siri:
| Tool | Kind | What it does on the iPhone |
|---|---|---|
household | Read | Returns people, monthly plan, savings pots, goals, and currency |
find | Read | Searches expenses, monthly costs, contracts, To confirm drafts, and saved scenarios |
summarize | Read | Aggregates totals by category, person, or period using the app’s own Decimal math |
month_report | Read | Reads a full month’s plan, extras, settlement balance, and sobra |
project | Read | Runs multi-change look-ahead projections through ScenarioProjection.report (never saves a scenario) |
open | Action | Renders an in-app button to jump straight to a screen (e.g. Settle, Month, Contracts) |
propose | Write | Builds one confirmation card for up to 10 changes—applied only after the user taps Save |
Keeping the tools on the device solved three hard problems at once:
- One source of truth for money math. Justina cannot hallucinate a split or drift from the Home screen’s settlement figure because it calls the exact same cent-accurate calculators.
- No silent writes.
proposeis the only write tool. Whether Justina adds an extra, edits one, splits a receipt into two expenses, or adjusts a monthly cost, the model only returns a proposal. The app pins that proposal to the activehouseholdID, shows a native confirmation card, and writes nothing until the user taps Save (isolating rollback so a failed save never touches unrelated edits). - Real household guidance without financial-advice liability. Because
projectandEmergencyFund.reportcompute the household’s real savings cushion and monthly headroom on-device, Justina can answer practical questions—how much could be saved, whether an emergency fund is covered, what parental leave does to the plan—while strictly refusing to name investment products, promise returns, or give tax advice.
What Justina supports in the app
Inside Justa, Justina is designed to feel like part of the app rather than a webview bolted onto a tab:
- Natural questions, Markdown, and native charts. Answers stream in real time (with a Stop button mid-answer) and render native Markdown—tables, lists, headings, inline formatting—while stripping links and blocking remote images so ledger text can never trigger outbound requests. When a comparison helps, Justina renders native bar or line charts directly from the app’s own totals.
- Receipts and PDFs via camera, library, or Files. Users can snap a receipt with the document camera, pick a photo, or attach a PDF.
CompanionPhotoMakerscales it on-device to at most 1,024 points on the long edge and under 100 KB of JPEG. It has its own first-time consent, travels only with that question’s turns, and is tagged as data—never instructions. - Local conversation history and privacy controls. Up to 30 conversations (30 exchanges each) are stored locally in
Application Support/Companion/with complete file protection, never synced to the shared folder and never stored on the server. Explicit consent is required before the first request, can be withdrawn at any time from the sidebar (wiping all local history), and Hide amounts redacts proposal card figures for public demos.
Why it lives on ai-platform
A month ago, in Evaluating the Justa agent, Justa had its own bespoke Cloudflare Worker (justa-ask) serving /ask for the website and /chat for early TestFlight builds. When I built a second AI product—the exam tutor for Ensino—I realized I was about to duplicate gateway auth, spend pools, streaming, circuit breakers, and eval passes for the second time.
Instead, I extracted the shared infrastructure into aacnsilva/ai-platform: a multi-tenant TypeScript runtime on Cloudflare Workers backed by Durable Objects. The platform holds the mechanisms; zero product logic lives in it. Every product is a JSON tenant document pushed through an admin API.
Moving Justina onto ai-platform (as the justa-companion tenant, alongside justa-ask for the website) changed how fast I could iterate and scale:
- One push, no runtime deploys. Justa’s entire server integration is a pure builder (
tenant/companion-tenant.js) that compiles the prompt (src/chat-prompt.js), version-gated product notes (knowledge/justa.md), contract tools (contracts/ask-justa/v*/tools.json), and limits (wrangler.toml) into a ~288 KB tenant document. Updating a prompt, tightening a guardrail, or shipping new app-version notes is one command (npm run companion-tenant -- --push ...)—no Worker redeploy, no risk to other tenants. - Strict dev vs. production isolation out of the box. The platform runs two completely separate Worker deployments (
agent-runtime-devandagent-runtime) with separate Durable Objects and secrets. Debug builds from Xcode and TestFlight installs talk to the dev tenant (which accepts development App Attest keys, SandboxAppTransactions, Sandbox purchases, and a hashed eval secret). App Store builds talk to production, which accepts verified Production Justa Max transactions and nothing else. - Built-in observability and resilience. Every request writes one redacted metrics record (outcome, latency, token counts, euro cost—never user text) to the platform dashboard. Model routing uses capability tiers (
faston Claude Haiku 5.5,balancedon Sonnet 5.5) with per-model circuit breakers and fallback before any text streams. - Multi-product leverage. The same Worker that serves Justina’s stateless client-tool loop also serves Ask Justa’s anonymous website Q&A and Ensino’s stateful RAG tutor—each isolated by tenant ID, auth mode, and monthly euro budget.
Auth and metering without user accounts
Justa has no accounts, no emails, and no login screen. Running a paid AI tier without accounts meant solving two problems at the gateway: proving the request came from a real copy of Justa, and proving the user holds an active Justa Max subscription.
ai-platform’s app_attest authenticator handles both:
- On first use,
CompanionDeviceCredentialsgenerates an Apple App Attest key on the iPhone and attests it against the tenant’s challenge endpoint. - Every chat request signs
SHA-256(rawBody + "\n" + jws)with that hardware-backed key (X-Justa-Assertion) and attaches the StoreKit 2 signed transaction JWS (X-Store-Transaction). - The runtime verifies the App Attest assertion, checks the Apple certificate chain on the JWS, and meters usage per subscriber—300 messages per UTC month—inside a Durable Object, backed by a tenant-wide monthly EUR pool with reserve-and-settle accounting.
The economics that keep it sustainable
AI features in indie apps die quietly when a handful of power users burn through the subscription margin. Before setting Justa Max’s price (€5.99/month or €49.99/year, which also includes everything in Justa Pro), I modeled the worst-case ceiling against ai-platform’s limits:
- Counting rule: one question plus its first tool round counts as 1 message; each additional tool round counts as 1 more.
- Typical vs. ceiling cost: on Claude Haiku 5.5 (
loweffort), an average 2-call question uses ~29,880 input tokens and ~294 output tokens—about €0.0029 with prompt caching. Even at the absolute uncached ceiling (two calls at the 40,000-character conversation cap and full output limit), one counted message costs €0.0054, or €1.64 for all 300 messages. - Margin check: after 23% Portuguese VAT and Apple’s 15% Small Business Program cut, Justa Max adds €2.07/month (monthly) or €1.73/month (yearly) over Justa Pro—covering even a 100%-ceiling subscriber without subsidising tokens.
Evaluating the whole loop
Because Justina chains live tools, prompt-only evals are not enough. Justa ships a 53-case companion eval suite (scripts/run-companion-evals.sh) that runs against the real dev tenant on ai-platform with a seeded household, executing the real Swift CompanionTools on every round. That caught real issues before release: multi-round language drift, overly eager write proposals, and edge cases around financial-guidance boundaries.
Putting the ledger on the iPhone and the shared gateway in ai-platform meant I could ship a full tool-using, photo-reading, chart-drawing assistant as a solo developer—without compromising local-first privacy and without rebuilding AI infrastructure for every app I build next.