How electron/forge works
Project Type and Purpose
• This is a monorepo for “Electron Forge,” an open-source CLI and toolkit that unifies build, packaging, templating, plugin, maker and publisher workflows for Electron apps. It exposes:
• A CLI front-end (packages/api/cli)
• A core API (packages/api/core)
• A rich plugin system (under packages/plugin)
• Maker modules (packages/maker) for various target formats (deb, dmg, zip, AppX, etc.)
• Publisher modules (packages/publisher) for different endpoints (GitHub, S3, GCS, etc.)
• Project templates (packages/template)
• Utility libraries (packages/utils)
• External integration code (packages/external)
• Tooling scripts (tools/)
• It’s written in TypeScript, orchestrated with Lerna/Nx, tested via Vitest, and CI’d on CircleCI/GitHub Actions.
File-Structure Analysis
• Top-level config: lerna.json, nx.json, tsconfig.base.json, CI pipelines (.circleci, .github/workflows).
• Monorepo packages/ grouped by domain:
• api/cli and api/core – command dispatch and core orchestration
• external – wrappers for third-party tools (e.g., create-electron-app)
• maker – build-output generators
• plugin – plug-in extension points for webpack, vite, natives unpacking, etc.
• publisher – deployment targets
• template – boilerplate app templates
• utils – shared helpers (core-utils, test-utils, tracer, types, logger)
• Tools/ holds documentation and code-generation scripts.
• Each package has its own src/, spec/ or test/ directories, package.json, README and often a Config.ts + main class.
Key Architecture Insights from the README
• Core goals: single-command start → CLI → core API → sequence of init|start|make|publish steps
• Under the hood it orchestrates Electron Rebuild, Electron Packager and user-supplied plugins/makers/publishers.
• Extensible plugin/maker/publisher pattern so users can drop in new modules.
Diagramming the Architecture
a. Main Components to Model
• CLI Front-End (packages/api/cli)
• Core Orchestrator (packages/api/core)
• Plugin System (packages/plugin/*)
• Maker Modules (packages/maker/*)
• Publisher Modules (packages/publisher/*)
• Template Engine (packages/template/*)
• Utilities (packages/utils/*)
• External Tools (packages/external/*)
• CI/CD Pipelines (CircleCI, GitHub Actions)
b. Relationships & Interactions
• User invokes CLI → CLI parses commands/options → passes control to Core API
• Core API loads Config → initializes plugins → calls:
– init (template generation)
– start (dev server, watchers)
– make (Electron Packager + makers)
– publish (publishers)
• Plugins intercept build steps via hook interface, alter webpack/vite configs or native unpacking
• Makers produce output artifacts (dmg, deb, zip, AppX…)
• Publishers upload artifacts (GitHub, S3, GCS, etc.)
• Utilities provide shared helper functions (file resolution, process spawning, logging)
• External modules (e.g., create-electron-app) are thin wrappers that call API/CLI internally
c. Architectural Patterns & Principles
• Modular monorepo managed with Lerna/Nx
• Plugin architecture (inversion-of-control via hook interfaces)
• Strategy pattern for makers/publishers/templates
• Separation of concerns: CLI vs Core vs Extension modules vs Utilities
• TypeScript + strong typing for Config and plugin contracts
d. Key Technologies & Frameworks
• Node.js + TypeScript
• Electron Packager & Electron Rebuild
• Lerna & Nx for monorepo orchestration
• Vitest for testing
• ESLint, Prettier, Husky for code quality
• CircleCI & GitHub Actions for CI/CD