Context Mapper Examples

repository·master·Indexed 42 days ago

https://github.com/contextmapper/context-mapper-examples

A collection of example Domain-Driven Design (DDD) Context Maps written in the Context Mapper Language (CML). This resource provides business-oriented and technical architectural models, including examples for Insurance, Lakeside Mutual, and the DDD Cargo sample, as well as demonstrations of Architectural Refactorings (AR) such as splitting aggregates by entities, splitting bounded contexts by features or owner, and extracting aggregates by volatility.

Tokens
10.8K
Snippets
14
Records
41
Agent score
53%

What's inside Context Mapper

  1. Overview of Bounded Contexts in the Insurance Example

    master

    The insurance scenario is composed of several functional bounded contexts:

    • Customer Management: A central context responsible for managing all customer data.
    • Customer Self-Service Management: A web application context for customer logins and basic data updates (e.g., address changes).
    • Policy Management: Manages customer contracts and policies. It uses a partnership with Risk Management and a shared kernel with Debt Collection.
    • Debt Collection: Manages financial income (debts) derived from contracts and policies.
    • Risk Management: Calculates risks that influence contracts and policies via a close relationship with Policy Management.
    • Printing Context: An external system accessed via API by internal contexts to handle document printing (e.g., debts, policies).
  2. Explore Context Mapper DSL examples

    master

    This repository provides various DDD (Domain-Driven Design) Context Maps written in the ContextMapper DSL (CML). The examples range from business-oriented models to technical architectural models:

    • Insurance Example: A classic DDD context map and a team map (illustrating bounded contexts implemented by specific teams) for a fictitious insurance company.
    • Lakeside Mutual: A microservices-focused example demonstrating Microservice API Patterns (MAP), reverse-engineered from a real project.
    • Context Mapper Example: A model of the Context Mapper tool and framework itself.
    • DDD Cargo Sample: A model based on Eric Evans' DDD sample, split into three bounded contexts.
    • Architectural Refactoring (AR) Examples: Examples showing input and output CML models for various architectural refactorings provided by the tool.
  3. Explore the Lakeside Mutual Example

    master

    The Lakeside Mutual example demonstrates Context Mapper capabilities using a fictitious insurance project. It showcases two primary modeling approaches:

    1. Reverse Engineering: The CML model was generated using the context-map-discovery library.
    2. Event Storming: The model was enhanced to include a future 'claim processing' feature by modeling results from an Event Storming session.

    You can find the complete CML model in LakesideMutual.cml.

  4. Understand the OOAD Sample Claims workflow

    master

    The OOAD sample demonstrates a specific transformation pipeline:

    1. Use Case Definition: A use case is defined in CML (e.g., claims-use-case.cml).
    2. Domain Derivation: The use case is transformed to derive the Subdomain and Bounded Context.
    3. Entity Generation: The derived model is used to generate a JDL file (e.g., claims-use-case-entities.jdl).
    4. Application Generation: The JDL file is used to generate a microservice application.
  5. Strategies for suspending a Partnership relationship

    master

    When performing the Suspend Partnership refactoring, you must choose one of the following three strategies depending on your architectural goal:

    1. Merge the two Bounded Contexts: Merges the two teams and their models into a single Bounded Context. This effectively executes the AR-7 Merge Bounded Contexts refactoring. The resulting model contains one Bounded Context containing all aggregates from the original two.

    2. Extract a new Bounded Context for commonalities: If the interdependence is caused by shared domain parts or APIs, this strategy extracts those common parts into a new Bounded Context. It establishes two new upstream-downstream ([ U ] -> [ D ]) relationships: one from the new context to the first original context, and one from the new context to the second original context.

    3. Replace Partnership with an upstream-downstream relationship: One context takes the lead on common parts/APIs, making the dependency unidirectional. You must specify which Bounded Context becomes the upstream ([ U ]) context and which becomes the downstream ([ D ]) context.

  6. Configure aggregate likelihoodForChange in CML

    master

    In the Context Mapper DSL, you can specify how frequently an aggregate is expected to change using the likelihoodForChange attribute. This attribute is used by architectural refactorings like AR-4: Extract Aggregates by Volatility to group or isolate components.

    Available values for likelihoodForChange:

    • RARELY
    • NORMAL
    • OFTEN
    Aggregate CustomerFrontend {
      likelihoodForChange = OFTEN
      // ...
    }
  7. Model Event Storming results in Context Mapper

    master

    This example demonstrates how to extend a reverse-engineered CML model by incorporating results from an Event Storming session. In this specific case, the model was extended to support a future 'claim processing' subdomain.

    While a formal tutorial is pending, the example provides a visual reference of how Event Storming results (such as domain events and processes) can be mapped into the Context Mapper domain model.

  8. Concept: Shared Kernel vs. Extracted Bounded Context

    master

    Shared Kernel

    A Shared Kernel describes a close relationship where two Bounded Contexts share a portion of their domain models, typically implemented via a shared library maintained by both teams. While useful for small shared parts, it creates tight coupling: changes in the shared code affect both teams simultaneously.

    Extracted Bounded Context (via AR-8)

    When the Shared Kernel grows too large, it is refactored into its own Bounded Context. This transition changes the relationship from a mutual dependency to a formal upstream-downstream model:

    1. Autonomy: The shared logic is now owned by a dedicated context (and potentially a dedicated team).
    2. Relationship Change: Instead of ContextA [SK]<->[SK] ContextB, the model shows NewContext [ U ] -> [ D ] ContextA and NewContext [ U ] -> [ D ] ContextB.
    3. Decoupling: This increases the autonomy of the original teams by formalizing how they consume the shared functionality.
  9. Understand the DDD Cargo Sample Architecture

    master

    The DDD Cargo sample is modeled using three bounded contexts to demonstrate specific relationship patterns in Context Mapper:

    1. Core Application: The primary bounded context.
    2. Voyage Scheduling: A separate bounded context that shares code with the core application, modeled using a Shared Kernel relationship.
    3. Locations: A bounded context modeled as an Open Host Service (OHS) to provide location-related capabilities to other contexts.

    This structure demonstrates how to model different interaction patterns between bounded contexts in CML.

  10. How to model Team Maps in CML

    master

    CML allows you to model organizational teams and their relationships similarly to how you model bounded contexts. To create a Team Map, you must:

    1. Change the type of a bounded context from SYSTEM, FEATURE, or APPLICATION to TEAM.
    2. Set the type of the context map to ORGANIZATIONAL.
    3. Use the realizes keyword to define which teams are responsible for specific systems, applications, or features.

    When using the graphical Context Map generator, you can produce either unclustered or clustered illustrations to visualize the relations between development teams and system bounded contexts.

  11. Architectural Refactoring AR-2: Split Bounded Context by Features

    master

    The Split Bounded Context by Features refactoring decomposes a single bounded context into multiple bounded contexts by grouping aggregates based on the use cases or user stories they support. This is used to increase cohesion and reduce coupling by ensuring that aggregates used by the same feature reside within the same context.

    When to use this AR

    Use this refactoring when a single bounded context contains aggregates that are used by different features (use cases or user stories).

    Preconditions

    • The bounded context must contain at least two aggregates.
    • The aggregates must be assigned to different use cases and/or user stories.

    Expected Outcome

    The refactoring produces multiple bounded contexts. Each new context contains one or more aggregates that share the same use cases or user stories.

    Inverse Refactoring

  12. Concept: AR-1 Split Aggregate by Entities

    master

    The Split Aggregate by Entities refactoring is a structural change applied at the Bounded Context level to optimize the granularity of aggregates.

    Mental Model: In Domain-Driven Design (DDD), aggregates should group attributes that belong to the same identity and share a common lifecycle. If an aggregate grows too large and contains entities with different lifecycles, it creates unnecessary coupling. This refactoring automates the process of promoting entities to aggregate roots and moving them into distinct aggregate containers.

    Relationship to other ARs: