<jupyter_start><jupyter_text>🖼️ Diagrams  PlantUML (iPython)<jupyter_code>import iplantuml
%%plantuml --jar --name sample_database

@startuml
' hide the spot
hide circle

' avoid problems with angled crows feet
skinparam linetype ortho

skinparam packageStyle rectangle

package Tables {
entity "Feed" as feed {
  *id : number <<generated>>
  --
  *name : text
  *type : number <<FK>>
  *uri : text
  update : datetime
}

entity "Feed Type" as feedtype {
  *id : number <<generated>>
  --
  *name : text
  *specification : text
  *schema : text
  update : datetime
}

entity "User Feed" as userfeeds {
  *id : number <<generated>>
  --
  *feed_id : number <<FK>>
  *user_id : number <<FK>>
  *order_seq : number
  update : datetime
}

entity "User" as users {
  *id : number <<generated>>
  --
  *name : text
  *email : text
  update : datetime
}


entity "User Schedule" as usersched {
  *id : number <<generated>>
  --
  *user_id : number <<FK>>
  *active : boolean
  *cronsched : text
  *timezone : text
  update : datetime
}
}

package "Config Flatfile" as flatfile{
entity "Ingest File" as ingest #lightgreen {
  *filename : text
  --
  *user name : text
  *user email : text
  *user cronsched : text
  *user timezone : text
  *user feeds : obj
}
}

feedtype ||..o{ feed
userfeeds }o..o{ feed
userfeeds }o..|| users
usersched ||..|| users
@enduml
%%plantuml --jar --name sample_deploy

@startuml
file "Config File" as configfile
interface "FastAPI" as fastapi
rectangle "NiFi" as nifi
rectangle "NiFi Registry" as nifireg
rectangle "HWX Schema Registry" as schemareg
queue "Kafka" as kafka
database "MySQL" as mysql
database "MS SQL" as mssql
cloud "Internet" as internet

configfile --> fastapi
fastapi <--> nifi
fastapi <--> internet
nifi <--> nifireg
nifi <--> kafka
nifi <--> internet
schemareg --> nifi
schemareg --> kafka
mssql --> kafka
mysql <--> nifi
@enduml<jupyter_output><empty_output><jupyter_text>Graphviz<jupyter_code># referece: https://github.com/xflr6/graphviz/blob/master/examples/graphviz-notebook.ipynb
# http://www.graphviz.org/pdf/dotguide.pdf Figure 20

from graphviz import Digraph

g = Digraph("G")
g.attr(compound="true")

with g.subgraph(name="cluster0") as c:
    c.edges(["ab", "ac", "bd", "cd"])

with g.subgraph(name="cluster1") as c:
    c.edges(["eg", "ef"])

g.edge("b", "f", lhead="cluster1")
g.edge("d", "e")
g.edge("c", "g", ltail="cluster0", lhead="cluster1")
g.edge("c", "e", ltail="cluster0")
g.edge("d", "h")

g<jupyter_output><empty_output><jupyter_text>mingrammer/diagrams<jupyter_code># reference: https://diagrams.mingrammer.com/docs/getting-started/examples

from diagrams import Cluster, Diagram
from diagrams.aws.compute import ECS, EKS, Lambda
from diagrams.aws.database import Redshift
from diagrams.aws.integration import SQS
from diagrams.aws.storage import S3

with Diagram("Event Processing", show=False) as diag:
    source = EKS("k8s source")

    with Cluster("Event Flows"):
        with Cluster("Event Workers"):
            workers = [ECS("worker1"), ECS("worker2"), ECS("worker3")]

        queue = SQS("event queue")

        with Cluster("Processing"):
            handlers = [Lambda("proc1"), Lambda("proc2"), Lambda("proc3")]

    store = S3("events store")
    dw = Redshift("analytics")

    source >> workers >> queue >> handlers
    handlers >> store
    handlers >> dw

diag<jupyter_output><empty_output><jupyter_text>Kroki (Remote)<jupyter_code>import base64
import sys
import zlib

import requests
from IPython.display import SVG

kroki_host = "https://kroki.io"
puml = b"""
start
:Hello world;
:This is defined on
several **lines**;
stop
"""
encoded_diag = base64.urlsafe_b64encode(zlib.compress(puml, 9))
encoded_diag.decode("utf-8")
result = requests.get(
    "{}/plantuml/svg/{}".format(kroki_host, encoded_diag.decode("utf-8"))
)
result
SVG(result.content)
erd = """[Person] {bgcolor: "#ececfc"}
*name
height
weight
+birth_location_id

[Location] {bgcolor: "#d0e0d0"}
*id
city
state
country

Person *--1 Location
"""
data = {
    "diagram_source": erd,
    "diagram_type": "erd",
    "output_format": "svg",
}
result = requests.post(kroki_host, json=data)
SVG(result.content)<jupyter_output><empty_output><jupyter_text>Kroki (Local JAR)<jupyter_code>import base64
import os
import subprocess
import sys
import zlib

import psutil
import requests
from IPython.display import SVG

kroki_jar = (
    "https://github.com/yuzutech/kroki/releases/download/v0.7.1/kroki-server-0.7.1.jar"
)
kroki_host = "http://localhost:8000"
# download the jar if not already available
kroki_jar_filepath = "{}/{}".format(os.getcwd(), os.path.basename(kroki_jar))
if not os.path.isfile(kroki_jar_filepath):
    result = requests.get(kroki_jar)
    with open(kroki_jar_filepath, "wb") as f:
        f.write(result.content)
# run the jar
kroki_proc = subprocess.Popen(["java", "-jar", kroki_jar_filepath])
print("kroki host process started with pid: {}".format(kroki_proc.pid))
print("kroki pid exists: {}".format(psutil.pid_exists(kroki_proc.pid)))
data = {
    "diagram_source": "Bob -> Alice : hello",
    "diagram_type": "plantuml",
    "output_format": "svg",
}
result = requests.post(kroki_host, json=data)
SVG(result.content)
# kill the kroki subprocess
proc_killed = kroki_proc.kill()
print("kroki pid exists: {}".format(psutil.pid_exists(kroki_proc.pid)))<jupyter_output>kroki pid exists: False
{'fraction_non_alphanumeric': 0.1484520701230884, 'fraction_numerical': 0.008019395747855278, 'mean_word_length': 4.461303462321792, 'pattern_counts': {'":': 6, '<': 44, '<?xml version=': 0, '>': 59, 'https://': 4, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '490160', 'license': 'MIT', 'n_tokens_mistral': 2021, 'n_tokens_neox': 1961, 'n_words': 479, 'path': 'diagrams.ipynb', 'repo_name': 'd33bs/notebook_letterpress', 'size': '5362'}