# raam751/agentx architecture

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

- Interactive diagram: https://gitdiagram.com/raam751/agentx
- Repository: https://github.com/raam751/agentx

## Overview

1. **Project shape**
   - This is a Node.js browser-automation service with a live web dashboard.
   - The backend orchestrates a Playwright-driven browser, an LLM decision layer, and a real-time UI over Socket.IO.
   - It is packaged for Docker deployment and exposed on port `3000` locally / `7860` in the container setup.

2. **Top-level runtime boundary**
   - `server.js` is the entry point and likely owns the Express HTTP server plus the Socket.IO channel.
   - That server serves the static dashboard from `public/` and also acts as the coordination hub for agent execution and telemetry.

3. **Core automation pipeline**
   - The agent loop follows a tight cycle: capture screenshot, annotate interactive elements, ask the LLM what to do, execute the action in the browser, then verify the result.
   - This makes the system fundamentally different from selector-driven scripts: decisions are based on annotated visual state rather than DOM selectors alone.

4. **Browser control subsystem**
   - `src/browser.js` is the Playwright wrapper.
   - It encapsulates browser/page management and is called by the agent for navigation, clicks, typing, scrolling, screenshots, and state checks.
   - The README notes it is iframe-aware, which matters because the automation needs to work across embedded frames, not just the top document.

5. **Vision/annotation subsystem**
   - `src/annotator.js` is responsible for extracting interactive elements from the current page and drawing numbered bounding boxes onto screenshots.
   - That annotated image is the main input to the LLM, so the annotation layer is the bridge between raw browser state and model reasoning.

6. **LLM decision layer**
   - `src/llm.js` abstracts over model providers and supports at least Groq and OpenAI.
   - The architecture uses the LLM as a planner/selector: it interprets the screenshot plus task context and returns an action targeting an element number or a browser command.
   - The provider abstraction is important because it keeps the agent logic independent from any one API vendor.

7. **Agent orchestration and self-correction**
   - `src/agent.js` is the central control loop and owns step-by-step task execution.
   - It is responsible for turning LLM output into browser actions, then checking whether the intended effect occurred.
   - If verification fails, the agent feeds back failure context and retries, which is the system’s main resilience mechanism.

8. **Logging and telemetry path**
   - `src/logger.js` emits structured runtime events and streams them to connected clients through Socket.IO.
   - This creates a second output channel besides browser actions: human-readable reasoning, action logs, and progress updates for the dashboard.

9. **Dashboard frontend**
   - `public/index.html`, `public/styles.css`, and `public/app.js` make up the monitoring UI.
   - The frontend connects back to the Socket.IO server, receives live screenshots and logs, and presents the agent’s activity in real time.
   - The dashboard is a consumer of backend events rather than the control plane itself.

10. **State and artifacts**
   - The repo includes a `screenshots/` output directory in the README flow, implying the system persists visual artifacts during execution.
   - Those screenshots are important for debugging, replaying failures, and showing the agent’s current view in the UI.

11. **Configuration and deployment boundaries**
   - Environment variables in `.env.example` control provider choice, API keys, headless mode, maximum steps, and server port.
   - `Dockerfile` and the README’s SDK metadata indicate the project is intended to run as a containerized service, which is the main deployment unit.

12. **Primary data flow for an architecture diagram**
   - User enters a natural-language task in the dashboard.
   - The backend agent captures the current browser viewport via Playwright.
   - The annotator overlays element numbers and passes that image to the LLM.
   - The LLM returns an action decision.
   - The browser wrapper executes the action.
   - Verification checks success; failures loop back into another LLM-guided attempt.
   - Throughout the loop, logger events stream to the frontend for live visibility.

