DEV Community

tarun
tarun

Posted on

Shipping one codebase to web, Android, and Windows with Next.js and Capacitor

GumStory runs the same Next.js web app on the web, on Android, and on Windows. One early decision made that possible: keep a single codebase and wrap it instead of building three separate apps. Here's roughly how it works, and the parts that were tricky.

The setup

The product is a normal Next.js app. For the mobile and desktop builds, Capacitor wraps it, loading the web app inside a native shell and exposing native APIs where needed.


The model that makes this manageable: the web app is the source of truth, and the native builds are thin shells pointing at it. So most features just work everywhere, and platform-specific code is only needed at the edges.

Where it gets interesting

A few areas needed real platform handling:

  • Knowing where the app is running. Checking the Capacitor user agent lets the app behave a little differently inside the native shell versus a normal browser tab, for example on the launch screen.

  • OAuth on mobile. This was the hardest part. A login flow that opens an external browser does not automatically return to the app. It needs a custom URL scheme and deep links so the native app actually receives the callback, instead of stranding the user in Chrome.

  • Builds. Web deploys normally, Android ships through the Play Store, Windows through the Microsoft Store, all on the same web bundle.

Worth it?

For a small team, yes. A feature written once shows up on three platforms. The cost is the occasional sharp edge like the OAuth flow, but that beats maintaining three apps forever.

GumStory itself is a workspace for planning sprints, running tests, and auto-generating daily status reports. It's at https://gumstory.com if it's useful to anyone. Questions about the Capacitor side are welcome in the comments.

Top comments (0)