It is software that can draw an architecture diagram with python.
https://diagrams.mingrammer.com
A few days ago, my motivation was that I wanted to do something like the following about my eyes.
<img src='http://localhost:8080/?
with Diagram("Grouped Workers", show=False, direction="TB"):
ELB("lb") >> [EC2("worker1"),
EC2("worker2"),
EC2("worker3"),
EC2("worker4"),
EC2("worker5")] >> RDS("events")
I wrestled for about 10 hours and created it. The complete source code is the following repository.
https://github.com/tamuto/diagrams-server
First and foremost, the question is how to compile the Python source code passed in the URL? is. It's okay to get it from query_string, but you have to format it and then compile it. I used yapf as a library.
I was planning to have them describe it, including the import statement, as it is posted in examples. However, the query_string is attached like ``` ... import EC2from ...` ````, and even if it is formatted, it cannot be separated (obviously).
Here, we were able to implement the expected behavior. It is rewritten using NodeTransformer, compiled and executed by exec.
I got an error saying that there was no lineno on the way, but I solved it safely with `ast.fix_missing_location`
. (I think I did ...)
If you output with svg, an icon request will be generated separately. I forcibly processed it with Flask's route. (Because it is running in docker, it should be allowed !?)
I tried my best to make it, but I think there are various problems.
Normally, it should be written as an issue ...
For some reason, I rushed to release it with a time trial feeling. After this, I would like to sit down and respond.
Recommended Posts