# nat/natbot architecture

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

- Interactive diagram: https://gitdiagram.com/nat/natbot
- Repository: https://github.com/nat/natbot

## Overview

Key Components to Include:

##### Core Components
- Browser Interface component
- Natbot.py core engine
- DOM Parser/Serializer

##### Data Flow Architecture
a. User Input/Command → natbot.py
b. natbot.py → GPT-3 API (prompt processing)
c. GPT-3 → natbot.py (action decisions)
d. natbot.py → Browser (execution)
e. Browser → natbot.py (DOM feedback)

- [User Layer]
- ↕
- [Core Layer: natbot.py]
- ↕
- [Service Layer: GPT-3 API]
- ↕
- [Browser Layer]

##### Component Representation
- Use rectangles for local components (natbot.py)
- Use clouds for external services (GPT-3)
- Use hexagons for processing units (DOM serializer)

##### Connection Types

Special Considerations:

##### Feedback Loops
- Circular nature of the browser interaction
- How DOM information feeds back into the decision-making process

##### State Management
- A component showing how browser state is maintained
- How commands are translated into browser actions

##### Future Extensibility
- Multi-tab support
- Feedback collection system
- Prompt chain processor

- Component types (local, external, browser)
- State indicators

Level of Detail:
- Prompt handling
- Browser control logic
- DOM serialization
- Command parsing

Remember to indicate potential expansion points for the improvements mentioned in the README, but keep them visually distinct from the current implementation.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles
    classDef core fill:#3498db,stroke:#2980b9,color:white
    classDef external fill:#2ecc71,stroke:#27ae60,color:white
    classDef browser fill:#e67e22,stroke:#d35400,color:white
    classDef processing fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef planned fill:none,stroke:#34495e,stroke-dasharray: 5 5

    %% User Layer
    subgraph UserLayer
        User[User Input/Command]
    end

    %% Core Layer
    subgraph CoreLayer
        NatBot[natbot.py Core Engine]:::core
        PromptHandler[Prompt Handler]:::core
        CommandParser[Command Parser]:::core
        BrowserControl[Browser Control Logic]:::core
        DOMProcessor[DOM Parser/Serializer]:::processing
    end

    %% Service Layer
    subgraph ServiceLayer
        GPT3[GPT-3 API]:::external
    end

    %% Browser Layer
    subgraph BrowserLayer
        Browser[Browser Interface]:::browser
        BrowserState[Browser State]:::browser
    end

    %% Planned Features
    subgraph PlannedFeatures
        MultiTab[Multi-tab Support]:::planned
        FeedbackSystem[Feedback Collection]:::planned
        PromptChain[Prompt Chain Processor]:::planned
    end

    %% Connections
    User --> NatBot
    NatBot --> PromptHandler
    PromptHandler -.-> GPT3
    GPT3 -.-> PromptHandler
    PromptHandler --> CommandParser
    CommandParser --> BrowserControl
    BrowserControl --> Browser
    Browser --> DOMProcessor
    DOMProcessor --> NatBot
    Browser <--> BrowserState

    %% Legend
    subgraph Legend
        L1[Local Component]:::core
        L2[External Service]:::external
        L3[Browser Component]:::browser
        L4[Processing Unit]:::processing
        L5[Planned Feature]:::planned
    end

    %% Click Events
    click NatBot "https://github.com/nat/natbot/blob/main/natbot.py"
    click PromptHandler "https://github.com/nat/natbot/blob/main/natbot.py"
    click CommandParser "https://github.com/nat/natbot/blob/main/natbot.py"
    click BrowserControl "https://github.com/nat/natbot/blob/main/natbot.py"
    click DOMProcessor "https://github.com/nat/natbot/blob/main/natbot.py"
    click Browser "https://github.com/nat/natbot/blob/main/natbot.py"
```
