R
R
raxid436952020-11-11 10:44:28
Node.js
raxid43695, 2020-11-11 10:44:28

What architecture and structure should such an application have?

Good day!
There will be a lot of text and ideas .. It would be great if you could tell me how best to do it.

1. A module that receives values ​​from an external API. Based on these values, further actions will be taken.

2. The module that is responsible for the notification. For example, let's take a telegram bot. He will be closest to understanding.

As I imagine it:
0.1 client authorization (module 2)
0.2 api authorization (module 1 from the above)

1.0 infa comes through 1 module
1.1 entry to the database
1.2 determine whether the data matches the condition or not
2. If the data from 1.2 fits which - certain conditions call the desired script (myscript1, for example)
3.1. Inside the myscript1 script, some interactions with data are described
3.2. Calling methods from 0.2 to notify

The problem is how to separate the functionality into files and make it all work.
There were ideas:
a) What I described above, but I ran into problems that I will describe below.
b) All in one file to do with further processing. Immediately rejected
c) Make independent scripts. Roughly speaking, one listens to api and writes to the database. The second script reads the database for new records and processes the data, followed by writing to the database for script three. The third script reads base and is engaged in the notification.

In paragraph "a" there were problems with the fact that at the final stage it was not always possible to forward an authorized client telegram for notification.
Suppose in main.js everything is authorized through promises, all this happens sequentially. But then you have to transfer the client from 0.1 (telAPI.js) to 0.2 (devAPI), and then to 3.2. Before that, there was an attempt to export sending messages from 0.1 to 3.2 directly, but 0.1 did not always manage to connect before 1.2 before exporting to 3.2 and events in 0.2 ..
It turned out that inside 3.1 (myscript1) the script tries to call a method from 0.1, but it is still undefined

Ask questions if something is not clear!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir, 2020-11-11
@HistoryART

Only one thing is clear, the project is still in theory, I also did this when I had little understanding in the implementation, they did the right thing by contacting here. First you need to get familiar with module.exports = {} to implement this: The problem is how to separate the functionality into files and make it work. You don't need to separate each operation into files, you have a module - for example authorization, one file. In which there will be a record and excavation from the database. You can split it into 2 reg/auth files and put it in a folder. I strongly recommend doing what is convenient for you , and only then look for established solutions.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question