|
| 1 | +--- |
| 2 | +layout: default |
| 3 | +title: Archetypes |
| 4 | +parent: Structurizr DSL |
| 5 | +nav_order: 6 |
| 6 | +permalink: /dsl/archetypes |
| 7 | +--- |
| 8 | + |
| 9 | +# Archetypes |
| 10 | + |
| 11 | +The archetypes feature (from v4.0.0) provides a way to create user defined types that extend the basic element/relationship types |
| 12 | +and optionally add some defaults for descriptions, technology, tags, properties, and perspectives. |
| 13 | +The key benefits are as follows: |
| 14 | + |
| 15 | +- Archetypes reduce duplication (define a type once, use it anywhere). |
| 16 | +- Archetypes lead to more concise DSL definitions. |
| 17 | +- Archetypes allow teams to build their own ubiquitous language on top of the C4 model. |
| 18 | + |
| 19 | +## Element archetypes |
| 20 | + |
| 21 | +For example, you could define archetypes named `application` and `datastore` |
| 22 | +that are essentially just aliases for `container`. |
| 23 | + |
| 24 | +``` |
| 25 | +workspace { |
| 26 | +
|
| 27 | + model { |
| 28 | + archetypes { |
| 29 | + application = container |
| 30 | + datastore = container |
| 31 | + } |
| 32 | + |
| 33 | + softwareSystem "A" { |
| 34 | + webapp = application "Web Application" |
| 35 | + db = datastore "Database Schema" |
| 36 | + |
| 37 | + webapp -> db "Reads from" |
| 38 | + } |
| 39 | + } |
| 40 | + |
| 41 | +} |
| 42 | +``` |
| 43 | + |
| 44 | +Archetypes can have a set of defaults defined too: |
| 45 | + |
| 46 | +``` |
| 47 | +workspace { |
| 48 | +
|
| 49 | + model { |
| 50 | + archetypes { |
| 51 | + application = container { |
| 52 | + technology "Java" |
| 53 | + tag "Application" |
| 54 | + } |
| 55 | + datastore = container { |
| 56 | + technology "MySQL" |
| 57 | + tag "Data Store" |
| 58 | + } |
| 59 | + } |
| 60 | + |
| 61 | + softwareSystem "A" { |
| 62 | + webapp = application "Web Application" |
| 63 | + db = datastore "Database Schema" |
| 64 | + |
| 65 | + webapp -> db "Reads from" |
| 66 | + } |
| 67 | + } |
| 68 | + |
| 69 | +} |
| 70 | +``` |
| 71 | + |
| 72 | +Archetypes can also be extended: |
| 73 | + |
| 74 | +``` |
| 75 | +workspace { |
| 76 | +
|
| 77 | + model { |
| 78 | + archetypes { |
| 79 | + application = container { |
| 80 | + technology "Java" |
| 81 | + tag "Application" |
| 82 | + } |
| 83 | + springBootApplication = application { |
| 84 | + technology "Spring Boot" |
| 85 | + } |
| 86 | + datastore = container { |
| 87 | + technology "MySQL" |
| 88 | + tag "Data Store" |
| 89 | + } |
| 90 | + } |
| 91 | + |
| 92 | + softwareSystem "A" { |
| 93 | + webapp = springBootApplication "Web Application" |
| 94 | + db = datastore "Database Schema" |
| 95 | + |
| 96 | + webapp -> db "Reads from" |
| 97 | + } |
| 98 | + } |
| 99 | + |
| 100 | +} |
| 101 | +``` |
| 102 | + |
| 103 | +## Relationship archetypes |
| 104 | + |
| 105 | +Relationship archetypes are also supported: |
| 106 | + |
| 107 | +``` |
| 108 | +workspace { |
| 109 | +
|
| 110 | + model { |
| 111 | + archetypes { |
| 112 | + sync = -> { |
| 113 | + tags "Synchronous" |
| 114 | + } |
| 115 | + https = --sync-> { |
| 116 | + technology "HTTPS" |
| 117 | + } |
| 118 | + } |
| 119 | + |
| 120 | + a = softwareSystem "A" |
| 121 | + b = softwareSystem "B" |
| 122 | + |
| 123 | + a --https-> b "Makes APIs calls using" |
| 124 | + } |
| 125 | +
|
| 126 | +} |
| 127 | +``` |
0 commit comments