Architecture

Core Architecture & Edge Mesh

Deep architectural breakdown of Next.js 16 App Router, edge middleware proxying, and pre-rendering.

Last Synchronized: 2026-09-22β€’Verified: Next.js 16 + React 19

High-Level System Topology

NexusCore leverages a hybrid edge-first model. Static documentation routes are generated during build-time for sub-millisecond TTFB (Time to First Byte), while edge middleware intercepts international sub-paths to proxy translated content with zero duplicate bundle overhead.

MultiLipi Edge Middleware Pipeline

Incoming Request
/hi/docs/quickstart
Edge Middleware
Extracts Locale Header
Dynamic Rewrite
Renders Target Route

Edge Middleware Implementation

The core logic inside middleware.ts handles route extraction and header preservation:

middleware.ts
typescript
import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";

export function middleware(request: NextRequest) {
  const { pathname, search } = request.nextUrl;
  const segments = pathname.split("/").filter(Boolean);
  const locale = segments[0];

  if (["hi", "fr", "de", "nl", "es", "ja"].includes(locale)) {
    const strippedPath = "/" + segments.slice(1).join("/");
    const destination = strippedPath === "" ? "/" : strippedPath;
    
    const requestHeaders = new Headers(request.headers);
    requestHeaders.set("x-multilipi-locale", locale);

    return NextResponse.rewrite(new URL(destination + search, request.url), {
      request: { headers: requestHeaders },
    });
  }

  return NextResponse.next();
}