create-davbyte-mfe
v1.20260727.0
Published
Scaffold DavByte micro-frontends with Next.js
Maintainers
Readme
create-davbyte-mfe
Scaffold DavByte micro-frontends with Next.js. Cross-platform CLI for Windows, macOS, and Linux.
Designed for the DavByte Platform monorepo: MFEs mount at /apps/<slug> via the Cloudflare router Worker (no Next.js basePath), and auth uses shared/mfe + the HttpOnly auth_token cookie.
Usage
# From Platform root or apps/
pnpm dlx create-davbyte-mfe@latest <mfeName>
# or
npx create-davbyte-mfe@latest <mfeName>Windows: If
npm createfails with "not recognized", usenpx create-davbyte-mfe@latest <mfeName>instead.
Options:
--ci– Non-interactive mode: auto-assign port (3401–3499), overwrite if exists. Useful for CI/automation.
Requirements
- Node.js 20+
- npm (or pnpm inside the Platform workspace)
- Platform workspace with
shared(exportsshared/mfe) for a buildable MFE
Generated Project
Each scaffolded project includes:
- TypeScript – Full TypeScript setup
- Next.js App Router – App Router + TypeScript (
transpilePackages: ["shared"]) - Cloudflare – OpenNext Workers with
preview/deploy;workers_devandpreview_urlsare false (private; router service bindings only) - Mount path –
NEXT_PUBLIC_MFE_MOUNT=/apps/<kebab-slug>forgetMfeBasePath(); no NextbasePath/assetPrefix - Tailwind CSS – DavByte theme with company colors
- shadcn/ui – Bundled base-nova preset with
lib/utils.ts, Button, and Card; dependencies resolved at scaffold time. In monorepos, install runs once at the workspace root viapnpm install. Add more components withpnpm dlx shadcn@latest add [component](ornpxoutside a pnpm workspace). - Auth –
AuthProvider/useAuth/AuthGuardviaverifyAuthWithCookie+handleAuthMefromshared/mfe; scope{kebab-slug}:user - Identity –
mfe-info.json+lib/mfe-config.ts(MFE_NAME,MFE_SLUG,MFE_APP_SCOPE) - Testing – Vitest with
testandtest:ciscripts, plus example tests
Dependencies (Next.js, React, Cloudflare, Tailwind, Vitest, Testing Library, etc.) are resolved from the npm registry when you scaffold — latest patch within the configured Next.js major, with React and related packages matched to Next peer requirements. Auto-fixable audit issues are applied with npm audit fix (or pnpm audit --fix in monorepos). Inside Platform, "shared": "workspace:*" is added automatically.
Monorepo behavior
In a pnpm workspace with an apps/ folder, the CLI always scaffolds to apps/<mfeName> — whether you run it from the repo root or from apps/. Dependencies install via pnpm install at the workspace root. If client/src/lib/mfe-config.ts exists, the MFE is autolinked with router /apps/<slug> URLs (not public MFE workers.dev hosts).
Prompts
When scaffolding interactively, you are only prompted if port allocation fails or the target directory already exists.
Auth
- Token is read from the
auth_tokencookie (HttpOnly viaGET /api/auth/me→handleAuthMe). - App scope is
{kebab-slug}:user(example:"My Cool App"→"my-cool-app:user"). - Browser verify uses
getMfeBasePath()so API calls hit the MFE under the router mount, not the shell.
Environment
A .env.local file is created with:
AUTH_API_URL="http://localhost:3201/api/auth"
NEXT_PUBLIC_AUTH_API_URL="http://localhost:3201/api/auth"
NEXT_PUBLIC_MFE_MOUNT="/apps/<slug>"
NEXT_PUBLIC_PLATFORM_URL="http://localhost:3111"After scaffold (Platform checklist)
- Router — add
ROUTES+ service binding inrouter/wrangler.jsoncfor/apps/<slug> - Auth — register app in supabase-exchange / JWKS registry if the MFE uses Supabase
- Operations —
app_definitions+ subscription scope - Secrets — set Worker secrets (
AUTH_API_URL, etc.); MFE is not public on workers.dev - Client — confirm autolink entry in
client/src/lib/mfe-config.ts(MFE_APPS)
