Architecture Overview
Electron apps have three main components:- Main process - Node.js backend, manages windows and system access
- Renderer process - Chromium frontend, runs the React UI
- Preload scripts - Secure bridge between main and renderer
Main Process
The main process is the entry point for the Electron app.Location and Configuration
- Source:
apps/x/apps/main/src/main.ts - Output:
.package/dist/main.cjs(bundled) - Package:
apps/x/apps/main/package.json
Build Process
The main process uses a two-step build:Why bundle? pnpm uses symlinks for workspace packages. Electron Forge’s dependency walker can’t follow symlinks. Bundling with esbuild creates a single file with all code, eliminating the need for
node_modules in the packaged app.Dependencies
Renderer Process
The renderer process is a React application built with Vite.Location and Configuration
- Source:
apps/x/apps/renderer/src/main.tsx - Output:
apps/renderer/dist/ - Dev server:
http://localhost:5173
Development Mode
In development, Vite provides:- Fast hot module replacement (HMR)
- Instant updates without full reload
- React Fast Refresh
The main process waits for the Vite dev server to be ready before starting Electron. This is handled by the
wait-on package.Technology Stack
- React 19 - UI framework
- Vite 7 - Build tool and dev server
- TailwindCSS - Utility-first CSS
- Radix UI - Accessible component primitives
- TypeScript - Type safety
Preload Scripts
Preload scripts run in a context that has access to both Node.js APIs and the DOM.Location and Purpose
- Source:
apps/x/apps/preload/src/preload.ts - Output:
apps/preload/dist/preload.js - Purpose: Expose safe APIs to the renderer via
contextBridge
Security Model
Build Order and Dependencies
The workspace packages must be built in a specific order:Building Dependencies
npm run deps command chains these together:
Development Workflow
Starting the App
The
dev script uses concurrently to run both:
Making Changes
Renderer (Hot Reload)
Changes to React components hot-reload automatically:Main Process (Restart Required)
Changes to the main process require a restart:Shared/Core Packages (Rebuild Required)
Changes to workspace packages require rebuilding:Common Development Tasks
Add a New Dependency
Add a Shared Type
Verify Compilation
Electron Entry Points
| Component | Entry | Output |
|---|---|---|
| main | apps/main/src/main.ts | .package/dist/main.cjs |
| renderer | apps/renderer/src/main.tsx | apps/renderer/dist/ |
| preload | apps/preload/src/preload.ts | apps/preload/dist/preload.js |
Key Configuration Files
forge.config.cjs- Electron Forge packaging configurationbundle.mjs- esbuild bundler for main processvite.config.ts- Vite configuration for renderertsconfig.json- TypeScript compiler options (per package)