# ourfreewp/wp2 architecture

> Architecture diagram of the GitHub repository ourfreewp/wp2, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ourfreewp/wp2
- Repository: https://github.com/ourfreewp/wp2

## Overview

##### Project Type & Purpose
- WP2 Framework is a modular, PHP-centric WordPress boilerplate that lives alongside a normal WordPress install.
- Its goal is to simplify building advanced, block-driven sites by auto-registering modules (blocks, models, integrations) based on file location.

##### High-Level Architecture
a. WordPress Core & Database
- Core PHP entry points, hooks, plugin API
- MySQL (or compatible) storing posts, metadata, options, custom tables
b. File-System Layers (all under wp-content/)
- MU-Plugins (“Daemons” loaded first):
– wp2-core: registers CPTs, taxonomies, statuses, patterns
– wp2-new: site cloning & auto-install routines
– wp2-studio: asset loading (CSS/JS), Twig support, block rendering controller
– wp2-run: WP-CLI integration, lifecycle commands, webhook services
– wp2-build: schema definitions, code generation, build helpers
- Standard Plugins:
– wp2s, wp2-factory, wp2-new (non-MU version), etc.
- Themes:
– wp2s theme with parts, templates, static assets
- Uploads: user media, documentation, optional modules

c. Modular Components (“Zones,” “Integrations,” “Libraries,” “Plugins”)
- Zones: pre-bundled collections of modules by purpose (e.g., wp2-directory), accelerate project setup
- Integrations: connectors to third-party APIs/SaaS (Cloudflare, Shopify, Marker.io)
- Libraries: shared utilities & assets (Floating-UI, Micromodal) under mu-plugins or theme
- Plugins: core WP2 functionality delivered MU-style or via regular plugin installs

##### Module Registration Flow
1. WP2 Daemons scan their own directories at init (init.php, init-helpers.php, init-flows.php)
2. Each module folder with block.json is auto-registered as a Gutenberg block (PHP index.php + assets)
3. Models folders register custom post types, taxonomies, and REST endpoints
4. Integrations register hooks/services to external APIs
5. Assets (CSS/JS) auto-enqueued via file naming conventions and WP2_NAMESPACE constants
6. Theme parts/templates are served by Twig or PHP for front-end rendering

##### Key Architectural Patterns
- File-System-Based Registration: directory structure drives registration logic (convention over configuration)
- MVC-Like Separation:
- Models: custom post types & taxonomies under /src/models
- Views: block.json + PHP/Twig templates under /src/blocks and theme parts
- Controllers: init-flows.php, init-helpers.php registering hooks & filters
- Dependency Injection via constants (WP2_NAMESPACE, WP2_PREFIX) for multi-tenant setups
- Zero-Setup Asset Pipeline: Blockstudio compiles SCSS/JS, auto-discovers build scripts

a. Frontend Layer
- WP2 Theme ← consumes blocks & parts ← Registered by WP2 Daemons
- Browser ← JS/CSS assets from wp2-studio via enqueue hooks
b. Backend Layer
- MU-Plugins (wp2-core, wp2-studio, etc.) ← initialize modules, register REST routes, CLI commands
- Standard WP2 Plugins ← optional extensions, integrate with core daemons
- WordPress Core ← hook system, database API
c. Data Layer
- MySQL Database ← stores core & module data (posts, custom tables, taxonomies)
d. External Services
- Integrations (Shopify, Cloudflare, etc.) ← WP2 modules call APIs, webhooks
- Blockstudio Build Process (local or CI) ← compiles assets, generates block.json

##### Essential Details to Capture
- Module load order (MU-Plugins → Plugins → Themes)
- Convention-driven registration (block.json + index.php + init scripts)
- Role of wp2-studio as orchestration layer
- Integration points: REST endpoints, CLI commands, webhooks
- Asset pipeline: Blockstudio build → enqueued CSS/JS

## Diagram (Mermaid)

