# developertirth/netrabrowser architecture

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

- Interactive diagram: https://gitdiagram.com/developertirth/netrabrowser
- Repository: https://github.com/developertirth/netrabrowser

## Overview

1. **Project type and runtime**
   - NetraBrowser is an **Electron desktop application** written in **JavaScript**.
   - It has the standard Electron split: a **main process**, a **renderer UI**, and a **webview-specific preload layer** for content running inside the embedded browser surface.

2. **Primary architecture**
   - The app is organized around a **control plane** in the Electron main process and a **visual browser surface** in a webview.
   - The renderer is the user-facing control panel where goals, settings, and agent state are shown.
   - The webview hosts the actual target website that the agent observes and manipulates.

3. **Main process boundary**
   - `src/main.js` is the central orchestration layer.
   - In an Electron app like this, the main process typically owns window creation, lifecycle, IPC routing, and privileged browser control.
   - This is the boundary where browser automation, security-sensitive actions, and model-provider coordination are most likely concentrated.

4. **Renderer boundary**
   - `src/renderer/index.html`, `src/renderer/renderer.js`, and `src/renderer/index.css` make up the UI layer.
   - This layer is responsible for the visible application shell: user input, status display, settings, and the “agent HUD” described in the README.
   - It should be treated as presentation-only relative to the browser automation engine.

5. **Webview boundary**
   - `src/webview/preload-webview.js` indicates a separate preload script for content inside the embedded browsing context.
   - This is the natural place for page-side instrumentation: injecting overlays, collecting viewport state, and mediating interactions with the target site.
   - The webview is the closest layer to the actual webpage and is distinct from the app renderer.

6. **IPC as the main data channel**
   - The key internal communication path is **IPC between renderer, main process, and webview**.
   - User goals and UI actions originate in the renderer, are forwarded to the main process, and then become browser actions or page instrumentation in the webview.
   - Results, screenshots, and agent state flow back in the opposite direction for display and next-step decisions.

7. **Browser automation model**
   - The README describes a **vision-driven agent loop** rather than DOM-selector-based automation.
   - The browser captures the page visually, overlays **Netra IDs / NIDs** around interactive elements, and uses those visual cues as the input to model reasoning.
   - Actions are then dispatched natively through browser control, described as CDP-backed input events.

8. **AI/model integration boundary**
   - The repository is designed for **BYOM**: local or cloud model providers.
   - The README names **Ollama** for local VLMs and cloud APIs such as **OpenAI, Anthropic, and Gemini**.
   - Architecturally, this means model calls are an external service boundary consumed by the agent loop, not by the UI directly.

9. **Agent loop and state flow**
   - The operational cycle is: user goal → page capture/annotation → model reasoning → structured action → browser interaction → updated page state.
   - The model produces an action plan, and the app applies it to the webview.
   - This loop repeats until the task completes or the user interrupts it.

10. **Security and privilege separation**
   - The Electron split is important here: the renderer should remain constrained, while the main process holds the privileged browser control path.
   - The webview preload is a separate trust boundary because it runs in the target-page context and can observe or inject into that page.
   - This separation is central to the architecture diagram because it shows where untrusted webpage content ends and app-controlled automation begins.

11. **Packaging and build tooling**
   - `forge.config.js` indicates the app is packaged with **Electron Forge**.
   - That matters architecturally because Forge shapes distribution, entry points, and packaging of the Electron app into a desktop binary.
   - `package-lock.json` and `package.json` define the Node/Electron dependency graph and runtime setup.

12. **What to show in an architecture diagram**
   - Draw three main zones: **Renderer UI**, **Main Process Orchestrator**, and **Webview Target Browser**.
   - Connect them with IPC arrows in both directions.
   - Add an external **Model Provider** box for Ollama/OpenAI/Anthropic/Gemini.
   - Show the browser automation loop cycling between webview state capture, model decision-making, and native interaction dispatch.

13. **Key repository takeaway**
   - This repo is not a generic browser clone; it is an **agentic browser control system**.
   - The core architectural distinction is between:
     - human-facing control UI,
     - privileged orchestration,
     - and the embedded browsing surface that is visually observed and programmatically driven.

