// OTHERS

MDE - Code Generation

A Model Driven Engineering pipeline that automatically generates a Java Spring Boot REST API code from a high-level healthcare admission model.

ROLEDeveloper
TEAMTeam project
CONTEXTUniversity project
CREATED2026
EMF (Eclipse)OCLATLAcceleoJavaSpring BootREST API
Model Driven Engineering - Code Generation

Overview

This project investigates how Model Driven Engineering (MDE) can be used to automatically generate Java Spring Boot REST API backend code from a high-level, abstract healthcare admission model.

Healthcare systems are large and complex, and building the backend for one involves a lot of repetitive work. Every entity needs the same layers (entity, repository, service, controller) with only the names and fields changing. Instead of writing all of that by hand, we describe the system once as a model and let the tools generate the code. Since the generated code follows the rules defined by the metamodel, it is also easier to reuse and maintain.

The project was developed as part of a university Model Driven Engineering course in a team of two, and was split into three tasks:

  1. Metamodelling: a Healthcare admission metamodel and a model based on it & a Spring Boot REST API metamodel
  2. Model transformations: an ATL transformation from the healthcare admission model to a Spring Boot REST API model
  3. Code generation: Acceleo templates that turn the Spring Boot REST API model into Java source code

This article focuses on the big picture: the pipeline, the design decisions, and the results. It doesn’t go into code-level detail, but if you’d like the full code or a deeper technical walkthrough, feel free to contact me.

Scope

The project intentionally has a limited scope. It doesn’t attempt to model a complete healthcare and hospital system. The functionality such as Medical diagnosis, Payment processing, Detailed medical records, Authentication and authorization, Complex scheduling, Billing, Database configuration are outside of our scope. This project is instead focused on demonstrating that a high-level abstract hospital model can be transformed into working Java Spring Boot REST API code.

A note on terminology. The model is called healthcare admission, but you’ll still see hospital in some names, such as HospitalAdmissionModel and Hospital2RASB.atl. We started the project with hospital and later chose healthcare for a wider scope. By then, the metamodels, transformation rules, and templates already depended on the original names, so renaming them risked breaking the pipeline. We kept the existing names, and both terms refer to the same model.

Alternatives and justification of chosen solution

EMF (Eclipse Modeling Framework). EMF gives us Ecore metamodels, model editors, and validation in one environment, and the rest of the tools (OCL, ATL, Acceleo) integrate directly with it.

OCL. OCL lets us add constraints to the metamodels so that incomplete or invalid models are rejected before they reach the transformation or the generator. With OCLinEcore, the constraints live in the same .ecore file as the metamodel.

ATL over QVT. ATL’s rule-based declarative syntax makes it easy to describe what should be created from what, while the engine handles the rest. QVT, especially QVT Operational, felt heavier for what we needed and has a steeper learning curve. ATL also works well in our Eclipse environment, so it was the more practical choice.

Acceleo. We were already using Eclipse/EMF for the metamodels and ATL for the transformation, so Acceleo fits in the same toolchain. It works directly on our Spring Boot REST API metamodel and uses OCL, which we already knew from the earlier tasks.

Java Spring Boot and REST API. We learned Spring Boot in another course (SOA - Service-Oriented Architecture with Web Services) and wanted to put it into practice. It has a clear layered structure (controller, service, repository, entity), but implementing it involves a lot of repetitive boilerplate code. That repetition makes it a good fit for a template-based generator. We write the template once and can produce all the layers for each entity, such as patient, doctor, nurse, room, and admission.

Architecture

The project follows a typical MDE pipeline, where each step feeds into the next:

No Step Artifact Tool
1. Metamodels (Source + Target) Healthcare metamodel, Spring Boot REST API metamodel + OCL constraints EMF ( .ecore ) + OCLinEcore
2. Source Model Healthcare admission model EMF ( .xmi )
3. Model Transformation Healthcare admission model → Spring Boot REST API model ATL ( .atl )
4. Target Model Spring Boot REST API model EMF ( .xmi )
5. Code Generation Spring Boot REST API model → Java project Acceleo ( .mtl )

The two metamodels describe the problem at different levels. The Healthcare admission metamodel describes the domain (entities with roles such as patient, staff, or resource, their attributes and relationships, and admissions with states and transitions) and contains no Spring Boot concepts. The Spring Boot REST API metamodel describes the code structure (controllers, services, repositories, entities, endpoints, operations, and types).

Transformation Mapping Overview

ATL transformation mapping preview

