You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+33
Original file line number
Diff line number
Diff line change
@@ -84,3 +84,36 @@ This project is built on [GitHub Actions](https://github.com/bcmi-labs/arduino-e
84
84
git push origin 1.2.3
85
85
```
86
86
87
+
### Architecture overview
88
+
89
+
The Pro IDE consists of three major parts:
90
+
- the _Electron main_ process,
91
+
- the _backend_, and
92
+
- the _frontend_.
93
+
94
+
The _Electron main_ process is responsible for:
95
+
- creating the application,
96
+
- managing the application lifecycle via listeners, and
97
+
- creating and managing the web pages for the app.
98
+
99
+
In Electron, the process that runs the main entry JavaScript file is called the main process. The _Electron main_ process can display a GUI by creating web pages. An Electron app always has exactly on main process.
100
+
101
+
By default, whenever the _Electron main_ process creates a web page, it will instantiate a new `BrowserWindow` instance. Since Electron uses Chromium fordisplaying web pages, Chromium's multi-process architecture is also used. Each web pagein Electron runs in its own process, which is called the renderer process. Each `BrowserWindow` instance runs the web page in its own renderer process. When a `BrowserWindow` instance is destroyed, the corresponding renderer process is also terminated. The main process manages all web pages and their corresponding renderer processes. Each renderer process is isolated and only cares about the web page running in it.<sup>[[1]]</sup>
102
+
103
+
In normal browsers, web pages usually run in a sandboxed environment, and accessing native resources are disallowed. However, Electron has the power to use Node.js APIs in the web pages allowing lower-level OS interactions. Due to security reasons, accessing native resources is an undesired behavior in the Pro IDE. So by convention, we do not use Node.js APIs. (Note: the Node.js integration is [not yet disabled](https://github.com/eclipse-theia/theia/issues/2018) although it is not used). In the Pro IDE, only the _backend_ allows OS interaction.
104
+
105
+
The _backend_ process is responsible for:
106
+
- providing access to the filesystem,
107
+
- communicating with the Arduino CLI via gRPC,
108
+
- running your terminal,
109
+
- exposing additional RESTful APIs,
110
+
- performing the Git commands in the local repositories,
111
+
- hosting and running any VS Code extensions, or
112
+
- executing VS Code tasks<sup>[[2]]</sup>.
113
+
114
+
The _Electron main_ process spawns the _backend_ process. There is always exactly one _backend_ process. However, due to performance considerations, the _backend_ spawns several sub-processes forthe filesystem watching, Git repository discovery, etc. The communication between the _backend_ process and its sub-processes is established via IPC. Besides spawning sub-processes, the _backend_ will start an HTTP server on a random available port, and serves the web application as static content. When the sub-processes are up and running, and the HTTP server is also listening, the _backend_ process sends the HTTP server port to the _Electron main_ process via IPC. The _Electron main_ process will load the _backend_'s endpointin the `BrowserWindow`.
115
+
116
+
The _frontend_ is running as an Electron renderer process and can invoke services implemented on the _backend_. The communication between the _backend_ and the _frontend_ is done via JSON-RPC over a websocket connection. This means, the services running in the _frontend_ are all proxies, and will ask the corresponding service implementation on the _backend_.
0 commit comments