# Building blocks

## What are building blocks?

Building blocks let you package a reusable subprocess with its own data model and version it separately from cases. This allows them to use their own data and configuration. You can use the same building block in multiple case definitions and across environments, while keeping a clear input and output contract.

Building blocks are isolated by design. They should not directly read or write case data. Instead, you define the inputs and outputs when you link them to a case. This isolation ensures that building blocks remain reusable and maintainable across different contexts.

The building block lifecycle follows these steps:

1. Create a building block definition (name, version, description).
2. Define the data it needs and the data it produces.
3. Add the processes and choose the main process.
4. Link the building block to a **Call activity** in a case process.
5. Map inputs and outputs, and choose when outputs are synced.

### When to use building blocks

Building blocks are useful when:

* The same subprocess is needed in multiple cases.
* You want one place to update a shared step.
* You want a consistent way to pass data in and get results back.

**Example:** A "Household verification" building block can be used in both subsidy and permit cases. Each case passes in the citizen data, the building block runs the checks, and the outcome is synced back to the case.

{% hint style="info" %}
This feature is different from the Process Exchange building blocks that you download and copy into projects. For those, see [Process Exchange building blocks](https://github.com/valtimo-platform/valtimo-docs-v3/blob/main/fundamentals/process-exchange/building-blocks.md).
{% endhint %}

## Creating a building block

### 1. Create the definition

* Go to **Admin** in the left sidebar.
* Select **Building blocks**.
* Click **Create**.
* Enter a **Name**, **Version**, and (optional) **Description**.
* Click **Save**.

<figure><img src="https://3348485295-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGVh8ZudZXQZAtqCQlSKR%2Fuploads%2Fgit-blob-d75296770a9383cde9917c5fbc4422b8ee13f4e9%2Fbuilding-block-create-modal.png?alt=media" alt=""><figcaption><p>Create a new building block</p></figcaption></figure>

### 2. Add general information

* Open the **General** tab.
* Optionally upload **Artwork**.
* Review the list of **Plugins used** so you know which plugin types must be configured later. Initially, the list will be empty. This will be updated as you add plugins or other building blocks to the processes of your building block.

<figure><img src="https://3348485295-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGVh8ZudZXQZAtqCQlSKR%2Fuploads%2Fgit-blob-39ef40bf1db176a0753eb0e2b83ec70c50b6f555%2Fbuilding-block-general.png?alt=media" alt=""><figcaption><p>General information and artwork</p></figcaption></figure>

### 3. Define the data fields

* Open the **Document** tab.
* Add the fields the building block needs (inputs) and may return (outputs) and any other data the building block will need to use internally.
* Mark fields as required if the case must provide them when using the building block. Required fields must be mapped in the input mapping when linking the building block to a case.
* Click **Save**.

<figure><img src="https://3348485295-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGVh8ZudZXQZAtqCQlSKR%2Fuploads%2Fgit-blob-2fa2aa6ba1cf967ce412d36133e1919da7352f3f%2Fbuilding-block-document.png?alt=media" alt=""><figcaption><p>Define data fields for the building block</p></figcaption></figure>

### 4. Add processes

* Open the **Processes** tab.
* Either **Upload** a BPMN file or **Create** a new process.
* Select which process should be the **Main process** for the building block, or use the process that has been created with the building block.
* You can use plugins in these processes just like in case processes, but you select the plugin type instead of a specific configuration.

<figure><img src="https://3348485295-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGVh8ZudZXQZAtqCQlSKR%2Fuploads%2Fgit-blob-461b2442bfe2bcae2657025d777d537b3908a3ef%2Fbuilding-block-processes.png?alt=media" alt=""><figcaption><p>Processes inside the building block</p></figcaption></figure>

* When a building block has multiple processes, you can create call activities from one process to another. Set the process definition key (the **Key** value shown in the processes list) and include a reference to the current building block in the **Version tag** field. The version tag has the format `BB:<building-block-key>:<building-block-version>`.

<figure><img src="https://3348485295-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGVh8ZudZXQZAtqCQlSKR%2Fuploads%2Fgit-blob-e0ce94c0f34361d94a93b95daca5a09c8ea456d1%2Flink-additional-process.png?alt=media" alt=""><figcaption><p>Link to a different process in the building block</p></figcaption></figure>

{% hint style="warning" %}
User tasks are not yet supported in building blocks. This means form, form flow, and custom UI component process links cannot be used. Only plugin and building block process links are available.
{% endhint %}

### 5. Finalize the version

Building blocks use **draft** and **final** versions, similar to case definitions.

Before you finalize, **test the building block thoroughly**. Final versions cannot be changed.

* In the **More** menu, choose **Make version final** to lock the version.
* To make changes later, create a **new draft** from a final version.

Only **final** building blocks can be used when finalizing a case definition.

<figure><img src="https://3348485295-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGVh8ZudZXQZAtqCQlSKR%2Fuploads%2Fgit-blob-ca69bbd626cb95fcc1cdf758be513b50dff301b2%2Fbuilding-block-finalize.png?alt=media" alt=""><figcaption><p>Finalize a building block version</p></figcaption></figure>

## Using a building block in a case

### 1. Add a Call activity

* Open the case process where you want to use the building block.
* Add a **Call activity** to the process model.

<figure><img src="https://3348485295-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGVh8ZudZXQZAtqCQlSKR%2Fuploads%2Fgit-blob-71ed0b0efabb946b852402084569e98953b54daa%2Fbuilding-block-call-activity.png?alt=media" alt=""><figcaption><p>Call activity in a case process</p></figcaption></figure>

### 2. Link the building block

* Open the **Process link** for the Call activity.
* Choose **Building block** as the link type.
* Choose the **Building block** you want to use.

<figure><img src="https://3348485295-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGVh8ZudZXQZAtqCQlSKR%2Fuploads%2Fgit-blob-ca1227efc8d5febac965caca3d3605b6b9676c9b%2Fbuilding-block-process-link-select.png?alt=media" alt=""><figcaption><p>Select a building block and version</p></figcaption></figure>

### 3. Configure plugin mappings

* Select the building block **Version** you want to use.

If this version uses plugins, you must map each **plugin type** to a **plugin configuration** that already exists in your environment.

* Select the saved plugin configuration for each plugin type.

<figure><img src="https://3348485295-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGVh8ZudZXQZAtqCQlSKR%2Fuploads%2Fgit-blob-c44666583ca7743c90714f4f1fc555c3e44f4199%2Fbuilding-block-plugin-mapping.png?alt=media" alt=""><figcaption><p>Configure plugin mappings</p></figcaption></figure>

### 4. Map inputs and sync outputs

* Map **Inputs** from the case data to the building block fields.
  * All required fields (marked as required in the building block document definition) are listed by default and must be mapped.
  * Any optional inputs can be added manually by clicking **Add input**.
* Map **Outputs** from the building block back to the case.
  * Fields can be added for syncing by clicking **Add sync**.
  * When the building block completes, the specified fields are written from the building block back to the case document.
  * This is one way. Any changes to the case document will not be automatically synced to the building block instance.

<figure><img src="https://3348485295-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGVh8ZudZXQZAtqCQlSKR%2Fuploads%2Fgit-blob-ac0eca1319ff91483cbefe91b56a77ee1c242450%2Fbuilding-block-input-output-mapping.png?alt=media" alt=""><figcaption><p>Input and output mapping</p></figcaption></figure>

### 5. Save and deploy

* Click **Complete** to save the process link.
* Save and deploy the updated case process.

## Import and export building blocks

Building blocks are automatically included in case definition exports. You can also export or import a building block separately when you want to move or reuse it on its own.

### Import

{% hint style="info" %}
Before importing, make sure any required process definitions or plugin configurations already exist in your environment.
{% endhint %}

* Go to **Admin** → **Building blocks**.
* Click **Upload**.
* Select a `.zip` export file.
* Confirm the overwrite warning. This will replace all existing resources (document definition, processes, and settings) for this building block version if it already exists in your environment.
* Follow the steps in the wizard.

<figure><img src="https://3348485295-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGVh8ZudZXQZAtqCQlSKR%2Fuploads%2Fgit-blob-89a037111c5f4e53ec7d9475c7a71cc43d419afd%2Fbuilding-block-import.png?alt=media" alt=""><figcaption><p>Import a building block definition</p></figcaption></figure>

### Export

* Open a building block.
* Click **More** → **Export**.

<figure><img src="https://3348485295-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGVh8ZudZXQZAtqCQlSKR%2Fuploads%2Fgit-blob-37afad56f6cec817bc232b5d669fb19e9232e47b%2Fbuilding-block-export.png?alt=media" alt=""><figcaption><p>Export a building block definition</p></figcaption></figure>

## Related

* [Cases](https://github.com/valtimo-platform/valtimo-docs-v3/blob/main/configuration-guides/cases/README.md) - Building blocks are used within case processes
* [Plugins](https://github.com/valtimo-platform/valtimo-docs-v3/blob/main/configuration-guides/plugins/README.md) - Building blocks can use plugin types
* [Processes](https://github.com/valtimo-platform/valtimo-docs-v3/blob/main/configuration-guides/cases/processes.md) - Understanding process links and call activities
* [Process Exchange building blocks](https://github.com/valtimo-platform/valtimo-docs-v3/blob/main/fundamentals/process-exchange/building-blocks.md) - Different type of building blocks
