Created
November 15, 2023 00:52
-
-
Save smatthewenglish/caa2e9c55848639d7e51f9b2d7864d85 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from matplotlib import pyplot as plt | |
import matplotlib | |
from matplotlib.patches import Rectangle, Arrow | |
import matplotlib.lines as mlines | |
# UML Sequence Diagram for NFT Transaction Broadcast System | |
# Configurations | |
fig, ax = plt.subplots(figsize=(12, 8)) | |
ax.set_xlim(0, 10) | |
ax.set_ylim(0, 12) | |
plt.axis('off') | |
matplotlib.rcParams['text.color'] = 'blue' | |
# Lifelines | |
plt.plot([2, 2], [0, 12], color='black', linestyle='dashed') | |
plt.plot([4, 4], [0, 12], color='black', linestyle='dashed') | |
plt.plot([6, 6], [0, 12], color='black', linestyle='dashed') | |
plt.plot([8, 8], [0, 12], color='black', linestyle='dashed') | |
# Lifeline Labels | |
plt.text(2, 12.1, 'User', horizontalalignment='center') | |
plt.text(4, 12.1, 'Django App\n(Transaction Broadcaster)', horizontalalignment='center') | |
plt.text(6, 12.1, 'Celery Task', horizontalalignment='center') | |
plt.text(8, 12.1, 'Blockchain\n(Infura/Alchemy)', horizontalalignment='center') | |
# Process Steps | |
# 1. User initiates transaction | |
ax.add_patch(Rectangle((1.5, 10), 1, 0.6, fill=True, color='lightblue', edgecolor='black')) | |
plt.text(2, 10.3, 'Initiate\nTransaction', horizontalalignment='center', verticalalignment='center') | |
# 2. Django App receives transaction request | |
ax.add_patch(Rectangle((3.5, 9), 1, 0.6, fill=True, color='lightblue', edgecolor='black')) | |
plt.text(4, 9.3, 'Receive\nTransaction Request', horizontalalignment='center', verticalalignment='center') | |
# 3. Celery Task starts | |
ax.add_patch(Rectangle((5.5, 7.5), 1, 0.6, fill=True, color='lightblue', edgecolor='black')) | |
plt.text(6, 7.8, 'Start Celery Task\nPoll Blockchain', horizontalalignment='center', verticalalignment='center') | |
# 4. Blockchain checks | |
ax.add_patch(Rectangle((7.5, 6), 1, 0.6, fill=True, color='lightblue', edgecolor='black')) | |
plt.text(8, 6.3, 'Check\nConfirmation', horizontalalignment='center', verticalalignment='center') | |
# 5. Celery Task timeout/rebroadcast | |
ax.add_patch(Rectangle((5.5, 4.5), 1, 0.6, fill=True, color='lightblue', edgecolor='black')) | |
plt.text(6, 4.8, 'Timeout &\nRebroadcast', horizontalalignment='center', verticalalignment='center') | |
# 6. Transaction confirmed | |
ax.add_patch(Rectangle((7.5, 3), 1, 0.6, fill=True, color='lightblue', edgecolor='black')) | |
plt.text(8, 3.3, 'Confirm\nTransaction', horizontalalignment='center', verticalalignment='center') | |
# Arrows | |
# User to Django App | |
ax.add_patch(Arrow(2, 10, 1.9, -0.9, width=0.1, color='black')) | |
# Django App to Celery Task | |
ax.add_patch(Arrow(4, 9, 1.9, -1.4, width=0.1, color='black')) | |
# Celery Task to Blockchain | |
ax.add_patch(Arrow(6, 7.5, 1.9, -1.4, width=0.1, color='black')) | |
# Blockchain response | |
ax.add_patch(Arrow(8, 6, -1.9, -1.4, width=0.1, color='black')) | |
# Celery Task timeout/rebroadcast | |
ax.add_patch(Arrow(6, 4.5, 1.9, -1.4, width=0.1, color='black')) | |
# Blockchain final confirmation | |
ax.add_patch(Arrow(8, 3, -1.9, -2.4, width=0.1, color='black')) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment