# ticktockbent/charlotte architecture

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

- Interactive diagram: https://gitdiagram.com/ticktockbent/charlotte
- Repository: https://github.com/ticktockbent/charlotte

## Overview

1. **What this repository is**
   Charlotte is a TypeScript/Node.js MCP server that sits between an AI agent and a live Chromium browser. Its core job is to turn browser state into compact, structured page representations and expose browser actions as MCP tools over stdio.

2. **Top-level runtime boundaries**
   There are three major runtime surfaces:
   - the **MCP server** in `src/`
   - the **benchmark harness** in `benchmarks/`
   - the **marketing/documentation site** in `site/`
   
   The server is the product; the other two support evaluation and distribution.

3. **Server entrypoint and transport**
   `src/index.ts`, `src/cli.ts`, and `src/server.ts` define the process startup path and MCP transport. The server is designed to be launched locally or in Docker and communicate with clients via standard input/output, not via HTTP.

4. **Browser control subsystem**
   `src/browser/` manages the persistent browser session and tab/page lifecycle. The key responsibilities are browser startup/shutdown, page switching, and lower-level CDP session handling. This is the boundary where MCP actions become browser operations.

5. **Rendering and page decomposition pipeline**
   `src/renderer/` is the architectural core. It extracts and fuses browser signals into a `PageRepresentation`, including:
   - accessibility tree data
   - layout/bounding boxes
   - structural landmarks and headings
   - interactive element metadata
   - content summaries
   - stable element IDs
   
   The pipeline is what enables Charlotte’s token-efficient output: it decides how much detail to return for `navigate`, `observe`, and related tools.

6. **State, snapshots, and diffs**
   `src/state/` holds cross-call page state:
   - snapshot storage
   - artifact storage
   - structural differ
   
   This supports screenshot persistence, comparison against prior snapshots, and page-diff workflows. State is a distinct layer from rendering so tools can reason over time, not just a single page view.

7. **Tool layer and capability groups**
   `src/tools/` defines the MCP surface area: navigation, observation, interaction, monitoring, session management, dev mode, evaluation, and meta-tool/profile management. The repo’s profile system is important architecturally: it selectively exposes subsets of tools to reduce tool-definition overhead, so tool registration is not a flat “all tools always on” model.

8. **Interaction model**
   Charlotte’s interaction tools are built around stable element IDs and structured page metadata. Actions such as click, type, select, drag, and submit depend on the renderer’s IDs and the browser layer’s current page context. This creates a clear flow: render page → identify target → perform browser action → re-render or update state.

9. **Development-mode subsystem**
   `src/dev/` adds a local feedback loop for working on sites:
   - static file serving
   - file watching
   - audit checks
   - state tracking for dev mode
   
   This is separate from core browsing because it supports serving local content, live reload, and automated audits rather than agent browsing of arbitrary remote pages.

10. **External-facing page types and representation**
   The README’s minimal/summary/full detail levels map directly to the rendering layer’s output strategy. Charlotte is optimized for progressive disclosure: first return orientation, then targeted detail, then full text only when explicitly requested. That output contract is the main product boundary clients consume.

11. **Benchmarking and evaluation harness**
   `benchmarks/` contains reproducible scenarios, test runners, metrics collection, and saved raw results. This is an independent subsystem used to validate the token-efficiency and tool-overhead claims against Charlotte profiles and against Playwright MCP-style behavior.

12. **Test architecture**
   `tests/unit/` and `tests/integration/` cover the server at multiple levels, with HTML fixtures under `tests/fixtures/pages/` and sandbox pages under `tests/sandbox/`. The integration tests exercise browser behavior, rendering, interaction, session management, and artifact handling against real pages rather than mocks.

13. **Packaging and deployment**
   The repo includes Dockerfiles, compose config, and GitHub Actions for CI and image publishing. That means the server is expected to be deployable as a self-contained local process, with containerization as a first-class distribution path.

14. **Documentation and consumer surface**
   `docs/` and the Next.js `site/` form the external-facing documentation and benchmark presentation layer. They do not participate in runtime behavior, but they are important for understanding configuration, profiles, and the expected MCP client integration model.

15. **Overall data flow to draw**
   The central architecture diagram should show:
   AI agent/MCP client → MCP server/tools → browser manager/CDP → renderer pipeline → structured page/state outputs → back to agent.
   
   Side flows branch from the server to dev-mode file serving/auditing, and from the repo to benchmarks, tests, docs, and Docker packaging.

