# mayneyao/eidos architecture

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

- Interactive diagram: https://gitdiagram.com/mayneyao/eidos
- Repository: https://github.com/mayneyao/eidos

## Overview

##### Main Components
- Desktop App (Electron-based): This is the recommended, fully featured offline version. Include subcomponents such as:
- Electron Main Process & Preload Scripts (found under the “electron” folder)
- Window Manager and IPC (for inter-process communications)
- Native integrations (file-system, updater, protocol handler)
- Publish App: Represents another mode – perhaps for exporting or publishing data – located in apps/publish.
- Core Data Modules and Database Backends:
- SQLite Integration: Both the native SQLite in Electron and SQLite-wasm in the browser.
- Local Data Storage: Modules under lib/storage, which interact with IndexedDB or native files.
- AI and Extension Framework:
- AI integration modules (e.g., components/ai-chat, lib/ai, and worker/service-worker/ai)
- Extension mechanisms including Micro blocks, Doc Plugin, Script, and UDF functionality (visible in various folders including apps/desktop/settings and components/doc/plugins)
- Worker and Background Services:
- Background workers (worker folder) for tasks like data transformation, SQLite operations in a web-worker context, and AI processing.
- API/SDK Layer and Hooks:
- Common hooks (under “hooks”) and API/SDK modules (lib/action, lib/ai/functions, etc.) that allow extension and integration.
- Presentation/Rendering Components:
- A thorough components library (components/*) that handles UI elements from basic UI (buttons, dialogs, sidebar, etc.) to complex document and table rendering.

##### Relationships and Interactions
- For the Desktop App:
- How the Electron Main Process communicates with Renderer Processes (React UI) via IPC.
- How worker processes (electron/worker-manager and the worker folder) provide asynchronous data processing and AI features.
- For the Web App:
- PWA components that render in the browser, relying on SQLite-wasm for database operations.
- External libraries used in the web context (e.g., Lexical for the document editor, glide-data-grid for tables, web-llm for AI).
- Shared and Cross-Cutting Elements:
- The “lib” and “packages” directories hold core logic and standardization (e.g., a consistent SQLite interface throughout the system).
- The extension points (micro blocks, doc plugins, scripts) allow modular customization – indicate these as plug-in modules that hook into various parts of the system.

##### Important Architectural Patterns and Technologies
- Modular and Extensible Design: The project’s directory structure separates concerns into independent modules (UI components, hooks, workers, etc.) and extension points.
- Electron Architecture: Distinct separation between main process, renderer processes, and background services.
- Client-Side Database Standardization: Each “table” is a SQLite table, with standardized interfaces provided through lib/sqlite and related modules.
- Use of Web Workers/Service Workers: For asynchronous processing in both desktop and web contexts.
- Integration of AI Services: Using multiple vendors under lib/ai and components/ai-chat.
- Use of modern frontend frameworks and supporting libraries (e.g., React, Tailwind CSS, and Lexical).

##### Instructing the Principal Software Engineer
UI Components (Renderer) → IPC → Electron Main Process → Native File System / SQLite Provider.
Similarly, for the web app, show:
Web UI Components → Web Worker → SQLite-wasm / AI Processing.
- Blue for core application layers (Electron main/renderer)
- Green for data management and storage modules
- Orange for worker/service layers
- Purple for AI and extension modules.
- Connections with key protocols or library calls—for instance, mention “IPC”, “HTTP/WebRTC (for SQLite channel)”, or “Service Worker requests” where applicable.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        UI["UI Components Library"]:::blue
    end

    %% API/SDK & Hooks Layer
    subgraph "API/SDK & Hooks"
        API["API/SDK Modules"]:::blue
        Hooks["Hooks"]:::blue
    end

    %% Desktop App (Electron)
    subgraph "Desktop App (Electron)"
        WM["Window Manager & IPC"]:::blue
        EMP["Electron Main Process"]:::blue
        Preload["Preload Scripts"]:::blue
        NI["Native Integrations"]:::blue
        EWM["Electron Worker Manager"]:::orange
    end

    %% Web App (PWA)
    subgraph "Web App (PWA)"
        WEB["Web App Frontend"]:::blue
    end

    %% Publish App
    subgraph "Publish App"
        PA["Publish App Mode"]:::blue
        PP["SQLite Provider (Publish)"]:::green
        PW["Publish Worker"]:::orange
    end

    %% Core Data Modules
    subgraph "Core Data Modules"
        SS["SQLite Server"]:::green
        LDS["Local Data Storage"]:::green
    end

    %% Worker and Background Services
    subgraph "Workers & Background Services"
        BW["Background Workers"]:::orange
    end

    %% AI and Extension Framework
    subgraph "AI & Extension Framework"
        AI["AI Integration Modules"]:::purple
        EX["Extension Mechanisms"]:::purple
    end

    %% Connections from Presentation/ API to Desktop
    UI -->|"triggers"| API
    UI -->|"triggers"| Hooks
    API -->|"invokes"| WM
    Hooks -->|"hooksInto"| WM

    WM -->|"sendsIPC"| EMP
    EMP -->|"runs"| Preload
    EMP -->|"invokes"| NI
    EMP -->|"queries"| SS
    NI -->|"accesses"| LDS
    EMP -->|"communicates"| EWM
    EWM --> BW
    Hooks -->|"hooksInto"| WEB

    %% Connections from Presentation to Web App
    UI -->|"triggers"| WEB
    WEB -->|"delegatesTo"| BW
    WEB -->|"accesses"| LDS

    %% Connections from Presentation to Publish App
    UI -->|"postsDataTo"| PA
    PA --> PP
    PA --> PW
    PP -->|"queries"| SS
    PP -->|"accesses"| LDS

    %% Connections from Workers to AI & Extension Framework
    BW --> AI
    BW --> EX
    API --> EX

    %% AI & Extension feedback to Presentation Layer
    AI -->|"enhances"| UI
    EX -->|"customizes"| UI

    %% Style Definitions
    classDef blue fill:#b3d9ff,stroke:#1a75ff,stroke-width:2px;
    classDef green fill:#d6f5d6,stroke:#33cc33,stroke-width:2px;
    classDef orange fill:#ffe0b3,stroke:#ff9933,stroke-width:2px;
    classDef purple fill:#e6ccff,stroke:#9933ff,stroke-width:2px;
    
    %% Click Events
    click EMP "https://github.com/mayneyao/eidos/blob/dev/electron/main.ts"
    click Preload "https://github.com/mayneyao/eidos/blob/dev/electron/preload.ts"
    click WM "https://github.com/mayneyao/eidos/tree/dev/electron/window-manager/"
    click NI "https://github.com/mayneyao/eidos/tree/dev/electron/file-system/"
    click EWM "https://github.com/mayneyao/eidos/blob/dev/electron/worker-manager.ts"
    click WEB "https://github.com/mayneyao/eidos/tree/dev/apps/web-app"
    click PA "https://github.com/mayneyao/eidos/tree/dev/apps/publish"
    click PW "https://github.com/mayneyao/eidos/blob/dev/apps/publish/_worker.ts"
    click PP "https://github.com/mayneyao/eidos/tree/dev/apps/publish/lib/sqlite-provider"
    click SS "https://github.com/mayneyao/eidos/blob/dev/electron/sqlite-server/index.ts"
    click LDS "https://github.com/mayneyao/eidos/blob/dev/lib/storage/eidos-file-system.ts"
    click AI "https://github.com/mayneyao/eidos/tree/dev/components/ai-chat"
    click EX "https://github.com/mayneyao/eidos/tree/dev/components/doc/plugins"
    click API "https://github.com/mayneyao/eidos/blob/dev/lib/action/action.ts"
    click Hooks "https://github.com/mayneyao/eidos/blob/dev/hooks/use-actions.ts"
    click UI "https://github.com/mayneyao/eidos/tree/dev/components/"
```
