Monorepo & Package Architecture
Internal architecture of the ForgeWP monorepo, package responsibilities, cross-package linking, and build pipelines.
The ForgeWP framework is architected as a modular monorepo managed with PNPM workspaces. The repository separates compiler tooling, the isomorphic React runtime, UI component registries, theme templates, and scaffolding utilities into distinct, decoupled packages.
This architecture enables developers to contribute enhancements to the compiler, add new React hooks, expand the UI registry, or create new framework adapters with immediate Hot Module Replacement (HMR) across the testbed theme.
1. Monorepo Structure
The monorepo root configures workspace packages in pnpm-workspace.yaml:
1packages:
2 - "packages/*"Directory Anatomy
Path Package Name Responsibility packages/compiler/@forgewp/compilerAST parsing, Vite build plugins, SSR render engine ( render-theme.mts), asset orchestrator (Sharp/WOFF2), and the 25 canonical forgewp command keys.packages/react/@forgewp/reactZero-dependency isomorphic runtime, WordPress data hooks ( useWpTitle, useWpQuery), primitives (<WpImage>, <WpQueryLoop>), and schema definitions (defineBlock, defineEditable).packages/ui/@forgewp/uiAccessible UI component registry consumed by pnpm forgewp add <component>.packages/create-forgewp/create-forgewpInteractive scaffolding CLI published to npm as npm create forgewp@latest.packages/starter/starterThe canonical React starter theme template and active development testbed. packages/html-starter/html-starterVanilla HTML framework adapter template. packages/auth/@forgewp/authFrontend and REST authentication, registration, session management, and verification emails. packages/woocommerce/@forgewp/woocommerceWooCommerce storefront data bridge, cart management, and product loop primitives. packages/plugin-seo/@forgewp/plugin-seoFirst-party compiler plugin for metadata injection and social share cards. scripts/Internal Tooling Template sync scripts ( sync-cli-template.mjs), workspace runner (run-workspace.mjs), and WordPress sync utilities. |
|---|
2. Core Package Responsibilities
@forgewp/compiler
The engine of ForgeWP. Located in packages/compiler/, it handles the complete translation from modern web code to WordPress theme output:
- CLI Commands (
bin/): Implementsforgewp export,doctor,repair,clean,fresh,add,make:*,sync:*,seed, andi18n:*. - AST Parser & Transpiler (
lib/): Shared Babel parser that converts JSX loops (<WpQueryLoop>) into native PHPWP_Queryloops, transpiles Gutenberg block definitions intoblock.jsonmanifests, and extracts hydration islands. - Node SSR Engine (
lib/render-theme.mts): Executes React components inside Node.js to capture initial server markup while polyfilling browser environments. - Asset Pipeline (
lib/build-assets.js,lib/asset-loader.js): Bundles client JavaScript chunks, converts raster images to responsive WebP with Sharp, and downloads Google Fonts to local.woff2files. - Theme Generator (
lib/generate-theme.js): Emitsstyle.css,theme.jsonv3,functions.php, and WordPress template hierarchy files (index.php,single.php,archive.php).
@forgewp/react
The isomorphic client library. Located in packages/react/, it provides the declarative React APIs used by theme authors:
- Zero Client Overhead: Primitives like
<WpQueryLoop>,<WpMenu>, and data hooks (useWpTitle(),useWpDate()) are purely compile-time constructs that emit PHP code during export and return mock data during local development. - Context System (
src/context.ts): ManagesWpPostContextandWpBlockContextfor providing contextual post data across component trees. - Schema Builders (
src/config.ts,src/hooks.ts): DefinesdefineBlock(),defineEditable(), field helpers (text(),richText(),image(),repeater()), and blueprint seeding helpers (defineWpPosts(),defineWpMenus(),defineWpOptions()).
@forgewp/ui
The component registry. Located in packages/ui/, it houses accessible UI primitives (buttons, modals, dropdowns, sheet drawers, tabs):
- Components are built using Tailwind CSS and Radix UI primitives.
- Supports dual styling modes:
shadcn(rounded borders) andforgewp(sharp, geometric aesthetic). - Distributed via copy-paste scaffolding through
pnpm forgewp add <name>, giving theme authors full ownership of component source code.
create-forgewp
The project scaffolder. Located in packages/create-forgewp/:
- Ships with embedded starter templates in
packages/create-forgewp/template/(React) andtemplate-html/(Vanilla HTML). - Detects the active package manager (
pnpm,npm,yarn,bun) and monorepo workspace configurations. - Configures Tailwind CSS 4, TypeScript, and initial WordPress blueprints.
3. Cross-Package Linking & Workspaces
The monorepo uses PNPM workspace protocol references (workspace:*). This links framework packages locally without publishing to npm:
1{
2 "dependencies": {
3 "@forgewp/react": "workspace:*",
4 "@forgewp/compiler": "workspace:*"
5 }
6}Live Workspace Development
When you run pnpm dev at the monorepo root, the script runner delegates execution to packages/starter:
- Any code changes made inside
packages/react/src/orpackages/compiler/lib/are immediately picked up by the Vite dev server running inpackages/starter. - Vite Hot Module Replacement (HMR) updates the browser instantly without requiring manual rebuilding or relinking of packages.
4. Monorepo Scripts Reference
The root package.json provides unified commands that orchestrate tasks across the monorepo:
Command Action pnpm devStarts the local development server in packages/starter with live reload.pnpm buildExecutes production compilation across all workspace packages. pnpm typecheckRuns TypeScript type checking across the entire monorepo ( tsc --noEmit).pnpm exportRuns the production theme export pipeline in packages/starter, producing .forgewp/out/.pnpm previewPreviews the compiled production build locally. pnpm sync:templateSynchronizes files from packages/starter into packages/create-forgewp/template.pnpm sync:template-htmlSynchronizes files into packages/create-forgewp/template-html.pnpm test:compiler-adaptersRuns runtime and typing test suites for compiler framework adapters. pnpm test:createTests the create-forgewp interactive scaffolding process.pnpm test:create-htmlTests non-interactive HTML adapter project scaffolding. |
|---|
Next Steps
Now that you understand the monorepo architecture and package contracts, proceed to the Contribution Guidelines & Testing to set up your local development environment, run test suites, and submit pull requests.