How seamia/protodot works
Project Type and Purpose
• protodot is a command‐line utility (written in Go) that
• parses Protocol Buffer (.proto) files,
• builds an internal representation (AST),
• renders that model via Go templates into Graphviz .dot format,
File Structure
• Entry point: main.go (parses CLI flags, orchestrates flow)
• Configuration: config.go + config.json (load user options, Graphviz paths)
• Parser & Model: proto.go, payload.go, maybe.go (read & represent .proto AST)
• Graph Builder: graphviz.go, table.go, support.go (construct nodes/edges)
• Template Engine:
• plus/templates.go and templates/*.tmpl (customizable output templates)
• staticAssets.go + assets (default template set)
• I/O & Utilities: io.go, functions.go, debug.go (file read/write, logging)
• Output & Execution: calls out to Graphviz “dot” tool if configured
• Distribution: binaries/ (prebuilt executables for multiple platforms, including WebAssembly)
Gather Insights from the README
• There is a clear data‐pipeline:
[CLI invocation] → [config load] → [proto parse] → [AST filter/select] → [DOT render via templates] → [write .dot] → [optional Graphviz invocation] → [.svg/.png]
• The tool is highly configurable via a JSON file and template files.
Main Components & Their Interactions
a. CLI Interface (main.go)
• Parses flags (-src, -config, -select, etc.)
• Kicks off the pipeline
b. Config Loader (config.go)
• Reads config.json—Graphviz locations, output options
• Feeds settings to downstream modules
c. Proto Parser & Model Builder (proto.go, payload.go)
• Uses Go’s I/O routines to parse .proto
• Constructs an internal AST/data model (messages, enums, services)
d. Selector/Filter (maybe.go)
• Applies -select logic (all, imports, specific elements)
e. Graph Model Builder (graphviz.go, table.go, support.go)
• Converts filtered AST into Graphviz primitives (nodes, edges)
f. Template Engine (plus/templates.go + templates/*.tmpl)
• Renders nodes & edges into .dot syntax via text templates
• Users can override templates in templates/ dir or via -install
g. Output Manager & Graphviz Invoker (io.go, staticAssets.go)
• Writes .dot output
• If enabled, calls external dot binary to generate .svg/.png
h. Static Assets & Distribution (assets, binaries/)
• Default templates shipped as assets
• Multi-platform binaries, including WASM for online demo
Architectural Patterns & Design Principles
• Modular Package Layout: each concern has its own Go file/package
• Pipeline/Chain of Responsibility: data flows through distinct stages
• Template‐Driven Output: separation of logic vs. presentation
• Extensibility: users supply custom templates and configuration
• Cross‐Platform Distribution: prebuilt binaries for various OS/architectures