# @dani-builder/strapi-plugin-builder

Strapi v5 plugin providing 12 content types, 43 components, and smart API endpoints for a page builder CMS. Installed as a Strapi plugin — not used standalone.

## Installation & Setup

```bash
# 1. Install the plugin
pnpm add @dani-builder/strapi-plugin-builder

# 2. Enable in Strapi config (config/plugins.ts)
export default () => ({
  builder: { enabled: true },
});

# 3. Start Strapi — the plugin registers all Builder content types itself
```

**Do not copy Builder schemas into `src/api/`.** The plugin owns the content
types and their core REST routes; copied schemas duplicate collection names and
prevent Strapi from booting.

Install `react-intl` at the host `@strapi/admin` version (6.6.2 for Strapi
5.60.0), so Builder hooks share the host IntlProvider context.

## Content Types (12)

### Collection Types (9)

| singularName | pluralName | REST endpoint | draftAndPublish | i18n |
|---|---|---|---|---|
| page | pages | `api/builder/pages` | true | yes |
| legal-document | legal-documents | `api/builder/legal-documents` | true | yes |
| article | articles | `api/builder/articles` | true | yes |
| faq | faqs | `api/builder/faqs` | true | yes |
| category | categories | `api/builder/categories` | false | yes |
| tag | tags | `api/builder/tags` | false | yes |
| author | authors | `api/builder/authors` | false | no |
| inquiry | inquiries | Storage only; submit through forms | false | no |
| series | all-series | `api/builder/all-series` | false | yes |

### Single Types (3)

| singularName | pluralName | REST endpoint | draftAndPublish | i18n |
|---|---|---|---|---|
| navigation | navigations | `api/builder/navigation` | true | yes |
| global | globals | `api/builder/global` | true | yes |
| site-setting | site-settings | `api/builder/site-setting` | false | no |

**Series quirk:** `pluralName` is `all-series` (not `series`) because Strapi requires singular and plural names to differ.

## Components (43)

### Blocks (16) — used in Page.blocks dynamic zone

`blocks.hero`, `blocks.features`, `blocks.cta`, `blocks.slider`, `blocks.inquiry-form`, `blocks.faq`, `blocks.highlights`, `blocks.bento-grid`, `blocks.testimonials`, `blocks.logo-cloud`, `blocks.stats`, `blocks.pricing`, `blocks.price-list`, `blocks.local-nav`, `blocks.content`, `blocks.team`

### Elements (2)

`elements.section`, `elements.footer`

### Shared (25)

`shared.tracking`, `shared.action`, `shared.analytics-setting`, `shared.bento-item`, `shared.brand-colors`, `shared.chatbot-setting`, `shared.feature-item`, `shared.highlight-item`, `shared.image`, `shared.link`, `shared.local-nav-item`, `shared.logo-item`, `shared.navigation-group`, `shared.organization`, `shared.postal-address`, `shared.pricing-tier`, `shared.price-group`, `shared.price-item`, `shared.seo`, `shared.site-verification`, `shared.sitemap-entry`, `shared.slider-item`, `shared.stat-item`, `shared.team-member`, `shared.testimonial-item`

## Smart API Endpoints

Server-side deep populate — no need for client-side populate building.

| Method | Path | Description |
|---|---|---|
| GET | `/api/builder/pages` | List pages (minimal populate) |
| GET | `/api/builder/pages/:documentId` | Single page with all blocks deeply populated |
| GET | `/api/builder/global` | Global settings (siteWideBlocks + footer, fully populated) |

## Critical Rules

1. **Component registration** — The plugin uses `strapi.get('components').add(map)`. Never assign directly to `strapi.components[uid]`.
2. **Components require metadata** — Each component JSON must include `__schema__`, `globalId`, and `collectionName` fields.
3. **`__component` required in dynamic zones** — Every block object needs `"__component": "blocks.hero"` etc.
4. **Block text lives in `section`** — heading, subheading, and theme are on the `section` sub-component, NOT at block root.
5. **Section.theme is a Tailwind preset key** — Values like `'dark'`, `'default'`. No arbitrary CSS colors.
6. **`name` fields are admin-only** — Used for CMS identification. Never display in frontend.
7. **All media fields are nullable** — Render defensively even for "required" media fields.
8. **CT directory names match singularName** — `site-setting/` not `site-settings/`.