The green dashed arrows with a ? are optional mappings. An entity can be used as the parameter or return type of an operation and endpoint (e.g. getById returns a Patient), but it doesn’t have to be. A method could also take or return another type, like a String or an Integer, so this mapping depends on the operation and is not fixed by the transformation.

Healthcare Admission (Source) Spring Boot REST API (Target) Acceleo Code
HospitalAdmissionModel RestApiSpringBoot Project folder
Entity (non-abstract) Entity + Repository + Service + Controller Java classes
Attribute Attribute Class variables
Relationship Attribute (collection/object type) Class variables
AdmissionState Attribute (BOOLEAN) Class variables
AdmissionTransition Endpoint & Operation Methods in Controller and Service classes

Technical approach

  1. Metamodels ( .ecore ) and model ( .xmi )

    The first version of the Healthcare metamodel was too specific, and a model made from it could not be properly transformed. We replaced it with a more generalized one, but aimed for a balance, not so abstract that it could describe anything, and not so concrete that it only fits one hospital.

    The core concept is a generic Entity. Instead of hard-coding classes like Patient and Doctor, the modeller creates their own entities, each with a name, a role ( Patient, Staff, Resource, or Other ), attributes, and relationships to other entities. Entities can also be abstract and have a supertype. For example, an abstract Person can be the parent of Patient and Doctor. To keep the metamodel tied to the healthcare domain, we added OCL rules, such as requiring at least one patient, staff, and resource role, and exactly one admission.

    The domain-specific part is the AdmissionEntity, which inherits from Entity and adds the lifecycle of an admission: a set of states (e.g. pending, active, completed, cancelled) and transitions between them (e.g. admit, transfer, discharge), each with an optional guard.

    The Spring Boot metamodel was also tightened. Types used to be plain strings, so nothing stopped you from writing a type that doesn’t exist. We introduced an abstract Type class (extended by DataType, Entity, CollectionType, and MapType ), added isIdentifier, isRequired, and isUnique to attributes, separated Endpoint from Operation, and made multiplicities stricter so the metamodel rejects incomplete models.

    See the metamodels and models in the preview section.

  2. Constraints (OCL, embedded in .ecore )

    OCL constraints were added directly to both metamodels using the OCLinEcore editor, so they are stored as invariants inside the .ecore files. For example:

    • The healthcare admission model must have at least one patient, staff, and resource role, and exactly one admission
    • An identifier attribute must be required and unique
    • Relationship bounds must be valid (non-negative, and the lower bound can’t exceed the upper)
    • Entity and data type names must be unique, and no two endpoints may share the same HTTP method and path
    • Every entity needs at least one identifier
      invariant AtLeastOneIdentifier:
      self.attribute->exists(a | a.isIdentifier);
  3. Model transformation ( .atl )

    Only the root rule (HospitalAdmissionModel2RASB) is a matched rule. All other rules are unique lazy rules that are called explicitly, which gives full control over what gets created and when. Because they are unique, calling the same rule for the same source element always returns the same target object, which matters since the entity, repository, service, and controller all point to each other.

    Some key design decisions:

    • Abstract entities are skipped, and their attributes are pulled into the concrete subclasses with a helper (allAttributes)

      helper context HOSPITAL!Entity def: allAttributes : Sequence(HOSPITAL!Attribute) =
          self.attribute->asSequence() ->union(
              if self.supertype.oclIsUndefined()
              then Sequence{}
              else self.supertype.allAttributes
              endif
          )->asSequence();
    • Helpers manage which data types are actually needed in the target model

    • Each AdmissionTransition becomes an extra operation and a PUT endpoint (e.g. updateAdmitPatient) that checks the source state and guard before changing the state

    • Every non-abstract entity gets a basic set of CRUD endpoints (getAll, getById, create, update, delete)

      Operation HTTP Method Path
      getAll GET /patient
      getById GET /patient/{id}
      create POST /patient
      update PUT /patient/{id}
      delete DELETE /patient/{id}
  4. Code generation ( .mtl )

    Acceleo templates generate one Java file per element in the REST API model:

    • Entity: a class with variables, an empty constructor, and getters/setters. Imports are added only when needed.
    • Repository: an interface extending JpaRepository, typed on the entity and its identifier
    • Service: methods that call the matching repository method depending on the operation type
    • Controller: a @RestController with the right mapping annotation ( @GetMapping, @PostMapping, etc.) per endpoint, calling the matching service

    Acceleo queries handle the type mapping (e.g. DATE → LocalDate, collections → List) and work out which service or repository belongs to which controller.

    Folder structure of the generated code:

    result/
        pom.xml
        src/main/java/com/mde/task3/
            Application.java
            entity/
            controller/
            service/
            repository/

    To run it, navigate to the result folder and start the app with mvn spring-boot:run. The API is then available at localhost:8080/api.

