# reorproject/reor architecture

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

- Interactive diagram: https://gitdiagram.com/reorproject/reor
- Repository: https://github.com/reorproject/reor

## Overview

##### Main Components
- Electron Environment:
– The main process (located in the “electron/main” directory) which houses many submodules: common utilities (chunking, error handling, window management), electron-store (for persistent config/data handling), and specialized modules such as “llm”, “filesystem”, “vector-database”, and “path”.
– The preload script in “electron/preload” that sets up a secure bridge between the Electron main process and the renderer.
- Renderer Process:
– Your React-based UI found in the “src” directory (App.tsx, components, contexts, lib, and styles) which implements the note-taking, chat, and settings functionality.
- Local Data and AI Modules:
– The LLM module (in “electron/main/llm” and “src/lib/llm”) interacts with local AI models (Ollama, Transformers.js) and handles Q&A, context retrieval, and supporting generative AI workflows.
– The vector-database component (in “electron/main/vector-database”) is responsible for embedding/chunking notes and performing semantic searches.
- External Service and Integration Modules:
– Integration with local models and potentially external APIs (e.g., as seen in the settings documentation from Reor and scripts for downloading or notarizing).

##### Relationships and Data Flow
– “common” and “electron-utils” for generic utilities.
– “llm” for AI model interactions.
– “filesystem” for handling note files.
– “vector-database” for semantic search and embeddings.
– “electron-store” for persistent storage.
– The React application drawn from “src” (which comprises UI components such as Chat interfaces, Editor, File management, Settings, and Sidebars).
– UI state management via the “contexts” directory, which binds the interactions.
– From the Renderer to the Main Process via the Preload’s IPC channels. The user actions (like a note update or a search query) propagate to the respective Electron modules (e.g., filesystem for note updates, vector-database for search, llm for Q&A).

##### Architectural Patterns and Design Principles
- Separation of Concerns:
– Electron main process handles OS-level tasks and back-end logic (LLM processing, database operations).
– The renderer (React UI) is solely responsible for user interactions and presentation.
- Modular Decomposition:
- IPC Messaging:
– Show clearly how the Preload layer bridges the security and communication between the main process and the renderer.
- Usage of External Libraries:
– Note that local AI functionality is built upon projects like Ollama, Transformers.js, and LanceDB, integrating into the vector-database and llm modules.

- Annotations that highlight technology (e.g., “React/TypeScript” for the UI layer, “Electron IPC” for communication, “Local LLM via Ollama” for AI components).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Electron Main Process and its Modules
    subgraph "Electron Main Process"
        EMP["Main Process"]:::main
        UTIL["Common Utilities"]:::module
        STORE["Electron-Store"]:::module
        FS["Filesystem Module"]:::module
        LLM_MOD["LLM Module"]:::module
        VECTOR["Vector-Database"]:::module
        PATH_MOD["Path Management"]:::module
    end

    %% Preload Script / IPC Bridge
    PRELOAD["Preload IPC Bridge"]:::preload

    %% Renderer Process and its Components
    subgraph "Renderer Process"
        UI["React UI"]:::renderer
        RLLM["Renderer LLM Functionality"]:::module
    end

    %% External Integration Scripts
    subgraph "External Integrations"
        DL_SCRIPT["Download Script"]:::external
        NT_SCRIPT["Notarize Script"]:::external
    end

    %% Data Flow Connections
    UI -->|"IPC"| PRELOAD
    PRELOAD -->|"IPC"| EMP
    UI -->|"NoteUpdate"| FS
    UI -->|"ChatQuery"| LLM_MOD
    UI -->|"SearchQuery"| VECTOR
    UI -->|"Settings"| STORE
    UI -->|"LLMReq"| RLLM
    DL_SCRIPT -->|"ModelDownload"| EMP
    NT_SCRIPT -->|"Notarization"| EMP

    %% Internal Module Connections within Electron Main Process
    EMP -->|"Utils"| UTIL
    EMP -->|"Store"| STORE
    EMP -->|"Files"| FS
    EMP -->|"LLM"| LLM_MOD
    EMP -->|"VectorOps"| VECTOR
    EMP -->|"Path"| PATH_MOD

    %% Click Events for Electron Main Process Components
    click EMP "https://github.com/reorproject/reor/tree/main/electron/main"
    click UTIL "https://github.com/reorproject/reor/tree/main/electron/main/common"
    click STORE "https://github.com/reorproject/reor/tree/main/electron/main/electron-store"
    click FS "https://github.com/reorproject/reor/tree/main/electron/main/filesystem"
    click LLM_MOD "https://github.com/reorproject/reor/tree/main/electron/main/llm"
    click VECTOR "https://github.com/reorproject/reor/tree/main/electron/main/vector-database"
    click PATH_MOD "https://github.com/reorproject/reor/tree/main/electron/main/path"
    
    %% Click Event for Preload Script / IPC Bridge
    click PRELOAD "https://github.com/reorproject/reor/blob/main/electron/preload/index.ts"
    
    %% Click Events for Renderer Process Components
    click UI "https://github.com/reorproject/reor/tree/main/src"
    click RLLM "https://github.com/reorproject/reor/tree/main/src/lib/llm"

    %% Click Events for External Integration Scripts
    click DL_SCRIPT "https://github.com/reorproject/reor/blob/main/scripts/downloadOllama.js"
    click NT_SCRIPT "https://github.com/reorproject/reor/blob/main/scripts/notarize.js"

    %% Styles and Color Definitions
    classDef main fill:#FFCC00,stroke:#333,stroke-width:2px;
    classDef preload fill:#A8DADC,stroke:#333,stroke-width:2px;
    classDef renderer fill:#CDE7BE,stroke:#333,stroke-width:2px;
    classDef module fill:#F4A261,stroke:#333,stroke-width:2px;
    classDef external fill:#90EE90,stroke:#333,stroke-width:2px;
```
