# nerdsaver/browser-use architecture

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

- Interactive diagram: https://gitdiagram.com/nerdsaver/browser-use
- Repository: https://github.com/nerdsaver/browser-use

## Overview

##### Component Relationships

- API calls between layers
- Event handling paths

##### Specific Implementation Details

Key architectural elements:
**┌─────────────────────────────────────────────┐**
- User Interface               │
- (CLI, Gradio, Cloud Interface)            │
- ┬──┘
- ↓                      │
**┌─────────────────────────────────────────┼──┐**
- Agent Controller           │  │
- ┌─────────────┐  ┌─────────────┐      │  │
- Registry  │  │   Message   │      │  │
- Service   │←→│   Manager   │      │  │
- ┘  └─────────────┘      │  │
- ┬──────────┼──┘
- ↓         │          │
**┌─────────────────────────────┼──────────┼──┐**
- Browser Layer      │          │  │
- ┌─────────────┐  ┌─────────┴───┐      │  │
- Browser    │←→│     DOM     │      │  │
- Control    │  │   Handler   │      │  │
- ┘  └─────────────┘      │  │
- ┼──┘
- ↑                      │
**┌─────────────────────────────────────────┼──┐**
- Integration Layer            │  │
- ┌─────────────┐  ┌─────────────┐      │  │
- LLM      │  │  External   │      │  │
- Models    │←→│  Services   │      │  │
- ┘  └─────────────┘      │  │
- ┴──┘

##### Important Details

- Telemetry System (telemetry/)
- Custom Function Support (examples/custom-functions/)
- Model Integration Points (examples/models/)
- Browser Communication Protocol
- Authentication Flow
- Error Handling Paths

##### Documentation References

References to:
- API Documentation
- Configuration Options
- Custom Integration Points
- Security Considerations

Remember to include the project's key features like:
- Multi-tab handling
- Parallel agent support
- Custom output formats
- Various model integrations
- Browser automation capabilities

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph UI["User Interface Layer"]
        CLI["CLI Interface"]
        GRADIO["Gradio Interface"]
        CLOUD["Cloud Interface"]
    end

    subgraph AGENT["Agent Control Layer"]
        AC["Agent Controller"]
        RS["Registry Service"]
        MM["Message Manager"]
        AS["Agent Service"]
    end

    subgraph BROWSER["Browser Interaction Layer"]
        BM["Browser Module"]
        DH["DOM Handler"]
        CM["Context Management"]
        BV["Browser Views"]
        DV["DOM Views"]
        DTB["DOM Tree Builder"]
        HTP["History Tree Processor"]
    end

    subgraph AI["AI Integration Layer"]
        MI["Model Integrations"]
        APS["Agent Prompts System"]
    end

    subgraph SUPPORT["Supporting Systems"]
        TS["Telemetry System"]
        CF["Custom Functions"]
    end

    %% Connections
    CLI & GRADIO & CLOUD --> AC
    AC --> RS
    AC --> MM
    AC --> AS
    AS --> BM
    BM --> DH
    BM --> CM
    BM --> BV
    DH --> DV
    DH --> DTB
    DH --> HTP
    AS --> MI
    AS --> APS
    AC --> TS
    AS --> CF

    %% Click Events
    click CLI "https://github.com/nerdsaver/browser-use/blob/main/examples/ui/command_line.py"
    click GRADIO "https://github.com/nerdsaver/browser-use/blob/main/examples/ui/gradio_demo.py"
    click CLOUD "https://github.com/nerdsaver/browser-use/blob/main/docs/cloud/implementation.mdx"
    click AC "https://github.com/nerdsaver/browser-use/blob/main/browser_use/controller/service.py"
    click RS "https://github.com/nerdsaver/browser-use/blob/main/browser_use/controller/registry/service.py"
    click MM "https://github.com/nerdsaver/browser-use/blob/main/browser_use/agent/message_manager/service.py"
    click BM "https://github.com/nerdsaver/browser-use/blob/main/browser_use/browser/browser.py"
    click DH "https://github.com/nerdsaver/browser-use/blob/main/browser_use/dom/service.py"
    click CM "https://github.com/nerdsaver/browser-use/blob/main/browser_use/browser/context.py"
    click MI "https://github.com/nerdsaver/browser-use/tree/main/examples/models"
    click APS "https://github.com/nerdsaver/browser-use/blob/main/browser_use/agent/prompts.py"
    click TS "https://github.com/nerdsaver/browser-use/blob/main/browser_use/telemetry/service.py"
    click CF "https://github.com/nerdsaver/browser-use/tree/main/examples/custom-functions"
    click DTB "https://github.com/nerdsaver/browser-use/blob/main/browser_use/dom/buildDomTree.js"
    click HTP "https://github.com/nerdsaver/browser-use/blob/main/browser_use/dom/history_tree_processor/service.py"
    click AS "https://github.com/nerdsaver/browser-use/blob/main/browser_use/agent/service.py"
    click BV "https://github.com/nerdsaver/browser-use/blob/main/browser_use/browser/views.py"
    click DV "https://github.com/nerdsaver/browser-use/blob/main/browser_use/dom/views.py"

    %% Styling
    classDef ui fill:#f9f,stroke:#333,stroke-width:2px
    classDef agent fill:#bbf,stroke:#333,stroke-width:2px
    classDef browser fill:#bfb,stroke:#333,stroke-width:2px
    classDef ai fill:#ffb,stroke:#333,stroke-width:2px
    classDef support fill:#fbb,stroke:#333,stroke-width:2px

    class CLI,GRADIO,CLOUD ui
    class AC,RS,MM,AS agent
    class BM,DH,CM,BV,DV,DTB,HTP browser
    class MI,APS ai
    class TS,CF support
```
