buildzr 0.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. buildzr-0.0.1/.gitignore +18 -0
  2. buildzr-0.0.1/CONTRIBUTING.md +158 -0
  3. buildzr-0.0.1/LICENSE.md +21 -0
  4. buildzr-0.0.1/PKG-INFO +140 -0
  5. buildzr-0.0.1/README.md +110 -0
  6. buildzr-0.0.1/buildzr/__about__.py +1 -0
  7. buildzr-0.0.1/buildzr/__init__.py +4 -0
  8. buildzr-0.0.1/buildzr/dsl/__init__.py +18 -0
  9. buildzr-0.0.1/buildzr/dsl/dsl.py +990 -0
  10. buildzr-0.0.1/buildzr/dsl/explorer.py +67 -0
  11. buildzr-0.0.1/buildzr/dsl/expression.py +208 -0
  12. buildzr-0.0.1/buildzr/dsl/factory/__init__.py +1 -0
  13. buildzr-0.0.1/buildzr/dsl/factory/gen_id.py +23 -0
  14. buildzr-0.0.1/buildzr/dsl/interfaces/__init__.py +14 -0
  15. buildzr-0.0.1/buildzr/dsl/interfaces/interfaces.py +207 -0
  16. buildzr-0.0.1/buildzr/dsl/relations.py +367 -0
  17. buildzr-0.0.1/buildzr/encoders/__init__.py +1 -0
  18. buildzr-0.0.1/buildzr/encoders/encoder.py +61 -0
  19. buildzr-0.0.1/buildzr/models/__init__.py +1 -0
  20. buildzr-0.0.1/buildzr/models/generate.sh +21 -0
  21. buildzr-0.0.1/buildzr/models/models.py +1739 -0
  22. buildzr-0.0.1/pyproject.toml +76 -0
  23. buildzr-0.0.1/tests/__init__.py +1 -0
  24. buildzr-0.0.1/tests/abstract_builder.py +28 -0
  25. buildzr-0.0.1/tests/samples/__init__.py +0 -0
  26. buildzr-0.0.1/tests/samples/component_view.py +45 -0
  27. buildzr-0.0.1/tests/samples/container_view.py +40 -0
  28. buildzr-0.0.1/tests/samples/container_view_sugar.py +24 -0
  29. buildzr-0.0.1/tests/samples/groups.py +61 -0
  30. buildzr-0.0.1/tests/samples/implied_relationships.py +46 -0
  31. buildzr-0.0.1/tests/samples/simple.py +46 -0
  32. buildzr-0.0.1/tests/samples/simple_dsl.py +21 -0
  33. buildzr-0.0.1/tests/samples/system_context_view.py +41 -0
  34. buildzr-0.0.1/tests/samples/system_landscape_view.py +46 -0
  35. buildzr-0.0.1/tests/test_dsl.py +801 -0
  36. buildzr-0.0.1/tests/test_explorer.py +83 -0
  37. buildzr-0.0.1/tests/test_expression.py +307 -0
  38. buildzr-0.0.1/tests/test_views.py +415 -0
  39. buildzr-0.0.1/tests/test_workspaces.py +104 -0
