# usewaypoint/email-builder-js architecture

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

- Interactive diagram: https://gitdiagram.com/usewaypoint/email-builder-js
- Repository: https://github.com/usewaypoint/email-builder-js

## Overview

##### Project type and purpose
- Project type: A monorepo (npm/yarn workspace) containing
– A no-code email template **editor** (React SPA in packages/editor-sample),
– A **core builder** library (packages/document-core),
– Individual **block** packages (packages/block-avatar, block-button, …),
– A **reader**/renderer library (packages/email-builder).
- Purpose: Let developers embed a drag-and-drop email template builder in their apps, produce a JSON configuration or HTML string, and then send that via email APIs or render in a React page.

##### File structure
- Top-level config & CI: ESLint, Prettier, GitHub Workflows (ci.yaml, github-pages.yaml).
- packages/block-*: Self-contained React “block” components with their own tests and tsconfigs.
- packages/document-core: Shared code for building block configurations, schemas, and React block wrappers.
- packages/editor-sample: React + Vite SPA demonstrating the builder UI. It imports document-core and block-* packages.
- packages/email-builder: React Reader component and renderToStaticMarkup for server-side or client‐side HTML output.
- Root ensures all packages share common tsconfig and dependency management.

##### README insights
- It describes the builder’s input/output (JSON or HTML), the playground/demo, and consumption patterns (nodemailer, HTTP email API).
- Highlights that each block is an independent npm package.
- Mentions self-hosting instructions (using editor-sample).

