Building Block View
Level 1: Overall System
Motivation
At the centre sits a small core engine — model (the JSONC world), drawio (the XML world), and sync as the mediator between them, so changes to one format never leak into the other package. Around this core, a set of feature packages add analysis, evolution, interop, and styling, and a thin CLI layer (cmd/bausteinsicht) wires commands to them. A second binary (cmd/bausteinsicht-lsp) reuses the same library code to serve editors over the Language Server Protocol.
In total the system is two binaries over ~23 production packages (plus two test-only helper packages). The complete map is in the Package Map below; the core engine is decomposed further in the Level 2 sections.
Building Blocks (core)
| Element | Kind | Technology | Description |
|---|---|---|---|
CLI |
container |
Go / Cobra |
Command-line interface providing validate, sync, export, and watch commands |
draw.io |
container |
Go / etree |
draw.io XML document handling — elements, connectors, templates, and labels |
Export |
container |
Go |
Diagram export to PNG and SVG formats via draw.io CLI |
Model |
container |
Go |
JSONC architecture model management — loading, validation, and mutation |
Sync Engine |
container |
Go |
Bidirectional synchronization engine between JSONC model and draw.io diagrams |
Watcher |
container |
Go / fsnotify |
File system monitoring for automatic sync on model or diagram changes |
Developer |
actor |
Developer using the Bausteinsicht CLI to manage architecture models |
|
draw.io App |
external_system |
draw.io desktop or web application for visual diagram editing |
|
IDE |
external_system |
IDE with JSON Schema support for JSONC editing with autocompletion |
Important Interfaces
| Interface | Description |
|---|---|
|
Parses a JSONC file into the Go model struct. Validates against schema constraints. |
|
Writes the model back to JSONC, preserving comments where possible. |
|
Parses a draw.io XML file into a manipulable document structure. |
|
Writes the document back to uncompressed draw.io XML. |
|
Reads a template file and extracts styles keyed by |
|
Executes one full bidirectional sync cycle — a pure function with no I/O. |
|
Reads the |
|
Writes the updated sync state after successful sync. |
Package Map (all building blocks)
Every production package, grouped by role. Each row is a Level-1 building block: its responsibility and its source location. The core three (model, drawio, sync) are decomposed further in the Level 2 sections below.
| Package | Responsibility | Source |
|---|---|---|
|
DSL types, JSONC loader (comment-preserving patch + full save), validation, ID/wildcard resolution |
|
|
Read/write draw.io XML: document, element, connector, template, HTML label |
|
|
Bidirectional sync: diff, forward/reverse apply, conflict resolution, state, layout, badges, metadata |
|
|
fsnotify file watcher driving |
|
| Package | Responsibility | Source |
|---|---|---|
|
Evaluate architectural rules from the model ( |
|
|
Relationship-graph analysis: cycles, dependency depth, centrality ( |
|
|
Architecture health score across weighted categories ( |
|
|
Detect unused/forgotten elements, using git history ( |
|
|
Full-text search over elements, relationships, views ( |
|
|
Group, merge, and validate multiple models together as one workspace ( |
|
| Package | Responsibility | Source |
|---|---|---|
|
Versioned model captures, semantically diffable ( |
|
|
As-is vs. to-be model comparison ( |
|
|
Architecture changelog between two git points ( |
|
| Package | Responsibility | Source |
|---|---|---|
|
Hierarchical auto-layout engine ( |
|
|
Generate a draw.io template from the specification ( |
|
|
Apply/remove metric heatmap overlays on diagrams ( |
|
| Package | Responsibility | Source |
|---|---|---|
|
Import models from Structurizr DSL and LikeC4 ( |
|
|
Export the model as Structurizr DSL |
|
|
Render views as text diagrams: C4-PlantUML, Mermaid, DOT, D2, HTML, sequence ( |
|
|
Render element attributes as AsciiDoc/Markdown tables ( |
|
|
Export diagram pages to PNG/SVG via headless draw.io ( |
|
|
Generate the JSON Schema from the Go model types ( |
|
| Package | Responsibility | Source |
|---|---|---|
|
Language Server Protocol server: diagnostics, code lenses; backs the |
|
|
Note
|
internal/chaos (fault-injection helper) and internal/benchmarks are test-only utilities, not production building blocks.
|
Level 2: Sync Engine
The sync engine is the most complex package. It decomposes into five sub-components.
Building Blocks
| Element | Kind | Technology | Description |
|---|---|---|---|
CLI |
container |
Go / Cobra |
Command-line interface providing validate, sync, export, and watch commands |
draw.io |
container |
Go / etree |
draw.io XML document handling — elements, connectors, templates, and labels |
Model |
container |
Go |
JSONC architecture model management — loading, validation, and mutation |
Conflict |
component |
Go |
Conflict detection and resolution when both model and diagram changed |
Diff |
component |
Go |
Three-way change detection comparing model, diagram, and last-sync state |
Engine |
component |
Go |
Main sync orchestrator coordinating diff, forward, reverse, and conflict resolution |
Forward Sync |
component |
Go |
Applies model changes to draw.io diagrams (model → drawio) |
Reverse Sync |
component |
Go |
Applies draw.io changes back to the JSONC model (drawio → model) |
State |
component |
Go |
Sync state persistence using SHA256 hashes for change detection |
Watcher |
container |
Go / fsnotify |
File system monitoring for automatic sync on model or diagram changes |
Level 2: DrawIO Package
The draw.io package handles all mxGraph XML concerns.
Building Blocks
| Element | Kind | Technology | Description |
|---|---|---|---|
Connector |
component |
Go |
Connector/relationship CRUD for edges between elements |
Document |
component |
Go |
XML parsing, page management, and file I/O for .drawio files |
Element |
component |
Go |
Element CRUD operations on mxGraphModel objects and mxCells |
Label |
component |
Go |
HTML label generation and parsing for element display text |
Template |
component |
Go |
Template loading and style lookup from .drawio template files |
Export |
container |
Go |
Diagram export to PNG and SVG formats via draw.io CLI |
Sync Engine |
container |
Go |
Bidirectional synchronization engine between JSONC model and draw.io diagrams |
draw.io App |
external_system |
draw.io desktop or web application for visual diagram editing |
Level 2: Model Package
Building Blocks
| Element | Kind | Technology | Description |
|---|---|---|---|
CLI |
container |
Go / Cobra |
Command-line interface providing validate, sync, export, and watch commands |
Loader |
component |
Go |
JSONC read/write with comment stripping and trailing comma handling |
Patch |
component |
Go |
Comment-preserving JSONC mutations for reverse sync |
Resolve |
component |
Go |
Dot-notation element resolution and wildcard pattern matching |
Types |
component |
Go |
Core struct definitions for elements, relationships, views, and specification |
Validate |
component |
Go |
Model validation rules for elements, relationships, and views |
Sync Engine |
container |
Go |
Bidirectional synchronization engine between JSONC model and draw.io diagrams |
IDE |
external_system |
IDE with JSON Schema support for JSONC editing with autocompletion |
Go Package Layout
The directory structure maps directly to the building blocks above (packages, not every file):
bausteinsicht/ ├── cmd/ │ ├── bausteinsicht/ // main CLI — one file per command (init, sync, add, repl, export*, …) │ └── bausteinsicht-lsp/ // Language Server Protocol binary ├── internal/ │ ├── model/ drawio/ sync/ watcher/ // core engine │ ├── constraints/ graph/ health/ stale/ search/ // analysis │ ├── snapshot/ diff/ changelog/ // evolution │ ├── layout/ template/ overlay/ // layout & styling │ ├── importer/ exporter/ diagram/ table/ export/ schema/ // interop & export │ ├── lsp/ // IDE integration │ └── chaos/ benchmarks/ // test-only helpers ├── go.mod └── go.sum
Conventions
-
cmd/bausteinsicht/contains only CLI wiring — no business logic; all logic lives ininternal/packages (so the LSP binary can reuse it). -
internal/ensures packages cannot be imported by external code. -
Each package has a clear single responsibility (see the Package Map).
-
Cross-package dependencies flow inward toward the core:
cmd → feature packages → sync → model + drawio. -
The
modelanddrawiopackages never depend on each other —syncis the only mediator. -
chaosandbenchmarksare imported only from_test.gofiles, so production code never depends on them.
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.