# Multi-App Monorepo Architecture: Next.js 16, Turborepo, and Cloudflare Workers

> By isolating each product domain into its own Next.js 16.4 app within a single npm + Turborepo workspace—backed by zero-build TypeScript internal packages, Tailwind CSS v4 @theme tokens, and OpenNext Cloudflare Workers—an independent studio can ship N properties with the operational overhead of one.

- **Category:** Studio, Security & Search
- **Author:** TengrX Team (Studio Engineering & Research)
- **Published:** 2026-10-06
- **Updated:** 2026-10-16
- **Reading time:** 7 min read (1466 words)
- **Canonical URL:** https://tengrx.com/blog/monorepo-architecture-nextjs-16-turborepo-cloudflare-workers
- **Tags:** nextjs-16, turborepo, cloudflare-workers, tailwind-v4, monorepo
- **Common Search Queries:** "nextjs 16 turborepo monorepo deployment to cloudflare workers opennext" · "sharing internal typescript packages without build steps in turborepo" · "replacing middleware.ts with proxy.ts in nextjs 16 multi-app repos"

## Section Headings

1. [The Multi-Product Studio Dilemma: Polyrepo Drift vs. Monolith Bloat](https://tengrx.com/blog/monorepo-architecture-nextjs-16-turborepo-cloudflare-workers#the-multi-product-studio-dilemma-polyrepo-drift-vs-monolith-bloat)
2. [Repository Topology: apps/* and Zero-Build packages/*](https://tengrx.com/blog/monorepo-architecture-nextjs-16-turborepo-cloudflare-workers#repository-topology-apps-and-zero-build-packages)
3. [Single Source of Truth: @tengrx/config and @tengrx/seo](https://tengrx.com/blog/monorepo-architecture-nextjs-16-turborepo-cloudflare-workers#single-source-of-truth-tengrxconfig-and-tengrxseo)
4. [Design Tokens Across Apps with Tailwind CSS v4 and oklch()](https://tengrx.com/blog/monorepo-architecture-nextjs-16-turborepo-cloudflare-workers#design-tokens-across-apps-with-tailwind-css-v4-and-oklch)
5. [Edge Routing with Next.js 16 proxy.ts](https://tengrx.com/blog/monorepo-architecture-nextjs-16-turborepo-cloudflare-workers#edge-routing-with-nextjs-16-proxyts)
6. [Deploying Next.js 16 to Cloudflare Workers via OpenNext](https://tengrx.com/blog/monorepo-architecture-nextjs-16-turborepo-cloudflare-workers#deploying-nextjs-16-to-cloudflare-workers-via-opennext)

## Key Takeaways

- Deploy one Next.js 16.4 application per product domain (apps/web, apps/amin, apps/versea) instead of multiplexing unrelated products inside a single giant host-header router.
- Export raw TypeScript (.ts/.tsx) directly from internal packages (@tengrx/config, @tengrx/seo, @tengrx/ui) and let Next.js transpilePackages compile them without fragile intermediate dist/ build steps.
- Replace legacy middleware.ts with Next.js 16's deterministic src/proxy.ts convention to handle edge locale negotiation and raw .md route rewrites.
- Compile each Next.js 16 app to an isolated Cloudflare Worker using @opennextjs/cloudflare with nodejs_compat and static asset bindings for sub-25ms global TTFB.

## The Multi-Product Studio Dilemma: Polyrepo Drift vs. Monolith Bloat

When an independent software studio ships five iPhone apps—[Amin](https://amin.tengrx.com), [Versea](https://versea.tengrx.com), [PageWard](https://pageward.vercel.app), [Octoshield](https://octoshield.app), and [Zenith](https://zenithalign.com)—alongside a central engineering publication at [`tengrx.com`](https://tengrx.com), web infrastructure quickly hits an architectural fork in the road:

1. **The Polyrepo Trap:** Put every product website in its own Git repository. Within six months, one repo is on Next.js 15, another is on Next.js 16.4, JSON-LD `Organization` schemas drift out of sync, Answer Engine Optimization (`/llms.txt`) fixes have to be copy-pasted four times, and launching a new app site takes two days of boilerplate wiring.
2. **The Multi-Tenant Monolith Trap:** Put every domain inside a single Next.js app and rewrite requests based on the `Host` header (`amin.tengrx.com` → `/_sites/amin/...`). Now every Markdown edit in Amin triggers a full rebuild of `tengrx.com` and Versea, all content files get bundled into a single huge worker artifact, and root-level metadata routes (`robots.ts`, `sitemap.ts`, `llms.txt`) become tangled `if/else` trees.

At TengrX, we chose the third path: a **Turborepo multi-app monorepo** where every domain hosted in-house is an independent, self-contained **Next.js 16.4** application inside `apps/*`, sharing zero-build TypeScript packages inside `packages/*`, and compiling down to isolated **Cloudflare Workers** via OpenNext.

| Architecture Pattern | Build Isolation | Worker Bundle Size | Shared Schema & UI | Adding App `N + 1` |
| :--- | :--- | :--- | :--- | :--- |
| **Separate Git Polyrepos** | High | Small | Copy-pasted / version drift | 1–2 days of setup |
| **Single Next.js Host-Router** | None (all-or-nothing) | Bloated (all content merged) | Shared in one `src/` | Risky route collisions |
| **TengrX Turborepo + OpenNext** | **Per-app (`turbo build`)** | **Minimal per-domain Worker** | **100% shared via `@tengrx/*`** | **< 15 minutes** |

---

## Repository Topology: `apps/*` and Zero-Build `packages/*`

Our workspace layout is intentionally flat and disciplined. Every deployable web property lives under `apps/`, and every cross-cutting concern lives under `packages/`:

```text
tengrx/
├── apps/
│   ├── web/            # tengrx.com (studio showcase, engineering blog, llms-full.txt)
│   ├── amin/           # amin.tengrx.com (4-locale Qur'an companion & sourced guides)
│   └── versea/         # versea.tengrx.com (4-locale Bible & prayer journal guides)
├── packages/
│   ├── config/         # @tengrx/config — single source of truth for apps & studio metadata
│   ├── seo/            # @tengrx/seo — JSON-LD builders, llms.txt, robots.txt, hreflang
│   └── ui/             # @tengrx/ui — shared primitives & theme tokens
├── biome.json          # Single Rust-based formatter & linter across all workspaces
├── tsconfig.base.json  # Strict TypeScript 6 base configuration
└── turbo.json          # Task pipeline caching .next/** and .open-next/**
```

### The Zero-Build Internal Package Pattern

A classic mistake in TypeScript monorepos is configuring internal packages (`packages/config`, `packages/seo`, `packages/ui`) with their own `tsc` or `tsup` build steps outputting to `dist/`. That forces developers to run background watch processes and causes cryptic CI failures when a package builds out of order.

Instead, our internal packages export their raw `.ts` and `.tsx` source files directly in `package.json`:

```json
// packages/seo/package.json
{
  "name": "@tengrx/seo",
  "version": "0.0.0",
  "private": true,
  "type": "module",
  "exports": {
    ".": "./src/index.ts"
  },
  "dependencies": {
    "schema-dts": "^1.1.5"
  },
  "peerDependencies": {
    "next": "^16.0.0",
    "react": "^19.0.0"
  }
}
```

Then, each Next.js 16 app declares those workspace packages in `transpilePackages`:

```typescript
// apps/versea/next.config.ts
import type { NextConfig } from "next";
import { initOpenNextCloudflareForDev } from "@opennextjs/cloudflare";

initOpenNextCloudflareForDev();

const nextConfig: NextConfig = {
  transpilePackages: ["@tengrx/config", "@tengrx/seo", "@tengrx/ui"],
  reactStrictMode: true,
};

export default nextConfig;
```

With this configuration, editing a schema builder in `packages/seo/src/schema.ts` or adding a new app Store URL in `packages/config/src/index.ts` immediately hot-reloads in `apps/web`, `apps/amin`, and `apps/versea` with full end-to-end TypeScript 6 type checking (`turbo run typecheck`) and zero intermediate build artifacts. (We also document these boundaries in our repository instructions so AI coding assistants never break workspace imports—see our guide on [writing CLAUDE.md and .cursorrules for SwiftUI and Next.js](/blog/writing-claude-md-and-cursorrules-for-swiftui-and-nextjs).)

---

## Single Source of Truth: `@tengrx/config` and `@tengrx/seo`

Why does `@tengrx/config` matter so much? Because an independent studio cannot afford factual drift across its web graph.

In `packages/config/src/index.ts`, we define a strictly typed `registry` array containing every app's `id`, `name`, `url`, `devUrl`, `tagline`, `description`, `category`, `schemaCategory`, `status` (`"live" | "beta" | "soon"`), `locales`, `stores.appStore`, `accent` color in `oklch()`, and `gaId`.

From that single constant:
1. **`tengrx.com`** renders the interactive app showcase, footer directory, and related-app cards on blog articles.
2. **`amin.tengrx.com`** and **`versea.tengrx.com`** call `getApp("amin")` and `getApp("versea")` to configure their canonical origin, supported locales (`["en", "tr", "ar", "ru"]` for Amin; `["en", "es", "ru", "de"]` for Versea), App Store download badges, and GA4 measurement IDs.
3. **`@tengrx/seo`** generates linked Schema.org `Organization`, `WebSite`, `MobileApplication`, `Article`, `BreadcrumbList`, and `FAQPage` JSON-LD graphs—plus `/llms.txt` and `/llms-full.txt` (as detailed in our [Answer Engine Optimization and llms.txt guide](/blog/answer-engine-optimization-aeo-llms-txt-guide-2026)).

When [Versea](https://versea.tengrx.com) transitions from `status: "soon"` to `status: "live"` with its App Store URL, changing three lines in `packages/config/src/index.ts` updates the studio homepage, the JSON-LD `MobileApplication` offers graph, the `/llms.txt` directory, and Versea's own header/footer download buttons simultaneously.

---

## Design Tokens Across Apps with Tailwind CSS v4 and `oklch()`

We run **Tailwind CSS v4** across all apps in the monorepo. Tailwind v4 replaced the legacy JavaScript `tailwind.config.js` file with a CSS-first `@theme` directive that compiles directly into native CSS custom properties.

This aligns with how we design product identities at TengrX. Every property shares the same typographic rhythm, dark obsidian surface hierarchy (`#08080a` base, `#0f1014` elevated card, hairline `rgba(255, 255, 255, 0.08)` borders), and fluid spacing, while expressing its own perceptual accent color in `oklch()`:

- **TengrX Studio (`apps/web`):** Cool celestial sky blue — `oklch(0.84 0.08 230)`
- **Amin (`apps/amin`):** Warm desert gold — `oklch(0.82 0.11 75)`
- **Versea (`apps/versea`):** Quiet sanctuary teal — `oklch(0.78 0.09 185)`
- **PageWard:** Warm parchment amber — `oklch(0.80 0.14 70)`
- **Octoshield:** High-signal terminal emerald — `oklch(0.85 0.19 145)`

```css
/* Shared CSS-first token architecture in Tailwind CSS v4 */
@import "tailwindcss";

@theme {
  --font-sans: var(--font-geist-sans), ui-sans-serif, system-ui, sans-serif;
  --font-serif: var(--font-instrument-serif), ui-serif, Georgia, serif;
  --font-mono: var(--font-geist-mono), ui-monospace, SFMono-Regular, monospace;

  --color-bg: #08080a;
  --color-bg-elevated: #0f1014;
  --color-fg: #f4f2ed;
  --color-fg-muted: #9a9890;
  --color-accent: oklch(0.84 0.08 230);
}
```

Why `oklch()` instead of hex or HSL? Because HSL distorts perceived brightness across hues—a `50%` lightness yellow looks blindingly bright while a `50%` lightness blue looks dark and muddy. In `oklch(L C H)`, keeping Lightness (`L`) between `0.78` and `0.86` and Chroma (`C`) between `0.08` and `0.19` guarantees that when we render app badges side-by-side on `tengrx.com`, every app's accent badge has identical visual weight and WCAG AA contrast against `#08080a`.

---

## Edge Routing with Next.js 16 `proxy.ts`

In Next.js 16, `src/proxy.ts` replaces the older `middleware.ts` convention, providing a clear, lightweight boundary for request routing before route rendering begins.

In `apps/amin` and `apps/versea`, `src/proxy.ts` performs two critical jobs in under 1 millisecond at the edge:

1. **LLM Markdown Mirror Rewriting:** Any request matching `/{locale}/{slug}.md` (for example, `/en/patience.md` or `/ar/sabr.md`) is transparently rewritten to our `/md/{locale}/{slug}` route handler, which returns raw `text/markdown; charset=utf-8` directly from the Markdown content store.
2. **Privacy-Preserving Locale Negotiation:** Any unprefixed path (`/patience`) resolves the visitor's preferred locale using a strict priority chain (`LOCALE_COOKIE` › Cloudflare `cf-ipcountry` header › `Accept-Language` header › `en`) and issues a `307 Temporary Redirect` with `Cache-Control: private, no-store` (we explore the full i18n and RTL architecture in our [multilingual and RTL localization engineering guide](/blog/multilingual-rtl-app-localization-arabic-turkish-russian-ios-web)).

```typescript
// apps/versea/src/proxy.ts
import { type NextRequest, NextResponse } from "next/server";
import { LOCALE_COOKIE } from "@/lib/i18n/config";
import { detectLocale } from "@/lib/i18n/detect";
import { hasLocale } from "@/lib/site";

export function proxy(request: NextRequest) {
  const url = request.nextUrl;
  const [first, ...rest] = url.pathname.split("/").filter(Boolean);

  if (hasLocale(first)) {
    if (url.pathname.endsWith(".md")) {
      url.pathname = `/md/${first}/${rest.join("/").replace(/\.md$/, "")}`;
      return NextResponse.rewrite(url);
    }
    return;
  }

  const locale = detectLocale({
    cookie: request.cookies.get(LOCALE_COOKIE)?.value,
    country:
      request.headers.get("cf-ipcountry") ??
      request.headers.get("x-vercel-ip-country"),
    acceptLanguage: request.headers.get("accept-language"),
  });
  url.pathname = `/${locale}${url.pathname === "/" ? "" : url.pathname}`;
  const res = NextResponse.redirect(url, 307);
  res.headers.set("Vary", "Cookie, Accept-Language");
  res.headers.set("Cache-Control", "private, no-store");
  return res;
}
```

---

## Deploying Next.js 16 to Cloudflare Workers via OpenNext

Every app in `apps/*` compiles to a standalone Cloudflare Worker using `@opennextjs/cloudflare` and deploys via Wrangler (`wrangler.jsonc`).

```jsonc
// apps/versea/wrangler.jsonc
{
  "$schema": "../../node_modules/wrangler/config-schema.json",
  "main": ".open-next/worker.js",
  "name": "versea",
  "compatibility_date": "2026-10-12",
  "compatibility_flags": ["nodejs_compat", "global_fetch_strictly_public"],
  "assets": {
    "directory": ".open-next/assets",
    "binding": "ASSETS"
  },
  "services": [
    {
      "binding": "WORKER_SELF_REFERENCE",
      "service": "versea"
    }
  ],
  "observability": {
    "enabled": true
  }
}
```

In `turbo.json`, we declare both `.next/**` and `.open-next/**` as cached task outputs:

```json
{
  "$schema": "https://turborepo.com/schema.json",
  "ui": "tui",
  "tasks": {
    "build": {
      "dependsOn": ["^build"],
      "outputs": [".next/**", "!.next/cache/**", ".open-next/**"]
    },
    "dev": { "cache": false, "persistent": true },
    "typecheck": { "dependsOn": ["^typecheck"] }
  }
}
```

Because every editorial article and blog post is statically generated at build time (`generateStaticParams` + `dynamicParams = false`), HTML pages, `/llms.txt`, sitemaps, and OpenGraph images are served straight from Cloudflare's edge asset layer in over 300 cities with near-zero compute cost and sub-25ms Time to First Byte (TTFB), while `proxy.ts` and `.md` routes run in V8 isolates with zero cold starts.

## Frequently Asked Questions

### Why run separate Next.js apps in a monorepo instead of multi-tenant host routing inside a single Next.js app?

Multiplexing multiple domains inside one Next.js app forces every deployment to rebuild all sites, merges disparate content collections into a single Worker bundle (hitting Cloudflare Worker size ceilings), and risks cross-domain route leaks. Isolating each domain in apps/{name} preserves independent build caching and tiny Worker bundles while sharing 100% of common infrastructure through packages/*.

### Why do internal packages in the TengrX monorepo point exports directly to ./src/index.ts instead of a compiled ./dist folder?

Maintaining separate tsc or tsup build watchers for internal packages introduces stale-build bugs and slows down local development. By exporting ./src/index.ts and listing @tengrx/config, @tengrx/seo, and @tengrx/ui in each app's next.config.ts transpilePackages array, Turbopack and TypeScript resolve changes instantaneously with zero intermediate build artifacts.

### How did proxy.ts replace middleware.ts in Next.js 16?

Next.js 16 introduced src/proxy.ts exporting a proxy(request: NextRequest) function to clarify the boundary between lightweight network routing (redirects, rewrites, header inspection) and heavy application logic. In our monorepo, proxy.ts handles Accept-Language / cf-ipcountry locale redirects and rewrites /{locale}/{slug}.md requests to raw Markdown handlers.

### How does @opennextjs/cloudflare serve static assets alongside dynamic server rendering?

OpenNext splits the Next.js build output into .open-next/worker.js (the server runtime) and .open-next/assets (static chunks, fonts, and pre-rendered HTML). Cloudflare Workers Assets serves .open-next/assets directly from the edge cache without invoking the Worker script, while dynamic routes and rewrites execute inside the V8 isolate.


## Sources & References

- [Next.js 16 Documentation: App Router & proxy.ts File Convention](https://nextjs.org/docs)
- [OpenNext for Cloudflare Workers (@opennextjs/cloudflare)](https://opennext.js.org/cloudflare)
- [Turborepo Documentation: Structuring an Internal Packages Monorepo](https://turborepo.com/docs)
- [Tailwind CSS v4.0: CSS-First Configuration and @theme Tokens](https://tailwindcss.com/docs)