Skip to content

plugins/model: stop Generate from re-running eval.RunDSL and duplicating views - #1149

Open
raphael wants to merge 2 commits into
mainfrom
goa-plugin-no-reeval
Open

raphael wants to merge 2 commits into
mainfrom
goa-plugin-no-reeval

Conversation

@raphael

@raphael raphael commented Oct 30, 2026 •

Copy link
Copy Markdown
Member

The model Goa plugin (goa.design/model/plugins/model) generates gen/structurizr/model.json, the Structurizr C4 workspace JSON for a Goa design that imports goa.design/model/dsl. Today, running goa gen on any design with a C4 model writes every view twice into gen/structurizr/model.json, and in designs with explicit element relationships it also duplicates model relationships and view animation steps.

goa gen already runs eval.RunDSL() once before invoking registered codegen plugins. plugin.Generate in plugins/model/generate.go called eval.RunDSL() a second time, re-executing every top-level DSL closure and appending a second copy of every view and relationship onto expr.Root. For example, examples/basic emitted two SystemContext views and two Container View views, and examples/big_bank_plc emitted 25 duplicate relationships and repeated animation steps. Generate also deleted any pre-existing gen/structurizr/model.json on disk before returning its codegen.File, even though Goa's renderer already overwrites generated files when writing output.

plugin.Generate now reads the already-evaluated expr.Root directly without calling eval.RunDSL() again or removing files from disk prior to rendering.

TestGenerateDescribesTheEvaluatedDesignOnce runs a single eval.RunDSL() pass followed by Generate on examples/big_bank_plc and verifies that every view key and every identified model element appears once in the rendered model.json (which failed previously with duplicate SystemLandscape views and duplicate relationship IDs). Regenerating all ten repository examples produces identical model.json output with the duplicate views, relationships, and animation steps removed.

The model plugin's Generate ran eval.RunDSL a second time and deleted
gen/structurizr/model.json before returning the file. goa gen evaluates
the design before it calls plugins, so the second run executed every DSL
function again: the generated workspace listed each view twice, and in
larger designs (big_bank_plc) repeated 25 model relationships and
recorded view animations that included the repeats. Rendering the
returned file already replaces any previous one, so deleting it first
was unnecessary and made planning files touch the file system.

Generate now reads the evaluated model only. On every example design the
new output equals the old output with its repeated entries removed. A
test checks that big_bank_plc lists every view and identified element
once; it fails on the previous code.
@raphael raphael changed the title Stop the model plugin from listing views and relationships twice plugins/model: stop Generate from re-running eval.RunDSL and duplicating views Oct 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant