Skip to content

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

  • electron in devDependencies and a main field in package.json
  • new BrowserWindow(...) and webPreferences.preload
  • ipcMain.handle, ipcRenderer.invoke and contextBridge.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

  1. package.json main, which points to the main process entry
  2. The preload script, which defines everything the UI can ask for
  3. ipcMain.handle registrations

How a request moves through the code

  1. 1Electron starts the main process, which creates a BrowserWindow with a preload script.
  2. 2The preload script exposes functions on window through contextBridge.
  3. 3The renderer calls one, such as window.api.saveFile(data).
  4. 4That sends an IPC message on a channel; ipcMain.handle for that channel runs in the main process.
  5. 5The 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 nodeIntegration off and contextIsolation on 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 nodeIntegration in a window that loads remote content is a serious security risk.