$ show pistazie/cdk-dia
The cdk-dia tool is a CLI utility that generates visual diagrams from AWS CDK applications. It reads the synthesized cloud assembly (tree.json) produced by `cdk synth` and constructs a hierarchical tree of CDK constructs. This tree is then transformed into a diagram representation, where nodes represent constructs (annotated with AWS service icons and labels) and edges represent relationships resolved via CloudFormation intrinsic functions. The tool supports customization via CDK construct decorators (e.g., to collapse or ignore nodes) and can output diagrams in two formats: static PNGs via Graphviz or interactive HTML via Cytoscape. The architecture is modular, separating concerns into CDK tree parsing (`src/cdk/`), diagram generation (`src/diagram/`), and rendering (`src/render/`). The diagram generation process involves recursively building a component tree, resolving edges, applying customizations, and post-processing (collapsing/ignoring nodes). Renderers are selected via a strategy pattern, allowing easy extension to new output formats. The tool demonstrates strong encapsulation in its core data structures (Tree and Node classes) and link management (ComponentLinks class), which are largely independent of CDK-specific logic and could be reused in other tree-based applications. Maintenance appears active, with a recent commit history and ongoing issue activity. Dependencies are up-to-date (no Dependabot alerts), and the tool aligns with current CDK v2 practices. Technical drift is low, as the codebase avoids deprecated APIs and maintains compatibility with modern TypeScript and Node.js ecosystems. The project includes comprehensive snapshot tests to ensure correctness across various CDK infrastructure patterns, from simple queue-topic subscriptions to complex CI/CD pipelines.
The LLM identified 2 files worth highlighting for reuse:
Defines generic Tree and Node classes for representing hierarchical structures. The Tree.fromObject method skillfully reconstructs a tree from a flat list of nodes with path-based relationships (as in CDK's tree.json). This isolated data structure has no internal dependencies beyond itself and could be extracted for any tree modeling task.
Manages bidirectional links between diagram components to ensure referential integrity. The ComponentLinks class provides methods to add links and retrieve incoming/outgoing connections for any component. With only two internal dependencies (Link and RootComponent, which are simple data classes), this pattern is easily reusable in any graph-based application requiring consistent forward and reverse edge tracking.