Skip to content

Product Engineering

One Codebase, Three Platforms: React, Capacitor, Stripe and RevenueCat

4 min read

Tracademic is built to run on the web, iOS and Android from a single React codebase, wrapped for mobile with Capacitor. That decision saved a huge amount of duplicated work as a solo developer, but it also introduced a class of bug I hadn't had to think about before: the same feature behaving correctly on one platform and incorrectly on another, for reasons that had nothing to do with the UI.

Why one codebase mattered

Building three separate native apps was never realistic for one person. Capacitor takes a React web app and wraps it in a native shell, giving access to native APIs where needed while keeping the actual application logic, components and business rules in one place. Every feature, every bug fix, every UI change ships to all three platforms at once. That's the whole appeal, and it's held up well — but it means platform differences that do exist have to be handled deliberately, not left to chance.

Web payments vs in-app purchases

Payments are the clearest example of a genuine platform split. On the web, Stripe handles subscription billing directly. On iOS and Android, Apple and Google both require in-app purchases for digital subscriptions delivered through their apps, so Tracademic uses RevenueCat to manage those purchases and keep entitlement state in sync across both mobile platforms.

That means the app needs to know, at runtime, which payment path it's allowed to offer:

import { Capacitor } from '@capacitor/core';

function getPaymentProvider() {
  return Capacitor.getPlatform() === 'web' ? 'stripe' : 'revenuecat';
}

That part is straightforward once you know the rule exists. The harder problem was what happens after a purchase succeeds — specifically, what the rest of the app is allowed to assume about a user's access level once they're "Pro."

The mistake: hiding the button isn't a guard

Early on, "Pro" features were gated the way it's easiest to gate anything: by hiding the relevant button or screen from users who weren't subscribed. That's a reasonable first pass, and it's often enough — until you remember that a codebase shared across platforms doesn't just share UI, it shares every function underneath it too. A hidden button stops a normal user from finding a feature. It does nothing to stop a code path from being reached some other way: a stale cached screen state, a deep link, a function called from somewhere the UI gate didn't anticipate, or simply a bug introduced later by a change that didn't realise a particular function was meant to be gated.

On iOS specifically, this stopped being a hypothetical the first time an entitlement check I assumed was "obviously" covered by the UI turned out not to be checked at all further down the call stack. The UI was correct. The function it called wasn't defending itself.

Guarding at every entry point

The fix was to stop treating "Pro" as a UI concern and start treating it as something every relevant function had to verify for itself, on its own, regardless of how it was reached:

function generateWeightedGrade(user, data) {
  if (!user.isPro) {
    throw new Error('Pro required');
  }

  // ... Pro-only logic
}

This looks almost too simple to be a lesson, but the discipline is in the "every function" part, not the code itself. One shared codebase across three platforms means one bug in a single unguarded function is a bug on web, iOS and Android simultaneously. The UI gate is still worth keeping — it's good UX to not show someone a button they can't use — but it's a convenience, not a security boundary. The real boundary has to be an early-exit guard inside every function that grants Pro behaviour, checked independently of whatever screen the user happened to arrive from.

I found the unguarded function myself, by reading back through the code.

The takeaway

Sharing one codebase across platforms is one of the best decisions I made building Tracademic solo, but it raises the cost of an unguarded code path, because that path exists everywhere at once. Platform-specific decisions like Stripe versus RevenueCat are easy to spot and easy to isolate behind a single function. The harder discipline is making sure anything that grants access checks that access itself, on every entry point, rather than trusting that the UI upstream already handled it — a habit that mattered just as much when it came to getting the iOS build through App Store review, which is its own story: What App Store Rejection Taught Me.