Main entry points: [`src/agent.js`](https://github.com/raam751/agentx/blob/main/src/agent.js) (Agent loop), [`server.js`](https://github.com/raam751/agentx/blob/main/server.js) (Server), [`src/browser.js`](https://github.com/raam751/agentx/blob/main/src/browser.js) (Browser), [`public/app.js`](https://github.com/raam751/agentx/blob/main/public/app.js) (Client app)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime"]
  node_server["Server<br/>HTTP + Socket.IO entry<br/>[server.js]"]
  node_agent(("Agent loop<br/>Task orchestrator<br/>[agent.js]"))
  node_browser["Browser<br/>Playwright wrapper<br/>[browser.js]"]
  node_annotator["Annotator<br/>Vision overlay<br/>[annotator.js]"]
  node_llm{{"LLM<br/>Provider adapter<br/>[llm.js]"}}
  node_logger["Logger<br/>Event stream<br/>[logger.js]"]
end

subgraph group_ui["Dashboard"]
  node_dashboard["Dashboard<br/>UI shell<br/>[index.html]"]
  node_app["Client app<br/>Socket.IO client<br/>[app.js]"]
  node_styles["Styles<br/>UI styling<br/>[styles.css]"]
end

subgraph group_deploy["Deployment"]
  node_dockerfile["Dockerfile<br/>Container build"]
  node_env["Env config<br/>Runtime settings<br/>[.env.example]"]
end

node_server -->|"serves"| node_dashboard
node_server -->|"starts"| node_agent
node_server -->|"streams"| node_logger
node_dashboard -->|"loads"| node_app
node_app -->|"connects"| node_server
node_agent -->|"controls"| node_browser
node_agent -->|"captures"| node_annotator
node_agent -->|"asks"| node_llm
node_llm -->|"decides"| node_agent
node_annotator -->|"reads state"| node_browser
node_browser -->|"reports"| node_agent
node_logger -->|"updates"| node_app
node_dockerfile -.->|"packages"| node_server
node_env -.->|"configures"| node_server

click node_server "https://github.com/raam751/agentx/blob/main/server.js"
click node_agent "https://github.com/raam751/agentx/blob/main/src/agent.js"
click node_browser "https://github.com/raam751/agentx/blob/main/src/browser.js"
click node_annotator "https://github.com/raam751/agentx/blob/main/src/annotator.js"
click node_llm "https://github.com/raam751/agentx/blob/main/src/llm.js"
click node_logger "https://github.com/raam751/agentx/blob/main/src/logger.js"
click node_dashboard "https://github.com/raam751/agentx/blob/main/public/index.html"
click node_app "https://github.com/raam751/agentx/blob/main/public/app.js"
click node_styles "https://github.com/raam751/agentx/blob/main/public/styles.css"
click node_dockerfile "https://github.com/raam751/agentx/tree/main/Dockerfile"
click node_env "https://github.com/raam751/agentx/blob/main/.env.example"

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_server,node_agent,node_browser,node_annotator,node_llm,node_logger toneBlue
class node_dashboard,node_app,node_styles toneAmber
class node_dockerfile,node_env toneMint
```

## Components

### Runtime

Server-side automation and coordination

- [Server](https://github.com/raam751/agentx/blob/main/server.js): HTTP + Socket.IO entry · Starts the app, serves the dashboard, and coordinates browser automation and live events. · `server.js`
- [Agent loop](https://github.com/raam751/agentx/blob/main/src/agent.js): Task orchestrator · Runs the stepwise capture, plan, act, verify cycle and handles retries on failure. · `src/agent.js`
- [Browser](https://github.com/raam751/agentx/blob/main/src/browser.js): Playwright wrapper · Owns browser and page control for navigation, clicks, typing, scrolling, screenshots, and checks. · `src/browser.js`
- [Annotator](https://github.com/raam751/agentx/blob/main/src/annotator.js): Vision overlay · Finds interactive elements and draws numbered boxes onto screenshots for model input. · `src/annotator.js`
- [LLM](https://github.com/raam751/agentx/blob/main/src/llm.js): Provider adapter · Abstracts model providers and turns task context plus annotated state into an action decision. · `src/llm.js`
- [Logger](https://github.com/raam751/agentx/blob/main/src/logger.js): Event stream · Emits structured runtime events and forwards logs and progress to connected clients. · `src/logger.js`

### Dashboard

Live monitoring frontend

- [Dashboard](https://github.com/raam751/agentx/blob/main/public/index.html): UI shell · Browser-facing page that displays the agent’s live activity and task state. · `public/index.html`
- [Client app](https://github.com/raam751/agentx/blob/main/public/app.js): Socket.IO client · Receives live updates, screenshots, and logs from the backend and renders them in the dashboard. · `public/app.js`
- [Styles](https://github.com/raam751/agentx/blob/main/public/styles.css): UI styling · Presentation layer for the monitoring dashboard. · `public/styles.css`

### Deployment

Container and environment boundaries

- [Dockerfile](https://github.com/raam751/agentx/tree/main/Dockerfile): Container build · Defines the packaged runtime image and deployment container shape. · `Dockerfile`
- [Env config](https://github.com/raam751/agentx/blob/main/.env.example): Runtime settings · Documents provider choice, API keys, headless mode, step limits, and port configuration. · `.env.example`

## Connections

- Server → Dashboard: serves · Hosts the dashboard assets over HTTP.
- Server → Agent loop: starts · Creates and supervises the automation loop.
- Server → Logger: streams · Publishes runtime events to connected clients.
- Dashboard → Client app: loads · The page includes the client-side dashboard script.
- Client app → Server: connects · Subscribes to live updates through Socket.IO.
- Agent loop → Browser: controls · Uses the browser wrapper to operate the page.
- Agent loop → Annotator: captures · Requests annotated screenshots and interactive element maps.
- Agent loop → LLM: asks · Sends annotated state and task context for the next action.
- LLM → Agent loop: decides · Returns the action or browser command to execute.
- Annotator → Browser: reads state · Consumes screenshots and page content from the browser session.
- Browser → Agent loop: reports · Provides results, screenshots, and verification signals.
- Logger → Client app: updates · Feeds logs, progress, and visual artifacts to the UI.
- Dockerfile → Server: packages · Builds the service for container deployment.
- Env config → Server: configures · Supplies provider and runtime settings.
