Build Electron Apps Like NestJS: Modular Architecture, Multi-Window Management, and Typed IPC Communication
When we develop Electron applications, the main process often becomes a tangled mess: window creation logic is scattered everywhere, ipcMain
handlers are registered imperatively all over the place, and communication logic is tightly coupled. Maintenance becomes increasingly difficult as the application grows.
As a full-stack developer with experience in NestJS, I wanted to apply Nestβs modular thinking to the Electron main process.
Thatβs why I created this project:
π π GitHub Repository: X29w/electronest
β¨ What Is This Project?
This is a highly scalable and elegant Electron + Vite + NestJS full-featured template that supports:
- π Main process architecture inspired by NestJS
- πͺ Modular multi-window management system
- π Type-safe, decorator-based IPC communication
- π¦ Independent NestJS server integrated into Electron
- π Built-in auto-registration of modules, services, and IPC handlers
- π‘ Perfect for large Electron applications
π Core Innovations
1. π§± NestJS-Inspired Architecture for Electron Main Process
Inspired by @Module()
, @Injectable()
, and @Controller()
in NestJS, this project brings a similar architecture to the Electron main process.
- IPC logic is encapsulated in modules
- Dependency injection is used for services
- Clean separation of concerns
β No more imperative
ipcMain.on(...)
scattered everywhere!
2. πͺ Declarative Multi-Window Management with Decorators
Instead of managing windows manually in random files, you can now use decorators like:
@RegisterWindow('home')
export class HomeWindow { ... }
And auto-register them via:
@AutoRegisterWindows([HomeWindow, SettingsWindow])
export class WindowModule {}
All windows are created declaratively, lifecycle-aware, and can expose methods for main/renderer communication.
3. π Decorator-Based IPC Communication (with TypeScript support)
You can define IPC handlers like this:
@IPCHandle('get-user-info')
handleUserInfo(payload: UserPayload) {
return this.userService.getUserInfo(payload.id);
}
And on the renderer side, TypeScript will provide autocomplete & type-checks:
window.electronAPI.invoke('get-user-info', { id: '123' });
β Supports full request/response structure, type inference, and automatic registration.
4. π Embedded NestJS Server
A full NestJS backend is embedded in Electron and runs alongside your main process. You can:
- Expose REST APIs
- Reuse backend logic in the main process
- Use it to drive IPC logic or window lifecycle behavior
This is especially useful for heavy logic processing or multi-window state management.
π¦ Tech Stack
- Electron β Desktop runtime
- Vite β Lightning-fast frontend builder
- React β UI rendering (can replace with Vue/Svelte/etc.)
- NestJS β Backend architecture (used inside and alongside Electron)
- TypeScript β Full type safety
π οΈ Get Started
git clone https://github.com/X29w/electronest
cd electronest
pnpm install
pnpm dev
Youβll have a fully running Electron app with a NestJS server, multi-window setup, and IPC system in just one command.
π Conclusion
This template is perfect for developers who:
- Want to build scalable Electron apps
- Prefer structured architecture
- Value type safety and modular design
- Are familiar with NestJS or want to bring backend patterns to desktop development
If you found this project interesting, feel free to βοΈ it on GitHub:
π https://github.com/X29w/electronest
Happy coding!
Top comments (0)