# Strategic Modeling

## About

In Strategic Modeling, we learn to get a bigger Domain, understand it knowledge areas *(which are its sub-domains)* and find what is the best way to physically divide this into different code bases [#bounded-contexts](#bounded-contexts "mention") *(Identify and define boundaries between the Bounded Contexts)*.

When modeling we must have a general vision on how things fit on each other.

Because eventually different Bounded Contexts will:

* Complement each other,
* Talk to each other,
* One serve the other.

So we must create a more strategic modelling by mapping our contexts.

{% hint style="danger" %}
You can adopt DDD Strategic Modeling without adopting the Tactical Modeling.

Ex.: You can break your monolith application into diferent sub-domains (which now would kind of be like a `Microservice` architecture), and use a `Transaction Script` model which don't use any Domain Object types from Tactical Modeling.
{% endhint %}

As you better understand the business Domain, you end up dividing it in Subdomains and start recognizing the importance levels in each of them.

## Problems vs Solutions

The definition of the Domain will result in the Analysis and modeling of it.

And the Domain modeling will result in understanding of the Subdomains problems that will usually result in Bounded Contexts.

<img src="https://4117899876-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzHW4Qy3sVvzzQVSgW17m%2Fuploads%2FW9ebd44TxFyh0WrU8q7Q%2Ffile.excalidraw.svg?alt=media&#x26;token=abe8e7c9-1ef2-4ec8-9028-472462d91a6c" alt="" class="gitbook-drawing">

## What is a Domain?

The Domain is directly tied to the what the business **mainly** does. *(General vision of it)*

{% hint style="info" %}
*It is the problem, in business terms, that needs to be resolved independently of used technology.*

It is the heart of the software.
{% endhint %}

*(It is not always easy to extract the knowledge related to the domain)*

{% hint style="danger" %}
This Domain is not the same as project's Domain.
{% endhint %}

## What are Subdomains?

Are parts of the software that together can generate and aggregate value to the business.

*(More detailed and specific vision of the Domain)*

{% hint style="warning" %}
Identify Subdomains is the possibility of dividing your codebase. *(Not a rule)*
{% endhint %}

### Types of Domains/Subdomains

<img src="https://4117899876-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzHW4Qy3sVvzzQVSgW17m%2Fuploads%2FXFhdNiwiIYAqM2CS1Ydr%2Ffile.excalidraw.svg?alt=media&#x26;token=3e05f025-ceba-4b86-be27-988adf8097c3" alt="" class="gitbook-drawing">

<figure><img src="https://4117899876-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzHW4Qy3sVvzzQVSgW17m%2Fuploads%2FnZOveqVf1GQH3NQ7iDBs%2Fimage.png?alt=media&#x26;token=dd0c3703-a029-4a21-a483-f4d27a004862" alt=""><figcaption></figcaption></figure>

#### Core/Basic

The most important one, and the one that brings value to the company.

Where you put most and best effort on.

*Ex.: Checkout subdomains of an Ecommerce.*

#### Support/Auxiliary

Complements the `Core` domains/subdomains. Without these, it may be harder to succeed.

But you won't put too much effort on these.

*Ex.: Stock subdomains of an Ecommerce.*

#### Generic

Subdomains that can be delegated to other companies or even be third party applications.

*Ex.: Login/Auth subdomains of an Ecommerce.*

## Bounded Contexts

A Bounded Context is an **explicit boundary** within which a domain model exists. *(Meaning a physical project)*

It is **the implementation** of a Subdomain. Bounded Contexts **are** the division of codebase between different subdomains. *(Meaning similar Subdomains can be in the same Bounded Context)*

{% hint style="info" %}
Inside the boundary all terms and phrases of the Ubiquitous Language have specific meaning, and the model reflects the Language with exactness.
{% endhint %}

### Subdomains and Bounded Contexts

The segreggation of Subdomains in Bouded Contexts are highly dependant on the nessary coupling between these Subdomains and the complexity to develop and integrate these projects separated.

*Ex.: Bellow in the* `E-Commerce` *Bounded Context, you have 5 Subdomains that are highly dependant on each other. So segregating them on different projects would greatly impact performance, since they would have to communicate with each other all the time.*

<img src="https://4117899876-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzHW4Qy3sVvzzQVSgW17m%2Fuploads%2FT9taMv3OHyQxx3eFpbck%2Ffile.excalidraw.svg?alt=media&#x26;token=fe2c514e-457e-49cb-aebe-336abdb78131" alt="" class="gitbook-drawing">

<figure><img src="https://4117899876-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzHW4Qy3sVvzzQVSgW17m%2Fuploads%2FdIz2ePJtLuVEXTdW7bqf%2Fimage.png?alt=media&#x26;token=3f1b154a-52ba-4193-87ef-eae361ed91bf" alt=""><figcaption></figcaption></figure>

### Contexts

They determine what area of the business we are working on, what type of problem we are dealing with.

When the same word have different meanings, probably they are in different contexts.

But different words with the same meaning, also indicates that they are in different contexts.

<img src="https://4117899876-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzHW4Qy3sVvzzQVSgW17m%2Fuploads%2FfzvYGtPsFfRjb4ZhnQVC%2Ffile.excalidraw.svg?alt=media&#x26;token=af542648-7af9-4f51-8710-55c7f195d09b" alt="" class="gitbook-drawing">

### Transversal Elements

When different contexts talks to each other, by Entities or Elements.

The Client is the same guy, but they are in different contexts.

They still should be separated, so that a `Client` class is not bloated with information to be used by different contexts.

*(Ex.: Creating separated `Client` entities for each Bounded Context, even in a monolithic envirnoment)*

<img src="https://4117899876-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzHW4Qy3sVvzzQVSgW17m%2Fuploads%2F0oxnHlziHJwHEdoylWfc%2Ffile.excalidraw.svg?alt=media&#x26;token=33967a78-4833-4d58-bce1-2b49605f52cb" alt="" class="gitbook-drawing">

## Context Map

Is how Bounded Contexts interact and integrate with each other.

<img src="https://4117899876-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzHW4Qy3sVvzzQVSgW17m%2Fuploads%2FXKH98infRtDlGRPxb3Jg%2Ffile.excalidraw.svg?alt=media&#x26;token=c7bd39cc-9d58-467f-ae9d-7f01e110fa7a" alt="" class="gitbook-drawing">

## Integration Patterns

{% embed url="<https://github.com/ddd-crew/context-mapping>" %}

Integration Patterns define the type of relationship between each Bounded Context in a Context Map.

<img src="https://4117899876-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzHW4Qy3sVvzzQVSgW17m%2Fuploads%2FApJDyw9bc2yq1yAs96Si%2Ffile.excalidraw.svg?alt=media&#x26;token=ef6259fc-238f-4c97-8805-d49ffcb8dd58" alt="" class="gitbook-drawing">

#### Example of using these Patterns

<figure><img src="https://4117899876-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzHW4Qy3sVvzzQVSgW17m%2Fuploads%2F1IJGfcZuw1m9fWTswW5E%2Fimage.png?alt=media&#x26;token=4ebcb49b-58e7-4796-b0e2-8952f6b1e095" alt=""><figcaption></figcaption></figure>

### Partnership

When two or more Teams work synchronously in a deliver that involves two or more Bounded Contexts.

<img src="https://4117899876-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzHW4Qy3sVvzzQVSgW17m%2Fuploads%2FklOanlsO66ZpVPaFJKl0%2Ffile.excalidraw.svg?alt=media&#x26;token=f051ceee-f1fa-4ec3-951d-30328a4885fb" alt="" class="gitbook-drawing">

*Ex.: Two different Teams develop different Bounded Contexts in a coordinated way. And they communicate to establish how these Bounded Context will integrate.*

### Shared Kernel

When you share code between Bounded Contexts.

It is relatively normal to share part of the code between several Bounded Contexts, specially for unrelated purposes *(like infrastructure)*.

{% hint style="info" %}
More technically, the code can be shared by a direct relationship in a monorepo or some type of versioned library published internally.
{% endhint %}

{% hint style="danger" %}
A managing dependency process is essential for reduced productivety impacts.

*Ex.: Breaking changes in this shared library.*
{% endhint %}

<img src="https://4117899876-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzHW4Qy3sVvzzQVSgW17m%2Fuploads%2FsZNIkat201IsGlrfqLn1%2Ffile.excalidraw.svg?alt=media&#x26;token=30e475e1-ef29-4425-8a8d-d9c8091f8ed8" alt="" class="gitbook-drawing">

*Ex.: Part of two Bounded Context projects are equal, so you segregate that to a separate project.*

### Customer-Supplier Development

There is a relationship of supply where both the Customer and Supplier can determine how the contract *(interface)* should be between them.

{% hint style="warning" %}
Might be interesting to always have **tests** that garantee the integration health.
{% endhint %}

<img src="https://4117899876-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzHW4Qy3sVvzzQVSgW17m%2Fuploads%2FhKAd1QjwNv0u0ZjX82hS%2Ffile.excalidraw.svg?alt=media&#x26;token=2c9f8c25-b14c-4d3b-bce1-3f924439b887" alt="" class="gitbook-drawing">

### Conformist

There is potentialy no partnership between teams, meaning they don't talk to each other.

So the Customer has to conform to how the Supplier provides his interface.

<img src="https://4117899876-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzHW4Qy3sVvzzQVSgW17m%2Fuploads%2FPZC1YIQbawVXqGaXwQ9Z%2Ffile.excalidraw.svg?alt=media&#x26;token=20e2dffb-e1bc-4ccc-aa55-c1e6a5e19e9f" alt="" class="gitbook-drawing">

*Ex.: When using an external third-party API, you probably won't be able to ask them to change their API for your needs.*

### Open Host Service

A Bounded Context may make available a set of services using a default protocol with abundant documentation.

<img src="https://4117899876-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzHW4Qy3sVvzzQVSgW17m%2Fuploads%2FWEPtku3uFo3o4KR187Yg%2Ffile.excalidraw.svg?alt=media&#x26;token=95188e03-c2b5-4bfc-94c2-8d403c1d3cdc" alt="" class="gitbook-drawing">

*Ex.: An API that provide interface with different Versions (v1, v2).*

### ACL (Anticorruption Layer)

Usually `Conformist` relationships demand a translation to your Domain. *(So that you are not coupled to outside/third-party interfaces)*

This is done by adapters *(that translates interfaces)*, allowing your to use different or even change providers.

<img src="https://4117899876-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzHW4Qy3sVvzzQVSgW17m%2Fuploads%2FRiZE2S2kBBUzZuxCZPzb%2Ffile.excalidraw.svg?alt=media&#x26;token=e16dcc7d-da8f-4429-83d7-2d2faba65531" alt="" class="gitbook-drawing">

### Published Language

### Separated Ways

### Big Ball of Mud