Main entry points: [`src/renderer/renderer-pipeline.ts`](https://github.com/ticktockbent/charlotte/blob/main/src/renderer/renderer-pipeline.ts) (Renderer), [`src/server.ts`](https://github.com/ticktockbent/charlotte/blob/main/src/server.ts) (Server), [`src/browser/browser-manager.ts`](https://github.com/ticktockbent/charlotte/blob/main/src/browser/browser-manager.ts) (Browser), [`src/state/snapshot-store.ts`](https://github.com/ticktockbent/charlotte/blob/main/src/state/snapshot-store.ts) (State)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime"]
  node_src_index["Entry<br/>[index.ts]"]
  node_src_cli["CLI<br/>arg parsing<br/>[cli.ts]"]
  node_src_server["Server<br/>mcp transport<br/>[server.ts]"]
  node_browser_mgr["Browser<br/>[browser-manager.ts]"]
  node_page_mgr["Pages<br/>page lifecycle<br/>[page-manager.ts]"]
  node_cdp_session["CDP<br/>session bridge<br/>[cdp-session.ts]"]
  node_renderer_pipe["Renderer<br/>representation pipeline"]
  node_a11y_extractor["A11y<br/>signal extractor"]
  node_layout_extractor["Layout<br/>signal extractor"]
  node_interactive_extractor["Interactives<br/>signal extractor"]
  node_tree_extractor["Structure<br/>signal extractor"]
  node_content_extractor["Content<br/>signal extractor"]
end

subgraph group_state["State"]
  node_state_store[("State<br/>[snapshot-store.ts]")]
  node_artifact_store[("Artifacts<br/>artifact store<br/>[artifact-store.ts]")]
  node_differ["Diffs<br/>structural diff<br/>[differ.ts]"]
end

subgraph group_support["Support"]
  node_dev_tools["Dev mode<br/>developer tools<br/>[dev-mode-state.ts]"]
  node_tool_groups["Tools<br/>tool registry<br/>[tool-groups.ts]"]
end

subgraph group_evaluation["Evaluation"]
  node_benchmarks["Benchmarks<br/>evaluation suite<br/>[run-benchmarks.ts]"]
end

subgraph group_docs["Docs"]
  node_site_app["Site<br/>[page.tsx]"]
  node_docs_main["Docs<br/>specs and guides<br/>[CHARLOTTE_SPEC.md]"]
end

subgraph group_quality["Quality"]
  node_tests_int["Integration<br/>system tests"]
  node_tests_unit["Unit<br/>component tests"]
end

subgraph group_delivery["Delivery"]
  node_dockerfile["Docker<br/>deployment packaging"]
end

node_src_index -->|"starts"| node_src_cli
node_src_cli -->|"creates"| node_src_server
node_src_server -->|"registers"| node_tool_groups
node_src_server -->|"drives"| node_browser_mgr
node_browser_mgr -->|"manages"| node_page_mgr
node_browser_mgr -->|"uses"| node_cdp_session
node_page_mgr -->|"renders"| node_renderer_pipe
node_renderer_pipe -->|"fuses"| node_a11y_extractor
node_renderer_pipe -->|"fuses"| node_layout_extractor
node_renderer_pipe -->|"fuses"| node_interactive_extractor
node_renderer_pipe -->|"fuses"| node_tree_extractor
node_renderer_pipe -->|"fuses"| node_content_extractor
node_renderer_pipe -->|"emits"| node_state_store
node_state_store -->|"persists"| node_artifact_store
node_state_store -->|"compares"| node_differ
node_tool_groups -->|"exposes"| node_dev_tools
node_dev_tools -->|"controls"| node_browser_mgr
node_src_server -->|"shares"| node_state_store
node_benchmarks -.->|"measures"| node_tool_groups
node_site_app -->|"publishes"| node_docs_main
node_tests_int -.->|"covers"| node_renderer_pipe
node_tests_int -.->|"covers"| node_browser_mgr
node_tests_unit -.->|"covers"| node_tool_groups
node_dockerfile -->|"packages"| node_src_server

click node_src_index "https://github.com/ticktockbent/charlotte/blob/main/src/index.ts"
click node_src_cli "https://github.com/ticktockbent/charlotte/blob/main/src/cli.ts"
click node_src_server "https://github.com/ticktockbent/charlotte/blob/main/src/server.ts"
click node_browser_mgr "https://github.com/ticktockbent/charlotte/blob/main/src/browser/browser-manager.ts"
click node_page_mgr "https://github.com/ticktockbent/charlotte/blob/main/src/browser/page-manager.ts"
click node_cdp_session "https://github.com/ticktockbent/charlotte/blob/main/src/browser/cdp-session.ts"
click node_renderer_pipe "https://github.com/ticktockbent/charlotte/blob/main/src/renderer/renderer-pipeline.ts"
click node_a11y_extractor "https://github.com/ticktockbent/charlotte/blob/main/src/renderer/accessibility-extractor.ts"
click node_layout_extractor "https://github.com/ticktockbent/charlotte/blob/main/src/renderer/layout-extractor.ts"
click node_interactive_extractor "https://github.com/ticktockbent/charlotte/blob/main/src/renderer/interactive-extractor.ts"
click node_tree_extractor "https://github.com/ticktockbent/charlotte/blob/main/src/renderer/structural-tree-extractor.ts"
click node_content_extractor "https://github.com/ticktockbent/charlotte/blob/main/src/renderer/content-extractor.ts"
click node_state_store "https://github.com/ticktockbent/charlotte/blob/main/src/state/snapshot-store.ts"
click node_artifact_store "https://github.com/ticktockbent/charlotte/blob/main/src/state/artifact-store.ts"
click node_differ "https://github.com/ticktockbent/charlotte/blob/main/src/state/differ.ts"
click node_dev_tools "https://github.com/ticktockbent/charlotte/blob/main/src/dev/dev-mode-state.ts"
click node_tool_groups "https://github.com/ticktockbent/charlotte/blob/main/src/tools/tool-groups.ts"
click node_benchmarks "https://github.com/ticktockbent/charlotte/blob/main/benchmarks/run-benchmarks.ts"
click node_site_app "https://github.com/ticktockbent/charlotte/blob/main/site/app/page.tsx"
click node_docs_main "https://github.com/ticktockbent/charlotte/blob/main/docs/CHARLOTTE_SPEC.md"
click node_tests_int "https://github.com/ticktockbent/charlotte/blob/main/tests/integration/renderer-pipeline.test.ts"
click node_tests_unit "https://github.com/ticktockbent/charlotte/blob/main/tests/unit/tools/create-server.test.ts"
click node_dockerfile "https://github.com/ticktockbent/charlotte/tree/main/Dockerfile"

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_src_index,node_src_cli,node_src_server,node_browser_mgr,node_page_mgr,node_cdp_session,node_renderer_pipe,node_a11y_extractor,node_layout_extractor,node_interactive_extractor,node_tree_extractor,node_content_extractor,node_dockerfile toneBlue
class node_state_store,node_artifact_store,node_differ toneAmber
class node_dev_tools,node_tool_groups toneMint
class node_benchmarks toneRose
class node_site_app,node_docs_main toneIndigo
class node_tests_int,node_tests_unit toneTeal
```

## Components

### Runtime

Core MCP server and browser-facing execution path

- [Entry](https://github.com/ticktockbent/charlotte/blob/main/src/index.ts): mcp entrypoint · Process startup and CLI handoff · `src/index.ts`
- [CLI](https://github.com/ticktockbent/charlotte/blob/main/src/cli.ts): arg parsing · Command-line startup and configuration · `src/cli.ts`
- [Server](https://github.com/ticktockbent/charlotte/blob/main/src/server.ts): mcp transport · MCP server wiring over stdio · `src/server.ts`
- [Browser](https://github.com/ticktockbent/charlotte/blob/main/src/browser/browser-manager.ts): browser session · Persistent Chromium session and tab lifecycle · `src/browser/browser-manager.ts`
- [Pages](https://github.com/ticktockbent/charlotte/blob/main/src/browser/page-manager.ts): page lifecycle · Page switching and page-scoped operations · `src/browser/page-manager.ts`
- [CDP](https://github.com/ticktockbent/charlotte/blob/main/src/browser/cdp-session.ts): session bridge · Low-level Chrome DevTools Protocol session handling · `src/browser/cdp-session.ts`
- [Renderer](https://github.com/ticktockbent/charlotte/blob/main/src/renderer/renderer-pipeline.ts): representation pipeline · Builds compact structured page representations · `src/renderer/renderer-pipeline.ts`
- [A11y](https://github.com/ticktockbent/charlotte/blob/main/src/renderer/accessibility-extractor.ts): signal extractor · Accessibility tree extraction · `src/renderer/accessibility-extractor.ts`
- [Layout](https://github.com/ticktockbent/charlotte/blob/main/src/renderer/layout-extractor.ts): signal extractor · Bounding boxes and layout signals · `src/renderer/layout-extractor.ts`
- [Interactives](https://github.com/ticktockbent/charlotte/blob/main/src/renderer/interactive-extractor.ts): signal extractor · Interactive elements and stable IDs · `src/renderer/interactive-extractor.ts`
- [Structure](https://github.com/ticktockbent/charlotte/blob/main/src/renderer/structural-tree-extractor.ts): signal extractor · Landmarks, headings, and structural tree · `src/renderer/structural-tree-extractor.ts`
- [Content](https://github.com/ticktockbent/charlotte/blob/main/src/renderer/content-extractor.ts): signal extractor · Page text and content summaries · `src/renderer/content-extractor.ts`

### State

Page state, snapshots, and diffs

- [State](https://github.com/ticktockbent/charlotte/blob/main/src/state/snapshot-store.ts): page state · Cross-call page state and snapshot coordination · `src/state/snapshot-store.ts`
- [Artifacts](https://github.com/ticktockbent/charlotte/blob/main/src/state/artifact-store.ts): artifact store · Screenshot and artifact persistence · `src/state/artifact-store.ts`
- [Diffs](https://github.com/ticktockbent/charlotte/blob/main/src/state/differ.ts): structural diff · Compare current state with prior snapshots · `src/state/differ.ts`

### Support

Development mode and shared helpers

- [Dev mode](https://github.com/ticktockbent/charlotte/blob/main/src/dev/dev-mode-state.ts): developer tools · Local file serving, watching, and audits · `src/dev/dev-mode-state.ts`
- [Tools](https://github.com/ticktockbent/charlotte/blob/main/src/tools/tool-groups.ts): tool registry · Capability groups and profile-based tool exposure · `src/tools/tool-groups.ts`

### Evaluation

Benchmarks and harness

- [Benchmarks](https://github.com/ticktockbent/charlotte/blob/main/benchmarks/run-benchmarks.ts): evaluation suite · Reproducible scenarios and saved results · `benchmarks/run-benchmarks.ts`

### Docs

Documentation and marketing site

- [Site](https://github.com/ticktockbent/charlotte/blob/main/site/app/page.tsx): nextjs site · Documentation and benchmark presentation site · `site/app/page.tsx`
- [Docs](https://github.com/ticktockbent/charlotte/blob/main/docs/CHARLOTTE_SPEC.md): specs and guides · Repository documentation and MCP usage guidance · `docs/CHARLOTTE_SPEC.md`

### Quality

Test coverage and fixtures

- [Integration](https://github.com/ticktockbent/charlotte/blob/main/tests/integration/renderer-pipeline.test.ts): system tests · End-to-end tests against real browser behavior · `tests/integration/renderer-pipeline.test.ts`
- [Unit](https://github.com/ticktockbent/charlotte/blob/main/tests/unit/tools/create-server.test.ts): component tests · Focused tests for browser, renderer, state, and tools · `tests/unit/tools/create-server.test.ts`

### Delivery

Packaging and deployment

- [Docker](https://github.com/ticktockbent/charlotte/tree/main/Dockerfile): deployment packaging · Container build and self-contained runtime distribution · `Dockerfile`

## Connections

- Entry → CLI: starts · Entry delegates to CLI startup
- CLI → Server: creates · CLI configures and launches the MCP server
- Server → Tools: registers · Server exposes grouped MCP capabilities and profiles
- Server → Browser: drives · Tools translate client requests into browser operations
- Browser → Pages: manages · Browser session hands off page/tab lifecycle
- Browser → CDP: uses · Browser control is mediated through CDP sessions
- Pages → Renderer: renders · Current page context is rendered into structured output
- Renderer → A11y: fuses · Pipeline incorporates accessibility signals
- Renderer → Layout: fuses · Pipeline incorporates layout signals
- Renderer → Interactives: fuses · Pipeline incorporates interactive metadata and stable IDs
- Renderer → Structure: fuses · Pipeline incorporates structural landmarks and headings
- Renderer → Content: fuses · Pipeline incorporates text and summary signals
- Renderer → State: emits · Rendered representations are stored and reused across calls
- State → Artifacts: persists · Snapshots link to saved artifacts such as screenshots
- State → Diffs: compares · Prior snapshots are used for structural diffs
- Tools → Dev mode: exposes · One capability group covers development mode operations
- Dev mode → Browser: controls · Dev mode still routes through the browser/session layer when needed
- Server → State: shares · Server tools read and update page state
- Benchmarks → Tools: measures · Benchmark harness evaluates profiles and tool overhead
- Site → Docs: publishes · Site surfaces docs and benchmark narratives
- Integration → Renderer: covers · Integration tests validate the render pipeline
- Integration → Browser: covers · Integration tests exercise browser control and interactions
- Unit → Tools: covers · Unit tests validate server profiles and tool assembly
- Docker → Server: packages · Container builds the local MCP server runtime
