# vitaminc1989/electron-template architecture

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

- Interactive diagram: https://gitdiagram.com/vitaminc1989/electron-template
- Repository: https://github.com/vitaminc1989/electron-template

## Overview

##### Main Components
- Main Process – This includes components for initializing the application, managing windows, setting up IPC communication, logging, and data persistence. Files like src/main/index.ts, src/main/ipc.ts, src/main/windows/main.ts, src/main/logger.ts, and src/main/electronStore.ts are key here.
- Preload Scripts – These scripts run before the renderer process and expose a controlled API to it. Key files include src/preload/index.ts, src/preload/logger.ts, and src/preload/store.ts.
- Renderer Process – This part is built with Vue 3 and handles the user interface, routing, state management, and display of components. Look to files such as src/renderer/src/main.ts, App.vue, the Vue components, and router and store configurations.
- Configuration & Build Tools – Although not core logic, configuration files (like electron.vite.config.ts, electron-builder.yml, vite.config.ts, and the various tsconfig files) underline how the app is built, bundled, and deployed.

##### Relationships and Interactions
- Main Process and Preload: The preload scripts act as an intermediary, safely exposing IPC and storage APIs (e.g., logger, electron-store) from the main process to the renderer process.
- Data Persistence and Logging: Highlight how components like electronStore (in the main process) and the custom logging utilities (in both main and preload) interact with user actions or system events.
- External Configurations: Display how build and deployment configurations (such as electron-builder, Vite, and TypeScript settings) support the overall structure without being primary runtime components.

##### Architectural Patterns and Design Principles
- Separation of Concerns: The clear split between main, preload, and renderer processes.
- IPC Communication: The design ensures secure bi-directional communication between the renderer and the main process using preloaded APIs.
- Modular Organization: Components are organized modularly (e.g., different directories for components, plugins, router, and store in the Vue app; separate folders for main process utilities and window management).

##### Relevant Technologies
- Electron – Underlying framework for building the desktop application.
- Vue 3 – For building the UI in the renderer process.
- TypeScript – Enforces type safety across the project.
- electron-store – For persistent local data storage.
- electron-log – For logging functionality.
- Vite – For bundling and development server setups.
- ESLint/Prettier – For coding standards and formatting.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Main Process
    subgraph "Main Process"
        M1["Main: index.ts"]:::mainProc
        M2["IPC: ipc.ts"]:::mainProc
        M3["Logger: logger.ts"]:::mainProc
        M4["Store: electronStore.ts"]:::mainProc
        subgraph "Window Management"
            M5["Windows: main.ts"]:::mainProc
        end
    end

    %% Preload Scripts
    subgraph "Preload Scripts"
        P1["Preload: index.ts"]:::preload
        P2["Logger: logger.ts"]:::preload
        P3["Store: store.ts"]:::preload
    end

    %% Renderer Process
    subgraph "Renderer Process"
        R1["Renderer: index.html"]:::renderer
        R2["Vue Main: main.ts"]:::renderer
        R3["Vue App: App.vue"]:::renderer
        R4["Components"]:::renderer
        R5["Router"]:::renderer
        R6["Store"]:::renderer
    end

    %% IPC & Configuration
    subgraph "IPC & Configuration"
        C1["IPC Comm: communication.ts"]:::config
        C2["Windows Config: windows.ts"]:::config
        C3["CSP Config: CSP.ts"]:::config
    end

    %% Build & Deployment
    subgraph "Build & Deployment"
        B1["Electron Vite Config: electron.vite.config.ts"]:::build
        B2["Electron Builder: electron-builder.yml"]:::build
        B3["Vite Config: vite.config.ts"]:::build
        B4["TS Configs"]:::build
    end

    %% Connections between components
    R2 -->|"IPC_call"| P1
    P1 -->|"Exposes_API"| M2
    C1 -->|"configures"| M2
    R3 -->|"uses_Config"| C1
    M2 -->|"triggers"| M5
    M3 <==>|"sync"| P2
    M4 <==>|"sync"| P3
    R3 -->|"composes"| R4
    R3 -->|"routes"| R5
    R3 -->|"manages"| R6

    %% Styles for legend via classes
    classDef mainProc fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef preload fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef renderer fill:#d1ecf1,stroke:#0c5460,stroke-width:2px;
    classDef config fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef build fill:#f8d7da,stroke:#721c24,stroke-width:2px;

    %% Click Events for Main Process
    click M1 "https://github.com/vitaminc1989/electron-template/blob/main/src/main/index.ts"
    click M2 "https://github.com/vitaminc1989/electron-template/blob/main/src/main/ipc.ts"
    click M3 "https://github.com/vitaminc1989/electron-template/blob/main/src/main/logger.ts"
    click M4 "https://github.com/vitaminc1989/electron-template/blob/main/src/main/electronStore.ts"
    click M5 "https://github.com/vitaminc1989/electron-template/blob/main/src/main/windows/main.ts"

    %% Click Events for Preload Scripts
    click P1 "https://github.com/vitaminc1989/electron-template/blob/main/src/preload/index.ts"
    click P2 "https://github.com/vitaminc1989/electron-template/blob/main/src/preload/logger.ts"
    click P3 "https://github.com/vitaminc1989/electron-template/blob/main/src/preload/store.ts"

    %% Click Events for Renderer Process
    click R1 "https://github.com/vitaminc1989/electron-template/blob/main/src/renderer/index.html"
    click R2 "https://github.com/vitaminc1989/electron-template/blob/main/src/renderer/src/main.ts"
    click R3 "https://github.com/vitaminc1989/electron-template/blob/main/src/renderer/src/App.vue"
    click R4 "https://github.com/vitaminc1989/electron-template/tree/main/src/renderer/src/components"
    click R5 "https://github.com/vitaminc1989/electron-template/tree/main/src/renderer/src/router"
    click R6 "https://github.com/vitaminc1989/electron-template/tree/main/src/renderer/src/store"

    %% Click Events for IPC & Configuration
    click C1 "https://github.com/vitaminc1989/electron-template/blob/main/src/config/communication.ts"
    click C2 "https://github.com/vitaminc1989/electron-template/blob/main/src/config/windows.ts"
    click C3 "https://github.com/vitaminc1989/electron-template/blob/main/src/config/CSP.ts"

    %% Click Events for Build & Deployment
    click B1 "https://github.com/vitaminc1989/electron-template/blob/main/electron.vite.config.ts"
    click B2 "https://github.com/vitaminc1989/electron-template/blob/main/electron-builder.yml"
    click B3 "https://github.com/vitaminc1989/electron-template/blob/main/vite.config.ts"
    click B4 "https://github.com/vitaminc1989/electron-template/blob/main/tsconfig.json"
```