Preview

Metamodel: Healthcare Admission Metamodel: Healthcare Admission preview

Source Model: Healthcare Admission Source Model: Healthcare Admission preview

Metamodel: Spring Boot REST API Metamodel: Spring Boot REST API preview

Target Model: Generated Spring Boot REST API model

Metamodel: Spring Boot REST API preview 1 Metamodel: Spring Boot REST API preview 2

Generated Source Code (sneak peek)

The full generated code isn’t published here, but feel free to contact me if you’d like to see it.

Generated Source Code preview Generated Source Code preview Generated Source Code preview

Generated Code Ran Successfully Generated Code Ran Successfully preview Generated Code Ran Successfully 2 preview

Running application tested with Postman Running application tested with Postman preview

Test and Evaluation Strategy

Models and constraints. The OCL constraints were tested by creating a valid example model (which passes validation) and then deliberately breaking each constraint, for example removing the staff entity, adding a second admission, using a non-unique identifier, or using a negative bound.

Valid Model

healthcare admission model validation preview SBRA model validation preview

Invalid Model (sneak-peek)

healthcare admission model bounds order validation preview SBRA duplicate endpoints model preview

Generated code. We tested the generated application with Postman, one entity at a time, using a request collection that can be re-run quickly:

  1. Create base data with POST (patient, doctor, nurse, room), then an admission linked to them
  2. Read everything back with getAll and getById, including a non-existent id
  3. Update an admission with PUT, then GET again to confirm it was really saved
  4. Run the state transitions (admit, discharge, cancel) and check that the status changes
  5. Delete an admission and check that the patient, doctor, and room still exist
  6. Send bad requests (missing fields, empty body) to check they are not accepted

Testing Summary. Below are the table containing the summary of our testing attempts.

No. Test Case Result
1 Run Acceleo on the model ✓
2 mvn compile ✓
3 mvn spring-boot:run (app starts on port 8080) ✓
4 GET ( getAll ) on every entity ✓
5 GET ( getById ) with a valid ID on every entity ✓
6 POST with valid input on every entity ✓
7 PUT with valid input on every entity ✓
8 DELETE with a valid ID on every entity ✓
9 Compare generated entities with the model ✓
10 Admission state transitions ✓
Requirement Achieved
Entities 1-to-1 ✓
REST endpoints ✓
Endpoints & Operations 1-to-1 ✓
Runnable ✓
API completeness ×

Challenges

  • Metamodel/model mismatch. We were still learning MDE when the project started, so our first metamodel was too close to a regular class diagram, with specific classes like patient and doctor, and the model just filled it with concrete examples. That didn’t fit how a metamodel and model should relate, and it couldn’t be transformed properly into the Spring Boot REST API model. We had to rethink the metamodel at a more general level, which cost extra time and meant we couldn’t complete everything we originally planned.
  • Knowing what comes later. It was hard to tell early on which metamodel decisions would cause problems in the later steps. We only found out once we got to the transformation and code generation.
  • Silent failures in Eclipse. Working with Eclipse tooling can be pretty unforgiving. If there was a small mistake in an ATL or Acceleo file, like a syntax error or a misplaced space, the transformation or generation would often just produce nothing, with no error message at all. Finding the cause meant a lot of trial and error, and sometimes it felt like debugging in the dark.

Future improvements

Because of time constraints, and because we had to change parts of the design along the way, there are a few things we couldn’t finish. With better time planning and what we learned from this project, these are the improvements I’d focus on next:

  • Generate Swagger/OpenAPI documentation so the API can be explored and tested without a separate tool like Postman
  • Add descriptive error messages to the generated code, such as rejecting invalid state transitions and missing fields
  • Move from transient storage to persistent storage so data survives restarts

Lessons learned

This project showed me how a good design can save so much time and work later. If the metamodels and models are designed properly, the rest is much easier. When something was wrong, we fixed it once in the model or the Acceleo template, instead of editing every generated file.

It was also hard to know what problems would show up later. We only found out once we reached the transformation and code generation, and sometimes we had to go back and fix earlier parts. In hindsight, we could have planned better.

Overall, I learned how to use EMF, OCL, ATL, and Acceleo, and a new way of building software. Describe it once at a high level, then generate the code (and potentially more in the future, such as documentation and tests).

Shoutout to my teammate Lilya for the great teamwork, and for sticking with me through all the metamodel debugging 🙌😅