##### Main components & interactions
a. Components
1. Monorepo Package Manager (Yarn/NPM workspace)
2. Block Packages (block-avatar, block-button, …)
3. Document Core (builders + utils)
4. Editor Sample (React SPA + Inspector UI)
5. Email Builder (Reader component + renderToStaticMarkup)
6. External Email Senders (nodemailer, Waypoint API, etc.)
b. Relationships
– **Editor Sample** imports **Document Core** and all **Block Packages**.  User actions in the UI ► produce a configuration JSON.
– **Document Core** orchestrates block configuration schemas and component builders.
– The configuration JSON can be passed to **Email Builder**:
- `<Reader />` React component (client).
- `renderToStaticMarkup()` (server or client) ► outputs raw HTML.
– HTML output flows to **External Email Senders** (nodemailer process or HTTP POST).
c. Architectural patterns/principles
– **Monorepo workspace** with isolated package per block for independent versioning and tests.
– **Plugin-style architecture**: blocks are plugins to the core builder.
– **Separation of concerns**: core building logic vs. UI vs. rendering.
– **TypeScript** enforced across all packages.
d. Key technologies
– React + Vite (editor UI)
– TypeScript + Zod (schema validation in document-core)
– Jest (unit tests, snapshots)
– renderToStaticMarkup (ReactDOMServer)
– npm/yarn workspaces

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Monorepo Core
    subgraph "Monorepo Root"
        direction TB
        PM["Monorepo Package Manager"]:::repo
        CI_CI["CI Workflow (ci.yaml)"]:::repo
        CI_PAGES["Pages Workflow (github-pages.yaml)"]:::repo
    end

    %% Block Packages
    subgraph "Block Packages"  
        direction TB
        Avatar["block-avatar"]:::repo
        Button["block-button"]:::repo
        ColumnsContainer["block-columns-container"]:::repo
        Container["block-container"]:::repo
        Divider["block-divider"]:::repo
        Heading["block-heading"]:::repo
        HTMLBlock["block-html"]:::repo
        Image["block-image"]:::repo
        Spacer["block-spacer"]:::repo
        Text["block-text"]:::repo
    end

    %% Document Core
    subgraph "Document Core (packages/document-core)"
        direction TB
        DC_Index["index.ts"]:::repo
        DC_Utils["utils.ts"]:::repo
        DC_BuildComponent["buildBlockComponent.tsx"]:::repo
        DC_BuildDict["buildBlockConfigurationDictionary.ts"]:::repo
        DC_BuildSchema["buildBlockConfigurationSchema.ts"]:::repo
    end

    %% Editor Sample
    subgraph "Editor Sample (packages/editor-sample)"  
        direction TB
        ES_App["src/App"]:::ui
        ES_Docs["src/documents"]:::ui
        ES_Config["src/getConfiguration"]:::ui
        ES_Main["src/main.tsx"]:::ui
        ES_Vite["vite.config.ts"]:::ui
    end

    %% Email Builder
    subgraph "Email Builder (packages/email-builder)"
        direction TB
        EB_Index["src/index.ts"]:::repo
        EB_Reader["src/Reader/core.tsx"]:::ui
        EB_Render["src/renderers/renderToStaticMarkup.tsx"]:::repo
        subgraph "Block Readers"
            direction TB
            EB_Columns["ColumnsContainerReader.tsx"]:::repo
            EB_Container["ContainerReader.tsx"]:::repo
            EB_Layout["EmailLayoutReader.tsx"]:::repo
        end
    end

    %% Data Artifacts
    ConfigJSON[(Configuration JSON)]:::data
    HTMLOutput[(HTML Output)]:::data

    %% External Services
    subgraph "External Email Services"
        direction TB
        Nodemailer["nodemailer"]:::external
        Waypoint["Waypoint API"]:::external
    end

    %% Relationships
    PM -->|manages workspace| Avatar
    PM --> Button
    PM --> ColumnsContainer
    PM --> Container
    PM --> Divider
    PM --> Heading
    PM --> HTMLBlock
    PM --> Image
    PM --> Spacer
    PM --> Text
    PM --> DC_Index
    PM --> ES_App
    PM --> EB_Index
    PM --> CI_CI
    PM --> CI_PAGES

    ES_App -->|imports| DC_Index
    ES_App -->|imports| Avatar
    ES_App -->|imports| Button
    ES_App -->|imports| ColumnsContainer
    ES_App -->|imports| Container
    ES_App -->|imports| Divider
    ES_App -->|imports| Heading
    ES_App -->|imports| HTMLBlock
    ES_App -->|imports| Image
    ES_App -->|imports| Spacer
    ES_App -->|imports| Text

    ES_App -->|produces| ConfigJSON
    ConfigJSON -.->|input to| EB_Reader
    ConfigJSON -.->|input to| EB_Render
    EB_Reader -->|renders| HTMLOutput
    EB_Render -->|renders| HTMLOutput
    HTMLOutput -->|sent via| Nodemailer
    HTMLOutput -->|sent via| Waypoint

    %% Click Events
    click PM "https://github.com/usewaypoint/email-builder-js/blob/main/package.json"
    click CI_CI "https://github.com/usewaypoint/email-builder-js/blob/main/.github/workflows/ci.yaml"
    click CI_PAGES "https://github.com/usewaypoint/email-builder-js/blob/main/.github/workflows/github-pages.yaml"
    click Avatar "https://github.com/usewaypoint/email-builder-js/tree/main/packages/block-avatar"
    click Button "https://github.com/usewaypoint/email-builder-js/tree/main/packages/block-button"
    click ColumnsContainer "https://github.com/usewaypoint/email-builder-js/tree/main/packages/block-columns-container"
    click Container "https://github.com/usewaypoint/email-builder-js/tree/main/packages/block-container"
    click Divider "https://github.com/usewaypoint/email-builder-js/tree/main/packages/block-divider"
    click Heading "https://github.com/usewaypoint/email-builder-js/tree/main/packages/block-heading"
    click HTMLBlock "https://github.com/usewaypoint/email-builder-js/tree/main/packages/block-html"
    click Image "https://github.com/usewaypoint/email-builder-js/tree/main/packages/block-image"
    click Spacer "https://github.com/usewaypoint/email-builder-js/tree/main/packages/block-spacer"
    click Text "https://github.com/usewaypoint/email-builder-js/tree/main/packages/block-text"
    click DC_Index "https://github.com/usewaypoint/email-builder-js/blob/main/packages/document-core/src/index.ts"
    click DC_Utils "https://github.com/usewaypoint/email-builder-js/blob/main/packages/document-core/src/utils.ts"
    click DC_BuildComponent "https://github.com/usewaypoint/email-builder-js/blob/main/packages/document-core/src/builders/buildBlockComponent.tsx"
    click DC_BuildDict "https://github.com/usewaypoint/email-builder-js/blob/main/packages/document-core/src/builders/buildBlockConfigurationDictionary.ts"
    click DC_BuildSchema "https://github.com/usewaypoint/email-builder-js/blob/main/packages/document-core/src/builders/buildBlockConfigurationSchema.ts"
    click ES_App "https://github.com/usewaypoint/email-builder-js/tree/main/packages/editor-sample/src/App"
    click ES_Docs "https://github.com/usewaypoint/email-builder-js/tree/main/packages/editor-sample/src/documents"
    click ES_Config "https://github.com/usewaypoint/email-builder-js/tree/main/packages/editor-sample/src/getConfiguration"
    click ES_Main "https://github.com/usewaypoint/email-builder-js/blob/main/packages/editor-sample/src/main.tsx"
    click ES_Vite "https://github.com/usewaypoint/email-builder-js/blob/main/packages/editor-sample/vite.config.ts"
    click EB_Index "https://github.com/usewaypoint/email-builder-js/blob/main/packages/email-builder/src/index.ts"
    click EB_Reader "https://github.com/usewaypoint/email-builder-js/blob/main/packages/email-builder/src/Reader/core.tsx"
    click EB_Render "https://github.com/usewaypoint/email-builder-js/blob/main/packages/email-builder/src/renderers/renderToStaticMarkup.tsx"
    click EB_Columns "https://github.com/usewaypoint/email-builder-js/blob/main/packages/email-builder/src/blocks/ColumnsContainerReader.tsx"
    click EB_Container "https://github.com/usewaypoint/email-builder-js/blob/main/packages/email-builder/src/blocks/ContainerReader.tsx"
    click EB_Layout "https://github.com/usewaypoint/email-builder-js/blob/main/packages/email-builder/src/blocks/EmailLayoutReader.tsx"

    %% Styles
    classDef repo fill:#D0E6FF,stroke:#333,stroke-width:1px
    classDef ui fill:#D0FFD0,stroke:#333,stroke-width:1px
    classDef external fill:#E0E0E0,stroke:#333,stroke-width:1px
    classDef data fill:#FFE0B2,stroke:#333,stroke-width:1px
```
