# deedy/mac_computer_use architecture

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

- Interactive diagram: https://gitdiagram.com/deedy/mac_computer_use
- Repository: https://github.com/deedy/mac_computer_use

## Overview

##### Project type and purpose
- This is a full‑stack, locally‑hosted “agent” application for macOS.
- It exposes a web UI (via Streamlit) that takes user prompts, sends them to an LLM (Anthropic, Bedrock, or Vertex), then executes the model’s responses as native macOS commands (screen capture, mouse/keyboard control, file edits, etc.).

##### File structure
- Top‑level files:
- Dockerfile (legacy container support)
- streamlit.py (Streamlit app entry point)
- loop.py (agent orchestration loop)
- setup.sh / requirements.txt (installation)
- tools/ (Python modules that wrap different OS‑interaction commands)
- The `tools` package contains submodules for each class of action (bash, edit, run, computer [mouse/keyboard], collection, base).
- No database or external storage—state flows through memory and the OS file system.

##### README for additional insights
- Purpose: Replace the Dockerized demo with a native macOS version.
- Key technologies: Python 3.12, Streamlit, cliclick, native `screencapture`, Anthropic LLM API (with optional Bedrock/Vertex).
- Operational flow: UI → LLM API → OS command execution → UI.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User
    User["User"]:::external

    %% Frontend Layer
    subgraph "Frontend Layer"
        Streamlit["Streamlit UI<br/>(streamlit.py)"]:::frontend
    end

    %% Backend Orchestrator
    subgraph "Backend Layer"
        Agent["Agent Loop<br/>(loop.py)"]:::backend
    end

    %% Tools Adapters
    subgraph "Tools Adapters"
        Base["Base Adapter<br/>(tools/base.py)"]:::backend
        Bash["Bash Adapter<br/>(tools/bash.py)"]:::backend
        Run["Run Adapter<br/>(tools/run.py)"]:::backend
        Edit["Edit Adapter<br/>(tools/edit.py)"]:::backend
        Collection["Collection Adapter<br/>(tools/collection.py)"]:::backend
        Computer["Computer Adapter<br/>(tools/computer.py)"]:::backend
    end

    %% OS Utilities
    subgraph "macOS Utilities"
        Screencapture["screencapture"]:::os
        Cliclick["cliclick"]:::os
        FS["File System"]:::os
    end

    %% External LLM APIs
    subgraph "LLM Providers"
        Anthropic["Anthropic API"]:::external
        Bedrock["Bedrock API"]:::external
        Vertex["Vertex AI"]:::external
    end

    %% Config Layer
    subgraph "Configuration"
        Setup["setup.sh"]:::config
        Req["requirements.txt"]:::config
    end

    %% Legacy Docker Support
    Docker["Docker Engine<br/>(Dockerfile)"]:::external

    %% Connections
    User -->|"HTTP localhost:8501"| Streamlit
    Streamlit -->|"invoke"| Agent
    Agent -->|"load"| Setup
    Agent -->|"load"| Req
    Agent -->|"select & call"| Anthropic
    Agent -->|"or"| Bedrock
    Agent -->|"or"| Vertex
    Agent -->|"delegate"| Base
    Agent -->|"delegate"| Bash
    Agent -->|"delegate"| Run
    Agent -->|"delegate"| Edit
    Agent -->|"delegate"| Collection
    Agent -->|"delegate"| Computer
    Base -->|"subprocess"| FS
    Bash -->|"subprocess"| FS
    Run -->|"subprocess"| FS
    Edit -->|"subprocess"| FS
    Collection -->|"subprocess"| FS
    Computer -->|"subprocess"| FS
    FS -->|"access"| Screencapture
    FS -->|"access"| Cliclick
    Agent -->|"fallback"| Docker
    Agent -->|"update results"| Streamlit

    %% Click Events
    click Streamlit "https://github.com/deedy/mac_computer_use/blob/main/streamlit.py"
    click Agent "https://github.com/deedy/mac_computer_use/blob/main/loop.py"
    click Base "https://github.com/deedy/mac_computer_use/blob/main/tools/base.py"
    click Bash "https://github.com/deedy/mac_computer_use/blob/main/tools/bash.py"
    click Run "https://github.com/deedy/mac_computer_use/blob/main/tools/run.py"
    click Edit "https://github.com/deedy/mac_computer_use/blob/main/tools/edit.py"
    click Collection "https://github.com/deedy/mac_computer_use/blob/main/tools/collection.py"
    click Computer "https://github.com/deedy/mac_computer_use/blob/main/tools/computer.py"
    click Setup "https://github.com/deedy/mac_computer_use/blob/main/setup.sh"
    click Req "https://github.com/deedy/mac_computer_use/blob/main/requirements.txt"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#004085,color:#004085;
    classDef backend fill:#d4edda,stroke:#155724,color:#155724;
    classDef external fill:#e2e3e5,stroke:#6c757d,color:#383d41;
    classDef os fill:#fff3cd,stroke:#856404,color:#856404;
    classDef config fill:#e2e3e5,stroke:#6c757d,color:#383d41;
```
