Share from 0:00
0:00
/

Family Superapp Code Walkthrough: RIBs-KMP app, native view layer on iOS, Android, macOS, and Web

A walkthrough of the Family Superapp code as if you were my teammate onboarding onto the project. RIBs architecture, KMP app, native view layer: iOS/SwiftUI, Android/Jetpack, macOS/AppKit, Web/React.

Watch it above, or on YouTube. Timestamps for the video (linked to YouTube) are at the bottom of this page.

In this episode

About 80% of Family Superapp’s code is written once in RIBs-KMP and runs on iOS, Android, macOS, Windows and the web, and only the native view layer (the last 20%) is written per platform.

I launched Family Superapp about a month ago, after roughly two months of part-time work after my day job, and Claude wrote most of the code.

I meant to write a series of blog posts about how I built it, but I couldn’t find the time to write them. So instead I recorded the walkthrough I’d give a new teammate joining me on the project.

We start with how I worked with Claude (I made the architectural decisions and delegated the bricklaying) and then go through what a RIB is, the app’s RIB tree and the repo layout.

The middle of the video follows one RIB, Groceries, from its builder through the interactor and presenter to its view, and then into the SwiftUI, Jetpack Compose and React code that renders it. We finish with how the app starts on iOS and macOS, and with Windows, the one platform where I broke my own rule.

It’s off the cuff and a little raw, and since I didn’t read every line Claude wrote, in a few places I’m discovering the code along with you.

But that’s kind of the point, because RIBs is what let me skip the code that doesn’t matter and focus on the parts that do.

Takeaways from the walkthrough

Here are the 13 things I’d want a new teammate to take away from this codebase and from how I built it with AI:

1. I made the architecture decisions and delegated the bricklaying to AI. I guided Claude to architect the app a certain way and made the high-level decisions (plus a bunch of low-level ones where they mattered), and Claude wrote the code.

I kept tabs on it by spot-checking the important pieces and doing high-level code reviews by talking to Claude, rather than reading every single line.

2. RIBs is what made that workable. Every RIB is structured, built and wired the same way, so I don’t have to read much of a new RIB to trust it.

What I do pay attention to is how the RIBs compose into a tree, how parents and children talk to each other, and the business logic inside each interactor.

“Everything’s standardized. Everything. But not everything is prescribed, only the important things such as your overall architectural structure and your communication between these RIBs. Everything else is up to you.”

3. RIBs is driven by business logic, not by the view. A RIB is a router, an interactor and a builder, plus a presenter and a view when it has something to show.

When a RIB displays something on screen, it’s just a side effect of the interactor asking its presenter to present some data, and the view never drives the logic (which is what sets RIBs apart from virtually every other client-side architecture).

4. Only the parts of the app the user is in exist in memory. When you first install the app, Root’s interactor sees you’re logged out and routes to Landing, so Main and every tab under it aren’t initialized and don’t hold any state.

When you log in, Landing tells Root, and Root detaches Landing and attaches Main.

5. The view is just a contract. Each RIB’s view is a Kotlin interface of render methods, plus a delegate interface for user input, and the shared code never creates a SwiftUI view, a Compose function or a React component.

To add a platform you implement those interfaces, and how that platform renders is its own implementation detail (and these days you can let AI figure it out).

6. RIBs doesn’t dictate a programming style. Unlike TCA or Redux-style architectures, nothing forces you to go reactive, so inside a RIB you can be as reactive as you want, and your view layer can be React, SwiftUI, AppKit or UIKit.

My app barely uses flows, except for location tracking, where we broadcast location changes across the app.

7. The one thing I policed was business logic creeping into the view layer. I paid the least attention to the platform view code, because AI handles that pretty well now.

But I did check whether Claude had put state, workarounds or business logic in the view layer instead of the shared RIBs, because it did that quite a few times and I had to force it not to (I’m working on linters to catch it automatically).

8. RIBs isn’t all-or-nothing. You can plug a single RIB, or a whole RIB subtree, into an existing app on any platform: a SwiftUI or view controller app on iOS, an Activity, Fragment or Compose app on Android, a React app on the web, and so on. You can even route from a RIB back to non-RIB views with adapters.

Family Superapp just happens to be RIBs end to end.

9. Sharing one app between mobile and desktop is a showcase, not a recommendation. The macOS and web apps reuse the mobile RIB tree (the tab bar becomes a menu), but I actually think mobile and desktop should be two separate apps.

I did it this way to show what’s possible with one codebase.

10. The presenter has two jobs. It maps domain models to view models and asks the view to render them, and it translates raw user input from the view into explicit user intents for the interactor.

The methods on each side are different on purpose (didTapItem in the view’s delegate, editItem on the interactor): the view reports what the user did, and the interactor says what the app should do.

11. View factories trickle down from one root factory. A RIB’s builder creates its view through a view factory that its parent injects.

Each platform’s entry point creates one root view factory right before building the Root RIB, and from there each parent’s factory provides its children’s factories, all the way down to leaves like Paywall or Family Invite.

12. On the web, React is just the view layer. The shared RIBs drive React the same way they drive SwiftUI and Compose, and the only workaround was asserting the view contract at runtime (Kotlin compiled to JavaScript couldn’t enforce the interface at compile time the way the other platforms do).

“You don’t have to succumb to changing your whole architecture because of React and because you decided to use React in your view layer on the web.”

13. Windows is the one place I broke my own rule. I couldn’t get a native .NET view layer working with Kotlin’s Windows binary fast enough, so the Windows app renders with Compose Multiplatform.

I think shared UI frameworks are a bad idea for the same reasons React Native is (you don’t want a lowest common denominator in your view layer), but I had to ship, and I can rebuild it natively once there are enough Windows users.

The Mobile Engineer posts relevant for this episode

Timestamps

  • 00:00 Intro: a video instead of a blog post

  • 02:01 Building with AI: I own the architecture, Claude lays the bricks

  • 04:48 RIBs is an architecture, not a language

  • 06:29 What a RIB is

  • 07:55 Anatomy of a RIB and the abstracted view layer

  • 09:11 The app’s RIB tree: Root, Landing and Main

  • 13:24 The repo: backend, shared RIBs and platform hosts

  • 17:22 The view is an interface

  • 19:50 No enforced reactive style

  • 21:41 The iOS host and the first AI-ism

  • 23:46 What to police: business logic in the view layer

  • 26:14 The Groceries RIB: the builder

  • 27:16 RIBs isn’t all-or-nothing

  • 28:57 Should mobile and desktop share one app?

  • 32:59 The interactor

  • 34:47 The presenter: domain models to view models

  • 37:31 User input and intents

  • 40:51 The view layer on iOS and Android

  • 44:39 View factories

  • 52:03 The web app: React as a view layer

  • 55:48 How the app starts on iOS

  • 59:44 macOS startup with AppKit

  • 61:23 Windows: the Compose Multiplatform exception

  • 64:10 Outro: RIBs-KMP is free on GitHub, and where to follow along

References

Where to find Alex Bush:

Where to get Family Superapp:

Mentions during the episode:

Technologies, tools, and vendors:

Discussion about this video

User's avatar

Ready for more?