# sambhavnrana/onlook architecture

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

- Interactive diagram: https://gitdiagram.com/sambhavnrana/onlook
- Repository: https://github.com/sambhavnrana/onlook

## Overview

##### Main Components Identification
- Studio App (Desktop Application):
- The “apps/studio” directory holds both the Electron components (main, preload) and the React-based front-end (src, routes, components).
- The Electron main process (found under apps/studio/electron/main) is responsible for window management, IPC, handling system-level events (like authentication, updates, hosting, payments) and triggering analytics.
- The Electron preload scripts (under apps/studio/electron/preload) expose controlled APIs for the renderer process.
- The Renderer process (found under apps/studio/src) is built using React—this includes detailed UI components, routes, code editors, and chat interfaces for live-coding/design interactivity.
- Modular Packages (under packages/):
- Packages like “ai,” “foundation,” “git,” “growth,” “models,” “supabase,” “types,” “ui,” and “utility” provide libraries, utilities, domain models, and integrations that the Studio app leverages.
- For example, the “ai” package supports chat-based code editing and generation, while “models” defines data structures and editor models.
- Plugins (under plugins/):
- Plugins for Babel and Next suggest that the system may offer extensibility or transformation tools.
- Supporting Scripts and Tooling:
- Build scripts, CI/CD workflows (in .github), and tooling configurations (e.g., Vite, eslint, husky, and prettier) are present to ensure consistent development, testing, and deployment lifecycle.

##### Relationships & Interactions
- The Electron main process communicates (via IPC) with the renderer (built in React) using preload scripts that expose secure APIs.
- The renderer provides the interactive UI (chat, code editing, element inspection) to let designers interact with live websites.
- Modular packages are imported where needed by the Electron processes or the React codebase to provide functionalities such as AI-driven code assistance, git operations, and handling design tokens.
- Plugins may be used during build or runtime transformation processes, adding an additional layer of extensibility to the system.
- External dependencies (e.g., Supabase in the “supabase” package) facilitate backend storage or authentication functionalities.

##### Architectural Patterns / Design Principles
- Separation of Concerns: Clear delineation between Electron main (backend/system-level operations), preload (API boundary), and renderer (frontend UI built with React).
- Modular/Monorepo Structure: The project is arranged in distinct packages and plugins, indicating internal modularization that facilitates code reuse and independent development.
- Layered Architecture: At the top, the UI layer (React) interacts with the application logic through defined APIs and leverages business logic encapsulated in the packages, while also communicating with lower-level services (filesystem, git, network operations via Electron).
- Extensibility through Plugins: The system is designed to be extended or modified via plugins (Babel and Next) that can hook into the build or runtime process.

##### Relevant Technologies, Frameworks, Libraries
- UI: React (in apps/studio/src) with TailwindCSS and Vite as the build tool.
- Desktop App Framework: Electron (with clear separation into main and preload components).
- AI and Chat: Custom AI packages under “packages/ai” that provide code prompts and LLM interactions.
- Additional Tools: Git integration, design models, and UI components are encapsulated in various packages.
- Development and Automation: GitHub workflows (.github/workflows), husky (pre-commit hooks), Prettier configuration, and various TypeScript configurations ensure cohesive development practices.

##### Detail
- Be very descriptive in labeling each component and showing interdependencies.
- Not only the major layers (Electron main, preload, renderer) but also the modular structure (packages, plugins) that underpins most features of the system.
- Optionally incorporate deployment/build elements (like Vite and GitHub workflows) if it adds clarity to how the system is maintained and released.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Studio App Container
    StudioApp["Studio App (Desktop Application)"]:::studio
    click StudioApp "https://github.com/sambhavnrana/onlook/tree/main/apps/studio"

    subgraph "Onlook Studio"
        EM["Electron Main Process"]:::electron
        click EM "https://github.com/sambhavnrana/onlook/tree/main/apps/studio/electron/main"
        EP["Electron Preload Scripts"]:::preload
        click EP "https://github.com/sambhavnrana/onlook/tree/main/apps/studio/electron/preload"
        R["Renderer (React UI)"]:::renderer
        click R "https://github.com/sambhavnrana/onlook/tree/main/apps/studio/src"
    end

    StudioApp --> EM
    StudioApp --> EP
    StudioApp --> R

    %% IPC Communication
    R -->|"IPC"| EP
    EP -->|"SecureAPI"| EM

    %% Modular Packages
    subgraph "Modular Packages"
        AI["AI Support"]:::pkg
        click AI "https://github.com/sambhavnrana/onlook/tree/main/packages/ai"
        FND["Foundation Utilities"]:::pkg
        click FND "https://github.com/sambhavnrana/onlook/tree/main/packages/foundation"
        GIT["Git Integration"]:::pkg
        click GIT "https://github.com/sambhavnrana/onlook/tree/main/packages/git"
        GROW["Growth Features"]:::pkg
        click GROW "https://github.com/sambhavnrana/onlook/tree/main/packages/growth"
        MODELS["Data Models & Editor Models"]:::pkg
        click MODELS "https://github.com/sambhavnrana/onlook/tree/main/packages/models"
        SUPA["Supabase Integration"]:::pkg
        click SUPA "https://github.com/sambhavnrana/onlook/tree/main/packages/supabase"
        TYPES["Shared Types"]:::pkg
        click TYPES "https://github.com/sambhavnrana/onlook/tree/main/packages/types"
        UI["UI Components"]:::pkg
        click UI "https://github.com/sambhavnrana/onlook/tree/main/packages/ui"
        UTIL["General Utilities"]:::pkg
        click UTIL "https://github.com/sambhavnrana/onlook/tree/main/packages/utility"
    end

    %% Connections from Studio components to Modular Packages
    EM -->|"Integrates"| AI
    EM -->|"Integrates"| FND
    EM -->|"Integrates"| GIT
    EM -->|"Integrates"| GROW
    EM -->|"Integrates"| MODELS
    EM -->|"Integrates"| SUPA

    R -->|"Uses"| TYPES
    R -->|"Uses"| UI
    R -->|"Uses"| UTIL

    %% Plugins
    subgraph "Plugins"
        BABEL["Babel Plugin"]:::plugin
        click BABEL "https://github.com/sambhavnrana/onlook/tree/main/plugins/babel"
        NEXT["Next Plugin"]:::plugin
        click NEXT "https://github.com/sambhavnrana/onlook/tree/main/plugins/next"
    end

    %% Connection from Renderer to Plugins (build transforms)
    R -->|"BuildTransforms"| BABEL
    R -->|"BuildTransforms"| NEXT

    %% Supporting Scripts & Tooling
    SS["Supporting Scripts & CI/CD Workflows"]:::supporting
    click SS "https://github.com/sambhavnrana/onlook/tree/main/.github/workflows"
    
    %% Connection from Supporting Scripts to Studio components
    SS -->|"Supports"| EM
    SS -->|"Supports"| R

    %% Styling definitions
    classDef studio fill:#C7F0DB,stroke:#2D7A46,stroke-width:2px;
    classDef electron fill:#FDD,stroke:#F88,stroke-width:2px;
    classDef preload fill:#DFD,stroke:#8F8,stroke-width:2px;
    classDef renderer fill:#DDF,stroke:#88F,stroke-width:2px;
    classDef pkg fill:#FFF7C0,stroke:#E2B400,stroke-width:2px;
    classDef plugin fill:#FCE,stroke:#EAA,stroke-width:2px;
    classDef supporting fill:#E0ECF8,stroke:#7AAFFF,stroke-width:2px;
```
