# loadmill/node-playwright-cua architecture

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

- Interactive diagram: https://gitdiagram.com/loadmill/node-playwright-cua
- Repository: https://github.com/loadmill/node-playwright-cua

## Overview

##### Component Identification
- User Input Interface: Represents commands coming either interactively from the terminal or from an instructions file.
- Main Controller (index.js): Acts as the central loop that reads user input, sends instructions, and processes the API response.
- API Communication Module (openai.js): Builds and sends requests with user commands and browser screenshots to the OpenAI computer-use API while handling conversation context.
- Action Handlers (actions.js): Contains functions to perform browser actions such as click, type, scroll, etc., based on the API’s response.
- Browser Automation Module (browser.js): Launches and manages the Chromium browser using Playwright, including optional HAR file generation.

##### Defining Relationships and Data Flow
- Loop where after an action is performed by the Action Handlers (which use browser.js), a screenshot is taken and sent back to the API Communication Module to continue the cycle.
- Feedback paths: API responses are processed by the Main Controller which then triggers appropriate browser actions.

##### Architectural Patterns
- Separation of concerns: one module handles user input and orchestration (index.js), one handles API communications (openai.js), one handles browser interactions (browser.js), and another executes concrete actions (actions.js).

##### Technologies and Key Details
- That Playwright is specifically used within browser.js.
- That OpenAI’s API is central to decision making and contextual conversation handling.
- That the system supports both interactive and file-based command inputs.

## Diagram (Mermaid)

```mermaid
flowchart TD
    UI["User Input Interface"]:::input
    MC["Main Controller (index.js)"]:::controller
    API["API Module (openai.js)"]:::api
    AH["Action Handlers (actions.js)"]:::action
    BM["Browser Module (browser.js)"]:::browser

    UI -->|"input"| MC
    MC -->|"send_command"| API
    MC -->|"trigger_action"| AH
    AH -->|"perform_action"| BM
    BM -->|"send_screenshot"| API
    API -->|"API_response"| MC

    click UI "https://github.com/loadmill/node-playwright-cua/blob/master/README.md"
    click UI "https://github.com/loadmill/node-playwright-cua/blob/master/example-instructions.txt"
    click MC "https://github.com/loadmill/node-playwright-cua/blob/master/index.js"
    click API "https://github.com/loadmill/node-playwright-cua/blob/master/openai.js"
    click AH "https://github.com/loadmill/node-playwright-cua/blob/master/actions.js"
    click BM "https://github.com/loadmill/node-playwright-cua/blob/master/browser.js"

    classDef input fill:#f9f2cc,stroke:#333,stroke-width:2px
    classDef controller fill:#d0e6ff,stroke:#333,stroke-width:2px
    classDef api fill:#d2f8d2,stroke:#333,stroke-width:2px
    classDef action fill:#ffd9e6,stroke:#333,stroke-width:2px
    classDef browser fill:#e0ffff,stroke:#333,stroke-width:2px
```
