ID generation as UUID. Development of modules. Change core NR behaviour

Hi everyone,

First of all, thanks to everyone who has been involved in developing this amazing application! This is my first forum post here and I started working with Node-RED several months ago during my Master's Thesis. Now, I'd like to incorporate NR in a larger, dockerized service-based application. I'm a bit of a noob in many things so please bear with me. I'd be very greateful for any tips or pointers where my train of thought is wrong or improvements to my ideas.
this is going to be a bit of a larger post but I'll try to structure it as best as I can. I put a tl:dr at the bottom as well.

In essence, here are my main goals:

  1. Change the generation of IDs to UUID4.
  2. Save flows independently in a Postgres Database.
  3. Provide an API to retrieve flows out of the Postgres Database.

I know this touches on the typical topic of integrating NR, instancing it, and providing multi-user features that have been discussed a lot and are on the roadmap (AFAIK?). However, with what I did so far, it was possible to achieve some of my previous goals, so I'm hoping that some smaller changes can go a long way until NR supports more of my needs natively.

Change the generation of IDs to UUID4.
As far as I understand, IDs for Flows (and nodes, wires, etc.) are generated in packages/node_modules/@node-red/util/lib/util.js. I used the uuid npm module and added

const { v4: uuidv4 } = require('uuid');

and changed the function to

function generateId() {
    return uuidv4();
}

Afterwards, I ran npm build. However, the ID generation behavior didn't change. Did I miss something?

Save flows independently in a Postgres Database.
For prototyping this functionality, I use a combination of two modules for NR.

  1. node-red-contrib-flow-manager
  2. node-red-contrib-storagemodule-postgres

Here, my general question is: How do these modules even work? :smiley:
I hacked them together, insofar as the flow-manager will save flows in the Postgres DB. However, I'm confused by the general working of these NR modules. The flow-manager comes with mainly a single JS file and does not any nodes to the palette. It is not referenced in the settings.js as a storage module. It just exports

module.exports = function(_RED) {
    RED = _RED;
    main();
};

This might be due to my poor understanding of JavaScript that I do not get how this works. Does this module overwrite functions of the Node-RED core? If yes, which and how? I'd like to emulate the behavior.

Are there any guides on how to develop modules like this? I couldn't find another module that behaves in a similar way and would appreciate any pointers greatly!

Provide an API to retrieve flows out of the Postgres Database.
I'm hoping that a better understanding of how modules are developed will enable me to design this API. the flow-manager module does create its own APIs that more or less do what I need.
If you have experience with the way these APIs are built and have any tips or some kind of tutorial on hand, that would obviously go a long way and be very much appreciated, though!

Why do I want to do all this? Our application allows the design of worklfows. These workflows can come from multiple sources. One of these sources is supposed to be Node-RED. In order to handle Node-RED flows the same as other workflows, they need to have a UUID4 as ID. While it would be possible to attach a UUID at a later stage, this does not make sense going forward. In the large-scale architecture, services request workflows from their respective source, in this case Node-RED, that have them stored in a database.

Thank you for bearing with me here. I will try to summarize again in short:
tl;dr
I want to change the IDs of flows to match the UUID4 definition. Flows should be saved on deploy in a postgres database where each flow is saved in a single row. For this, flows need to be split. I used the flow-manager module for that. However, I struggle with the understanding necessary for manipulation of that module and am looking for guidance on how development of modules for NR works.

If you have any tips at all or would like me to elaborate further on any point, I would appreciate your comment. Thank you very much for your time!

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.