Skip to content

feat(web-editor): v4 React Flow wire format for the editor backend - #628

Open
ArmenSl wants to merge 272 commits into
developmentfrom
feature/migration-react-flow-sync
Open

ArmenSl wants to merge 272 commits into
developmentfrom
feature/migration-react-flow-sync

Conversation

@ArmenSl

@ArmenSl ArmenSl commented Oct 13, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

This is the backend half of the move to the React Flow editor. The frontend PR is BESSER-PEARL/BESSER-Web-Modeling-Editor#214.

  • Converters speak v4 only. json_to_buml and buml_to_json now read and write the v4 {nodes, edges} editor format. That covers Class, Object, State Machine, Agent (the canvas plus its components map), User, NN, BPMN (agentic tasks and governance gateways), Component and Deployment, plus the project converter.
    • GUI and Quantum keep their own formats.
    • A legacy v3 payload (elements/relationships) is rejected with HTTP 400 and a clear message. Before, it was silently converted as an empty model.
  • Other readers of editor JSON now use nodes or the converters: routers, deploy, spec-driven model assembly and modify_run, the agent simulator, and KG/image import.
  • Docs. docs/source/migrations/uml-v4-shape.md is the shared wire contract. web_editor_backend.rst and CLAUDE.md are updated.
  • Fixes from the final review:
    • Nested v3 models in personalizationMapping[i].user_profile / .agent_model and in config.userProfileModel are now rejected. Before, they produced a ZIP built from an empty model (50ac6f1d).
    • Agent diagrams with no states. One holding only intents and LLMs is no longer dropped from projects (3b5a3d3a).
    • Object variable names. The code builder now runs object names through safe_var_name, so a name with a space or colon no longer breaks the generated Python. The v4 object fixture now uses the instance name (83c652c3).
    • Stray tooling. Removed the frontend scripts and v3 JSON under tests/corpus/, which nothing ran (ed6fdee8).
    • Default agent colour. It is now var(--besser-primary-contrast); the editor no longer defines the old Apollon token (248c7718).
  • Submodule. The frontend now points at 2f27ba0e, the head of Error message for incorrect BUML model when importing #214 (fb6dae5a).

Verification

Check Result
pytest tests/ -q --tb=short --ignore=tests/generators/nn 6186 passed, 97 skipped, 2 xfailed. One failure, test_sql_generator[mssql], comes from libodbc.so.2 missing in the test container; it fails the same way on development.
CI ruff command passes
python docs/check_docs.py --offline 0 warnings

test_shell_session::test_an_idle_session_is_torn_down… failed once while the machine was heavily loaded. It then passed 5/5 on this branch and 3/3 on development. This branch doesn't touch besser/spec_driven_agent.

A round trip of a project containing all 8 UML diagram types (JSON → B-UML → code → JSON → B-UML → code) produced the same code both times. Every node and edge type the backend emits is registered in the editor.

Known follow-ups (not in this PR)

  • The Docker Compose generator and /github/deploy-webapp still require canvas nodes on agent diagrams, so a components-only agent is skipped there.
  • besser/BUML/metamodel/object/object.py _create_link names links "{src}_to_{target}", which fails when a linked object's name contains a space.
  • Model id is not included in the *_to_json output. The editor falls back to a random id, so nothing breaks.

Merge order

Merge BESSER-PEARL/BESSER-Web-Modeling-Editor#214 into develop and this PR into development together. Each side reads only v4.

claude added 30 commits May 8, 2026 11:49
SA-7a preps the library for Phase 7's webapp cutover:
- Re-exports 6 OLD-ONLY symbols from lib/index.tsx (diagramBridge,
  settingsService, ClassNotation, multiplicity helpers, userMetaModel)
- Adds deprecation aliases nextRender → ready and
  unsubscribeFromModelChange → unsubscribe so 7 webapp call sites need
  no edit
- Renames @tumaet/apollon v4.3.0 → @besser/wme v3.0.0

Workspace conflict: both @besser/wme claimants (editor v2.5.0 and
library v3.0.0) caused npm install to fail with EDUPLICATEWORKSPACE.
SA-7a removed packages/editor from the root package.json workspaces
array. The editor SOURCE is intact on disk for reference / diffing
(per user direction); only npm-workspaces management is removed.
SA-7b will flip the webapp's vite + tsconfig alias next.

