Builds assets/architecture-diagram.png for an sfguide from a small Python script that stays in the repo (assets/architecture_diagram.py), so the diagram can be regenerated after edits.
The template at scripts/architecture_diagram.py is complete and tested. Copy it, then edit only the STYLE, NODES, and EDGES data and the figure limits. Do not rewrite the layout code.
What the template guarantees
- Square-cornered boxes sized to their text, with equal padding (
PAD_PX) on all four sides; bold title over a smaller subtitle. - Arrows clipped to box borders;
radgives a curved edge (use it to route around boxes). - Edge labels rotated to the arrow's direction, never upside down, placed beside the line with the same visible gap on both sides (descender-corrected).
- Labels keep
LINE_CLEAR_PXfrom every other line andLABEL_CLEAR_PXfrom boxes and other labels. If no clear spot exists, the script printswarning: label ... could not be placed cleanly. - Legend centered below the diagram, listing only object types that appear.
Workflow
- Read the guide. Find the
.mdunder the guide folder. List every Snowflake object the guide creates (tables, warehouses, procedures, tasks, services, Streamlit apps, stages, dynamic tables, agents, and so on) and every interaction between them (writes, reads, calls, schedules, polls). Note the SQL verb or action for each interaction; it becomes the edge label. - Confirm the inventory with the user in a short list (objects and edges) when the guide is ambiguous. Skip if it is clear.
- Copy the template to
<guide>/assets/architecture_diagram.py. - Fill the data:
STYLE: one entry per object type,(fill, edge)colors. Reuse the existing palette; add types with a light fill and darker edge.NODES:key: (x, y, type, TITLE, "subtitle"). Use the real object names in caps as titles, and a short role as subtitle (use\nfor two lines). Lay out on a grid, left to right in data-flow order, about 5 units between columns and 2.5 between rows.EDGES:(src, dst, "label", color, dashed, rad). Color the edge with the edge color of the type doing the action. Dashed for control/config/fallback flows, solid for data flow. Keep labels to 1-3 words; use\nfor two lines.- Set
figsize,xlim,ylimso the grid fits with a small margin.
- Render:
cd <guide>/assets && python3 architecture_diagram.py. Read the PNG to check it. - Fix problems by moving data, not code:
- Warning printed, or labels crowded: move nodes apart, or give a crossing edge a
rad(0.15 to 0.3) to bend it away. - Edge crosses a box: add
rador move one node. - Too much whitespace: tighten
xlim/ylim. - Wanting more breathing room: raise
LABEL_GAP_PX(all line gaps follow it) orPAD_PX.
- Warning printed, or labels crowded: move nodes apart, or give a crossing edge a
- Wire it into the guide: reference
assets/architecture-diagram.pngwith alt text, and add an HTML comment next to the image noting that it is generated byarchitecture_diagram.py. Remove any old.excalidrawsource withgit rm.
Examples
Prompt: Create an architecture diagram for the sfguide in this folder.
Output: assets/architecture_diagram.py with NODES and EDGES filled from the guide, plus the rendered assets/architecture-diagram.png. A minimal data block:
NODES = {
"sp": (2.0, 4.0, "Stored Procedure", "SP_LOAD", "Writes each tick"),
"orders": (7.0, 4.0, "Table", "ORDERS", "Latest snapshot"),
"dash": (12.0, 4.0, "Streamlit in Snowflake", "DASHBOARD", "Live charts"),
}
EDGES = [
("sp", "orders", "INSERT\nOVERWRITE", "#C2185B", False, 0.0),
("orders", "dash", "SELECT", "#0097A7", False, 0.0),
]
Notes
- Requires only
matplotlib(seepyproject.toml). If it is not installed, runuv run --with matplotlib python architecture_diagram.py. Do not add dependencies. - Keep
LINE_CLEAR_PXequal toLABEL_GAP_PXso every label has the same margin from every line. - Do not commit or push without asking the user.