# yajusta/chapito architecture

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

- Interactive diagram: https://gitdiagram.com/yajusta/chapito
- Repository: https://github.com/yajusta/chapito

## Overview

##### Project Type and Purpose
- Chapito is a “chat-to-API” proxy that enables API-dependent applications to use various web-based chatbots (e.g., Grok, Mistral, OpenAI, DeepSeek, Anthropic) without requiring additional API subscriptions.
- Its main goal is to forward API requests (formatted in an OpenAI-compatible manner) from client AI tools to an underlying web-based chatbot, leveraging browser automation to simulate the chatbot’s native interface.

##### File Structure
- Top-level files like main.py and pyproject.toml indicate this is a Python project.
- The “chapito” directory contains different modules for integrating with specific chatbots (e.g., anthropic_chat.py, grok_chat.py, mistral_chat.py, etc.). This pattern shows that the project uses a modular approach where each chatbot integration is encapsulated in its own module.
- Supporting files such as config.py, config.ini.sample, and the tools folder (with log.py and additional tools) suggest there is a well-defined configuration and logging mechanism.
- Tests are provided in a dedicated “tests” folder, which is useful for understanding component testing boundaries.

##### README for Additional Insights
- The README clearly outlines the purpose as a proxy server that bridges web-based chatbots and API-dependent applications.
- It details the workflow: a local proxy server opens a Chromium browser, interacting with a chatbot’s webpage, then returns responses customized to the OpenAI API format.
- The README also explains command-line parameters and configuration settings (via config.ini) which support the idea of a flexible and dynamic setup.

a. Main Components:
- API Proxy Server (main entry point – main.py): Acts as the interface receiving API requests from client applications.
- Chatbot Integration Modules: Each module (e.g., grok_chat.py, mistral_chat.py, openai_chat.py, etc.) encapsulates the logic for interfacing with a particular chatbot.
- Browser Automation Component: Responsible for launching and controlling a Chromium browser session to load the chatbot’s webpage and automate queries.
- Configuration & Logging Module: Includes config.py, config.ini.sample, and tools/log.py to manage settings and log activities.
- Client Applications / External AI Tools: These are tools like AIder, Cline, or Roo-Code that send API requests to Chapito.
- (Optional) Testing Suite: Represent the tests directory which ensures each component works as expected.

b. Relationships and Interactions:
- Application’s configuration flow by linking “Configuration & Logging Module” to the API Proxy Server and Integration Modules, indicating that parameters and logging are shared across components.

c. Architectural Patterns and Technologies:
- Modularity: each chatbot integration is self-contained, aligning with a plug-and-play approach.
- Use of browser automation to integrate non-API chatbots.
- That the system adheres to a proxy design pattern, acting as a mediator between internal chatbot modules and external API clients.
- Mention that the project uses Python (3.12+) and “uv” (a tool likely used for running and serving the application) as part of its runtime infrastructure.

- Since Chapito is effectively a proxy for APIs that uses browser automation, place extra emphasis on how requests from AI tools are routed through the local proxy and transformed into browser-based interactions.
- Flow from user-initiated API calls, through command-line parameters or config files, to the proper integration module, browser automation layer, and back to the user.
- Annotations for supported chatbots (e.g., Grok, Mistral, etc.) to show that the system can easily expand with additional modules.