## Variant-Based Layouts

Blocks use a `variant` enum instead of separate components per layout. Only use values defined in the schema:

| Block | Variants |
|---|---|
| content | `prose`, `wide`, `full-width` |
| cta | `inline-spread`, `inline-centered`, `inline-stacked`, `card-stacked`, `card-centered`, `card-horizontal` |
| features | `simple-grid`, `dual-column`, `media-aside`, `media-aside-compact` |
| hero | `side-by-side`, `media-extending`, `fullscreen-media`, `stacked-media` |
| highlights | `dual-column`, `triple-column`, `alternating` |
| logo-cloud | `inline`, `grid`, `split`, `marquee` |
| price-list | `table`, `list` |
| pricing | `two-column`, `three-column`, `single`, `with-comparison` |
| slider | `cover-flow`, `card-slider` |
| stats | `simple`, `card-grid`, `split` |
| team | `grid`, `large-image`, `compact` |
| testimonials | `centered`, `side-by-side`, `card-grid`, `subtle-grid` |

`bento-grid`, `faq`, `local-nav`, and `inquiry-form` have no variant attribute. A nullable variant uses the renderer default.

**Never invent variant values** — always check the schema definition.

## REST API Rules (for MCP / programmatic content creation)

```json
// POST api/builder/pages — create a page with blocks
{
  "data": {
    "title": "About",
    "slug": "about",
    "locale": "en",
    "blocks": [
      {
        "__component": "blocks.hero",
        "variant": "side-by-side",
        "section": {
          "heading": "About Us",
          "subheading": "Our story",
          "theme": "dark"
        },
        "ctaLink": { "label": "Learn more", "href": "/contact" }
      }
    ]
  }
}
```

1. **`data` wrapper required** — POST/PUT body must be `{ "data": { ... } }`
2. **`locale` required** — i18n-enabled CTs fail with `Invalid key` without it
3. **Media uploaded separately** — Upload via Strapi Upload API, then reference by ID
4. **Deep reads via Smart API** — Standard REST only populates 1 level; use `/api/builder/pages/:docId` for full data

## File Structure

```
server/src/
  content-types/       — Plugin-owned content type schemas
  register.ts         — Programmatic component registration
  controllers/        — Smart API controllers (page, global)
  services/           — Populate service (deep populate definitions for all 16 blocks)
  routes/             — Core and smart API route definitions
  components/         — Component JSON schemas (blocks, elements, shared)
```

## Peer Dependencies

- `@strapi/provider-upload-aws-s3` ^5.36.0 (optional)
- `@strapi/strapi` ^5.49.0
- `@strapi/utils` ^5.49.0 (optional)
- `@strapi/plugin-color-picker` ^5.0.0
- `@d3levvv/strapi-react-icons-plugin` ^1.0.0
- `react` ^17.0.0 || ^18.0.0
- `react-router-dom` ^6.30.3
- `react-intl` ^6.6.2
- `@strapi/design-system` ^2.2.0
- `@strapi/icons` ^2.2.0

## Publishing Type Subpaths

When adding or changing a public type subpath in `package.json#exports`:

1. Import its public symbols through the package specifier in a Vitest type
   test (for example, `@dani-builder/strapi-plugin-builder/types`) and assert
   them with `expectTypeOf`.
2. Keep a no-emit `check-types` script so the root Turbo task compiles the
   package source.
3. Run `pnpm verify:publish-tarballs` to confirm the declaration files are in
   the published artifact.
4. Add a changeset when the public contract changes; verification-only changes
   do not need one.

The `.claude/skills/builder-extender/references/` files are consumer-project
templates, not package source, so the package `check-types` task does not include
them. The public-specifier type test covers their imported Builder contract;
the copied template is compiled in its consumer project's Strapi context.
