# kontains/selectron architecture

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

- Interactive diagram: https://gitdiagram.com/kontains/selectron
- Repository: https://github.com/kontains/selectron

## Overview

##### Main System Components

a) Core Runtime Layer (Rust)
- Main Rust components from /src:
- backend.rs
- frontend.rs
- ipcchannel.rs
- main.rs

b) API Emulation Layer (Middle)
Three main API groups:
- Electron APIs (/src/electron)
- Node APIs (/src/node)
- Common APIs (/src/common)

c) WebView Layer (Top)
Two distinct WebView containers:
- NodeJS Backend WebView
- Electron Frontend WebView(s)

##### Component Relationships

- IPC channel connections between Frontend and Backend WebViews

##### Special Architectural Elements

Key features:
- XMLHttpRequest Communication System
- Native Browser Dev-Tools Integration
- Cross-Platform WebView Implementation

##### Implementation Details

Create subsections showing:
a) API Implementation Structure:
- Electron APIs (dialog, menu, etc.)
- Node APIs (fs, child_process, crypto, etc.)
- Addons (pty, spdlog, sqlite)

b) JavaScript Bridge:
- How /src/js connects frontend and backend
- Shared components in /src/js/shared

##### Technical Notes

Annotations for:
- Cross-platform compatibility
- Debug mode vs. Release mode
- API emulation strategy
- WebView isolation

##### The isolation of frontend and backend WebViews

Keep the abstraction level focused on the architectural components while showing enough detail to understand the unique approach of using Rust to emulate Electron/Node APIs through WebViews.

Remember to include a note about the build size optimization (10MB) and cross-platform nature of the application, as these are key architectural achievements of the system.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph WebView
        FW[Frontend WebView]
        BW[Backend WebView]
        FW_HTML["Frontend HTML"]:::html
        BW_HTML["Backend HTML Template"]:::html
    end

    subgraph API_Layer
        subgraph Electron_APIs
            DIALOG["Dialog API"]:::api
            MENU["Menu API"]:::api
        end

        subgraph Node_APIs
            FS["File System"]:::api
            CP["Child Process"]:::api
            NET["Network"]:::api
            CRYPTO["Crypto"]:::api
        end

        subgraph Node_Addons
            PTY["PTY"]:::addon
            SQLITE["SQLite"]:::addon
            SPDLOG["SPDLog"]:::addon
        end
    end

    subgraph Core_Runtime
        MAIN["Main Runtime"]:::core
        BACKEND["Backend Handler"]:::core
        FRONTEND["Frontend Handler"]:::core
        IPC["IPC Channel"]:::core
    end

    subgraph JS_Bridge
        FB["Frontend Bridge"]:::bridge
        BB["Backend Bridge"]:::bridge
        SHARED["Shared Components"]:::bridge
    end

    %% Connections
    FW <--> FB
    BW <--> BB
    FB <--> IPC
    BB <--> IPC
    FB --- SHARED
    BB --- SHARED
    
    IPC <--> FRONTEND
    IPC <--> BACKEND
    FRONTEND --- MAIN
    BACKEND --- MAIN

    Electron_APIs --> BACKEND
    Node_APIs --> BACKEND
    Node_Addons --> BACKEND

    %% Styling
    classDef core fill:#blue,stroke:#333,stroke-width:2px
    classDef api fill:#orange,stroke:#333,stroke-width:1px
    classDef addon fill:#orange,stroke:#333,stroke-width:1px
    classDef bridge fill:#purple,stroke:#333,stroke-width:1px
    classDef html fill:#green,stroke:#333,stroke-width:1px

    %% Click events
    click MAIN "https://github.com/kontains/selectron/blob/main/src/main.rs"
    click BACKEND "https://github.com/kontains/selectron/blob/main/src/backend.rs"
    click FRONTEND "https://github.com/kontains/selectron/blob/main/src/frontend.rs"
    click IPC "https://github.com/kontains/selectron/blob/main/src/ipcchannel.rs"
    click DIALOG "https://github.com/kontains/selectron/blob/main/src/electron/apis/dialog.rs"
    click FS "https://github.com/kontains/selectron/blob/main/src/node/apis/fs.rs"
    click CP "https://github.com/kontains/selectron/blob/main/src/node/apis/child_process.rs"
    click CRYPTO "https://github.com/kontains/selectron/blob/main/src/js/backend/node/apis/crypto.js"
    click NET "https://github.com/kontains/selectron/blob/main/src/node/apis/net.rs"
    click PTY "https://github.com/kontains/selectron/blob/main/src/node/addons/pty.rs"
    click SQLITE "https://github.com/kontains/selectron/blob/main/src/node/addons/sqlite.rs"
    click SPDLOG "https://github.com/kontains/selectron/blob/main/src/node/addons/spdlog.rs"
    click BW_HTML "https://github.com/kontains/selectron/blob/main/src/js/backend/backend.html"
    click BB "https://github.com/kontains/selectron/blob/main/src/js/backend/electrico.js"
    click FB "https://github.com/kontains/selectron/blob/main/src/js/frontend/electrico.js"
    click SHARED "https://github.com/kontains/selectron/tree/main/src/js/shared/"
```