0 TS errors. 32/32 round-trip tests still pass.

Bundle now contains 1 commit (SA-7a) on top of remote tip (0e51317 =
SA-2.2). Apply locally with the recipe in commit 13d2991.

https://claude.ai/code/session_01NJkiJA8SPNGRtYeYpkPnrF
SA-7b webapp cutover landed: alias flipped, model-shape rewritten,
storage migration in place, templates upgraded to v4. Webapp build
passes (20.83s). 0 new TS errors / lint errors. Tests 171/172
(1 pre-existing failure unrelated to migration).

Pragmatic deviation: ~30 small/medium files got direct v3→v4 site
rewrites; UMLModelingService, scaffoldObjectsFromClasses, and the
~110 assistant modifier sites use boundary-conversion seams via the
lib's convertV4ToV3* / migrate*V3ToV4 instead of full v4-native
internals. Backend remains v4-native per SA-6.1 (no contradiction at
the wire layer); only the webapp's internal data-walking helpers
keep operating on v3 shapes after a runtime conversion.

If we want the webapp internals to be truly v4-native (matching the
SA-6.1 backend rule), a follow-up SA-7b.1 can finish that rewrite.
For now: webapp + library + backend all interop cleanly via v4 wire.

Bundle now contains 2 commits (SA-7a, SA-7b) on top of remote tip
(0e51317 = SA-2.2). Apply locally with the recipe in commit 13d2991.

https://claude.ai/code/session_01NJkiJA8SPNGRtYeYpkPnrF
SA-PARITY-FINAL-3. Read-only audit of StateMachineDiagram across the
old packages/editor fork and the new packages/library lib at submodule
HEAD 771c064. Covers the 11 element types, 1 edge type, per-element
data fields, inspector form parity, constraints, visual shape, and
the round-trip test (3 cases).

Verdict: PASS with two MEDIUM and one LOW inspector-layer gaps.

  1. StateMachineDiagramEdgeEditPanel lacks flip + color editor
     (MEDIUM — both present in v3 and back-filled into ClassEdge /
     AgentDiagramEdge under SA-2.2 #26).
  2. StateMergeNode uses the shared StateLabelEditPanel and drops
     v3's decisions inline editor (MEDIUM — per-outgoing-transition
     rename surface; round-trip unaffected).
  3. Marker types (Initial / Final / Fork / ForkHorizontal) expose a
     name field despite v3's updatable:false gating (LOW — cosmetic;
     name is not painted on the canvas).

No data-shape gaps, no missing types, no constraint regressions.
SA-PARITY-FINAL-6 found that the backend's NN converter wrote/read the
bare `dimension` slug while the frontend qualifies it as
`pooling.dimension` / `batch_normalization.dimension` to disambiguate
the two layer kinds. Result: v4-authored Pooling and BatchNormalization
layers failed backend mandatory-field validation. SA-6.1's prior claim
of "matching backend disambiguation" did not match the code on this
branch.

Changes (mirrors frontend qualifySlug behavior):
- json_to_buml/nn_diagram_processor.py: get_element_attribute now tries
  `<layer_kind>.<slug>` first when the slug is in _COLLIDING_SLUGS,
  falling back to the bare slug for back-compat.
- buml_to_json/nn_diagram_converter.py: _attrs_dict() takes layer_kind;
  emits the qualified key for colliding slugs on Pooling /
  BatchNormalization. Other layer kinds unaffected.
- 4 NN fixture JSONs updated in-place to use the qualified slug.
- 2 test_converter_roundtrip.py cases updated to assert the qualified
  key on input + output (with comments explaining the wire spec).

407 passed / 5 skipped — same baseline as before. The 1 failing test
that surfaced this bug now passes.

https://claude.ai/code/session_01NJkiJA8SPNGRtYeYpkPnrF
Per-diagram and per-feature coverage map across the BESSER WME stack
(parent backend tests + frontend submodule vitest + Playwright e2e).

