# nghialt3670/chat2edit-python architecture

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

- Interactive diagram: https://gitdiagram.com/nghialt3670/chat2edit-python
- Repository: https://github.com/nghialt3670/chat2edit-python

## Overview

##### Project type and purpose
- Chat2Edit is a Python library/package (not a full‐stack web app) that provides an API/CLI for AI-assisted file editing.
- Its purpose is to let end-users or other programs call into Chat2Edit to orchestrate prompts, apply AI-driven diffs, and persist edits.

##### File structure
- Top‐level: project metadata and config (.github, pyproject.toml, requirements.txt, LICENSE, README.md).
- src/chat2edit – the core package subdivided into:
- base.py, chat2edit.py, constants.py – entry points and shared constants
- context/ – manages file I/O contexts, attachments, resource cleanup
- execution/ – orchestrates running code, diff application, error handling, feedback signals
- prompting/ – constructs LLM prompts, houses strategies, and abstracts LLM providers
– l l m s/ – specific connectors (OpenAI, Google)
– strategies/ – prompt‐construction policies
– stubbing/ – test harness for mocking LLMs
- models.py – data schemas (likely Pydantic)
- utils/ – helper routines (repr, Pydantic integration)

##### README for additional insights
- Confirms the library focus: AI-powered file editing, collaboration APIs.

