> ## Knowledge Base Index
> Fetch the complete knowledge base index at: https://help.swellsystem.com/sitemap.xml
> Use this file to discover available pages before exploring further.
> Pure-Markdown content can be obtained by appending a '.md' suffix to the content URLs listed in the sitemap (without the trailing slash).

# Blueprints and Marketplace

# Blueprints and Marketplace

Blueprints are reusable templates that users can import into their workspace. They package projects, workflows, email sequences, forms, workspace pages, proposals, contracts, or full account setups.

## Blueprint Types

| Type | Description | Import Creates |
|------|-------------|----------------|
| `project_template` | Project with task lists and tasks | Project |
| `workflow` | Automation workflow | Workflow |
| `email_sequence` | Drip/email campaign | DripCampaign |
| `form_template` | Multi-step form | Form with steps and fields |
| `workspace_structure` | Workspace pages with blocks | Workspace pages |
| `proposal_template` | Proposal layout/sections | ProposalTemplate |
| `contract_template` | Contract clauses | ProposalTemplate (contracts share Proposal model) |
| `account_setup` | Full account bundle | CRM pipeline + projects + workflows + sequences + workspace + forms |

## Building Blueprints

### Single-Source Blueprints (Project, Workflow, Email Sequence)

1. Go to **Marketplace** → **Build** (or `/marketplace/build`)
2. Choose type: Workflow, Project Template, or Email Sequence
3. Select the source item (e.g. an existing project to package)
4. Add name, description, category, tags
5. Click **Create Blueprint**

The system serializes the selected item into `blueprint_data` and creates a Blueprint record.

### Account Setup Blueprints (Bundle)

1. Go to **Marketplace** → **Build**
2. Choose type: **Account Setup (Bundle)**
3. Select items from built-in templates:
   - CRM Pipeline (agency, consultant, coach)
   - Project templates (checkboxes)
   - Workflows (checkboxes)
   - Email sequences (checkboxes)
   - Workspace structure (dropdown)
   - Form templates (checkboxes)
4. Add name and description
5. Click **Create Blueprint**

Import creates all selected items in dependency order.

## Importing Blueprints

1. Browse **Marketplace** or use **Import** with a blueprint ID
2. Select a blueprint and click **Import**
3. The `BlueprintService` reads `blueprint_data['type']` and routes to the correct importer
4. Plan gating: Account setup imports skip modules the tenant doesn't have active (e.g. if Forms module is off, form templates are skipped)

## Plan Gating (Account Setup)

Account setup imports respect the tenant's active modules. The mapping is defined in `config/blueprint_plan_gating.php`:

| Import Item | Required Module(s) |
|-------------|---------------------|
| CRM pipeline | `crm` |
| Project templates | `projects` |
| Workflows | `workflows` |
| Email sequences | `marketing` or `email` |
| Workspace structure | `workspace` |
| Form templates | `forms` |

To adjust gating (e.g. if module slugs change), edit `config/blueprint_plan_gating.php`. Skipped items are listed in the import result's `skipped` array.

## Built-in Blueprints

Seeded blueprints are defined in `config/builtin_blueprints.php` and created by `BlueprintSeeder` for the Demo Corp tenant. Sections:

- `project_templates` – Website Redesign, Brand Identity, Consulting Engagement, etc.
- `workflows` – New Lead Assign, Proposal Follow-up
- `email_sequences` – Client Onboarding, New Lead Nurture, Post-Project Follow-up
- `form_templates` – Client Intake, Discovery Questionnaire
- `workspace_structures` – Agency Starter Pages
- `proposal_templates` – Agency Project, Consulting Engagement, Coaching Program
- `contract_templates` – Master Service Agreement, Project Contract
- `account_setups` – Agency Starter, Consulting Pro, Coaching Practice

## Config Files

- `config/builtin_blueprints.php` – Blueprint definitions
- `config/marketplace.php` – Categories, suggested tags, featured by role
- `config/crm_pipeline_presets.php` – CRM pipeline presets for agency/consultant/coach

## API

Blueprint import is handled by `BlueprintService::importBlueprint(array $blueprintData, $userId = null)`. Pass `blueprint_data` from a Blueprint record.

## Adding Custom Blueprint Types

1. Add the type to the `blueprints.type` enum (migration)
2. Add a case in `BlueprintService::importBlueprint()` match
3. Implement the importer method (e.g. `importContractTemplate`)
4. Add config entries in `builtin_blueprints.php` if desired
5. Update `BlueprintSeeder` to seed the new type
