# alextorresdev/custom-electron-titlebar architecture

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

- Interactive diagram: https://gitdiagram.com/alextorresdev/custom-electron-titlebar
- Repository: https://github.com/alextorresdev/custom-electron-titlebar

## Overview

##### Project Type and Purpose
- The project is a TypeScript library specifically made for Electron applications.
- Its purpose is to provide a customizable title bar and menu system that replaces or enhances the native Electron title bar.
- Key usage is demonstrated by the README with code examples for integration in both main (using setupTitlebar and attachTitlebarToWindow) and preload (instantiating the Titlebar) contexts.

##### Analyzing the File Structure
- Top-level directories and files (such as src, example, docs, __test__, __mocks__) indicate that the project is maintained with good test coverage and documentation.
- The src directory is organized into several components/layers:
- src/base: Contains common utilities and browser-related functionality (like event handling, keyboard/mouse/touch, decorators, etc.), suggesting modular helper functions.
- src/main: Contains code that integrates with Electron’s main process to set up and attach the custom title bar to windows.
- src/menubar: Contains the logic for managing the menu structure (menu items, submenus, separators) for the custom title bar.
- src/titlebar: Contains the main titlebar component implementation and configuration options.
- Additional directories include:
- static/theme for the CSS styles tailored for different platforms (base, mac, win).
- example contains a sample Electron application to demonstrate the library's usage.
- Presence of build and configuration files (babel, eslint, tsconfig, GitHub Actions workflows) indicates the project follows modern development practices with CI/CD pipelines and code quality enforcement.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Electron Main Process Integration
    subgraph "Electron Main Process"
        A["setupTitlebar"] 
        B["attachTitlebarToWindow"]
        A -->|"initializes"| B
    end

    %% Renderer Process Integration
    subgraph "Renderer Process"
        C["Preload Script"]
        subgraph "Titlebar Component"
            D["Main Titlebar Implementation"]
            E["Titlebar Configuration Options"]
            F["Themebar Functionality"]
            D -->|"configuredBy"| E
            D -->|"enhancedBy"| F
        end
        C -->|"instantiates"| D
    end

    %% Menubar Component
    subgraph "Menubar"
        G["Menubar Core Logic"]
        H["Menu Items"]
        I["Menu Separators"]
        J["Menu Submenus"]
        K["Menubar Options"]
        %% Internal relationships among menu elements
        G -->|"composes"| H
        G -->|"composes"| I
        G -->|"composes"| J
        G -->|"configuredBy"| K
    end

    %% Base and Utility Modules
    subgraph "Base and Utilities"
        M["User Interactions"]
        L["Shared Base Utilities"]
        M -->|"triggers"| L
    end

    %% Styling and Theming
    subgraph "Styling and Theming"
        N["Base Theme"]
        O["Mac Theme"]
        P["Windows Theme"]
    end

    %% Inter-layer Connections
    B -->|"attachesTo"| C
    D -->|"integratesWith"| G
    D -->|"uses"| L
    G -->|"uses"| L
    D -->|"appliesTheme"| N
    D -->|"appliesTheme"| O
    D -->|"appliesTheme"| P

    %% Styles
    classDef main fill:#ffe6e6,stroke:#ff0000,stroke-width:2px;
    classDef renderer fill:#e6faff,stroke:#0066ff,stroke-width:2px;
    classDef menubar fill:#e6ffe6,stroke:#00cc00,stroke-width:2px;
    classDef utilities fill:#fef9e7,stroke:#f39c12,stroke-width:2px;
    classDef theming fill:#f0e6ff,stroke:#8e44ad,stroke-width:2px;

    class A,B main;
    class C,D,E,F renderer;
    class G,H,I,J,K menubar;
    class L,M utilities;
    class N,O,P theming;

    %% Click Events for Main Process Integration
    click A "https://github.com/alextorresdev/custom-electron-titlebar/blob/main/src/main/setup-titlebar.ts"
    click B "https://github.com/alextorresdev/custom-electron-titlebar/blob/main/src/main/attach-titlebar-to-window.ts"

    %% Click Events for Renderer Process Integration
    click C "https://github.com/alextorresdev/custom-electron-titlebar/blob/main/example/preload.js"
    click D "https://github.com/alextorresdev/custom-electron-titlebar/blob/main/src/titlebar/index.ts"
    click E "https://github.com/alextorresdev/custom-electron-titlebar/blob/main/src/titlebar/options.ts"
    click F "https://github.com/alextorresdev/custom-electron-titlebar/blob/main/src/titlebar/themebar.ts"

    %% Click Events for Menubar Component
    click G "https://github.com/alextorresdev/custom-electron-titlebar/blob/main/src/menubar/index.ts"
    click H "https://github.com/alextorresdev/custom-electron-titlebar/blob/main/src/menubar/menu/item.ts"
    click I "https://github.com/alextorresdev/custom-electron-titlebar/blob/main/src/menubar/menu/separator.ts"
    click J "https://github.com/alextorresdev/custom-electron-titlebar/blob/main/src/menubar/menu/submenu.ts"
    click K "https://github.com/alextorresdev/custom-electron-titlebar/blob/main/src/menubar/menubar-options.ts"

    %% Click Event for Base and Utility Modules
    click L "https://github.com/alextorresdev/custom-electron-titlebar/tree/main/src/base"

    %% Click Events for Styling and Theming
    click N "https://github.com/alextorresdev/custom-electron-titlebar/blob/main/static/theme/base.css"
    click O "https://github.com/alextorresdev/custom-electron-titlebar/blob/main/static/theme/mac.css"
    click P "https://github.com/alextorresdev/custom-electron-titlebar/blob/main/static/theme/win.css"
```
