Onlook

repository·main·Indexed 12 days ago

https://github.com/onlook-dev/onlook

An open-source, visual-first code editor for AI-native designers to build and edit Next.js and TailwindCSS applications through a Figma-like interface that syncs with the codebase. Features include an AST-based component mapping algorithm, a browser-based file system abstraction using ZenFS, and server-side image compression utilities.

Tokens
139.1K
Snippets
496
Records
635
Agent score
98%

What's inside Onlook

  1. What is Onlook?

    main

    Onlook is a visual-first code editor described as a "Cursor for Designers." It allows designers to make live edits to React and TailwindCSS projects directly within a browser-like DOM interface.

    Key capabilities include:

    • Visual Editing: Edit designs directly in a browser-like interface.
    • Code Synchronization: Changes made visually are automatically reflected in the underlying source code.
    • AI Assistance: Use AI to generate and modify code.
    • Theme Management: Manage project styling through a dedicated theme system.
    • Deployment: Deploy websites directly from the application.
  2. Core features of Onlook

    main

    Onlook provides a suite of visual and development tools for Next.js and TailwindCSS projects:

    Visual Editing

    • Figma-like UI: Edit your app visually using familiar design patterns.
    • Real-time Preview: See changes to your design and code immediately.
    • Layer & Page Management: Browse layers, create new pages, and navigate between them.
    • Asset Management: Manage project images and brand tokens.
    • Component Detection: Automatically detect and use components in your project.
    • Branching: Use branching to experiment with different design directions without affecting the main codebase.

    Development & Deployment

    • Real-time Code Editor: Edit code side-by-side with your visual design.
    • Code Mapping: Right-click any element in the visual preview to jump directly to its location in the code.
    • CLI Commands: Run commands via the integrated CLI.
    • Checkpoints: Save and restore project states using checkpoints.
    • Deployment: Generate sharable links or link custom domains to deploy your app quickly.
  3. Understand the Onlook interface areas

    main

    The Onlook interface is organized into several functional areas to facilitate visual editing of React components:

    • Canvas: The central workspace for interacting with and viewing your components.
    • Layers Panel: Displays the component hierarchy, functioning similarly to layers in design tools.
    • Properties Panel: Used for editing the properties of the currently selected component.
    • Style Editor: A visual interface specifically for modifying Tailwind styles.
    • Code Panel: Provides a view and editor for the generated code.
    • AI Chat: An interface to interact with AI for component generation and modification.
  4. Understand the technology stack in the T3 App

    main

    The apps/web/client project is built using the T3 Stack, which provides a type-safe foundation for full-stack applications. The core technologies used are:

    • Next.js: The React framework for building the web application.
    • Drizzle: An ORM used for database interactions.
    • Tailwind CSS: A utility-first CSS framework for styling.
    • tRPC: Enables end-to-end type safety between your client and server.
  5. Understand the Onlook Web project structure

    main

    The Onlook web application is composed of four primary architectural components:

    • Client: A Next.js client that serves as the main application front-end.
    • Server: A control server used to interact with the template application.
    • Shared: Contains all shared packages utilized across the web project.
    • Preload: A script injected into the Template app, enabling direct communication with the application's DOM via an iframe.
  6. Explore the Onlook documentation project structure

    main

    The documentation is built using Next.js. Key files and routes include:

    Core Files

    • lib/source.ts: Contains the code for the content source adapter, which provides the interface for accessing content.
    • app/layout.config.tsx: Contains shared options for layouts (optional but recommended).

    Routes

    • app/(home): Route group for the landing page and other general pages.
    • app/docs: The main documentation layout and pages.
    • app/api/search/route.ts: The Route Handler responsible for search functionality.
  7. Explore the Onlook interface

    main

    The Onlook interface is composed of several key panels designed for visual development:

    • Canvas: The central workspace where you interact with and view your components visually.
    • Layers Panel: Displays the hierarchical structure of your components.
    • Properties Panel: Used to edit the specific properties of a selected component.
    • Style Editor: A dedicated interface for modifying Tailwind CSS styles.
    • Code Panel: Provides a view of the underlying code, allowing for direct editing of the generated source.
  8. Understand Docker Compose deployment limitations

    main

    The Docker Compose deployment is a single-container setup designed for simplicity rather than high reliability.

    Key Limitations:

    • Single point of failure (no high availability).
    • No built-in load balancing or auto-scaling.
    • Manual backup and disaster recovery required.
    • Vertical scaling only.

    Best Use Cases:

    • Small teams (< 10 users).
    • Development and testing environments.
    • Proof of concept (PoC) deployments.

    For mission-critical workloads or large teams requiring 99.9%+ uptime, use the Cloud Deployment option instead.

  9. Understand the Onlook Web Architecture

    main

    Onlook has migrated from an Electron-based desktop application to a web-based architecture to enable real-time collaboration and remove local environment setup friction.

    Key architectural shifts include:

    • UI Layer: The previous Electron BrowserView is now a Next.js app.
    • Canvas/Frame: The previous Electron WebView is now an iFrame. Because the Onlook web app and the user's app reside on different origins, inter-process communication is handled via a preload script injected into the user app's layout via a CDN, utilizing the window.postMessage API.
    • Backend/Filesystem: Instead of a local Node server with direct filesystem access, Onlook uses Remote containers (e.g., CodeSandbox) that provide a filesystem API for reading, writing, and listening to file changes.
    • Data Persistence: Local serialized JSON files have been replaced by Supabase (Postgres) for project and user information, supplemented by a browser-side caching layer.
  10. Project Compatibility and Supported Technologies

    main

    Onlook is designed to work with any React and TailwindCSS project. This includes websites, web applications, dashboards, and more.

    If you have an existing Next.js + TailwindCSS project, you can import it into Onlook to begin making live visual edits to the browser DOM immediately.

  11. How the AST algorithm maps component instances

    main

    Onlook uses an AST (Abstract Syntax Tree) manager to map component usages by combining the DOM tree with an AST tree. This overcomes the limitations of both: the DOM tree lacks instance information (e.g., props or specific component call sites), and the AST lacks tree structure/hierarchy information.

    The Mapping Algorithm

    To find where a specific component instance is used, the system follows these steps:

    1. AST Parsing: Parse the source files and build a map that links data-oid values to their code location (file, start/end position) and component name (the JSX tag name or the containing function name).
    2. DOM Walking: Walk the DOM tree and inspect the parent of each node. If the component name of the current node differs from its parent's component name, the node is identified as a component instance.
    3. Verification: For identified instances, look up the parent's source code. Find the child at the same index with the same component name. If they match, the exact instance location in the source code is confirmed.
    // Example of the internal mapping generated during AST parsing
    {
        "parent": ["parent.jsx", "start and end location", "Parent"],
        "instance": ["parent.jsx", "start and end location", "Child"],
        "child": ["child.jsx", "start and end location", "Child"]
    }