Headline numbers
- Backend: 412 tests across 13 files; 109 of them exercise NNDiagram,
  zero exercise UserDiagram, and only 5 (`test_v4_round_trip.py`) cover
  the v4 wire shape across the 5-of-6 diagrams that have a fixture.
- Frontend: 794 vitest `it()` cases across 33 files (28 round-trip + 594
  library unit + 172 webapp unit). All six diagrams have >=3 round-trip
  cases (smallest is StateMachineDiagram at 3).

Critical gaps surfaced
1. No `TestAgentDiagramRoundtrip` / `TestUserDiagramRoundtrip` class in
   `test_converter_roundtrip.py` — agent + user converters have only
   fixture-shape assertions in `test_v4_round_trip.py`.
2. `test_api_integration.py` posts no NNDiagram or UserDiagram payload
   to any FastAPI endpoint, despite NN being the most-tested converter.
3. Inspector panels: 25 `.tsx` files across the 6 diagrams,
   0 React-level tests. The SA-2.1 / SA-2.2 audit fixes (#29 NN
   per-layer gating, #37 Integer-gated comparator, ClassEdgeEditPanel
   BESSER-specific edges) are exercised only via JSON round-trip.

High/medium gaps include the seven conversion-router endpoints with no
HTTP test, the missing `user_diagram_basic.json` v4 fixture, no test
for `lib/components/inspectors/registry.ts`, and zero node-render
tests in the library.

https://claude.ai/code/session_01NJkiJA8SPNGRtYeYpkPnrF
Confirm /github/deploy-webapp + /generate-output-from-project work on v4
class diagrams + GrapesJS GUI diagrams.

- New fixture tests/fixtures/v4/deploy_project.json mirrors the deploy
  request body (diagrams + currentDiagramIndices + deploy_config).
- Trace stops cleanly at gh.create_repository(); WebApp bundle (FastAPI
  + React + docker-compose) emits 36 files, all Python ast.parse-clean.
- Per-diagram references["ClassDiagram"] = "cd-1" resolves through
  ProjectInput.get_referenced_diagram; global currentDiagramIndices
  acts as fallback. Both confirmed.
- fa4e4d1's nodes-guard fixes at github_deploy_api.py:199 (agent deploy)
  and :970 (B-UML export loop) verified in-source.

Issues filed (all low/info, none critical):
- D-1 deploy _get_active duplicates ProjectInput logic, ignores
  per-diagram references.
- D-2 /deploy-app vs /github/deploy-webapp naming collision (Django
  Compose vs GitHub deploy).
- D-3 task wording 'Django from class' - generator emits FastAPI.
- D-4 silent None on missing entity-class-id binding in
  gui_processors/utils.py:get_element_by_id.

https://claude.ai/code/session_01NJkiJA8SPNGRtYeYpkPnrF
Sweep every v3 and v4 fixture across the repo through the @besser/wme
v3↔v4 migrators + reverse converters and report fixtures that fail to
round-trip cleanly.

47 fixtures tested (11 library v3, 8 editor v3, 21 webapp v4 templates +
project-wrapped diagrams, 7 backend tests/fixtures/v4): 22 PASS / 25 FAIL.

5 distinct failure clusters surfaced:
  1. tests/fixtures/v4 carry vestigial v3 metadata (id/interactive/size)
     that the v4→v3 path doesn't preserve (7 fixtures).
  2. Agent edge legacyShape isn't on v4-authored fixtures but gets
     stamped by convertV3ToV4 (4 fixtures).
  3. Parent-relative coordinates shift on Agent / SM / NN nodes whose
     parentId is set (10 fixtures).
  4. AgentDiagram edge data.legacy schema diverges between
     liftAgentTransitionDataToV4 and convertV4ToV3Agent (4 fixtures).
  5. CommunicationDiagram has no migrator/reverse converter (1 fixture).

Top-3 critical: object_diagram_basic.json drops referenceDiagramData;
agentDiagram.json fails the SA-4 "legacy preserved verbatim" promise;
4 webapp agent templates would shift coordinates on save→reload.
Append the actual sandbox run log (19 entries — 17 PASS / 0 FAIL /
2 SKIP) to A2-all-generators.md. The smoke harness
(tests/utilities/web_modeling_editor/backend/smoke_all_generators.py)
exercises every entry in the backend generator registry on a
representative v4 fixture, parses any emitted Python with ast.parse,
and reports per-generator status + output size.

