# archergu/vite-react-nestjs-electron architecture

> Architecture diagram of the GitHub repository archergu/vite-react-nestjs-electron, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-08-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/archergu/vite-react-nestjs-electron
- Repository: https://github.com/archergu/vite-react-nestjs-electron

## Overview

##### Project type and purpose
- This is an Electron-based desktop application template that combines:
- A NestJS-style “main process” for business logic and IPC endpoints
- A Vite-powered React “renderer process” for the UI
- A preload script that securely exposes IPC APIs to the renderer
- Purpose: give developers a boilerplate to build desktop apps with familiar web and Node backend frameworks (NestJS, Vite, React), packaged via electron-builder.

##### File structure
- Top-level config files:
- electron-builder.config.js – packaging rules
- vite.config.mts – build/dev server for renderer
- tsconfig.json / tsconfig.node.json – TypeScript settings
- package.json / pnpm-lock.yaml – dependencies & scripts
- src/main – Electron main process, structured like a NestJS app
- app.module.ts, app.controller.ts, app.service.ts: MVC modules, controllers, services
- index.ts: bootstraps Nest application inside Electron main
- src/preload – The preload script
- index.ts / index.d.ts: bridges main-renderer via secure IPC
- src/render – The React frontend
- main.tsx / App.tsx: entrypoints and root component
- index.html, assets, CSS: static UI resources
- CI/config: .github/workflows/ci.yml, renovate.json, .npmrc for pnpm, eslint.config.mjs

##### README insights
- Confirms use of:
- vite-plugin-doubleshot to run & build main process like a Node backend
- electron-nestjs modules for IPC transport and window management
- tsup and electron-builder via @doubleshot/builder for packaging
- Highlights fast DX & full integration between NestJS and Electron

a. Main components
- Electron Main Process (NestJS application)
- IPC Transport Layer (nestjs-electron IPC module)
- Preload Script (contextBridge exposing safe APIs)
- Renderer Process (React + Vite)
- Build & Packaging Tools (Doubleshot/Vite plugin, tsup, electron-builder)
- Local file system, OS window manager
b. Relationships & interactions
- Renderer ↔ Preload via window.api.* calls
- Preload ↔ Main Process via ipcRenderer / ipcMain channels
- Main controllers/services handle requests and manage state or file I/O
- Build tools transform src/main and src/render into production bundles
c. Architectural patterns
- MVC in the NestJS-style main process
- Modular separation: main, preload, render
- IPC-based service boundary between UI and backend logic
- Plugin-driven build orchestration (Doubleshot)
d. Key technologies
- Electron (main & renderer processes)
- NestJS and its Module/Controller/Service pattern
- Vite + React in the render layer
- TypeScript throughout
- electron-builder for packaging

