0Pricing
React Academy · Lesson

Electron Architecture: Main and Renderer Processes

Understand Electron's multi-process model: main process for native APIs and renderer process for React UI.

Electron Architecture: Main and Renderer Processes is a free React Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the React Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

What Is Electron?

Electron is a framework that combines Chromium (for web rendering) with Node.js (for native API access), enabling developers to build cross-platform desktop applications using familiar web technologies. Your React app runs inside a Chromium browser window, while Node.js gives you access to operating system capabilities.

The Main Process

The main process is the entry point of an Electron application — it manages the application lifecycle, creates and controls windows, and handles native OS interactions. It spawns renderer processes and has full access to Node.js APIs and the underlying operating system.

The Renderer Process

Each BrowserWindow spawns its own renderer process, which runs Chromium and executes your React application. There is one renderer process per window, and it behaves much like a regular browser tab — it renders HTML, CSS, and JavaScript.

Main Process Capabilities

Because the main process has full Node.js access, it can read and write the file system, create native menus, manage the system tray, spawn child processes, and interact with hardware. These capabilities are unavailable in the renderer by default for security reasons.

Renderer Process Sandboxing

When contextIsolation is set to true (the modern default), the renderer process is sandboxed and cannot directly access Node.js APIs. This security model prevents malicious web content from accessing your file system or executing arbitrary system commands.

IPC: The Bridge Between Processes

Inter-Process Communication (IPC) is the mechanism that allows the main and renderer processes to exchange messages. The main process uses ipcMain to listen for and respond to messages, while the renderer uses ipcRenderer to send them — all communication is asynchronous and message-based.

The Preload Script

The preload script occupies a special middle ground: it runs in the renderer process context but retains access to Node.js APIs before the page content loads. This makes it the secure bridge between the sandboxed renderer and the privileged main process.

contextBridge: Safe API Exposure

contextBridge.exposeInMainWorld allows the preload script to selectively expose a safe, curated API to the renderer. The renderer can call these exposed functions without ever getting direct access to Node.js or Electron internals, maintaining a strong security boundary.

Accessing Exposed APIs from React

Once contextBridge has exposed an API under a name like "api", your React components can call it via window.api.myFunction(). This feels just like calling a regular JavaScript function, but under the hood it routes through IPC to the main process.

Security Model Summary

The Electron security model explicitly forbids direct Node.js access in the renderer when contextIsolation is enabled. All privileged operations must go through the preload script and contextBridge, ensuring that even if an XSS attack occurs in the renderer, it cannot access the file system.

Process Communication Flow

A typical interaction flows like this: React component calls window.api.readFile() → preload invokes ipcRenderer.invoke() → main process ipcMain.handle() executes fs.readFile() → result returns as a Promise to the renderer. This architecture keeps the renderer clean and secure.

contextBridge Purpose

What is the primary purpose of contextBridge.exposeInMainWorld in Electron?

Lesson Recap

Electron combines Chromium and Node.js: the main process manages the app lifecycle and has full OS access, while renderer processes run your React UI in a sandboxed environment. The preload script and contextBridge form the secure bridge, and IPC enables safe communication between the privileged main process and the isolated renderer.

Frequently asked questions

Is the “Electron Architecture: Main and Renderer Processes” lesson free?

Yes — the full text of “Electron Architecture: Main and Renderer Processes” is free to read here on the web, and the React Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the React Academy course, upgrade to CoddyKit PRO.

What will I learn in “Electron Architecture: Main and Renderer Processes”?

Understand Electron's multi-process model: main process for native APIs and renderer process for React UI. You practise React Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start React Academy?

No prior experience is required. React Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Electron Architecture: Main and Renderer Processes” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this React Academy lesson?

Yes. Every React Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Electron Architecture: Main and Renderer Processes
  2. Setting Up React with Electron
  3. IPC Communication Between Processes
  4. Packaging and Distribution for Desktop Platforms
← Back to React Academy