# cortesi/tenx architecture

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

- Interactive diagram: https://gitdiagram.com/cortesi/tenx
- Repository: https://github.com/cortesi/tenx

## Overview

##### Main Components

a) Core Library (libtenx):
- Configuration Management
- Model Integration Layer
- Dialect System
- Patch Management
- Session Management

b) CLI Applications:
- tenx (main application)
- ttrial (benchmarking/testing tool)

##### Component Relationships

**┌─ User Interface Layer ─────────────────────┐**
- CLI (tenx, ttrial)                        │
- ┬─────────────────────────┘
- ↓
**┌─ Core Library (libtenx) ──────────────────┐**
- ┌─────────────┐  ┌──────────┐  ┌────────┐ │
- Configuration│  │ Session  │  │Context │ │
- Management   │←→│ Manager  │←→│Handler │ │
- ┘  └──────────┘  └────────┘ │
- ↑             ↑            ↑       │
- ┌─────────────┐  ┌──────────┐  ┌────────┐ │
- Dialect    │←→│  Model   │←→│ Patch  │ │
- System     │  │Interface │  │Manager │ │
- ┘  └──────────┘  └────────┘ │
- ┬─────────────────────────┘
- ↓
**┌─ External Services ──────────────────────┐**
- OpenAI │ Anthropic │ Google │ DeepInfra  │
- DeepSeek │ xAI │ Groq │ Ollama          │
- ┘

##### Important Details

a) Model Integration Layer:
- Supported models (OpenAI, Anthropic, Google, etc.)
- Model-agnostic nature of the system

b) Dialect System:
- Various dialect types (edit, replace, smart, system, udiff)
- Connection to patch management

c) Session Management:
- Undo/retry capabilities
- Connection to configuration system

##### Specific Implementation Notes

- Notes about the preflight and post-patch check systems
- Where benchmarking occurs (ttrial integration)
- Configuration file (.tenx.ron) interaction points

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph UI["User Interface Layer"]
        CLI["CLI (tenx)"]:::cli
        TTRIAL["TTrial (Benchmarking)"]:::cli
    end

    subgraph CORE["Core Library (libtenx)"]
        CONFIG["Configuration Management"]:::core
        SESSION["Session Manager"]:::core
        CONTEXT["Context Handler"]:::core
        DIALECT["Dialect System"]:::core
        MODEL["Model Integration"]:::core
        PATCH["Patch Manager"]:::core
        
        CONFIG <--> SESSION
        SESSION <--> CONTEXT
        DIALECT <--> MODEL
        MODEL <--> PATCH
        CONFIG --> MODEL
        SESSION --> PATCH
    end

    subgraph DIALECTS["Dialect Types"]
        EDIT["Edit Dialect"]:::dialect
        REPLACE["Replace Dialect"]:::dialect
        SMART["Smart Dialect"]:::dialect
        SYSTEM["System Dialect"]:::dialect
        UDIFF["UDiff Dialect"]:::dialect
    end

    subgraph EXTERNAL["External Services"]
        OPENAI["OpenAI"]:::external
        ANTHROPIC["Anthropic"]:::external
        GOOGLE["Google"]:::external
        DEEPINFRA["DeepInfra"]:::external
        DEEPSEEK["DeepSeek"]:::external
        XAI["xAI"]:::external
        GROQ["Groq"]:::external
        OLLAMA["Ollama"]:::external
    end

    CLI --> CONFIG
    TTRIAL --> CONFIG
    DIALECT --> DIALECTS
    MODEL --> EXTERNAL
    
    %% Click Events
    click CLI "https://github.com/cortesi/tenx/blob/main/crates/tenx/src/main.rs"
    click TTRIAL "https://github.com/cortesi/tenx/blob/main/crates/ttrial/src/main.rs"
    click CONFIG "https://github.com/cortesi/tenx/blob/main/crates/libtenx/src/config/mod.rs"
    click SESSION "https://github.com/cortesi/tenx/blob/main/crates/libtenx/src/session.rs"
    click CONTEXT "https://github.com/cortesi/tenx/blob/main/crates/libtenx/src/context.rs"
    click DIALECT "https://github.com/cortesi/tenx/blob/main/crates/libtenx/src/dialect/mod.rs"
    click MODEL "https://github.com/cortesi/tenx/blob/main/crates/libtenx/src/model/mod.rs"
    click PATCH "https://github.com/cortesi/tenx/blob/main/crates/libtenx/src/patch/mod.rs"
    click EDIT "https://github.com/cortesi/tenx/blob/main/crates/libtenx/src/dialect/tags-edit.txt"
    click REPLACE "https://github.com/cortesi/tenx/blob/main/crates/libtenx/src/dialect/tags-replace.txt"
    click SMART "https://github.com/cortesi/tenx/blob/main/crates/libtenx/src/dialect/tags-smart.txt"
    click SYSTEM "https://github.com/cortesi/tenx/blob/main/crates/libtenx/src/dialect/tags-system.txt"
    click UDIFF "https://github.com/cortesi/tenx/blob/main/crates/libtenx/src/dialect/tags-udiff.txt"
    click OPENAI "https://github.com/cortesi/tenx/blob/main/crates/libtenx/src/model/openai.rs"
    click ANTHROPIC "https://github.com/cortesi/tenx/blob/main/crates/libtenx/src/model/claude.rs"
    click GOOGLE "https://github.com/cortesi/tenx/blob/main/crates/libtenx/src/model/google.rs"

    classDef core fill:#2374ab,stroke:#2374ab,color:#fff
    classDef cli fill:#34a853,stroke:#34a853,color:#fff
    classDef dialect fill:#fbbc05,stroke:#fbbc05,color:#000
    classDef external fill:#ea4335,stroke:#ea4335,color:#fff

    %% Legend
    subgraph LEGEND["Legend"]
        L1["Core Components"]:::core
        L2["CLI Applications"]:::cli
        L3["Dialect Types"]:::dialect
        L4["External Services"]:::external
    end
```