@@ -0,0 +1,18 @@
1
+ # Environment variables.
2
+ .env
3
+
4
+ # Python artefacts and caches.
5
+ **/__pycache__
6
+ *.egg-info
7
+
8
+ # Temporary files are stored here -- used by scripts during development.
9
+ *.tmp
10
+
11
+ # Tests artefacts
12
+ tests/samples/.tests.**.json
13
+ tests/samples/*.puml
14
+ tests/structurizr_dsl_samples
15
+
16
+ # Build artefacts.
17
+ build
18
+ dist
@@ -0,0 +1,158 @@
1
+ # Contributing to buildzr
2
+
3
+ Thank you for considering contributing to buildzr! Your help is greatly appreciated. Below are some guidelines to help you get started.
4
+
5
+ _Happy Hacking 👩‍💻!_
6
+
7
+ ## Getting Started
8
+
9
+ ### Codespaces
10
+
11
+ I recommend using GitHub Codespaces for development. Codespaces provides a consistent development environment and simplifies the setup process.
12
+
13
+ You can quickly set up and start contributing to our project using GitHub Codespaces via GitHub CLI. Follow these steps:
14
+
15
+ 1. Install the GitHub CLI if you haven't already. Visit https://cli.github.com/.
16
+
17
+ 2. Authenticate with your GitHub account by running:
18
+
19
+ ```bash
20
+ gh auth login
21
+ ```
22
+
23
+ 3. Create a new codespace for this repository using the following command:
24
+
25
+ ```bash
26
+ gh codespace create -r amirulmenjeni/buildzr -b feature/my-aweseome-contrib
27
+ ```
28
+
29
+ 4. Once the codespace is created, you can [connect to it via VS Code](https://docs.github.com/en/codespaces/developing-in-a-codespace/using-github-codespaces-in-visual-studio-code#opening-a-codespace-in-vs-code) or `ssh`
30
+ into it:
31
+
32
+ ```bash
33
+ gh codespace ssh
34
+ ```
35
+
36
+ 5. Inside the workspace, setup and activate the Python environment:
37
+
38
+ ```bash
39
+ conda env create -f environment.yml
40
+ ```
41
+
42
+ To activate:
43
+
44
+ ```bash
45
+ conda activate buildzr-dev
46
+ ```
47
+
48
+ The codespace environment also includes useful tools developed by the Structurizr team such as [Structurizr CLI](https://docs.structurizr.com/cli) and [Structurizr Lite](https://docs.structurizr.com/lite) to view diagrams defined in [Structurizr DSL](https://docs.structurizr.com/dsl) or [JSON](https://structurizr.com/json). They're mostly helpful during development to validate the [Structurizr JSON schema](https://github.com/structurizr/json) generated by `buildzr`.
49
+
50
+ ### Running Tests
51
+
52
+ All tests are located in the `tests` folder. To run the tests, use the following command:
53
+ ```sh
54
+ pytest --mypy tests
55
+ ```
56
+
57
+ ### Testing `buildzr` Samples
58
+
59
+ Sometimes it is valuable to manually check the output of the Structurizr workspace generated by `buildzr` visually. For this reason, you can create `buildzr` samples in the [`tests/samples`](https://github.com/amirulmenjeni/buildzr/tree/master/tests/samples) directory.
60
+
61
+ Here's an example of the [`GroupSample`](https://github.com/amirulmenjeni/buildzr/blob/master/tests/samples/groups.py), to showcase the [group](https://docs.structurizr.com/dsl/cookbook/groups/) feature in Structurizr DSL used for grouping elements together:
62
+
63
+ ```python
64
+ import buildzr
65
+ from buildzr.dsl import *
66
+ from ..abstract_builder import AbstractBuilder
67
+
68
+ class GroupsSample(AbstractBuilder):
69
+
70
+ def build(self) -> buildzr.models.Workspace:
71
+
72
+ w = Workspace("w", scope=None)\
73
+ .contains(
74
+ Group(
75
+ "Company 1",
76
+ SoftwareSystem("A")\
77
+ .contains(
78
+ Container("a1"),
79
+ Container("a2"),
80
+ )
81
+ ),
82
+ Group(
83
+ "Company 2",
84
+ SoftwareSystem("B")\
85
+ .contains(
86
+ Container("b1"),
87
+ Container("b2")
88
+ .contains(
89
+ Component("c1"),
90
+ )
91
+ )
92
+ ),
93
+ SoftwareSystem("C"),
94
+ )\
95
+ .where(lambda w: [
96
+ w.software_system().a >> "Uses" >> w.software_system().b,
97
+ w.software_system().a.container().a1 >> "Uses" >> w.software_system().b.container().b1,
98
+ w.software_system().a >> "Uses" >> w.software_system().c,
99
+ ])\
100
+ .with_views(
101
+ SystemLandscapeView(
102
+ key='groups-sample',
103
+ description="Groups Sample"
104
+ ),
105
+ SystemContextView(
106
+ key='groups-sample-a',
107
+ software_system_selector=lambda w: cast(SoftwareSystem, w.a),
108
+ description="Groups Sample - Software System A"
109
+ ),
110
+ SystemContextView(
111
+ key='groups-sample-b',
112
+ software_system_selector=lambda w: cast(SoftwareSystem, w.b),
113
+ description="Groups Sample - Software System B"
114
+ ),
115
+ ContainerView(
116
+ key='groups-sample-b2',
117
+ software_system_selector=lambda w: w.software_system().b,
118
+ description="Groups Sample - Container B2"
119
+ ),
120
+ )\
121
+ .get_workspace()
122
+
123
+ return w.model
124
+ ```
125
+
126
+ By running `pytest tests/test_workspaces.py`, all the sample workspaces would be built, creating the corresponding JSON file with Structurizr schema. In the case of the `GroupSample` class, for example, the resulting output file path would be `tests/samples/.tests.samples.groups.json` -- named after the name of the Python file that contains the `GroupSample` class.
127
+
128
+ Note that the sample class must inherit the `AbstractBuilder` class.
129
+
130
+ ### Working with the `.json` files
131
+
132
+ What can you do with the generated `.json` files?
133
+
134
+ As mentioned, the `.json` file, if successfully and correctly generated using
135
+ `buildzr`, should follow the Structurizr JSON schema. Thus you can make use of existing and mature Structurizr tools such as the [Structurizr CLI](https://docs.structurizr.com/cli) and [Structurizr Lite](https://docs.structurizr.com/lite).
136
+
137
+ If you use codespaces (_highly recommended_), these tools are already pre-installed in the devcontainer image.
138
+
139
+ For example, to export the `tests/samples/.tests.samples.groups.json` to other format (say, [PlantUML](https://plantuml.com/)):
140
+
141
+ ```bash
142
+ structurizr.sh \
143
+ export \
144
+ --format plantuml \
145
+ --workspace tests/samples/.tests.samples.groups.json \
146
+ --output tests/samples/.tests.samples.groups.puml
147
+ ```
148
+
149
+ To view the rendering of `tests/samples/.tests.samples.groups.json` in the
150
+ browser at http://localhost:8080:
151
+
152
+ ```bash
153
+ structurizr-lite.sh tests/samples/.tests.samples.groups.json
154
+ ```
155
+
156
+ ## Submitting Changes
157
+
158
+ As usual, just fork the repo, make changes, and submit PRs!
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Amirul Menjeni
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
buildzr-0.0.1/PKG-INFO ADDED
@@ -0,0 +1,140 @@
1
+ Metadata-Version: 2.3
2
+ Name: buildzr
3
+ Version: 0.0.1
4
+ Summary: Structurizr for the `buildzr`s 🧱⚒️
5
+ Project-URL: homepage, https://github.com/amirulmenjeni/buildzr
6
+ Project-URL: issues, https://github.com/amirulmenjeni/buildzr/issues
7
+ Author-email: Amirul Menjeni <amirulmenjeni@pm.me>
8
+ License-File: LICENSE.md
9
+ Keywords: architecture,buildzr,c4model,design,diagram,structurizr
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.8
15
+ Classifier: Programming Language :: Python :: 3.9
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Requires-Python: >=3.8
20
+ Requires-Dist: pyhumps==3.8.0
21
+ Requires-Dist: pytest>=8.3.3
22
+ Provides-Extra: dev
23
+ Requires-Dist: datamodel-code-generator==0.26.2; extra == 'dev'
24
+ Requires-Dist: jsondiff==2.0.0; extra == 'dev'
25
+ Requires-Dist: mypy-extensions==1.0.0; extra == 'dev'
26
+ Requires-Dist: mypy==1.11.2; extra == 'dev'
27
+ Requires-Dist: pytest-mypy==0.10.3; extra == 'dev'
28
+ Requires-Dist: yq==3.4.3; extra == 'dev'
29
+ Description-Content-Type: text/markdown
30
+
31
+ # Structurizr for the `buildzr`s 🧱⚒️
32
+
33
+ `buildzr` is a [Structurizr](https://structurizr.com/) authoring tool for Python programmers.
34
+
35
+ If you're not familiar with Structurizr, it is both an open standard (see [Structurizr JSON schema](https://github.com/structurizr/json)) and a [set of tools](https://docs.structurizr.com/usage) for building software architecture diagrams as code. Structurizr derive its architecture modeling paradigm based on the [C4 model](https://c4model.com/), the modeling language for visualizing software architecture.
36
+
37
+ `buildzr` offers flexible and fluent APIs to write software architecture models based on the C4 model, leveraging the standard Structurizr JSON schema for interoperability with various rendering and authoring tools.
38
+
39
+ # Quick Start 🚀
40
+
41
+ ## Installation
42
+
43
+ _TODO_
44
+
45
+ ## Creating a workspace
46
+
47
+ The module `buildzr.dsl` contains all the classes you need to create a workspace containing all the architecture models.
48
+
49
+ Below is an example, where we:
50
+ 1. Create the models (`Person`, `SoftwareSystem`s, the `Container`s inside the `SoftwareSystem`, and the relationships between them)
51
+ 2. Define multiple views using the models we've created before.
52
+
53
+ ```python
54
+ import os
55
+ import json
56
+
57
+ from buildzr.encoders import JsonEncoder
58
+
59
+ from buildzr.dsl import (
60
+ Workspace,
61
+ SoftwareSystem,
62
+ Person,
63
+ Container,
64
+ SystemContextView,
65
+ ContainerView,
66
+ desc,
67
+ Group,
68
+ )
69
+
70
+ w = Workspace('w')\
71
+ .contains(
72
+ Group(
73
+ "My Company",
74
+ Person('Web Application User').labeled('u'),
75
+ SoftwareSystem('Corporate Web App').labeled('webapp')
76
+ .contains(
77
+ Container('database'),
78
+ Container('api'),
79
+ )\
80
+ .where(lambda s: [
81
+ s.api >> "Reads and writes data from/to" >> s.database,
82
+ ])
83
+ ),
84
+ Group(
85
+ "Microsoft",
86
+ SoftwareSystem('Microsoft 365').labeled('email_system'),
87
+ )
88
+ )\
89
+ .where(lambda w: [
90
+ w.person().u >> [
91
+ desc("Reads and writes email using") >> w.software_system().email_system,
92
+ desc("Create work order using") >> w.software_system().webapp,
93
+ ],
94
+ w.software_system().webapp >> "sends notification using" >> w.software_system().email_system,
95
+ ])\
96
+ .with_views(
97
+ SystemContextView(
98
+ lambda w: w.software_system().webapp,
99
+ key='web_app_system_context_00',
100
+ description="Web App System Context",
101
+ auto_layout='lr',
102
+ exclude_elements=[
103
+ lambda w, e: w.person().user == e,
104
+ ]
105
+ ),
106
+ ContainerView(
107
+ lambda w: w.software_system().webapp,
108
+ key='web_app_container_view_00',
109
+ auto_layout='lr',
110
+ description="Web App Container View",
111
+ )
112
+ )\
113
+ .get_workspace()
114
+
115
+ # Writes the Workspace model to a JSON file.
116
+ with open(os.path.join(os.path.curdir, f"{__file__.split('.')[0]}.json"), 'w', encoding='utf-8') as f:
117
+ json.dump(w.model, f, ensure_ascii=False, indent=4, cls=JsonEncoder)
118
+ ```
119
+
120
+ That's it 😊!
121
+
122
+ The JSON output can be found [here](examples/system_context_and_container_view.json). You can also try out https://structurizr.com/json to see how this workspace will be rendered.
123
+
124
+ # Why use `buildzr`?
125
+
126
+ ✅ Uses fluent APIs to help you create C4 model architecture diagrams in Python concisely.
127
+
128
+ ✅ Write Structurizr diagrams more securely with extensive type hints and [mypy](https://mypy-lang.org) support.
129
+
130
+ ✅ Stays true to the [Structurizr JSON schema](https://mypy-lang.org/) standards. `buildzr` uses the [datamodel-code-generator](https://github.com/koxudaxi/datamodel-code-generator) to automatically generate the "low-level" [representation](buildzr/models/models.py) of the Workspace model. This reduces deprecancy between `buildzr` and the Structurizr JSON schema.
131
+
132
+ ✅ Writing architecture diagrams in Python allows you to integrate programmability and automation into your software architecture diagramming and documentation workflow.
133
+
134
+ ✅ Uses the familiar Python programming language to write predicates for including/excluding elements and relationships in views.
135
+
136
+ # Contributing
137
+
138
+ Interested in contributing to `buildzr`?
139
+
140
+ Please visit [CONTRIBUTING.md](CONTRIBUTING.md).
@@ -0,0 +1,110 @@
1
+ # Structurizr for the `buildzr`s 🧱⚒️
2
+
3
+ `buildzr` is a [Structurizr](https://structurizr.com/) authoring tool for Python programmers.
4
+
5
+ If you're not familiar with Structurizr, it is both an open standard (see [Structurizr JSON schema](https://github.com/structurizr/json)) and a [set of tools](https://docs.structurizr.com/usage) for building software architecture diagrams as code. Structurizr derive its architecture modeling paradigm based on the [C4 model](https://c4model.com/), the modeling language for visualizing software architecture.
6
+
7
+ `buildzr` offers flexible and fluent APIs to write software architecture models based on the C4 model, leveraging the standard Structurizr JSON schema for interoperability with various rendering and authoring tools.
8
+
9
+ # Quick Start 🚀
10
+
11
+ ## Installation
12
+
13
+ _TODO_
14
+
15
+ ## Creating a workspace
16
+
17
+ The module `buildzr.dsl` contains all the classes you need to create a workspace containing all the architecture models.
18
+
19
+ Below is an example, where we:
20
+ 1. Create the models (`Person`, `SoftwareSystem`s, the `Container`s inside the `SoftwareSystem`, and the relationships between them)
21
+ 2. Define multiple views using the models we've created before.
22
+
23
+ ```python
24
+ import os
25
+ import json
26
+
27
+ from buildzr.encoders import JsonEncoder
28
+
29
+ from buildzr.dsl import (
30
+ Workspace,
31
+ SoftwareSystem,
32
+ Person,
33
+ Container,
34
+ SystemContextView,
35
+ ContainerView,
36
+ desc,
37
+ Group,
38
+ )
39
+
40
+ w = Workspace('w')\
41
+ .contains(
42
+ Group(
43
+ "My Company",
44
+ Person('Web Application User').labeled('u'),
45
+ SoftwareSystem('Corporate Web App').labeled('webapp')
46
+ .contains(
47
+ Container('database'),
48
+ Container('api'),
49
+ )\
50
+ .where(lambda s: [
51
+ s.api >> "Reads and writes data from/to" >> s.database,
52
+ ])
53
+ ),
54
+ Group(
55
+ "Microsoft",
56
+ SoftwareSystem('Microsoft 365').labeled('email_system'),
57
+ )
58
+ )\
59
+ .where(lambda w: [
60
+ w.person().u >> [
61
+ desc("Reads and writes email using") >> w.software_system().email_system,
62
+ desc("Create work order using") >> w.software_system().webapp,
63
+ ],
64
+ w.software_system().webapp >> "sends notification using" >> w.software_system().email_system,
65
+ ])\
66
+ .with_views(
67
+ SystemContextView(
68
+ lambda w: w.software_system().webapp,
69
+ key='web_app_system_context_00',
70
+ description="Web App System Context",
71
+ auto_layout='lr',
72
+ exclude_elements=[
73
+ lambda w, e: w.person().user == e,
74
+ ]
75
+ ),
76
+ ContainerView(
77
+ lambda w: w.software_system().webapp,
78
+ key='web_app_container_view_00',
79
+ auto_layout='lr',
80
+ description="Web App Container View",
81
+ )
82
+ )\
83
+ .get_workspace()
84
+
85
+ # Writes the Workspace model to a JSON file.
86
+ with open(os.path.join(os.path.curdir, f"{__file__.split('.')[0]}.json"), 'w', encoding='utf-8') as f:
87
+ json.dump(w.model, f, ensure_ascii=False, indent=4, cls=JsonEncoder)
88
+ ```
89
+
90
+ That's it 😊!
91
+
92
+ The JSON output can be found [here](examples/system_context_and_container_view.json). You can also try out https://structurizr.com/json to see how this workspace will be rendered.
93
+
94
+ # Why use `buildzr`?
95
+
96
+ ✅ Uses fluent APIs to help you create C4 model architecture diagrams in Python concisely.
97
+
98
+ ✅ Write Structurizr diagrams more securely with extensive type hints and [mypy](https://mypy-lang.org) support.
99
+
100
+ ✅ Stays true to the [Structurizr JSON schema](https://mypy-lang.org/) standards. `buildzr` uses the [datamodel-code-generator](https://github.com/koxudaxi/datamodel-code-generator) to automatically generate the "low-level" [representation](buildzr/models/models.py) of the Workspace model. This reduces deprecancy between `buildzr` and the Structurizr JSON schema.
101
+
102
+ ✅ Writing architecture diagrams in Python allows you to integrate programmability and automation into your software architecture diagramming and documentation workflow.
103
+
104
+ ✅ Uses the familiar Python programming language to write predicates for including/excluding elements and relationships in views.
105
+
106
+ # Contributing
107
+
108
+ Interested in contributing to `buildzr`?
109
+
110
+ Please visit [CONTRIBUTING.md](CONTRIBUTING.md).
@@ -0,0 +1 @@
1
+ VERSION = "0.0.1"
@@ -0,0 +1,4 @@
1
+ from . import models
2
+ from . import encoders
3
+ from .dsl import interfaces
4
+ from .dsl import expression
@@ -0,0 +1,18 @@
1
+ from .dsl import (
2
+ Workspace,
3
+ SoftwareSystem,
4
+ Person,
5
+ Container,
6
+ Component,
7
+ Group,
8
+ SystemLandscapeView,
9
+ SystemContextView,
10
+ ContainerView,
11
+ ComponentView,
12
+ )
13
+ from .relations import (
14
+ desc,
15
+ With,
16
+ )
17
+ from .explorer import Explorer
18
+ from .expression import Expression