Studio, Security & Search7 min read1,466 words

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.

By TengrX Team · Studio Engineering & Research
Published
Updated
Dependency graph of the TengrX Turborepo monorepo showing Next.js 16 apps sharing @tengrx/config, @tengrx/seo, and @tengrx/ui
One repository, independent edge workers: how tengrx.com, amin.tengrx.com, and versea.tengrx.com share types, SEO graphs, and design tokens.

Key Engineering 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, Versea, PageWard, Octoshield, and Zenith—alongside a central engineering publication at 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/:

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:

// 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:

// 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.)


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).

When Versea 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)
/* 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).
// 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).

// 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:

{
  "$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.

Tagged:#nextjs-16#turborepo#cloudflare-workers#tailwind-v4#monorepo
Searched on Google & AI:⌕ “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”

Common Questions

Frequently Asked Questions

01Why 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/*.

02Why 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.

03How 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.

04How 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 & Technical References

  1. [1]Next.js 16 Documentation: App Router & proxy.ts File Convention ↗
  2. [2]OpenNext for Cloudflare Workers (@opennextjs/cloudflare) ↗
  3. [3]Turborepo Documentation: Structuring an Internal Packages Monorepo ↗
  4. [4]Tailwind CSS v4.0: CSS-First Configuration and @theme Tokens ↗

Written by

TengrX Team · Studio Engineering & Research

The engineering and design team behind Amin, Versea, PageWard, Octoshield, YouX, Mibsy, and Zenith — building native iOS apps and edge web infrastructure.

Continue Reading

All articles →
Minimalist daily devotional and private prayer journal interface
Studio & AEO
5 min readVersea app iconVersea
·TengrX Team

Daily Devotional & Prayer Journal Apps Without Streak Guilt: A Practical Guide

Gamified streak counters turn prayer into a checkbox exercise that collapses the moment you miss a single day. A minimalist daily devotional and prayer journal app focuses instead on three quiet essentials: one verse, a short topical reflection, and a private prayer list where you can look back on answered prayers.

#prayer-journal-app#daily-devotional-app#answered-prayers
Combining intermittent fasting windows with protein and calorie tracking in YouX
Studio & AEO
5 min readYouX app iconYouX
·TengrX Team

Intermittent Fasting + Protein Macro Tracking: The 2026 Guide to Body Recomposition

Intermittent fasting simplifies meal timing, but fasting windows alone do not guarantee fat loss or muscle retention. Pairing a 16:8 fasting schedule with a daily protein target and simple calorie awareness prevents muscle loss, controls hunger, and drives sustainable body recomposition.

#intermittent-fasting-macros#protein-tracking#body-recomposition
Screen-free evening reading routine replacing late-night phone scrolling
Studio & AEO
5 min readPageWard app iconPageWard
·TengrX Team

Screen-Free Evening Routines: How to Replace Late-Night Doomscrolling With Physical Books

People are shifting away from half-measures like 'digital detox tips' toward strict screen-free evening boundaries. Charging your phone outside the bedroom, scheduling an automatic evening app shield, and keeping a physical book on your nightstand eliminates late-night doomscrolling and restores deep sleep.

#screen-free-evening#stop-doomscrolling#phone-addiction