Backend Integration

The backend needs to know how to process the JSON model generated by your new diagram. The backend services live in the BESSER repository under besser/utilities/web_modeling_editor/backend. If you are working in the WME repo, clone BESSER alongside it and make the backend changes there. For the full backend + metamodel workflow, see the BESSER guide: Add a New DSL.

1. Create a Processor

Create besser/utilities/web_modeling_editor/backend/services/converters/json_to_buml/my_new_diagram_processor.py in the BESSER repository.

from besser.BUML.metamodel.structural import DomainModel, Class
# Import other BUML metamodel classes as needed

def process_my_new_diagram(json_data: dict) -> DomainModel:
    """
    Converts MyNewDiagram JSON to a BUML model.
    """
    model = DomainModel(name=json_data.get("name", "MyModel"))

    elements = json_data.get("model", {}).get("elements", [])

    for element in elements:
        if element["type"] == "MyNewElement":
            # Map JSON properties to BUML objects
            new_class = Class(name=element["name"], parent=model)

    return model

2. Register the Processor

  • Export: Add to besser/utilities/web_modeling_editor/backend/services/converters/__init__.py.

    from .json_to_buml.my_new_diagram_processor import process_my_new_diagram
    
  • API Endpoint: The backend uses a modular router architecture. Add or update endpoints in the appropriate router under besser/utilities/web_modeling_editor/backend/routers/ (e.g., generation_router.py for code generation, conversion_router.py for import/export). Use the @handle_endpoint_errors decorator from routers/error_handler.py for consistent error handling:

    # In the appropriate router file (e.g., generation_router.py)
    from besser.utilities.web_modeling_editor.backend.routers.error_handler import handle_endpoint_errors
    
    @router.post("/generate-my-diagram")
    @handle_endpoint_errors("generate_my_diagram")
    async def generate_my_diagram(input_data: DiagramInput):
        json_data = input_data.model.model_dump() if input_data.model else {}
        buml_model = process_my_new_diagram(json_data)
        # ... pass to generator
    

3. Keep conversions and validation in sync

  • If the diagram can be imported back into the editor, also update the BUML -> JSON converters under besser/utilities/web_modeling_editor/backend/services/converters/buml_to_json.

  • Update validators under besser/utilities/web_modeling_editor/backend/services/validators so the new elements are checked consistently.

  • Align JSON element and relationship type names with the editor package definitions to avoid mismatches.