How to understand a Electron codebase
An Electron app is two programs: a Node.js main process that owns windows and the operating system, and one or more renderer processes that show web pages. A preload script bridges them, and IPC messages carry requests between them. Reading Electron code means tracking which process each file runs in.
How to tell it's Electron
electronindevDependenciesand amainfield inpackage.jsonnew BrowserWindow(...)andwebPreferences.preloadipcMain.handle,ipcRenderer.invokeandcontextBridge.exposeInMainWorld
Where things usually live
- src/main/ or electron/main.ts
- Main process: app lifecycle, windows, menus, native APIs.
- src/preload/
- Preload scripts exposing a safe API to the page with
contextBridge. - src/renderer/
- The UI, often a React or Vue app.
- electron-builder.yml or forge.config.ts
- Packaging, signing, auto-update settings.
Conventions, not rules. Real projects rename and move things, so confirm against the repository.
Where to start reading
package.jsonmain, which points to the main process entry- The preload script, which defines everything the UI can ask for
ipcMain.handleregistrations
How a request moves through the code
- Electron starts the main process, which creates a
BrowserWindowwith a preload script. - The preload script exposes functions on
windowthroughcontextBridge. - The renderer calls one, such as
window.api.saveFile(data). - That sends an IPC message on a channel;
ipcMain.handlefor that channel runs in the main process. - The main process uses Node or OS APIs and returns a result to the renderer.
Questions to ask about the repository
- List every IPC channel with its handler and caller.
- What does the preload script expose to the renderer?
- Is
nodeIntegrationoff andcontextIsolationon for every window?
What trips people up
- Renderer code can't use Node APIs when context isolation is on; such calls must go through the preload bridge.
- IPC channel names are strings, so search for them across main, preload and renderer.
- Enabling
nodeIntegrationin a window that loads remote content is a serious security risk.