Global electron app architecture



I have a few questions about the electron app structure. On the separation of concerns.
Lets take a simple functionality : I would like to list all files (recursively) in a folder and for each of those files perform an http request and display the result of the request for each of those files in a table.

Now, if I perform the directory scan in the window process, it will freeze the layout until the whole directory is scanned and than update the UI. (using react btw). Could I make the window responsive moving that code to the “main” process and send events to the UI process? Sort of re-implementing a client-server architecture?

Should the HTTP requests be made by the window process as well?
If I want my app to work even without the main window opened (sitting in taskbar) can I still use the window to do all this ?



Yes, you can move the code into the main process, and use it a lot like a client-server relationship. In fact, that’s the approach I take with most Electron apps (window process only for the UI, actual heavy work back in the main process). Although, I believe that mainly this should be done with things that the browser wouldn’t do normally (e.g. listing files in a folder, reading files, writing files, etc.). Things like performing HTTP requests should be done by the window process since they’re normally done by the browser.

However, note that this is really a matter of personal preference when coding, there’s no set way that it should be done. Someone else on this forum would probably give a completely different answer.

And yes, the window process still functions even when it’s window is hidden.


Blocking or over-burdening a renderer process or the main process is equally bad, the main process doesn’t just idly sit around doing nothing, one of its jobs is to herd renderer processes. However, if you’re doing non blocking IO (that’s not super intensive) you’re probably fine doing it in either process, HTTP requests should generally be handled in a renderer process to take advantage of Chromium’s built-in proxy handling. If you need to do anything CPU intensive or blocking IO you should spawn a background process to do it, this can be done either by using child_process.fork() or by creating a hidden BrowserWindow (in which case you might want to take a look at