The two SKIPs are environmental:
- django: requires the django-admin CLI, absent on this sandbox
- terraform: needs a populated DeploymentModel + .conf file (no v4
  deployment fixture yet)

No regressions in the v4 BUML wiring across the registry.

https://claude.ai/code/session_01NJkiJA8SPNGRtYeYpkPnrF
Simulate webapp migrateProjectToV5 on 4 v3 BesserProject snapshots
(class-only, state-machine, agent, full-stack); all pass with 27/27
nodes and 9/9 edges preserved across the corpus.

https://claude.ai/code/session_01NJkiJA8SPNGRtYeYpkPnrF
Submodule now at 343189d (includes SA-7a, SA-7b, SA-7b.1 partial,
plus the @/ resolver Windows path-sep fix). User reported npm run
dev failing on Windows because the conditional `@/*` resolver in
packages/webapp/vite.config.ts checked for path.sep ('\\\\' on
Windows) while vite normalizes importer paths to forward slashes.

Bundle refreshed accordingly. Apply locally with the recipe in
commit 13d2991.

SA-7b.2, SA-DEBRAND, SA-CONVERTER-SWEEP are still in flight; their
commits will land on top in subsequent bundle refreshes.

https://claude.ai/code/session_01NJkiJA8SPNGRtYeYpkPnrF
…on mentions

Bump the frontend submodule pointer to pick up the SA-DEBRAND rename in
`@besser/wme` (`packages/library/lib/`) and align backend / docs with the
new CSS-variable namespace and naming.

- Frontend submodule: bumped to commit `2031a1c`, which renames the
  public class `ApollonEditor` → `BesserEditor`, renames public types
  (`ApollonOptions`/`Mode`/`View`/`Node`/`Edge` → `Besser*`), flips
  `--apollon-*` CSS variables to `--besser-*`, and rebrands all `Apollon`
  mentions in the lib + webapp. Deprecated aliases keep webapp imports
  working during the transition.
- Backend CSS-variable refs (`backend/constants/default_config.json`,
  `services/utils/agent_config_recommendation_utils.py`,
  `docs/source/generators/agent_personalization.rst`) bumped to
  `--besser-*` to match the lib.
- `besser/utilities/kg_to_buml.py` + `tests/BUML/notations/kg_to_buml/`
  comment / variable rename: "Apollon/BUML" → "BESSER WME / BUML".
- `services/converters/buml_to_json/project_converter.py` docstring
  reword: "Apollon-driven" → "BESSER WME-driven".