##### Final Checklist
- Module (from main.py to the various "chapito/*_chat.py" modules) is represented.
- Interaction between the client application and Chapito’s API (including streaming vs. non-streaming aspects as described in the README).
- Don’t overlook the configuration flow (parameters, user-agent settings, logging) that influences how the proxy server operates.
- Notes on future extensibility (e.g., additional chatbot support like Gemini or Perplexity) to give context on how the system can evolve.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global Components
    ClientAI["Client AI Tools"]:::client

    subgraph "API Proxy Server"
        APIProxy["API Proxy Server"]:::api
    end

    ClientAI -->|"Sends_API_Request"| APIProxy

    subgraph "Chatbot Integration Modules"
        Anthrop["Anthropic Module"]:::module
        DeepSeek["DeepSeek Module"]:::module
        Gemini["Gemini Module"]:::module
        Grok["Grok Module"]:::module
        Mistral["Mistral Module"]:::module
        OpenAI["OpenAI Module"]:::module
        Perplexity["Perplexity Module"]:::module
    end

    %% API Proxy forwards to Chatbot Modules
    APIProxy -->|"Forwards_Request"| Anthrop
    APIProxy -->|"Forwards_Request"| DeepSeek
    APIProxy -->|"Forwards_Request"| Gemini
    APIProxy -->|"Forwards_Request"| Grok
    APIProxy -->|"Forwards_Request"| Mistral
    APIProxy -->|"Forwards_Request"| OpenAI
    APIProxy -->|"Forwards_Request"| Perplexity

    %% Chatbot Modules interact with Browser Automation
    Anthrop -->|"Uses_Browser"| Browser
    DeepSeek -->|"Uses_Browser"| Browser
    Gemini -->|"Uses_Browser"| Browser
    Grok -->|"Uses_Browser"| Browser
    Mistral -->|"Uses_Browser"| Browser
    OpenAI -->|"Uses_Browser"| Browser
    Perplexity -->|"Uses_Browser"| Browser

    Browser["Browser Automation Component"]:::browser

    %% Browser sends response back to API Proxy then to Client AI Tools
    Browser -->|"Response_Flow"| APIProxy
    APIProxy -->|"Sends_Response"| ClientAI

    %% Configuration & Logging Subsystem
    subgraph "Configuration & Logging"
        Config["Configuration Module"]:::config
        Logging["Logging Module"]:::config
    end

    Config --> APIProxy
    Config --> Anthrop
    Config --> DeepSeek
    Config --> Gemini
    Config --> Grok
    Config --> Mistral
    Config --> OpenAI
    Config --> Perplexity

    Logging --> APIProxy
    Logging --> Anthrop
    Logging --> DeepSeek
    Logging --> Gemini
    Logging --> Grok
    Logging --> Mistral
    Logging --> OpenAI
    Logging --> Perplexity

    %% Testing Suite
    Testing["Testing Suite"]:::testing
    Testing --- APIProxy
    Testing --- Anthrop
    Testing --- Config

    %% Click Events for API Proxy Server Components
    click APIProxy "https://github.com/yajusta/chapito/blob/main/main.py"
    click APIProxy "https://github.com/yajusta/chapito/blob/main/chapito/proxy.py"

    %% Click Events for Chatbot Integration Modules
    click Anthrop "https://github.com/yajusta/chapito/blob/main/chapito/anthropic_chat.py"
    click DeepSeek "https://github.com/yajusta/chapito/blob/main/chapito/deepseek_chat.py"
    click Gemini "https://github.com/yajusta/chapito/blob/main/chapito/gemini_chat.py"
    click Grok "https://github.com/yajusta/chapito/blob/main/chapito/grok_chat.py"
    click Mistral "https://github.com/yajusta/chapito/blob/main/chapito/mistral_chat.py"
    click OpenAI "https://github.com/yajusta/chapito/blob/main/chapito/openai_chat.py"
    click Perplexity "https://github.com/yajusta/chapito/blob/main/chapito/perplexity_chat.py"

    %% Click Events for Configuration & Logging Modules
    click Config "https://github.com/yajusta/chapito/blob/main/chapito/config.py"
    click Config "https://github.com/yajusta/chapito/blob/main/config.ini.sample"
    click Logging "https://github.com/yajusta/chapito/blob/main/chapito/tools/log.py"

    %% Click Events for Testing Suite
    click Testing "https://github.com/yajusta/chapito/tree/main/tests"
    click Testing "https://github.com/yajusta/chapito/blob/main/tests/test_anthropic.py"
    click Testing "https://github.com/yajusta/chapito/blob/main/tests/test_config.py"

    %% Click Event for Browser Automation Component
    click Browser "https://github.com/yajusta/chapito/blob/main/chapito/proxy.py"

    %% Styles
    classDef client fill:#ffccff,stroke:#333,stroke-width:2px;
    classDef api fill:#cce5ff,stroke:#333,stroke-width:2px;
    classDef module fill:#ccffcc,stroke:#333,stroke-width:2px;
    classDef browser fill:#ffcccc,stroke:#333,stroke-width:2px;
    classDef config fill:#ffffcc,stroke:#333,stroke-width:2px;
    classDef testing fill:#e0e0e0,stroke:#333,stroke-width:2px;
```
