I appreciate you reaching out with your thoughts on architectural methodology for your "viz" package. It's clear you're aiming for a robust, maintainable design that prioritizes abstraction, decoupling, and user experience—while keeping the entry point simple (e.g., viz.Generate()). Since you're not asking for code, I'll focus on high-level architectural guidance, drawing from the concepts you mentioned (DDD, Clean Architecture, Onion Architecture, Hexagonal Architecture, and Explicit Architecture). I'll tie these into your goal of identifying "universal steps" in the process and decoupling them from specific implementations.
To set the stage, your vision aligns well with these architectures because they all emphasize separating concerns, making the system adaptable, and ensuring the core logic isn't tied to external tools or frameworks. This is especially relevant for your use case, where you want to process Go source code into diagrams via an intermediary representation, while allowing flexibility for different parsing libraries, diagramming tools (e.g., PlantUML, Graphviz), or even custom configurations.
I'll break this down step by step: first, I'll outline the "universal steps" based on your description; then, I'll explain how to apply the architectural concepts to decouple and abstract those steps; and finally, I'll discuss how this promotes a better developer experience for both you (as the package maintainer) and users.
1. Identifying the Universal Steps
From your analogy to lexers, parsers, interpreters, and compilers, it's helpful to think of your process as a pipeline for transforming source code into visualizations. You've already sketched a solid high-level flow:
-
Step 1: Input Handling – Read the Go source code as text input. This is the entry point, where raw data is ingested. Universally, this involves dealing with files, strings, or other inputs, but it shouldn't dictate how the data is processed downstream.
-
Step 2: Parsing and Intermediary Representation – Convert the input into a structured, intermediary form (e.g., an Abstract Syntax Tree or a custom graph representation). This step abstracts the raw code into something meaningful for analysis, like identifying functions, structs, dependencies, etc. The key is that this representation should be generic enough to work with various tools but specific to your domain (code visualization).
-
Step 3: Processing/Transformation – Optionally manipulate the intermediary representation based on configuration (e.g., filtering elements, adding annotations, or adapting it for different diagram types). This is where user customizations come in, like specifying what aspects of the code to visualize.
-
Step 4: Output Generation – Feed the processed representation into a diagramming tool to produce the final output (e.g., a PlantUML file, SVG, or interactive graph). This step handles the "rendering" but should be decoupled so you can swap tools without affecting the earlier steps.