##### Detail
- Electron-builder invoking tsup for main and Vite for renderer at build time
- OS window manager as an external actor if window lifecycle is crucial
- Don’t shy away from layering: present dev vs. prod flows if beneficial

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Runtime Layers
    subgraph "React Renderer"
        direction TB
        RendererEntry["Renderer Entry (main.tsx)"]:::ui
        RendererApp["App Component (App.tsx)"]:::ui
        RendererCSS["Stylesheet (App.css)"]:::ui
        RendererHTML["HTML Template (index.html)"]:::ui
        RendererAssets["Assets Directory"]:::ui
        RendererPublic["Public Files"]:::ui
        RendererTypes["Renderer Types (vite-env.d.ts)"]:::ui
    end

    subgraph "Preload Bridge"
        direction TB
        PreloadIndex["Preload Script (index.ts)"]:::ipc
        PreloadDefs["Preload Types (index.d.ts)"]:::ipc
    end

    subgraph "Electron Main Process (NestJS)"
        direction TB
        MPIndex["Bootstrap (index.ts)"]:::backend
        AppModule["AppModule"]:::backend
        AppController["AppController"]:::backend
        AppService["AppService"]:::backend
    end

    %% Build Tools
    subgraph "Build Tools"
        direction TB
        ViteConfig["Vite Config (vite.config.mts)"]:::build
        TSNodeConfig["TS Node Config (tsconfig.node.json)"]:::build
        EBConfig["Electron Builder Config"]:::build
        PkgJson["package.json"]:::build
        Lockfile["pnpm-lock.yaml"]:::build
        TSConfig["tsconfig.json"]:::build
        CI["CI Workflow"]:::build
        Renovate["renovate.json"]:::build
        NpmRC[".npmrc"]:::build
        ESLint["eslint.config.mjs"]:::build
    end

    %% External
    OS["OS Window Manager"]:::external
    ApplicationBundle["Packaged App"]:::external

    %% Relationships
    RendererEntry -->|uses window.api| PreloadIndex
    RendererApp -->|calls API| PreloadIndex
    PreloadIndex -->|invokes ipcMain| MPIndex
    MPIndex -->|loads modules| AppModule
    AppModule -->|routes| AppController
    AppController -->|calls| AppService
    AppService -->|accesses OS| OS
    AppService -->|responds| PreloadIndex
    PreloadIndex -->|returns data| RendererApp

    %% Dev & Build
    ViteConfig -->|dev server| RendererEntry
    PkgJson -->|scripts| EBConfig
    EBConfig -->|packages| ApplicationBundle
    EBConfig -->|triggers build| TSNodeConfig
    EBConfig -->|triggers build| ViteConfig
    TSNodeConfig -->|builds main| MPIndex
    ViteConfig -->|builds renderer| RendererEntry

    %% Click Events
    click MPIndex "https://github.com/archergu/vite-react-nestjs-electron/blob/main/src/main/index.ts"
    click AppModule "https://github.com/archergu/vite-react-nestjs-electron/blob/main/src/main/app.module.ts"
    click AppController "https://github.com/archergu/vite-react-nestjs-electron/blob/main/src/main/app.controller.ts"
    click AppService "https://github.com/archergu/vite-react-nestjs-electron/blob/main/src/main/app.service.ts"
    click PreloadIndex "https://github.com/archergu/vite-react-nestjs-electron/blob/main/src/preload/index.ts"
    click PreloadDefs "https://github.com/archergu/vite-react-nestjs-electron/blob/main/src/preload/index.d.ts"
    click RendererEntry "https://github.com/archergu/vite-react-nestjs-electron/blob/main/src/render/main.tsx"
    click RendererApp "https://github.com/archergu/vite-react-nestjs-electron/blob/main/src/render/App.tsx"
    click RendererCSS "https://github.com/archergu/vite-react-nestjs-electron/blob/main/src/render/App.css"
    click RendererHTML "https://github.com/archergu/vite-react-nestjs-electron/blob/main/src/render/index.html"
    click RendererAssets "https://github.com/archergu/vite-react-nestjs-electron/tree/main/src/render/assets/"
    click RendererPublic "https://github.com/archergu/vite-react-nestjs-electron/tree/main/src/render/public/"
    click RendererTypes "https://github.com/archergu/vite-react-nestjs-electron/blob/main/src/render/vite-env.d.ts"
    click EBConfig "https://github.com/archergu/vite-react-nestjs-electron/blob/main/electron-builder.config.js"
    click ViteConfig "https://github.com/archergu/vite-react-nestjs-electron/blob/main/vite.config.mts"
    click TSConfig "https://github.com/archergu/vite-react-nestjs-electron/blob/main/tsconfig.json"
    click TSNodeConfig "https://github.com/archergu/vite-react-nestjs-electron/blob/main/tsconfig.node.json"
    click PkgJson "https://github.com/archergu/vite-react-nestjs-electron/blob/main/package.json"
    click Lockfile "https://github.com/archergu/vite-react-nestjs-electron/blob/main/pnpm-lock.yaml"
    click CI "https://github.com/archergu/vite-react-nestjs-electron/blob/main/.github/workflows/ci.yml"
    click Renovate "https://github.com/archergu/vite-react-nestjs-electron/blob/main/renovate.json"
    click NpmRC "https://github.com/archergu/vite-react-nestjs-electron/blob/main/.npmrc"
    click ESLint "https://github.com/archergu/vite-react-nestjs-electron/blob/main/eslint.config.mjs"

    %% Styles
    classDef backend fill:#D0E8FF,stroke:#3B82F6
    classDef ipc fill:#E6F9E6,stroke:#10B981
    classDef ui fill:#FEF9C3,stroke:#F59E0B
    classDef build fill:#F3F4F6,stroke:#6B7280
    classDef external fill:#F5F5F5,stroke:#9CA3AF,stroke-dasharray: 5 5
```
