|
1 | 1 |  |
2 | 2 | # Graphical DDD Context Map Generator |
3 | | -[](https://travis-ci.com/ContextMapper/context-map-generator) [](https://codecov.io/gh/ContextMapper/context-map-generator) [](https://opensource.org/licenses/Apache-2.0) |
| 3 | +[](https://travis-ci.com/ContextMapper/context-map-generator) [](https://codecov.io/gh/ContextMapper/context-map-generator) [](https://opensource.org/licenses/Apache-2.0) [](https://search.maven.org/search?q=g:%22org.contextmapper%22%20AND%20a:%22context-map-generator%22) |
4 | 4 |
|
5 | | -**Under construction (coming soon)** |
| 5 | +This repository contains a Java library to generate graphical DDD Context Maps inspired by [Brandolini](https://www.infoq.com/articles/ddd-contextmapping/) and [Vernon](https://www.amazon.de/Implementing-Domain-Driven-Design-Vaughn-Vernon/dp/0321834577). The generation of the Context Maps is based on [Graphviz](https://www.graphviz.org/) and used within the [Context Mapper](https://contextmapper.org) tool. |
| 6 | + |
| 7 | +## Usage |
| 8 | +The library is published to [Maven central](https://search.maven.org/search?q=g:%22org.contextmapper%22%20AND%20a:%22context-map-generator%22) and as an Eclipse feature to a [P2 repository](https://dl.bintray.com/contextmapper/context-map-generator-releases/). |
| 9 | + |
| 10 | +Therefore, you can easily include the library to your Maven or Gradle build: |
| 11 | + |
| 12 | +**Maven:** |
| 13 | +```xml |
| 14 | +<dependency> |
| 15 | + <groupId>org.contextmapper</groupId> |
| 16 | + <artifactId>context-map-generator</artifactId> |
| 17 | + <version>1.0.0</version> |
| 18 | +</dependency> |
| 19 | +``` |
| 20 | + |
| 21 | +**Gradle:** |
| 22 | +```gradle |
| 23 | +implementation 'org.contextmapper:context-map-generator:1.0.0' |
| 24 | +``` |
| 25 | + |
| 26 | +### Preconditions |
| 27 | +**Important note:** The generator requires [Graphviz](https://www.graphviz.org/) to be installed on the machine on which you run it. |
| 28 | + |
| 29 | +## Example |
| 30 | +The following Java programm illustrates how you can create a Context Map (png file in this case): |
| 31 | + |
| 32 | +```java |
| 33 | +BoundedContext customerManagement = new BoundedContext("Customer Management Context"); |
| 34 | +BoundedContext customerSelfService = new BoundedContext("Customer Self-Service Context"); |
| 35 | +BoundedContext printing = new BoundedContext("Printing Context"); |
| 36 | +BoundedContext debtCollection = new BoundedContext("Debt Collection Context"); |
| 37 | +BoundedContext policyManagement = new BoundedContext("Policy Management Context"); |
| 38 | +BoundedContext riskManagement = new BoundedContext("Risk Management Context"); |
| 39 | + |
| 40 | +ContextMap contextMap = new ContextMap() |
| 41 | + .addBoundedContext(customerManagement) |
| 42 | + .addBoundedContext(customerSelfService) |
| 43 | + .addBoundedContext(printing) |
| 44 | + .addBoundedContext(debtCollection) |
| 45 | + .addBoundedContext(policyManagement) |
| 46 | + .addBoundedContext(riskManagement) |
| 47 | + |
| 48 | + // Customer/Supplier relationship example |
| 49 | + .addRelationship(new UpstreamDownstreamRelationship(customerManagement, customerSelfService) |
| 50 | + .setCustomerSupplier(true)) |
| 51 | + |
| 52 | + // Upstream/Downstream relationship with OHS, PL, ACL, and CF examples |
| 53 | + .addRelationship(new UpstreamDownstreamRelationship(printing, customerManagement) |
| 54 | + .setUpstreamPatterns(OPEN_HOST_SERVICE, PUBLISHED_LANGUAGE) |
| 55 | + .setDownstreamPatterns(ANTICORRUPTION_LAYER)) |
| 56 | + .addRelationship(new UpstreamDownstreamRelationship(printing, policyManagement) |
| 57 | + .setUpstreamPatterns(OPEN_HOST_SERVICE, PUBLISHED_LANGUAGE) |
| 58 | + .setDownstreamPatterns(ANTICORRUPTION_LAYER)) |
| 59 | + .addRelationship(new UpstreamDownstreamRelationship(printing, debtCollection) |
| 60 | + .setUpstreamPatterns(OPEN_HOST_SERVICE, PUBLISHED_LANGUAGE) |
| 61 | + .setDownstreamPatterns(ANTICORRUPTION_LAYER)) |
| 62 | + .addRelationship(new UpstreamDownstreamRelationship(customerManagement, policyManagement) |
| 63 | + .setUpstreamPatterns(OPEN_HOST_SERVICE, PUBLISHED_LANGUAGE) |
| 64 | + .setDownstreamPatterns(CONFORMIST)) |
| 65 | + |
| 66 | + // Shared Kernel relationship example |
| 67 | + .addRelationship(new SharedKernel(debtCollection, policyManagement)) |
| 68 | + |
| 69 | + // Partnership relationship example |
| 70 | + .addRelationship(new Partnership(riskManagement, policyManagement)); |
| 71 | + |
| 72 | +// generate the Context Map |
| 73 | +new ContextMapGenerator().setLabelSpacingFactor(10) |
| 74 | + .setWidth(3600) |
| 75 | + .generateContextMapGraphic(contextMap, Format.PNG, "/home/user/myContextMap.png"); |
| 76 | +``` |
| 77 | + |
| 78 | +The program above generates the following Context Map: |
| 79 | + |
| 80 | +<a href="https://raw.githubusercontent.com/ContextMapper/context-map-generator/master/context-map-example.png" target="_blank"><img src="https://raw.githubusercontent.com/ContextMapper/context-map-generator/master/context-map-example.png" alt="Example Context Map" /></a> |
| 81 | + |
| 82 | +## Parameters |
| 83 | +With the following methods you can parameterize the `ContextMapGenerator`: |
| 84 | + |
| 85 | +| Method / Parameter | Description | Default value | |
| 86 | +|------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------| |
| 87 | +| setHeight(int height) | By using this parameter you can fix the height of the produced image. Note that if you use fix the height, the width will be adjusted dynamically. | 1500 | |
| 88 | +| setWidth(int width) | By using this parameter you can fix the width of the produced image. Note that if you use fix the width, the height will be adjusted dynamically. | 3600 | |
| 89 | +| setLabelSpacingFactor(int spacingFactor) | The Graphviz layouting algorithm doesn't ensure that the labels of the edges do not overlap. Especially the boxes with the relationship patterns (OHS, PL, ACL, CF) may often overlap in our case. By introducing spacing between the edges we can often bypass this issue. This parameter (a factor between 1 and 20) controls how much spacing we add. | 1 | |
| 90 | + |
| 91 | +## Supported Output Formats |
| 92 | +As illustrated in the example code above, the `generateContextMapGraphic` method takes a parameter to define the output format. The following formats are supported: |
| 93 | + |
| 94 | + * PNG |
| 95 | + * SVG |
| 96 | + * DOT ([Graphviz dot format](https://www.graphviz.org/doc/info/lang.html)) |
| 97 | + |
| 98 | +## Development / Build |
| 99 | +If you want to contribute to this project you can create a fork and a pull request. The project is built with Gradle, so you can import it as Gradle project within Eclipse or IntelliJ IDEA (or any other IDE supporting Gradle). |
| 100 | + |
| 101 | +## Contributing |
| 102 | +Contribution is always welcome! Here are some ways how you can contribute: |
| 103 | + * Create Github issues if you find bugs or just want to give suggestions for improvements. |
| 104 | + * This is an open source project: if you want to code, [create pull requests](https://help.github.com/articles/creating-a-pull-request/) from [forks of this repository](https://help.github.com/articles/fork-a-repo/). Please refer to a Github issue if you contribute this way. |
| 105 | + * If you want to contribute to our documentation and user guides on our website [https://contextmapper.org/](https://contextmapper.org/), create pull requests from forks of the corresponding page repo [https://github.com/ContextMapper/contextmapper.github.io](https://github.com/ContextMapper/contextmapper.github.io) or create issues [there](https://github.com/ContextMapper/contextmapper.github.io/issues). |
| 106 | + |
| 107 | +## Licence |
| 108 | +ContextMapper is released under the [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0). |
0 commit comments