# plainlab/plainbelt architecture

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

- Interactive diagram: https://gitdiagram.com/plainlab/plainbelt
- Repository: https://github.com/plainlab/plainbelt

## Overview

##### Main Components
a. Electron Main Process:
- Represented in the files like src/main.dev.ts and src/menu.ts—this process boots the app and creates windows, handles system tray functionality, and manages global hotkeys.
b. Electron Renderer Process:
- Shown by the presence of src/index.html, src/index.tsx, and all the React components (in src/components). This component renders the UI and encapsulates the various tools.
c. Build/Configuration and Assets:
- The .erb directory holds Electron-specific assets, configurations, and build scripts (webpack configs, ESLint configs, and various scripts for building, notarizing, and rebuilding native dependencies). It is essential to indicate that these resources control how the packaged application is built and deployed.
d. Utility/Helper Functions and Styles:
- Helpers in src/helpers and styling/configuration in tailwind.config.js, postcss.config.js, and babel.config.js are key for rendering consistency and cross-platform performance.

##### Diagramming the Relationships and Interactions
- Inside the Renderer Process, divide it into multiple smaller modules encapsulating the various tool components (e.g., Unix Timestamp Converter, Cron Editor, Markdown Converter, etc.)—each represented as separate blocks.

##### Architectural Patterns and Design Principles
- The separation into a Main Process (for desktop integration and system-level management) and a Renderer Process (powered by React and TypeScript) is a common, robust Electron architecture pattern. Highlight this separation.
- The extensive use of modular components (each tool provided in its own file under src/components) suggests maintainability and ease of extension. Emphasize modularity and encapsulation.

##### Technologies and Frameworks
- Electron: Underpins the desktop app as evidenced by build scripts like ElectronRebuild.js, Notarize.js, and the main process files.
- React with TypeScript: Indicated by the presence of .tsx files in the src/components folder along with the TypeScript configuration (tsconfig.json).
- Webpack & Babel: Multiple webpack configuration files hint at a flexible and multi-target build approach (for production and development for both main and renderer processes).
- Tailwind CSS & PostCSS: For styling, as seen with tailwind.config.js and postcss.config.js.
- ESLint: With configuration files in multiple locations to ensure code quality.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% PlainBelt Application
    subgraph "PlainBelt Application"
        %% Electron Processes
        subgraph "Electron Processes"
            subgraph "Main Process"
                MainDev("Boot Process (src/main.dev.ts)"):::mainStyle
                Menu("Menu & Tray Handler (src/menu.ts)"):::mainStyle
            end
            subgraph "Renderer Process"
                RendererHTML("Core HTML (src/index.html)"):::rendererStyle
                RendererTS("Renderer Boot (src/index.tsx)"):::rendererStyle
                subgraph "Tools"
                    Tools("UI Tools (src/components)"):::rendererStyle
                    Timestamp("Timestamp Converter"):::toolStyle
                    Cron("Cron Editor"):::toolStyle
                    Markdown("Markdown Converter"):::toolStyle
                end
            end
        end

        %% System Integrations (managed by Main Process)
        subgraph "System Integrations"
            SysClipboard("Clipboard Auto-detection"):::sysIntegrations
            SysHotkey("Global Hotkey Listener"):::sysIntegrations
            SysTray("Tray Icon Handler"):::sysIntegrations
        end

        %% Build/Configuration and Assets
        subgraph "Build & Configuration"
            BuildMain("Assets & Build Scripts (.erb)"):::buildStyle
            BuildConfigs("Configs (.erb/configs)"):::buildStyle
            BuildScripts("Scripts (.erb/scripts)"):::buildStyle
            BuildAssets("Assets (.erb/assets)"):::buildStyle
        end

        %% Utility/Helper Functions and Styles
        subgraph "Utilities"
            Helpers("Helpers (src/helpers)"):::utilStyle
            Tailwind("Tailwind Config (tailwind.config.js)"):::utilStyle
            PostCSS("PostCSS Config (postcss.config.js)"):::utilStyle
            Babel("Babel Config (babel.config.js)"):::utilStyle
        end
    end

    %% Connections within Electron Processes
    MainDev -->|"creates window"| RendererTS
    RendererTS -->|"loads"| RendererHTML
    RendererTS -->|"renders"| Tools
    Tools -->|"includes"| Timestamp
    Tools --> Cron
    Tools --> Markdown

    %% Connections from Main Process to System Integrations
    Menu -->|"controls"| SysClipboard
    Menu -->|"controls"| SysHotkey
    Menu -->|"controls"| SysTray

    %% Build & Configuration integration
    BuildMain --- BuildConfigs
    BuildMain --- BuildScripts
    BuildMain --- BuildAssets
    BuildMain ---|feeds| MainDev
    BuildMain ---|feeds| RendererHTML

    %% Utilities integration
    Helpers --- Tailwind
    Helpers --- PostCSS
    Helpers --- Babel
    Helpers ---|supports| MainDev
    Helpers ---|supports| RendererTS

    %% Click Events for Component Mapping
    click MainDev "https://github.com/plainlab/plainbelt/blob/develop/src/main.dev.ts"
    click Menu "https://github.com/plainlab/plainbelt/blob/develop/src/menu.ts"
    click RendererHTML "https://github.com/plainlab/plainbelt/blob/develop/src/index.html"
    click RendererTS "https://github.com/plainlab/plainbelt/blob/develop/src/index.tsx"
    click Tools "https://github.com/plainlab/plainbelt/tree/develop/src/components"
    click BuildMain "https://github.com/plainlab/plainbelt/blob/develop/.erb"
    click BuildConfigs "https://github.com/plainlab/plainbelt/tree/develop/.erb/configs"
    click BuildScripts "https://github.com/plainlab/plainbelt/tree/develop/.erb/scripts"
    click BuildAssets "https://github.com/plainlab/plainbelt/tree/develop/.erb/assets"
    click Helpers "https://github.com/plainlab/plainbelt/tree/develop/src/helpers"
    click Tailwind "https://github.com/plainlab/plainbelt/blob/develop/tailwind.config.js"
    click PostCSS "https://github.com/plainlab/plainbelt/blob/develop/postcss.config.js"
    click Babel "https://github.com/plainlab/plainbelt/blob/develop/babel.config.js"

    %% Styles
    classDef mainStyle fill:#ADD8E6,stroke:#000,stroke-width:1px,color:#000;
    classDef rendererStyle fill:#90EE90,stroke:#000,stroke-width:1px,color:#000;
    classDef toolStyle fill:#98FB98,stroke:#000,stroke-width:1px,color:#000;
    classDef buildStyle fill:#FFD700,stroke:#000,stroke-width:1px,color:#000;
    classDef utilStyle fill:#FFA500,stroke:#000,stroke-width:1px,color:#000;
    classDef sysIntegrations fill:#FFB6C1,stroke:#000,stroke-width:1px,color:#000;
```
