$ show mingrammer/diagrams
This repository provides 'Diagrams', a Python library that lets you define cloud system architecture diagrams as Python code. It renders diagrams using Graphviz, supporting a wide range of cloud providers (AWS, Azure, GCP, Kubernetes, etc.) through auto-generated node classes. The library includes a CLI tool to execute diagram scripts and a web-based playground (React/TypeScript) that runs the library in-browser via Pyodide, allowing interactive editing and export. The architecture is a library with a CLI entry point, plus a separate SPA playground. Key entry points are the `diagrams` CLI command and the `Diagram`/`Node` classes. External dependencies include Graphviz (system binary), Jinja2, and for the playground: Pyodide, @hpcc-js/wasm-graphviz, React, CodeMirror. The codebase is well-structured with a code generation pipeline for provider nodes, comprehensive testing, and a polished user experience.
The LLM identified 5 files worth highlighting for reuse:
Generic debounce function with leading/trailing options and cancellation. Well-tested and isolated, can be reused in any TypeScript project needing debounced execution.
Pure functions for zoom/pan calculations with clamp and fit-to-screen. Reusable for any infinite canvas or image viewer.
Encodes and decodes diagram code to/from URL hash using pako deflate and base64url. Self-contained and testable, applicable to any web app needing shareable state.
Handles diagram export to PNG/SVG/JPEG with icon inlining and download. The pattern of converting SVG to raster with embedded images is reusable for any diagramming tool.
Provides a base class for defining custom nodes with user-provided icons. Demonstrates a clean extensibility pattern that can be adapted for other icon-based node libraries.