Diagram Bridge Service¶
Object diagrams, agent diagrams, and other consumers often need structural information defined in class diagrams. The diagram bridge service provides a shared channel for exchanging that data without tightly coupling diagram implementations.
Location¶
packages/editor/src/main/services/diagram-bridge/diagram-bridge-service.ts
exports:
The
DiagramBridgeServiceclass (implementation).The singleton
diagramBridgeinstance used across the editor and webapp.Type definitions (
IClassDiagramData,IClassInfo,IAssociationInfo).
Data flow¶
When a class diagram becomes the active diagram, the webapp (see
packages/webapp/src/main/store/project/projectSlice.ts) pushes the current model intodiagramBridge.setClassDiagramData.Consumers (object diagrams, agent diagrams, validation routines) query the bridge for classes, attributes, associations, or related classes whenever they need to populate dropdowns or validate references.
Data is cached in memory and persisted in
localStorageunder the keybesser-class-diagram-bridge-datato survive reloads.
Key capabilities¶
setClassDiagramData(data)Stores the raw
UMLModelsnapshot (elements + relationships) for later queries. Automatically persists tolocalStorageas a backup.getClassDiagramData()Returns the latest stored data or
nullwhen none is available. Falls back tolocalStorageif memory has been cleared.getAvailableClasses()Produces a collection of
IClassInfoobjects enriched with inherited attributes. The service walksClassInheritancerelationships so object diagrams can offer inherited attributes in their forms.getAvailableAssociations(sourceId, targetId)Lists associations (excluding inheritance/realisation links) that connect the two classes, including associations inherited through parent classes.
getRelatedClasses(classId)Returns classes reachable via non-inheritance relationships plus classes that inherit from, or are inherited by, those related classes. Useful when building contextual dropdowns.
getClassHierarchy(classId)andgetClassById(classId)Debug-oriented helpers that expose the inheritance chain and allow verifying that classes are correctly registered.
getStateMachineDiagrams()/setStateMachineDiagrams(data)Store and retrieve state machine diagram data for cross-diagram references (e.g., when class diagram methods reference state machine implementations).
getQuantumCircuitDiagrams()/setQuantumCircuitDiagrams(data)Store and retrieve quantum circuit diagram data for cross-diagram references.
clearDiagramData()/hasClassDiagramData()Maintenance utilities used when switching projects or flushing cached data.
Usage tips¶
Always call
diagramBridge.setClassDiagramDataafter persisting a class diagram so other diagrams stay in sync. The project slice already handles this when switching diagram types, but the same rule applies in custom integrations.Guard calls to
getAvailableClassesand related helpers withhasClassDiagramData()to avoid dereferencingnullwhen the user has not created a class diagram yet.The bridge stores raw element objects. Avoid mutating objects returned by the helpers; clone them first if you need to enrich the data.