# rsrohan99/tig architecture

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

- Interactive diagram: https://gitdiagram.com/rsrohan99/tig
- Repository: https://github.com/rsrohan99/tig

## Overview

##### Project type and purpose
- Tig is an open-source, terminal-based autonomous AI coding agent.
- It orchestrates multiple LLMs (via LlamaIndex workflows), analyzes and mutates a local codebase (using Tree-sitter, ripgrep, diff-match-patch), executes shell commands, and writes or updates files.

##### File structure
- Top-level: configuration (.env, pyproject.toml), README, CLI entry point.
- src/tig/modes.py: defines high-level modes (architect, code).
- src/tig/prompts: static prompt templates (system, task, environment, objectives, rules) and per-tool prompt docs.
- src/tig/services: integrations and wrappers
- llms.py → LLM provider adapter
- command_runner.py → shell execution
- tree_sitter/ → code parsing and syntax checking
- src/tig/tools: concrete implementations of “actions” (list_files, read_file, write_to_file, apply_diff, etc.) invoked by the agent.
- src/tig/utils: helper functions (intro messaging, verbose logging, XML templating, syntax checker utilities).
- src/tig/workflows/tig.py: orchestrates the overall LlamaIndex Workflow, bringing together modes, prompts, services, and tools.

##### README for insights
- Supported LLMs: Google Gemini, OpenAI, Claude, etc. → LLM abstraction layer.
- Dependencies: ripgrep, Tree-sitter, diff-match-patch.
- Two primary modes: Architect (design step) vs Code (implementation step).
- Interaction flow: user issues task → agent loops prompt→LLM→tool execution→update code.

##### Main components
a. CLI Interface
- Entry point “tig” CLI
- Parses flags (mode, auto-approve)
b. Workflow Orchestrator
- LlamaIndex Workflow defined in workflows/tig.py
- Controls conversation loop and task state
c. Prompt Manager
- Loads and renders prompt templates (src/tig/prompts/*)
- Supplies context (environment, objectives, rules)
d. LLM Provider Adapter
- Abstracts calls to different LLM providers (llms.py)
e. Tool Executor
- Exposes standardized tool API for codebase operations
- Tools: list_files, read_file, write_to_file, apply_diff, execute_command, etc.
f. Codebase Analyzers
- Tree-sitter parser & queries for function/class definitions, syntax checks
- Ripgrep for regex searches
g. Diff Engine
- Google diff-match-patch for computing and displaying deltas
h. Local File System & Shell
- Underlying resources: file read/write, shell command execution
i. External Services
- LLM endpoints (OpenAI, Google, Claude, etc.)

##### Relationships and data flows
- User CLI input → Workflow Orchestrator
- Orchestrator pulls prompt templates → Prompt Manager → renders full prompt
- Rendered prompt → LLM Adapter → external LLM → returns response
- Response → parsed by Orchestrator → decides tool to invoke
- Tool Executor → invokes Codebase Analyzer or Shell Command
- Analyzer/Command → returns result → Orchestrator
- Diff Engine computes changes → File System updated via Tool → Orchestrator loops or terminates

##### Architectural patterns & design principles
- Modular “tool” pattern: separates LLM reasoning from actionable code operations
- Dependency inversion: service interfaces (LLM, command runner, parser) abstract implementations
- Workflow orchestration: single coordinator managing state and multi-turn interactions
- Template-driven prompts for consistency and maintainability

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Core Components
    CLI["CLI Interface"]:::core
    click CLI "https://github.com/rsrohan99/tig/blob/master/pyproject.toml"
    Orchestrator["Workflow Orchestrator"]:::core
    click Orchestrator "https://github.com/rsrohan99/tig/blob/master/src/tig/workflows/tig.py"
    ModeDefs["Mode Definitions<br/>(Architect vs Code)"]:::core
    click ModeDefs "https://github.com/rsrohan99/tig/blob/master/src/tig/modes.py"

    %% Prompting
    PromptMgr["Prompt Manager"]:::prompt
    click PromptMgr "https://github.com/rsrohan99/tig/tree/master/src/tig/prompts/"

    %% LLM Integration
    LLMAdapter["LLM Provider Adapter"]:::execution
    click LLMAdapter "https://github.com/rsrohan99/tig/blob/master/src/tig/services/llms.py"
    ExternalLLM["External LLM Endpoints"]:::external

    %% Execution & Analysis
    ToolExec["Tool Executor"]:::execution
    click ToolExec "https://github.com/rsrohan99/tig/tree/master/src/tig/tools/"
    Analyzers["Codebase Analyzers"]:::execution
    click Analyzers "https://github.com/rsrohan99/tig/blob/master/src/tig/services/tree_sitter/parsers.py"
    ShellExec["Shell Executor"]:::execution
    click ShellExec "https://github.com/rsrohan99/tig/blob/master/src/tig/services/command_runner.py"

    %% Diff & File System
    DiffEngine["Diff Engine"]:::execution
    click DiffEngine "https://github.com/rsrohan99/tig/blob/master/src/tig/tools/apply_diff.py"
    FileOps["Local File System"]:::external

    %% Utilities
    Utilities["Utility Helpers"]:::utility
    click Utilities "https://github.com/rsrohan99/tig/tree/master/src/tig/utils/"

    %% Data Flows
    CLI -->|user command| Orchestrator
    Orchestrator --> ModeDefs
    Orchestrator -->|load templates| PromptMgr
    PromptMgr -->|rendered prompt| Orchestrator
    Orchestrator -->|prompt payload| LLMAdapter
    LLMAdapter -->|API call| ExternalLLM
    ExternalLLM -->|LLM response| LLMAdapter
    LLMAdapter -->|response| Orchestrator
    Orchestrator -->|invoke tool| ToolExec
    ToolExec -->|analyze code| Analyzers
    ToolExec -->|run shell| ShellExec
    Analyzers -->|analysis result| Orchestrator
    ShellExec -->|command output| Orchestrator
    Orchestrator -->|compute diff| DiffEngine
    DiffEngine -->|patch| FileOps
    Orchestrator -->|loop/terminate| CLI

    %% Utility Dependencies
    Orchestrator -.-> Utilities
    PromptMgr -.-> Utilities
    ToolExec -.-> Utilities

    classDef core fill:#D0E6FF,stroke:#0366d6,color:#0366d6
    classDef prompt fill:#E6FFEA,stroke:#28a745,color:#28a745
    classDef execution fill:#FFEFD5,stroke:#d2691e,color:#d2691e
    classDef external fill:#F0F0F0,stroke:#666,color:#333
    classDef utility fill:#FFF5E6,stroke:#DAA520,color:#DAA520
```