Main entry points: [`src/main.js`](https://github.com/developertirth/netrabrowser/blob/main/src/main.js) (Main), [`src/renderer/renderer.js`](https://github.com/developertirth/netrabrowser/blob/main/src/renderer/renderer.js) (Renderer), [`src/preload.js`](https://github.com/developertirth/netrabrowser/blob/main/src/preload.js) (App Preload), [`src/webview/preload-webview.js`](https://github.com/developertirth/netrabrowser/blob/main/src/webview/preload-webview.js) (Webview Preload)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_grp_renderer["Renderer UI"]
  node_node_renderer_html["Shell HTML<br/>ui markup<br/>[index.html]"]
  node_node_renderer_js["Renderer<br/>ui controller<br/>[renderer.js]"]
  node_node_renderer_css["Styles<br/>ui styling<br/>[index.css]"]
end

subgraph group_grp_main["Main Process"]
  node_node_main_js["Main<br/>electron orchestrator<br/>[main.js]"]
  node_node_preload_js["App Preload<br/>renderer bridge<br/>[preload.js]"]
  node_node_action_dispatch["Action Dispatch<br/>native input"]
  node_node_agent_loop(("Agent Loop<br/>orchestration loop"))
  node_node_model_gateway["Model Gateway<br/>provider adapter"]
end

subgraph group_grp_webview["Webview"]
  node_node_webview_preload["Webview Preload<br/>page bridge<br/>[preload-webview.js]"]
  node_node_browser_surface(("Target Page<br/>embedded browser"))
  node_node_capture_layer["Page Capture<br/>vision capture"]
  node_node_nid_overlay["NID Overlay<br/>annotation layer"]
end

subgraph group_grp_external["External Services"]
  node_node_ollama[("Ollama<br/>local model")]
  node_node_cloud_models[("Cloud APIs<br/>remote models")]
end

subgraph group_grp_tooling["Packaging"]
  node_node_forge["Electron Forge<br/>packaging<br/>[forge.config.js]"]
  node_node_package_json["Package<br/>node manifest<br/>[package.json]"]
  node_node_package_lock["Lockfile<br/>dependency lock<br/>[package-lock.json]"]
end

node_node_renderer_html -->|"bootstraps"| node_node_renderer_js
node_node_renderer_css -->|"styles"| node_node_renderer_js
node_node_renderer_js -->|"ipc"| node_node_preload_js
node_node_preload_js -->|"ipc"| node_node_main_js
node_node_main_js -->|"state"| node_node_renderer_js
node_node_main_js -->|"load"| node_node_webview_preload
node_node_webview_preload -->|"instrument"| node_node_browser_surface
node_node_browser_surface -->|"capture"| node_node_capture_layer
node_node_capture_layer -->|"annotate"| node_node_nid_overlay
node_node_nid_overlay -->|"observations"| node_node_agent_loop
node_node_renderer_js -->|"goal"| node_node_agent_loop
node_node_agent_loop -->|"reason"| node_node_model_gateway
node_node_model_gateway -->|"local"| node_node_ollama
node_node_model_gateway -->|"cloud"| node_node_cloud_models
node_node_model_gateway -->|"plan"| node_node_action_dispatch
node_node_action_dispatch -->|"act"| node_node_browser_surface
node_node_browser_surface -->|"update"| node_node_agent_loop
node_node_main_js -.->|"package"| node_node_forge
node_node_package_json -->|"runtime"| node_node_main_js
node_node_package_lock -->|"pins"| node_node_package_json

click node_node_main_js "https://github.com/developertirth/netrabrowser/blob/main/src/main.js"
click node_node_preload_js "https://github.com/developertirth/netrabrowser/blob/main/src/preload.js"
click node_node_renderer_html "https://github.com/developertirth/netrabrowser/blob/main/src/renderer/index.html"
click node_node_renderer_js "https://github.com/developertirth/netrabrowser/blob/main/src/renderer/renderer.js"
click node_node_renderer_css "https://github.com/developertirth/netrabrowser/blob/main/src/renderer/index.css"
click node_node_webview_preload "https://github.com/developertirth/netrabrowser/blob/main/src/webview/preload-webview.js"
click node_node_forge "https://github.com/developertirth/netrabrowser/blob/main/forge.config.js"
click node_node_package_json "https://github.com/developertirth/netrabrowser/blob/main/package.json"
click node_node_package_lock "https://github.com/developertirth/netrabrowser/blob/main/package-lock.json"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_node_renderer_html,node_node_renderer_js,node_node_renderer_css toneBlue
class node_node_main_js,node_node_preload_js,node_node_action_dispatch,node_node_agent_loop,node_node_model_gateway toneAmber
class node_node_webview_preload,node_node_browser_surface,node_node_capture_layer,node_node_nid_overlay toneMint
class node_node_ollama,node_node_cloud_models toneRose
class node_node_forge,node_node_package_json,node_node_package_lock toneIndigo
```

## Components

### Renderer UI

Human-facing control panel and HUD

- [Shell HTML](https://github.com/developertirth/netrabrowser/blob/main/src/renderer/index.html): ui markup · App shell and layout for the control panel · `src/renderer/index.html`
- [Renderer](https://github.com/developertirth/netrabrowser/blob/main/src/renderer/renderer.js): ui controller · User-facing state, inputs, and agent HUD behavior · `src/renderer/renderer.js`
- [Styles](https://github.com/developertirth/netrabrowser/blob/main/src/renderer/index.css): ui styling · Presentation layer for the control panel · `src/renderer/index.css`

### Main Process

Privileged Electron orchestration and IPC

- [Main](https://github.com/developertirth/netrabrowser/blob/main/src/main.js): electron orchestrator · Creates windows, routes IPC, and coordinates privileged browser actions · `src/main.js`
- [App Preload](https://github.com/developertirth/netrabrowser/blob/main/src/preload.js): renderer bridge · Preload bridge for the app window boundary · `src/preload.js`
- **Action Dispatch**: native input · Applies model-selected browser actions through CDP-backed interaction
- **Agent Loop**: orchestration loop · Repeats capture, reasoning, action, and state update cycles
- **Model Gateway**: provider adapter · Normalizes calls to local and cloud model providers

### Webview

Embedded target-browser surface and page instrumentation

- [Webview Preload](https://github.com/developertirth/netrabrowser/blob/main/src/webview/preload-webview.js): page bridge · Instrumentation and interaction bridge inside the embedded browser context · `src/webview/preload-webview.js`
- **Target Page**: embedded browser · The remote website being observed and manipulated
- **Page Capture**: vision capture · Collects visual page state for the agent loop
- **NID Overlay**: annotation layer · Draws Netra IDs around interactive elements

### External Services

Model providers consumed by the agent loop

- **Ollama**: local model · Local VLM/provider option
- **Cloud APIs**: remote models · OpenAI, Anthropic, and Gemini provider boundary

### Packaging

Electron Forge and Node packaging setup

- [Electron Forge](https://github.com/developertirth/netrabrowser/blob/main/forge.config.js): packaging · Builds and packages the desktop application · `forge.config.js`
- [Package](https://github.com/developertirth/netrabrowser/blob/main/package.json): node manifest · Dependency and runtime configuration · `package.json`
- [Lockfile](https://github.com/developertirth/netrabrowser/blob/main/package-lock.json): dependency lock · Pinned dependency resolution · `package-lock.json`

## Connections

- Shell HTML → Renderer: bootstraps · HTML loads the renderer controller
- Styles → Renderer: styles · Renderer UI styling supports the control panel
- Renderer → App Preload: ipc · Renderer sends UI events through the preload boundary
- App Preload → Main: ipc · Preload forwards controlled messages into the main process
- Main → Renderer: state · Main process returns status, results, and agent updates
- Main → Webview Preload: load · Main creates and configures the embedded browsing context
- Webview Preload → Target Page: instrument · Preload injects overlays and page instrumentation
- Target Page → Page Capture: capture · Visual page state is sampled from the target site
- Page Capture → NID Overlay: annotate · Interactive elements are marked with Netra IDs
- NID Overlay → Agent Loop: observations · Annotated state feeds the reasoning loop
- Renderer → Agent Loop: goal · User intent and settings enter the agent loop
- Agent Loop → Model Gateway: reason · The loop sends observations for model reasoning
- Model Gateway → Ollama: local · Routes to local model providers when selected
- Model Gateway → Cloud APIs: cloud · Routes to remote API providers when selected
- Model Gateway → Action Dispatch: plan · Model output is converted into a structured action
- Action Dispatch → Target Page: act · Native browser control executes the chosen action
- Target Page → Agent Loop: update · Updated page state re-enters the loop
- Main → Electron Forge: package · Main entry is packaged into the desktop app
- Package → Main: runtime · Manifest defines the Electron/Node runtime entrypoints
- Lockfile → Package: pins · Lockfile constrains dependency versions
