# stellarwp/kadence-blocks architecture

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

- Interactive diagram: https://gitdiagram.com/stellarwp/kadence-blocks
- Repository: https://github.com/stellarwp/kadence-blocks

## Overview

##### Main Components
- Core Plugin Loader and Initialization:
– Represent the main plugin entry point (kadence-blocks.php) and the central “includes” that bootstrap functionality.
- Block Registration and Business Logic:
– Map out the PHP classes and functions located in directories like “includes”, which handle block initialization, REST endpoints, and cache/health features.
- JavaScript and Frontend Assets:
– Include the “src/assets” and “gulp” directories that house JS, SCSS, and build tasks.
– Show the build pipeline from source files through Gulp tasks (clean, JS, styles, Webpack) to the final bundled assets used in the editor and frontend.
- AI Integration:
– Highlight the components that bring in AI capabilities (for example, inline AI text editing and AI-powered design library features). These are integrated into several blocks (like Advanced Text) and operated via dedicated JavaScript modules and PHP endpoints.
- External Integration and API Layers:
– Note the integration points with third-party services such as ActiveCampaign, Mailchimp, and other marketing or form service APIs.
– Add REST API endpoints (present in various includes) which handle external data exchange.
- Testing and Quality Assurance:
- Build and Deployment Pipelines:
– Include configuration files and GitHub workflow definitions (in “.github/workflows”) as part of the continuous integration/continuous deployment (CI/CD) process.

##### Relationships and Interactions
– Indicate the communication between the front-end editor modules (React components within “src/blocks” and “src/assets/js”) and the back-end PHP API endpoints.
– Illustrate the build process by linking the Gulp and Webpack configuration files to the source asset directories, demonstrating how source code is transformed into deployable code.
– Map out how testing components interact with the core modules for unit and integration tests.

##### Architectural Pattern and Design Principles
– Use a layered design: Separate the presentation layer (JavaScript components for the editor and frontend), the business logic (PHP classes and helper functions), and the build/deployment layer.
– Note the extensibility: There is a clear design intention to allow future additions (e.g., advanced integrations, block defaults, and settings) and third-party integrations.

##### Putting It All Together
– Start with a top-level “Plugin” container that divides into “Backend” and “Frontend” sections.
– Finally, add a peripheral section for “CI/CD & Deployment” that integrates with the GitHub workflows and build scripts.

Happy diagramming!

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Backend"
        A["Core Loader"]:::backend
        B["Bootstrap"]:::backend
        C["PHP Block Registration & Business Logic"]:::backend
        D["AI Events (PHP)"]:::integration
        E["AI Block (Advanced Heading AI Text)"]:::integration
        F["AI Wizard (Prebuilt Library)"]:::integration
        G["External API Integrations"]:::integration
        H["Testing Modules"]:::test
        A --> C
        B --> C
        C --> D
        C --> G
        D --> I
        E --> I
        F --> I
        A --> H
    end

    subgraph "Frontend"
        I["JavaScript Editor Blocks"]:::frontend
        J["JS & CSS Assets"]:::frontend
        K["Build Pipeline (Gulp/Webpack)"]:::pipeline
    end

    subgraph "Deployment"
        L["CI/CD & Deployment"]:::pipeline
    end

    %% Connections between Backend and Frontend
    C --> I
    I --> J
    J --> K
    K --> L

    %% Click Events
    click A "https://github.com/stellarwp/kadence-blocks/blob/master/kadence-blocks.php"
    click B "https://github.com/stellarwp/kadence-blocks/blob/master/includes/init.php"
    click C "https://github.com/stellarwp/kadence-blocks/tree/master/includes/blocks"
    click D "https://github.com/stellarwp/kadence-blocks/blob/master/includes/class-kadence-blocks-ai-events.php"
    click E "https://github.com/stellarwp/kadence-blocks/tree/master/src/blocks/advancedheading/ai-text"
    click F "https://github.com/stellarwp/kadence-blocks/tree/master/src/plugins/prebuilt-library/ai-wizard"
    click G "https://github.com/stellarwp/kadence-blocks/tree/master/includes/advanced-form"
    click H "https://github.com/stellarwp/kadence-blocks/tree/master/tests"
    click I "https://github.com/stellarwp/kadence-blocks/tree/master/src/blocks"
    click J "https://github.com/stellarwp/kadence-blocks/tree/master/src/assets"
    click K "https://github.com/stellarwp/kadence-blocks/tree/master/gulp"
    click L "https://github.com/stellarwp/kadence-blocks/tree/master/.github/workflows"

    %% Styles
    classDef backend fill:#f9e79f,stroke:#7d6608,stroke-width:2px;
    classDef integration fill:#aed6f1,stroke:#2471a3,stroke-width:2px;
    classDef test fill:#fadbd8,stroke:#e74c3c,stroke-width:2px;
    classDef frontend fill:#d5f5e3,stroke:#27ae60,stroke-width:2px;
    classDef pipeline fill:#ebdef0,stroke:#8e44ad,stroke-width:2px;
```
