Techtiten
All notes

One Repo for Expo + Next.js: Shared Theme, Shared Logic and a Typed API

11 November 2026By Arun Kumar

If you ship a mobile app and a website for the same product, an Expo + Next.js monorepo saves you from writing the same colours, types and API calls twice. This post walks through the layout I use for my own apps: one repo, one theme, one set of API contracts, and typed hooks on the app side. I also packaged the whole setup as a generator, create-techtiten-app, so you can try it in one command.

Why put Expo and Next.js in one repo?

Most side projects start as "just an app". Then you need a landing page, legal pages for the Play Store, a small admin panel and an API. Before long you have three repos, and every change to a field name means three pull requests and one forgotten update.

A monorepo fixes that with a simple rule: anything both sides use lives in a shared package. The benefits show up quickly:

  • One source of truth for data. Change a request shape once and TypeScript tells you everywhere it breaks.

  • One brand. Colours, spacing and fonts come from the same tokens on mobile and web.

  • One install, one dev command. No juggling terminals across folders.

  • Easier reviews. A feature that touches the API and the app lands in a single pull request.

The Expo Next.js monorepo layout

Here is the structure, using plain npm workspaces:

  • apps/mobile: the Expo app (Expo Router). It also builds for web, with a responsive layout.

  • apps/web: the Next.js site, which also hosts the API through a catch-all route.

  • packages/theme: design tokens (colours, spacing, radius, fonts) plus a few theme presets.

  • packages/shared: zod schemas, API route contracts and shared helpers.

  • packages/config: shared TypeScript and lint config.

If you don't need a website, swap apps/web for apps/api running Express or Fastify. The shared packages stay exactly the same, which is the whole point.

Good news on tooling: Expo now detects workspaces and configures Metro for monorepos automatically from SDK 52, and it supports npm, Yarn, pnpm and Bun workspaces (Expo docs: Work with monorepos). On the Next.js side, Turbopack transpiles workspace packages automatically, and transpilePackages is there for the cases where you need to opt a package in (Next.js docs: transpilePackages). The days of hand-written watchFolders hacks are mostly behind us.

Shared theme: one set of tokens for app and web

The packages/theme package exports plain objects: a colour palette with light and dark values, a spacing scale, radius values and font names. No React Native or DOM code inside, so both apps can import it without pulling in the wrong platform.

The mobile app turns these tokens into a small UI kit: buttons, inputs, badges, list items, toasts, a bottom sheet, skeletons and empty states. The web app reads the same tokens for its pages. When you change your brand colour, both apps change with it.

In the generator you pick a preset (techtiten, ocean, sunset, royal, mono or retro), pass your own brand colour with --brand=#hex, and choose a font such as Inter, Poppins or Space Grotesk. You can switch later with add theme and add font.

Shared logic: a typed API contract with zod

This is the part that pays off the most. Every endpoint is described once in packages/shared/src/routes as a contract: method, path, request schema and response schema, all written in zod. Because zod can infer TypeScript types from a schema, you never write the same type by hand twice.

That one contract then does three jobs:

  1. The server validates with it. Bad input is rejected with a clear error before it reaches your controller.

  2. The app gets typed hooks from it. useApiQuery and useApiMutation know the exact input and output types, backed by TanStack Query (or RTK Query if you pick Redux).

  3. The docs are generated from it. An OpenAPI 3.1 spec is built from the same contracts and shown at /docs, open in development and behind a password in production.

So when you rename title to name on a note, the server, the hooks and the docs all move together. TypeScript points at every screen that still uses the old field. No more "the API changed and the app crashed" surprises after a release.

A clean server inside the same repo

The API follows a feature-folder layout: modules/<feature>/ with routes, controller, service and model files. Environment variables are validated with zod at startup, so a missing secret fails fast instead of failing at 2 am.

Out of the box you get the sensible defaults most tutorials skip:

  • Security headers, CORS from config, rate limiting and request ids (Express and Fastify).

  • Bearer token auth for admin routes and a separate key for cron jobs.

  • Database models for Postgres (with Drizzle), MongoDB or Firestore, plus a local-only docker-compose.yml for development.

  • A development .env with random secrets, already git-ignored.

With Next.js, all of this runs behind a single catch-all API route, so the site and API deploy together.

One command to run everything

npm run dev starts the API (its logs are prefixed with [api]) and Expo together, and keeps the Expo QR code in your terminal. Scan it on your phone and you are testing the app against your local API in seconds.

The mobile side also ships with the things every Play Store app ends up needing: a force-update gate, a rate-the-app prompt, a Settings screen, legal pages, and optional daily reminders with push registration. The web side gets /legal pages, a small /admin with a push form, and the .well-known files for Android app links and iOS universal links.

Try it: create-techtiten-app

Instead of copying this structure by hand, run:

npx create-techtiten-app my-app

It asks a few questions, or you can pass flags such as --web, --api=express|fastify, --db=postgres|mongo|firestore, --nav=stack|tabs, --state=zustand|redux and --notifications. Run --help for the full list. Later you can grow the project with add route, add notifications, add theme and add font, which read your choices from techtiten.json.

The generated projects target current Expo, Next.js, React 19 and TypeScript, and the combinations are type-checked and tested before each release. You can find the package on npm: create-techtiten-app.

If you're curious how the native side has changed lately, read React Native's New Architecture: what actually changed. And for a real app story, see Building FitPrep.


FAQ

Do I need Turborepo or Nx for an Expo + Next.js monorepo?

No. Plain npm workspaces are enough for one app, one site and a few shared packages. Add Turborepo later if build caching across many packages starts to matter.

Can Expo and Next.js share React components?

They can share logic, types and theme tokens easily. Sharing UI components is possible, but React Native and DOM components differ, so it's usually simpler to share tokens and build each UI natively for its platform.

Why zod for the API contract instead of hand-written types?

Zod gives you runtime validation on the server and inferred TypeScript types on the client from the same schema, so the two can't drift apart.

Does this work without a website?

Yes. Use --no-web with --api=express or --api=fastify for an app plus API, or skip the API for a mobile-only app.

Want to see apps built by the same maker? Check out FitPrep, an AI diet and gym tracker, and grab it on Google Play from its page.

Share: