# idoavrah/terraform-tui architecture

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

- Interactive diagram: https://gitdiagram.com/idoavrah/terraform-tui
- Repository: https://github.com/idoavrah/terraform-tui

## Overview

##### Main Components

a) Core Application Components:
- User Interface Layer (TUI)
- State Management System
- Plan Management System
- API Integration Layer
- Resource Operations Handler

b) External Dependencies:
- Terraform CLI
- PostHog Analytics (optional)
- Terraform State Files
- Terraform Plan Files

**┌─────────────────────────────────────────────┐**
- TFTUI                      │
- ┘
- ↓
**┌─────────────────────────────────────────────┐**
- User Interface                 │
- ┌──────────┐  ┌──────────┐  ┌──────────┐  │
- Tree    │  │ Resource │  │  Modal   │  │
- View    │  │  View    │  │ Dialogs  │  │
- ┘  └──────────┘  └──────────┘  │
- ┘
- ↕
**┌─────────────────────────────────────────────┐**
- Core Logic Layer                  │
- ┌──────────┐  ┌──────────┐  ┌──────────┐  │
- State   │  │   Plan   │  │ Resource │  │
- Manager  │  │ Manager  │  │Operations│  │
- ┘  └──────────┘  └──────────┘  │
- ┘
- ↕
**┌─────────────────────────────────────────────┐**
- External Interfaces               │
- ┌──────────┐  ┌──────────┐  ┌──────────┐  │
- Terraform │  │ PostHog  │  │  File    │  │
- CLI    │  │   API    │  │ System   │  │
- ┘  └──────────┘  └──────────┘  │
- ┘

##### Component Details

User Interface Layer:
- Tree View: Shows Terraform state hierarchy
- Resource View: Displays individual resource details
- Modal Dialogs: For confirmations and operations

Core Logic Layer:
- State Manager: Handles Terraform state operations
- Plan Manager: Manages plan creation and application
- Resource Operations: Handles taint/untaint/delete operations

External Interfaces:
- Terraform CLI Integration
- PostHog Analytics Integration (optional)
- File System Interface

##### Important Flows to Highlight

a) State Management Flow:
**User Input → UI Layer → State Manager → Terraform CLI → State Files**

b) Plan Creation Flow:
**User Input → UI Layer → Plan Manager → Terraform CLI → Plan Files**

c) Resource Operation Flow:
**User Selection → Resource Operations → Terraform CLI → State Update**

##### Key Technical Details to Note

- Python-based implementation
- Terminal-based UI using Textual framework
- File system interactions for state management
- CLI wrapper functionality
- Workspace management capabilities

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph TFTUI
        MainApp["Main Application"]:::main
        
        subgraph UI["User Interface Layer"]
            TreeView["Tree View"]:::ui
            ResourceView["Resource View"]:::ui
            ModalDialogs["Modal Dialogs"]:::ui
            UIStyles["UI Styling"]:::ui
        end

        subgraph Core["Core Logic Layer"]
            StateManager["State Manager"]:::core
            PlanManager["Plan Manager"]:::core
            ResourceOps["Resource Operations"]:::core
            Constants["Constants"]:::core
            DebugSystem["Debug System"]:::core
        end

        subgraph External["External Interfaces"]
            TerraformCLI["Terraform CLI"]:::external
            PostHogAPI["PostHog API"]:::external
            FileSystem["File System"]:::external
        end
    end

    %% Connections
    MainApp --> UI
    MainApp --> Core
    
    %% UI Layer Connections
    TreeView --> StateManager
    ResourceView --> ResourceOps
    ModalDialogs --> PlanManager
    
    %% Core Layer Connections
    StateManager --> TerraformCLI
    PlanManager --> TerraformCLI
    ResourceOps --> TerraformCLI
    
    %% External Interface Connections
    TerraformCLI --> FileSystem
    PostHogAPI -.- Core
    
    %% Click Events
    click MainApp "https://github.com/idoavrah/terraform-tui/blob/main/tftui/__main__.py"
    click ModalDialogs "https://github.com/idoavrah/terraform-tui/blob/main/tftui/modal.py"
    click StateManager "https://github.com/idoavrah/terraform-tui/blob/main/tftui/state.py"
    click PlanManager "https://github.com/idoavrah/terraform-tui/blob/main/tftui/plan.py"
    click PostHogAPI "https://github.com/idoavrah/terraform-tui/blob/main/tftui/apis.py"
    click Constants "https://github.com/idoavrah/terraform-tui/blob/main/tftui/constants.py"
    click DebugSystem "https://github.com/idoavrah/terraform-tui/blob/main/tftui/debug_log.py"
    click UIStyles "https://github.com/idoavrah/terraform-tui/blob/main/tftui/ui.tcss"

    %% Styles
    classDef main fill:#f9f,stroke:#333,stroke-width:2px
    classDef ui fill:#3498db,stroke:#2980b9,color:white
    classDef core fill:#2ecc71,stroke:#27ae60,color:white
    classDef external fill:#f1c40f,stroke:#f39c12
    
    %% Legend
    subgraph Legend
        L1["Main Application"]:::main
        L2["UI Components"]:::ui
        L3["Core Components"]:::core
        L4["External Interfaces"]:::external
    end
```
