TradesBrain
React Native / Generative AI / Supabase / Stripe
A complete cross-platform mobile application for plumbers and electricians. 'Rex', an AI co-pilot, takes a photo or a voice note from the job site and walks the tradesperson through diagnosis step by step, looks up the relevant trade code through a pgvector RAG index, then turns the session into a finalised job report or client quote — behind Supabase auth, Stripe subscriptions and Stripe Identity KYC.
- Year
- 2026
- Role
- Solo — mobile app, backend, AI pipeline and release engineering
- Source
- Not public
Technologies
- React Native
- Expo
- TypeScript
- Supabase
- pgvector
- Claude API
- RAG
- Stripe
- Edge Functions
- NativeWind
The problem
A plumber standing in front of an unfamiliar boiler has three problems at once: working out what is wrong, checking what the trade code actually requires, and then producing paperwork a client will accept. Today that means a phone call to someone more experienced, a PDF regulation document nobody reads on a phone, and a quote typed up hours later at home. The knowledge exists — it just is not available hands-dirty, on site, in the ninety seconds it is needed.
The solution
A mobile app built around a single AI session. The tradesperson photographs the problem or describes it by voice; Rex holds a staged diagnostic conversation, cites the trade code it retrieved rather than inventing one, and at the end of the session the same conversation becomes a locked job report or a priced client quote. Everything that touches a model key, a system prompt or a billing field runs server-side in Supabase Edge Functions, so the phone never holds a secret.
Architecture
How it is put together.
Capture
Photo capture with client-side compression, or a voice note transcribed through a Whisper proxy — the two inputs a tradesperson can actually manage with one hand on a job.
Retrieval
Trade code documents are chunked and embedded into pgvector; lookup runs an embedding proxy then a `match_documents` RPC filtered by trade type, so an electrician never gets a plumbing regulation back.
Model routing
A router picks the model per turn from the session stage and message type — the heavier model for diagnosis and code lookup, a cheap fast one for formatting and confirmation turns. Thinking budgets are pinned deliberately rather than left adaptive, because an adaptive budget was measurably truncating answers.
Safety markers
Rex emits an inline marker protocol for stage tracking and for safety panels. Stop/confirm/note markers survive into the persisted transcript, so a gas-safety warning is still visible when the job is reopened weeks later.
Documents
A finished session becomes a job report or quote. Once finalised, a database trigger makes the row permanently immutable — the document a client received can never be quietly edited afterwards.
Billing & identity
Stripe subscriptions with signature-verified webhooks, Apple IAP for iOS, a server-side trial counter the client cannot write to, and Stripe Identity KYC auto-initiated at sign-up and enforced twice — once client-side, once inside the checkout function.
Mother / country architecture
The engine was refactored into a country-agnostic 'mother' layer with country children deriving from it — trade codes, tax, legal copy, verification triggers and i18n all read from the child. Adding a second market becomes configuration rather than a fork.
Key features
What it actually does.
- AI diagnostic sessions from photo or voice input, with staged step-by-step guidance
- Trade code lookup grounded in a pgvector RAG index, filtered per trade
- Job reports and client quotes generated from the session, permanently locked once finalised
- Email, phone-OTP and Google sign-in, with a KYC verification chain before checkout
- Stripe subscriptions, Apple in-app purchase, trial metering and a customer portal
- Team accounts — owners add members, with read-only row-level access to member data
- Push notifications, offline network handling and a server-driven force-upgrade gate
- Country-agnostic core with per-country children for codes, tax, legal copy and i18n
Engineering challenges
The parts that were hard.
No API key may ever ship in the bundle
A mobile bundle is readable by anyone who downloads it, so every Anthropic, OpenAI and Stripe-secret call goes through an authenticated Supabase Edge Function proxy that verifies the caller's JWT first. System prompts moved server-side for the same reason — the client sends a trade type and context, and the server assembles the prompt.
React Native has no usable streaming
RN's fetch drops streamed chunks, so real SSE was not an option. The app makes a buffered request and reveals the text word by word, which gives the same live feel with a stable timeout path when the network is bad — which, on a job site, it usually is.
Session JWTs outgrew the keychain
Supabase session tokens exceed what a single secure-store entry will hold. The client uses a chunked SecureStore adapter that splits the token across sibling keychain keys, because storing a session in plain async storage on a tradesperson's phone was never acceptable.
One codebase, two markets, zero regressions
Turning a single-country app into a mother/child architecture risked breaking the market already running. Every refactor phase was gated against a frozen behavioural baseline of the original app, so 'identical' was something provable rather than asserted.
Outcomes
What came out of it.
Qualitative outcomes only — no invented benchmarks or metrics.
A complete production app — 28 screens, 23 Edge Functions, 13 tables with row-level security on every one
Shipped to both platforms: iOS through EAS cloud builds, Android built locally
No key, prompt or billing write exposed on the client
A country-agnostic core, so the second market is configuration rather than a second codebase
Next project
CricketVision AI
Turns raw cricket video into a structured, queryable per-delivery dataset.
Let’s build
Want something like this for your business?
Tell me the problem and I will come back with an architecture, a scope and a timeline.