Historical references in `docs/source/web_editor.rst` ("based on a fork
of the Apollon project") and `docs/source/releases/v7/v7.0.0.rst`
("replacing the legacy Apollon-based webapp") are left in place as
true historical context, not stale API references.

https://claude.ai/code/session_01NJkiJA8SPNGRtYeYpkPnrF
Bundle now contains 5 commits on top of remote tip (0e51317 = SA-2.2):
- 702251b SA-7a lib prep
- 771c064 SA-7b cutover
- 7a3b82a SA-7b.1 partial v4-native + tsconfig fix
- 343189d Windows vite-resolver fix
- 2031a1c SA-DEBRAND rename ApollonEditor → BesserEditor

Apollon mentions in lib/ reduced to 11 (deprecated aliases in
index.tsx only); webapp src/ has zero Apollon mentions.

SA-7b.2 (Object/Agent modifiers + scaffold) and SA-UX-FIX (7 user-
reported ClassDiagram UX bugs) are still in flight; their commits
will land in subsequent bundle refreshes.

User reported 5 more bugs in browser testing (Agent Intent inspector,
Class member overflow, StateInitialNode white-on-white, UserDiagram
content loss, NN layer icons retired). Will queue SA-UX-FIX-2 once
the working tree clears.

https://claude.ai/code/session_01NJkiJA8SPNGRtYeYpkPnrF
… output dir

SA-7b.2 finished the v4-native rewrite of ObjectDiagramModifier,
AgentDiagramModifier, and scaffoldObjectsFromClasses. TS errors
dropped 183 → 34 (the remaining 34 are all in deferred files:
GUIDiagramModifier + QuantumCircuitModifier still v3-shaped + a few
chatbot-kit / non-target files). Lint baseline unchanged. Webapp
build passes (18s). The only v3↔v4 shim that remains in webapp src
is the legitimate localStorage migrator at shared/types/project.ts:480.

Also adds /output/ to .gitignore — A2's all-generators smoke run
left a Flutter pubspec.yaml in the repo root.

Bundle refreshed: 6 commits on top of remote tip 0e51317.

https://claude.ai/code/session_01NJkiJA8SPNGRtYeYpkPnrF
trace_matching read the imported project as v3 (elements/relationships), so a
trace imported from a project file matched no class-diagram element and no
agent or state-machine element by name. It now reads nodes, their attribute,
method and constraint rows, edges and agent components.

The element-id and traced-generation tests from development are ported to v4
fixtures; the three template fixtures are the v4 editor templates (same ids).
reinject_hidden_containers, extract_user_profile_names,
extract_profile_personalization_rules and the unnamed-User check of
/validate-diagram read v3 elements/relationships, so on v4 models they found
no User box: no hidden containers, no profile names, no rules, no warning.
They now read UserModelName nodes, their data.attributes rows and
UserModelLink edges; rules ride on data.personalization, a row's
personalization and the User node's data.profilePersonalizationRules.
_element_ids read a v3 elements map, so a GUI bound to another class diagram
was never recognised. It now collects class node ids and their attribute and
method row ids.
…ield check

The v4 port of test_bpmn_converters.py kept 8 of the 28 Appendix A event
rows and replaced test_load_bearing_fields_preserved with a weaker stability
check. Both are back, on v4 fixtures.
…evelopment does

A method whose returnType names a deleted or renamed class (or an old
signature fragment) failed the whole class diagram with ConversionError.
Development logs "Ignoring unresolvable return type" and converts the
method untyped; the v4 processor now does the same, for returnType and the
attributeType fallback, and keeps a type parsed from the signature.
_normalise_agent_transitions dropped three fallbacks of development's
processor, which the editor's TS normaliser keeps:
- an intent name or file type stored only as conditionValue;
- custom conditions in a top-level conditions list;
- an idle custom bag (event "None") turned an intent transition into an
  unconditional one.
A v4 child position is relative to its parentId, but _emit_nn_container
passed development's absolute coordinates, so every layer of a B-UML NN
imported into the editor landed outside its container, overlapping its
neighbours. Positions are now relative and layers keep development's (and
the editor's) 110x110 size.
…t .py

The React Flow branch had dropped development's numbered BPMN section
header, so a project with more than one BPMN model came back as "BPMN
Diagram 1/2" unless the editor had recorded its diagram ids. The BPMN
block is development's again, in its place after the NN models.
… round trip

Drops what the branch added on top of development's .py import/export:
editor-id comment lines (diagram ids, titles, object diagram references,
class ids, project name), the builder banner strip, project names with any
non-identifier character, project metadata read from the definition only,
A2A tags written to and read from B-UML, every reply of a mixed agent body,
the default LLM moved to the diagram envelope, components-only agent
diagrams kept in projects, layout adoption with existing_model and the
buml-import-partial warnings.
A class description is again written as data.description and as a linked
comment, method pre/post contracts parsed from a .py are added to the model's
constraints as on development (and their boxes carry no name), a class named
Project is refused as on development, association handles face each other as
development computes them, colours and inheritance handles are no longer
stashed through B-UML, and an inheritance cycle is no longer answered with a
dedicated 400. The SDMX description test is an expected failure again.
…guards

An agent transition without a type reads as when_no_intent_matched, the
processor reads the config envelope only, and an agent diagram with
components but no states is skipped as on development instead of answering
400 in generation, Docker Compose and the GitHub deploy.
BPMN accepts only the BPMNDiagram model type and validation reads the BPMN
result as development does; NN metrics are written as development writes
them and adaptive pooling gets the default kernel as on development; a state
machine .py import reads plain transitions only, as on development.
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.

4 participants