Java flow - miguelperezcolom/mateu GitHub Wiki

Here we are gonna review the flow in the java side of Mateu.

Code generation

Mateu is generating 3 classes for any class XX annotated with @MateuUI:

  • XXConfig: a spring boot configuration for adding Mateu packages to spring boot class scanning
  • XXController: a controller for serving a index.html file at the path specified in the @MateuUI annotation
  • XXMateuController: a controller for serving the rest API which is the core of Mateu

This is how it looks in your project:

The journey starts

So, the user asks for the url as stated in the @MateuUI annotation.

That will go to the HelloController (remember, it's generated from our Hello class) which will serve the html, which includes the frontend component of Mateu which, in the end, is painting things in the browser and sending the user actions (e.g. clicks) to the Mateu API.

Once the component is loaded in the browser it will start asking the API for what to paint, according the following sequence:

The API calls

So, we have several endpoints / flows but the main calls are:

  • create ui (POST)
  • create journey (POST)
  • run action (POST)

Let's look at them in detail but, before, let's make clear how the requests arrive to Mateu's code:

So, the generated controller translates the http request to the MateuService class. From now we will look at the flow starting at MateuService. We will leave the remote UI thing out for the sake of simplicity.

It is important to understand that MateuService is a simply orchestrator which calls the approriate use case. The basic flow for any action is as follows:

So, we get an instance of the target object (perhaps using dependency injection) and we hydrate it. We call a method on it and we map the result (or the object itself if the method return type is void) to the api dtos in form of UI increments and commands.

Map to UI increment

The conversion from any object to the UI increment is done by running the following logic:

  1. if the object implements any of the known component interfaces, it's mapped to a known component
  2. the object is mapped to a form
  3. whatever the object is mapped to, it is included in a UI increment which is returned to the frontend together with the place that UI fragment is meant to replace
  4. commands and messages are also extracted and included in the UI increment

Conclusion

The backend side of Mateu is just about implementing the api. This backend connects the api calls to plain java objects which are instantiated as needed and, at some point, infers the views (the json which will travel back to the frontend) using java reflection.

⚠️ **GitHub.com Fallback** ⚠️