Skip to content

refactor: move the SVG renderer out of the domain into a driven adapter - #117

Merged
emaarco merged 1 commit into
mainfrom
emaarco/refactor-move-the-svg-renderer-out-of-the-domain
Oct 28, 2026
Merged

emaarco merged 1 commit into
mainfrom
emaarco/refactor-move-the-svg-renderer-out-of-the-domain

Conversation

@emaarco

@emaarco emaarco commented Oct 28, 2026

Copy link
Copy Markdown
Member

Summary

The SVG renderer only draws SVG, yet it lived in src/domain/views/render/, and two file adapters (FileImageWriter, PngRenderer) called it directly. This PR makes it a browser-safe driven adapter behind an outbound port, with byte-identical output.

  • New port and adapter: application/port/out/RenderDiagramPort is implemented by adapters/out/render/SvgRenderer. The renderer is grouped by step: crop/ (which part of the plane), paint/ (shapes, connections, labels), compose/ (frame, scale, badges, tiles); DocRenderer and types.ts stay on top. SvgRenderer carries a comment on why this is custom code instead of bpmn-js.
  • In-memory layout moves to the domain: domain/views/DrawableDoc parses the XML and lays out a file without a diagram (its own problems and the two notes, word for word). RenderSvgService and RenderDiagramService call it, then the port.
  • Image writing gets the finished drawing: WriteImagePort.ImageRequest carries drawn: RenderResult instead of XML and options, so out/files no longer imports the renderer. PngRenderer.render(drawn) only rasterises; the RENDER_MAX_SIZE default moved to renderPng in node.ts (the CLI always passes maxSize).
  • Public types: RenderOptions, RenderResult, RenderProblem, RenderTile, RenderHighlight, RENDER_MAX_SIZE, MIN_LABEL_SCALE and HALO_COLORS now live in port/in/RenderSvgUseCase.ts. The exports of index.ts and node.ts keep their names and signatures.
  • Architecture test: out/render is a registered adapter; new checks that no domain file contains <svg / <g and that adapters/out/render imports no node:*. The three render constants left the list of values re-exported from the domain.
  • Docs: CONTRIBUTING.md layout table, the diagram in docs/architecture.md, test paths in docs/testing.md. The render tests moved to test/adapters/out/render/.

Verification:

  • vitest run: 2395 passed, 246 skipped.
  • Byte-identical output: 36 outputs of bpmn render (SVG, PNG and the --json reports) saved before the change and compared with cmp after it, covering several planes, --problems, --tiles, --highlight, files without a diagram and tools/scenarios. No difference.
  • npm run build, biome lint, knip, knip --production --exclude dependencies, jscpd and tools/iso/check.mjs pass. The bench regression gate and the fuzz run of npm run gate were not run locally.
  • No command, option or output changed, so guide.ts needs no update.

Checklist

  • npm run typecheck passes
  • npm run gate passes
  • src/report/guide.ts and the matching page in docs/ are updated (only if a command, option or output changed)
  • PR title is a changelog-worthy Conventional-Commit summary

Linked issue

Closes #113

The renderer now lives in adapters/out/render behind a RenderDiagramPort,
grouped into crop/, paint/ and compose/. The in-memory layout of a file
without a diagram moves into the domain as DrawableDoc, and the image
writer receives the finished drawing instead of XML. The output stays
byte-identical.

Closes #113
@emaarco
emaarco enabled auto-merge (squash) October 28, 2026 08:13
@emaarco
emaarco merged commit 5439397 into main Oct 28, 2026
8 checks passed
@emaarco
emaarco deleted the emaarco/refactor-move-the-svg-renderer-out-of-the-domain branch October 28, 2026 08:19
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.

[Refactor]: Move the SVG renderer out of the domain into an out-adapter behind a port

1 participant