Context Mapper

repository·master·Indexed 42 days ago

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

An open-source tool providing a Domain-specific Language (CML) based on Domain-Driven Design (DDD) patterns. It enables developers to model context maps and bounded contexts to generate UML diagrams, MDSL service contracts, and other artifacts. Available as a Java library (version 6.12.0) and as plugins for Visual Studio Code and Eclipse.

Tokens
1.7K
Snippets
3
Records
10
Agent score
54%

What's inside Context Mapper

  1. Overview of Context Mapper DSL (CML) features

    master

    Context Mapper provides a Domain-specific Language (CML) for Domain-Driven Design (DDD) patterns. Key capabilities include:

    • Strategic DDD: Write context maps with bounded contexts and their relationships.
    • Tactic DDD: Specify bounded contexts using a Tactic DSL based on Sculptor.
    • Architectural Refactorings (ARs): Iteratively evolve and improve DDD context maps.
    • Code & Diagram Generation:
      • Graphical Context Maps (requires Graphviz).
      • PlantUML Diagrams: Component diagrams (from context maps), Class diagrams (from bounded contexts/subdomains), State diagrams (for aggregate states), and Use case diagrams.
      • MDSL: Generate (micro-) service contracts.
      • Generic Text: Generate files using Freemarker templates.
  2. How to model domain services in CML

    master

    In Context Mapper Language (CML), domain services should be modeled at the same level as aggregates. This means they should be defined directly inside a BoundedContext object rather than being nested inside an Aggregate.

    While the DSL supports the older pattern of modeling services inside aggregates for backwards compatibility, the recommended DDD pattern is to place them within the bounded context to ensure they are treated as first-class citizens alongside aggregates.

  3. Layout for Use Case Diagrams (PlantUML Generator)

    master

    When using the Context Mapper PlantUML generator for Use Case diagrams, the layout follows the 'Larman' standard rather than the default PlantUML arrow-based approach.

    Key visualization rules:

    • Connections: Instead of using arrows, actors are connected to use cases with simple lines.
    • Actor Placement: Primary actors are positioned on the left side of the diagram, and secondary actors are positioned on the right side.
    • Use Case Flow: Use cases are visualized in a top-to-bottom orientation.
  4. Set up the Eclipse IDE for development

    master

    Because Context Mapper is an Xtext project, follow these steps to set up a development environment in Eclipse:

    1. Download Eclipse: Use the Eclipse IDE for Java and DSL Developers (version 2019-12 or newer is recommended).
    2. Import Project: Use Import -> Existing Maven Project.
    3. Generate Infrastructure: You will see build errors initially because Xtext sources must be generated.
      • Locate the Eclipse launch configuration named GenerateContextMappingDSLInfrastructure.
      • Run this configuration.
    4. Clean Workspace: After the generation completes, execute Project -> Clean... -> Clean all projects to resolve remaining build errors.
  5. Use Context Mapper as a standalone Java library

    master

    If you want to integrate the Context Mapper DSL (CML) and its generator tools (PlantUML, MDSL, etc.) directly into your Java application, add the following dependency to your build configuration.

    For a complete implementation guide and code examples, refer to the context-mapper-standalone-example repository.

    // Gradle
    implementation 'org.contextmapper:context-mapper-dsl:6.12.0'
    <!-- Maven -->
    <dependency>
      <groupId>org.contextmapper</groupId>
      <artifactId>context-mapper-dsl</artifactId>
      <version>6.12.0</version>
    </dependency>
  6. Build the project using Maven or Gradle

    master

    The project uses different build tools depending on the target:

    Complete Build (Eclipse Plugin)

    Use the Maven Wrapper to build the full project, including the Eclipse plugin.

    # Standard build
    ./mvnw clean install
    
    # Build with integration tests
    ./mvnw clean integration-test

    Standalone Build (DSL and LSP)

    Use the Gradle Wrapper to build only the standalone DSL and IDE (LSP) projects.

    ./gradlew clean build

    To publish to your local Maven repository (requires a GPG key):

    ./gradlew clean publishToMavenLocal -Psigning.keyId=<your-gpg-key-id> -Psigning.password=<gpg-passphrase> -Psigning.secretKeyRingFile=<path-to-gpg-keyring-file>
  7. Configure system requirements for Context Mapper

    master

    To run Context Mapper, ensure your system meets these requirements:

    • Java: JDK 11 or newer.
    • IDE: Eclipse or Visual Studio Code.
    • Graphviz: Required if using the Context Map generator.
      • You must add the Graphviz bin directory to your system PATH.
      • Windows Note: If installed to C:\Program Files (x86)\GraphvizX.XX, you must manually add C:\Program Files (x86)\GraphvizX.XX\bin to your PATH variable.
    • PlantUML Visualization (Eclipse only): To view diagrams directly in Eclipse, install either Asciidoctor Editor or the PlantUML Eclipse Plugin. Both require Graphviz to be installed.
  8. Execute CML commands via LSP

    master

    The CMLCommandService allows for the execution of Context Mapper Language (CML) commands through a Language Server Protocol (LSP) interface. To execute a command, you must provide a valid command ID and a resource URI as an argument.

    Command Arguments:

    • The first argument must be a JsonPrimitive representing the URI of the CML resource to which the command should be applied.

    Return Values:

    • Success: Returns the string "Command executed."
    • Unknown Command: Returns "Unknown command ID!" if the provided command ID is not recognized.
    • Missing URI: Returns "Error occurred: No resource URI found in command arguments!" if no URI is provided.
    • Error: Returns "Error occurred: <error message>" if the command execution fails.
    // Example LSP ExecuteCommandParams structure
    {
      "command": "<COMMAND_ID>",
      "arguments": [
        { "value": "file:///path/to/your/model.cml" }
      ]
    }