##### Detailed breakdown
- Inside “Prompting”, separate “Strategies” and “Adapters”
- In “Execution”, call out decorators, feedback pipeline, exceptions
- Link “prompting.stubbing” back to “Prompting” to show the mock override path

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client Layer"
        CLI["CLI / API Entry Points"]:::client
    end

    %% Core Engine
    subgraph "Core Engine"
        Core["Chat2Edit Core (Chat2Edit)"]:::core
        Const["Constants"]:::core
    end

    %% Context Manager
    subgraph "Context Manager"
        Attachment["Attachment Handling"]:::context
        Manage["Context Lifecycle & Management"]:::context
        CtxUtil["Context Utilities"]:::context
    end

    %% Prompting Subsystem
    subgraph "Prompting Subsystem"
        subgraph "LLM Adapters"
            OpenAIAdapter["OpenAI Adapter"]:::adapter
            GoogleAdapter["Google Adapter"]:::adapter
        end
        Strategy["Prompt Construction Strategies"]:::strategy
        subgraph "Stubbing/Test Harness"
            StubBuilders["Stub Builders"]:::stub
            StubStubs["Stub Definitions"]:::stub
            StubDecorators["Stub Decorators"]:::stub
            StubReplacers["Stub Replacers"]:::stub
            StubConsts["Stubbing Constants"]:::stub
            StubUtils["Stubbing Utilities"]:::stub
        end
    end

    %% Execution Subsystem
    subgraph "Execution Subsystem"
        CodeRunner["Code Runner & Diff Applier"]:::execution
        ExecDecorators["Execution Decorators"]:::execution
        Signaling["Signaling"]:::execution
        Feedback["Feedback Pipeline"]:::execution
        Exceptions["Exception Handling"]:::execution
        ExecUtil["Execution Utilities"]:::execution
    end

    %% Models & Utils
    subgraph "Models & Utils"
        Models["Data Models"]:::model
        UtilPydantic["Pydantic Integration"]:::util
        UtilRepr["Representation Helpers"]:::util
    end

    %% External Services
    subgraph "External Services"
        OpenAIAPI["OpenAI API"]:::externalService
        GoogleAPI["Google LLM API"]:::externalService
    end

    %% File System
    FileSystem["Local File System"]:::filesystem

    %% Project Metadata & Config
    subgraph "Project Metadata & Config"
        PyProj["pyproject.toml"]:::metadata
        Req["requirements.txt"]:::metadata
        CI[".github/workflows/release.yaml"]:::metadata
        License["LICENSE / README.md"]:::metadata
    end

    %% Connections
    CLI -->|"invoke"| Core
    Core -->|"load files"| Attachment
    Core -->|"load files"| Manage
    Core -->|"context utils"| CtxUtil

    Core -->|"generate prompt"| Strategy
    Strategy -->|"uses adapters"| OpenAIAdapter
    Strategy -->|"uses adapters"| GoogleAdapter
    OpenAIAdapter -->|"calls"| OpenAIAPI
    GoogleAdapter -->|"calls"| GoogleAPI

    Core -->|"execute diff"| CodeRunner
    CodeRunner -->|apply| FileSystem
    Core -->|"handle exceptions"| Exceptions
    CodeRunner -->|"signal"| Signaling
    Signaling -->|feedback| Feedback
    Feedback -->|report| Core

    Core -->|"use models/util"| Models
    Core -->|"use models/util"| UtilPydantic
    Core -->|"use models/util"| UtilRepr

    %% Utils & Stubbing Integration
    Strategy -->|DI Override| StubBuilders
    StubBuilders --> StubStubs
    StubDecorators --> StubReplacers
    StubConsts --> StubUtils

    %% Export & Config
    Core --> PyProj
    Core --> Req
    Core --> CI
    Core --> License

    %% Filesystem
    Core --> FileSystem

    %% Click Events
    click CLI "https://github.com/nghialt3670/chat2edit-python/blob/main/src/chat2edit/base.py"
    click Core "https://github.com/nghialt3670/chat2edit-python/blob/main/src/chat2edit/chat2edit.py"
    click Const "https://github.com/nghialt3670/chat2edit-python/blob/main/src/chat2edit/constants.py"
    click Attachment "https://github.com/nghialt3670/chat2edit-python/blob/main/src/chat2edit/context/attachment.py"
    click Manage "https://github.com/nghialt3670/chat2edit-python/blob/main/src/chat2edit/context/manage.py"
    click CtxUtil "https://github.com/nghialt3670/chat2edit-python/blob/main/src/chat2edit/context/utils.py"
    click OpenAIAdapter "https://github.com/nghialt3670/chat2edit-python/blob/main/src/chat2edit/prompting/llms/openai_llm.py"
    click GoogleAdapter "https://github.com/nghialt3670/chat2edit-python/blob/main/src/chat2edit/prompting/llms/google_llm.py"
    click Strategy "https://github.com/nghialt3670/chat2edit-python/blob/main/src/chat2edit/prompting/strategies/otc_strategy.py"
    click StubBuilders "https://github.com/nghialt3670/chat2edit-python/blob/main/src/chat2edit/prompting/stubbing/builders.py"
    click StubStubs "https://github.com/nghialt3670/chat2edit-python/blob/main/src/chat2edit/prompting/stubbing/stubs.py"
    click StubDecorators "https://github.com/nghialt3670/chat2edit-python/blob/main/src/chat2edit/prompting/stubbing/decorators.py"
    click StubReplacers "https://github.com/nghialt3670/chat2edit-python/blob/main/src/chat2edit/prompting/stubbing/replacers.py"
    click StubConsts "https://github.com/nghialt3670/chat2edit-python/blob/main/src/chat2edit/prompting/stubbing/constants.py"
    click StubUtils "https://github.com/nghialt3670/chat2edit-python/blob/main/src/chat2edit/prompting/stubbing/utils.py"
    click CodeRunner "https://github.com/nghialt3670/chat2edit-python/blob/main/src/chat2edit/execution/code.py"
    click ExecDecorators "https://github.com/nghialt3670/chat2edit-python/blob/main/src/chat2edit/execution/decorators.py"
    click Signaling "https://github.com/nghialt3670/chat2edit-python/blob/main/src/chat2edit/execution/signaling.py"
    click Feedback "https://github.com/nghialt3670/chat2edit-python/blob/main/src/chat2edit/execution/feedbacks.py"
    click Exceptions "https://github.com/nghialt3670/chat2edit-python/blob/main/src/chat2edit/execution/exceptions.py"
    click ExecUtil "https://github.com/nghialt3670/chat2edit-python/blob/main/src/chat2edit/execution/utils.py"
    click Models "https://github.com/nghialt3670/chat2edit-python/blob/main/src/chat2edit/models.py"
    click UtilPydantic "https://github.com/nghialt3670/chat2edit-python/blob/main/src/chat2edit/utils/pydantic.py"
    click UtilRepr "https://github.com/nghialt3670/chat2edit-python/blob/main/src/chat2edit/utils/repr.py"

    %% Styles
    classDef client fill:#FFD700,stroke:#333,stroke-width:1px
    classDef core fill:#FF8C00,stroke:#333,stroke-width:1px
    classDef context fill:#87CEFA,stroke:#333,stroke-width:1px
    classDef adapter fill:#7FFFD4,stroke:#333,stroke-width:1px
    classDef strategy fill:#7FFFD4,stroke:#333,stroke-width:1px
    classDef stub fill:#E6E6FA,stroke:#333,stroke-dasharray: 5 5
    classDef execution fill:#98FB98,stroke:#333,stroke-width:1px
    classDef model fill:#D3D3D3,stroke:#333,stroke-width:1px
    classDef util fill:#D3D3D3,stroke:#333,stroke-width:1px
    classDef externalService fill:#FA8072,stroke:#333,stroke-width:1px
    classDef filesystem fill:#C0C0C0,stroke:#333,stroke-width:1px
    classDef metadata fill:#EEE8AA,stroke:#333,stroke-width:1px
```
