Triamorph Systems

Mobile & Native · 11 min read · Mar 24, 2024

Universal Monorepos with Turborepo & Expo: Sharing 85% Code Between Next.js and React Native

Engineering guide to Universal Monorepos: structuring Turborepo with Next.js 15, Expo React Native, Tamagui/NativeWind shared design tokens, and shared TanStack Query hooks.

By Hammad Haider

Core Engineering Takeaways

  • A universal monorepo eliminates duplicated API schemas, data fetching hooks, and business logic across web and mobile platforms.
  • Turborepo remote computation caching cuts CI build and test execution times by over 70%.
  • Universal UI libraries compile to standard HTML/CSS on web and native View/Text components on iOS and Android.

Maintaining separate Git repositories for web (Next.js) and mobile (React Native/Expo) creates massive engineering duplication: API clients are written twice, state management hooks are re-implemented, and brand design tokens constantly drift out of sync. By architecting a Universal Monorepo using Turborepo, pnpm workspaces, and universal UI primitives (Tamagui or NativeWind), engineering teams share 85%+ of their TypeScript codebase across web, iOS, and Android.

1. The Multi-Repo Code Duplication Tax

Why having separate web and mobile repositories doubles engineering overhead

When a backend engineer updates an API payload, frontend web and mobile developers must both manually update their respective models. In a monorepo, a single PR updates the shared package and propagates instantly across all apps.

Code Sharing Ratio
86%
Shared logic, hooks & types
CI Pipeline Acceleration
3.5x Faster
Turborepo remote artifact cache
Feature Delivery Velocity
+55%
Single PR ships to Web, iOS & Android

2. Turborepo Workspace Architecture

Structuring apps/ (next, expo) and packages/ (ui, api, db, config)

We organize the codebase into discrete workspace packages: `apps/web` (Next.js), `apps/mobile` (Expo), `packages/api` (typed RPC client), `packages/ui` (shared components), and `packages/validators` (Zod schemas).

turbo.json (json)
{
  "$schema": "https://turbo.build/schema.json",
  "tasks": {
    "build": {
      "dependsOn": ["^build"],
      "outputs": [".next/**", "!.next/cache/**", "dist/**"]
    },
    "lint": {},
    "typecheck": {
      "dependsOn": ["^build"]
    }
  }
}

3. Sharing TanStack Query Hooks & Zod Schemas

One shared hook serving both React Web and React Native screens

The exact same `useUserProfile(userId)` query hook runs on web Next.js pages and mobile Expo screens with identical caching and retry heuristics.

4. Universal UI Styling with NativeWind

Tailwind CSS utility classes compiled to native React Native styles

NativeWind allows developers to write `className="flex-1 bg-surface p-4 rounded-xl"` which compiles to CSS flexbox on web and native Yoga layout objects on mobile.

Tags: expo react native enterprise architectureturborepo monorepo mobile webcross platform design system react nativeReact Native Monorepo

Related Engineering Practice & Case Studies

Engineering Practice Blueprint

Mobile App Development (iOS & Android) →

Cross-platform mobile applications with offline-first synchronization and native device bridges.

View Practice Blueprint & Capabilities →
Production Client System

Task Sync Kro AI Productivity App →

Contextual Android productivity application prioritizing tasks by time and geofenced physical location.

Read Deployed Case Study (4.8-star user rating with zero sync drops) →

Related Engineering Articles & Guides

Explore all technical guides in our Articles & Guides Index → or discuss your architecture with our engineers via Technical Discovery →