```mermaid
graph TB
    %% MU-Plugins (Core Daemons)
    subgraph "MU-Plugins (Core Daemons)"
        direction TB
        core["wp2-core MU-Plugin"]:::mu
        newmu["wp2-new MU-Plugin"]:::mu
        studio["wp2-studio MU-Plugin"]:::mu
        run["wp2-run MU-Plugin"]:::mu
        build["wp2-build MU-Plugin"]:::mu
    end

    %% Zones
    subgraph "Zones"
        direction TB
        directory["wp2-directory Zone"]:::zone
    end

    %% Integrations
    subgraph "Integrations"
        direction TB
        shopify_studio["Shopify Integration (Studio)"]:::integration
        shopify_directory["Shopify Integration (Directory)"]:::integration
    end

    %% Libraries
    subgraph "Libraries"
        direction TB
        floatingUI["Floating-UI Library"]:::library
    end

    %% Plugins
    subgraph "Standard Plugins"
        direction TB
        wp2factory["wp2-factory"]:::plugin
        wp2new["wp2-new"]:::plugin
        wp2splugin["wp2s"]:::plugin
    end

    %% Theme
    theme["wp2s theme"]:::theme

    %% Core and Data
    coreWP["WordPress Core"]:::core
    db["MySQL Database"]:::db

    %% External and Build
    blockstudio["Blockstudio Build Process"]:::buildproc
    browser["Browser"]:::browser
    external["External Services"]:::external

    %% Relationships
    core -->|hooks & APIs| coreWP
    coreWP -->|reads/writes| db

    %% MU-Plugins initialization flow
    core --> coreWP
    coreWP -->|load MU-Plugins| core
    core --> newmu
    core --> studio
    core --> run
    core --> build

    %% Module scanning
    core -->|scans folders| studio
    build -->|scans models| directory
    studio -->|register blocks| directory
    studio -->|register blocks| shopify_studio
    directory -->|register integrations| shopify_directory
    directory -->|load libs| floatingUI

    %% Integration to external
    shopify_studio -->|API calls| external
    shopify_directory -->|API calls| external

    %% Standard plugins
    coreWP -->|load Plugins| wp2factory
    coreWP -->|load Plugins| wp2new
    coreWP -->|load Plugins| wp2splugin

    %% Theme and frontend
    studio -->|enqueue assets| browser
    blockstudio -->|build assets| studio
    browser -->|requests pages| theme
    theme -->|serves parts/templates| browser

    %% Click Events
    click core "https://github.com/ourfreewp/wp2/tree/stage/wp-content/mu-plugins/wp2-core"
    click newmu "https://github.com/ourfreewp/wp2/tree/stage/wp-content/mu-plugins/wp2-new"
    click studio "https://github.com/ourfreewp/wp2/tree/stage/wp-content/mu-plugins/wp2-studio"
    click run "https://github.com/ourfreewp/wp2/tree/stage/wp-content/mu-plugins/wp2-run"
    click build "https://github.com/ourfreewp/wp2/tree/stage/wp-content/mu-plugins/wp2-build"
    click directory "https://github.com/ourfreewp/wp2/tree/stage/wp-content/mu-plugins/wp2-directory/src"
    click shopify_studio "https://github.com/ourfreewp/wp2/tree/stage/wp-content/mu-plugins/wp2-studio/src/integrations/shopify"
    click shopify_directory "https://github.com/ourfreewp/wp2/tree/stage/wp-content/mu-plugins/wp2-directory/src/integrations/shopify"
    click floatingUI "https://github.com/ourfreewp/wp2/tree/stage/wp-content/mu-plugins/wp2-directory/src/libraries/floating-ui"
    click wp2factory "https://github.com/ourfreewp/wp2/tree/stage/wp-content/plugins/wp2-factory"
    click wp2new "https://github.com/ourfreewp/wp2/tree/stage/wp-content/plugins/wp2-new"
    click wp2splugin "https://github.com/ourfreewp/wp2/tree/stage/wp-content/plugins/wp2s"
    click theme "https://github.com/ourfreewp/wp2/tree/stage/wp-content/themes/wp2s"
    click buildproc "https://github.com/ourfreewp/wp2/tree/stage/Blockstudio Build Process"
    click browser "https://github.com/ourfreewp/wp2/tree/stage/Browser"
    click external "https://github.com/ourfreewp/wp2/tree/stage/External Services"
    click coreWP "https://github.com/ourfreewp/wp2/tree/stage/WordPress Core"
    click db "https://github.com/ourfreewp/wp2/tree/stage/MySQL Database"

    %% Styles
    classDef mu fill:#bdd7ee,stroke:#4f81bd,color:#000
    classDef zone fill:#c6e0b4,stroke:#6aa84f,color:#000
    classDef integration fill:#f9cb9c,stroke:#e69138,color:#000
    classDef library fill:#ffe599,stroke:#b45f06,color:#000
    classDef plugin fill:#d9d2e9,stroke:#8e7cc3,color:#000
    classDef theme fill:#a4c2f4,stroke:#3d85c6,color:#000
    classDef core fill:#ffffff,stroke:#999999,color:#000
    classDef db fill:#ffffff,stroke:#999999,color:#000
    classDef buildproc fill:#ffffff,stroke:#999999,color:#000
    classDef browser fill:#ffffff,stroke:#999999,color:#000
    classDef external fill:#ffffff,stroke:#999999,color:#000
```
