├── run-structurizr.sh ├── mkdocs.yml ├── export-structurizr-diagrams.sh ├── workspace.dsl ├── docs └── index.md ├── .github └── workflows │ └── update-pages.yml ├── requirements.txt ├── LICENSE ├── .gitignore └── README.md /run-structurizr.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | DOCS_PATH=$( cd "$(dirname "$0")" ; pwd -P ) 4 | echo "Starting structurizr/lite in $DOCS_PATH" 5 | docker pull structurizr/lite 6 | docker run -it --rm -p 8080:8080 -v $DOCS_PATH:/usr/local/structurizr structurizr/lite -------------------------------------------------------------------------------- /mkdocs.yml: -------------------------------------------------------------------------------- 1 | site_name: Structurizr MkDocs Sample 2 | site_url: https://jbrestan.github.io/structurizr-mkdocs-pages/ 3 | 4 | plugins: 5 | - search 6 | - macros 7 | - mermaid2: 8 | arguments: 9 | securityLevel: 'loose' 10 | 11 | theme: 12 | name: material 13 | -------------------------------------------------------------------------------- /export-structurizr-diagrams.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | DOCS_PATH=$( cd "$(dirname "$0")" ; pwd -P ) 4 | docker pull ghcr.io/aidmax/structurizr-cli-docker 5 | docker run --rm -v $DOCS_PATH:/root/data -w /root/data ghcr.io/aidmax/structurizr-cli-docker \ 6 | export --workspace workspace.dsl --format mermaid --output docs/diagrams/ 7 | -------------------------------------------------------------------------------- /workspace.dsl: -------------------------------------------------------------------------------- 1 | workspace { 2 | 3 | model { 4 | user = person "User" 5 | softwareSystem = softwareSystem "Software System" 6 | 7 | user -> softwareSystem "Uses" 8 | } 9 | 10 | views { 11 | systemContext softwareSystem "Diagram1" { 12 | include * 13 | autoLayout 14 | } 15 | 16 | theme default 17 | } 18 | 19 | } -------------------------------------------------------------------------------- /docs/index.md: -------------------------------------------------------------------------------- 1 | # Welcome 2 | 3 | This repo serves as an example of lightweight local-only or static pages Structurizr hosting using MkDocs to serve generated diagrams as well as additional documentation. 4 | 5 | ## Diagram From File 6 | 7 | This diagram has been exported to a Mermaid file from the Structurizr workspace/model, and included using mkdocs macros plugin. 8 | 9 | ```mermaid 10 | {% include 'diagrams/structurizr-Diagram1.mmd' %} 11 | ``` 12 | -------------------------------------------------------------------------------- /.github/workflows/update-pages.yml: -------------------------------------------------------------------------------- 1 | name: Update Pages 2 | 3 | on: 4 | push: 5 | branches: [ main ] 6 | workflow_dispatch: 7 | 8 | jobs: 9 | update: 10 | runs-on: ubuntu-latest 11 | 12 | steps: 13 | - uses: actions/checkout@v2 14 | 15 | - name: Export diagrams 16 | run: ./export-structurizr-diagrams.sh 17 | 18 | - name: Install mkdocs + dependencies 19 | run: pip install -r requirements.txt 20 | 21 | - name: Update pages branch 22 | run: mkdocs gh-deploy --force 23 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | beautifulsoup4==4.9.3 2 | certifi==2021.5.30 3 | charset-normalizer==2.0.1 4 | click==8.0.1 5 | EditorConfig==0.12.3 6 | ghp-import==2.0.1 7 | idna==3.2 8 | importlib-metadata==4.6.1 9 | Jinja2==3.0.1 10 | jsbeautifier==1.14.0 11 | Markdown==3.3.4 12 | MarkupSafe==2.0.1 13 | mergedeep==1.3.4 14 | mkdocs==1.2.1 15 | mkdocs-macros-plugin==0.5.12 16 | mkdocs-material==7.1.10 17 | mkdocs-material-extensions==1.0.1 18 | mkdocs-mermaid2-plugin==0.5.2 19 | packaging==21.0 20 | Pygments==2.9.0 21 | pymdown-extensions==8.2 22 | pyparsing==2.4.7 23 | python-dateutil==2.8.2 24 | PyYAML==5.4.1 25 | pyyaml-env-tag==0.1 26 | requests==2.26.0 27 | six==1.16.0 28 | soupsieve==2.2.1 29 | termcolor==1.1.0 30 | urllib3==1.26.6 31 | watchdog==2.1.3 32 | zipp==3.5.0 33 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Honza Brestan 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. 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | pip-wheel-metadata/ 24 | share/python-wheels/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | MANIFEST 29 | 30 | # PyInstaller 31 | # Usually these files are written by a python script from a template 32 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 33 | *.manifest 34 | *.spec 35 | 36 | # Installer logs 37 | pip-log.txt 38 | pip-delete-this-directory.txt 39 | 40 | # Unit test / coverage reports 41 | htmlcov/ 42 | .tox/ 43 | .nox/ 44 | .coverage 45 | .coverage.* 46 | .cache 47 | nosetests.xml 48 | coverage.xml 49 | *.cover 50 | *.py,cover 51 | .hypothesis/ 52 | .pytest_cache/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | target/ 76 | 77 | # Jupyter Notebook 78 | .ipynb_checkpoints 79 | 80 | # IPython 81 | profile_default/ 82 | ipython_config.py 83 | 84 | # pyenv 85 | .python-version 86 | 87 | # pipenv 88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 91 | # install all needed dependencies. 92 | #Pipfile.lock 93 | 94 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 95 | __pypackages__/ 96 | 97 | # Celery stuff 98 | celerybeat-schedule 99 | celerybeat.pid 100 | 101 | # SageMath parsed files 102 | *.sage.py 103 | 104 | # Environments 105 | .env 106 | .venv 107 | env/ 108 | venv/ 109 | ENV/ 110 | env.bak/ 111 | venv.bak/ 112 | 113 | # Spyder project settings 114 | .spyderproject 115 | .spyproject 116 | 117 | # Rope project settings 118 | .ropeproject 119 | 120 | # mkdocs documentation 121 | /site 122 | 123 | # mypy 124 | .mypy_cache/ 125 | .dmypy.json 126 | dmypy.json 127 | 128 | # Pyre type checker 129 | .pyre/ 130 | 131 | # Structurizr logs and artifacts 132 | eula.properties 133 | workspace.json 134 | logs/ 135 | images/ 136 | graphviz/ 137 | docs/diagrams/ 138 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Update Pages](https://github.com/jbrestan/structurizr-mkdocs-pages/actions/workflows/update-pages.yml/badge.svg)](https://github.com/jbrestan/structurizr-mkdocs-pages/actions/workflows/update-pages.yml) 2 | 3 | Sample repository showing how to develop version controlled [Structurizr](structurizr.com) [C4 model](c4model.com) of your architecture locally with resulting diagrams hosted using [MkDocs](mkdocs.org) static page generator. This is little more than a bit of glue code to contain everything in a single repo (could be part of your app repo if you want everything together) sprinkled with GitHub automation to host the result as GH Pages, but I hope this can be used to save you a bit of time if you're trying to solve the same problem and, like me a just few days ago, are not familiar with any of the tooling. 4 | 5 | You can see the generated documentation here: https://jbrestan.github.io/structurizr-mkdocs-pages/ 6 | 7 | ## Why 8 | Tl;dr version: if your organization needs, size and complexity allows it, I recommend giving [Structurizr cloud or self-hosted server](https://structurizr.com/pricing) a go. But if for any reason you can't or don't want to use cloud Structurizr and are looking for local or statically hosted option, read on! 9 | 10 | Using Structurizr to describe your app or the whole product landscape in a single place you can generate diagrams from can be a gamechanger if you want to keep your architecure documentation up to date across multiple apps or perspectives. There's a good explanation of the [difference between diagramming and modelling](https://c4model.com/#Modelling) on the C4 pages and Structurizr is a great implementation of this approach. However if you don't want to use the cloud or self-hosted Structurizr options and just need the diagrams to show in your documentation while still benefiting from the centralized model, it's usually up to you to figure out the exact tooling and process. This repo is an example of such process, using MkDocs as the static docs generator and GitHub pages as the hosting. 11 | 12 | ## How does it work 13 | [MkDocs](mkdocs.org) is a widely used solution to generate static pages from a bit of configuration and a hierarchy of markdown documents. It's a python tool that you can [install locally to get started](https://www.mkdocs.org/getting-started/) and add plugins to extend the behavior. The two important plugins for us are [macros](https://github.com/fralau/mkdocs_macros_plugin) and [mermaid2](https://github.com/fralau/mkdocs-mermaid2-plugin) which allow us to include contents of another file in our docs markdown document and render mermaid syntax as a diagram on the resulting page. 14 | 15 | We can get the diagrams in mermaid syntax using [Structurizr CLI](https://github.com/structurizr/cli) which offers [exporting the model into various other formats](https://github.com/structurizr/cli/blob/master/docs/export.md#examples). 16 | 17 | The rest is just glue to make this work together. As you make changes to the model file, you can either view them locally using [Structurizr Lite](https://structurizr.com/help/lite) by starting `run-structurizr.sh` on your machine and navigating to `localhost:8080`. To view the full result export the mermaid files using `export-structurizr-diagrams.sh` script, include them in the documentation with a macro like `{% include 'diagrams/structurizr-Diagram1.mmd' %}`, build the docs and serve on localhost with `mkdocs serve` and navigate to `localhost:8000` to see the result. 18 | 19 | Once you push the changes, [GH action](https://github.com/jbrestan/structurizr-mkdocs-pages/blob/main/.github/workflows/update-pages.yml) will handle the diagram export and GitHub pages update. 20 | --------------------------------------------------------------------------------