# infracost/vscode-infracost architecture

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

- Interactive diagram: https://gitdiagram.com/infracost/vscode-infracost
- Repository: https://github.com/infracost/vscode-infracost

## Overview

##### Project type and purpose
- This is a VS Code extension written in TypeScript, packaged via Webpack.
- Its purpose is to integrate Infracost cost estimates into the editor: showing inline code lenses, a tree view, a status bar indicator, and a webview for breakdowns.
- It orchestrates calls to the Infracost CLI or Cloud API to retrieve Terraform cost data.

##### File structure
- Top-level scripts & configs: `package.json`, `tsconfig.json`, `webpack.config.js` (build), `.github/workflows` (CI), lint/format configs.
- `src/extension.ts`: extension activation entrypoint.
- `src/cli.ts`: runs the Infracost CLI or Cloud API.
- `src/command.ts`: registers VS Code commands (e.g. “connect to Infracost”).
- UI components under `src/`:
- `lens.ts` for code lenses
- `tree.ts` for the cost tree view
- `webview.ts` for the cost-breakdown panel
- `statusBar.ts` for the status indicator
- Business logic & models: `config.ts`, `context.ts`, `project.ts`, `workspace.ts`, `block.ts`, `file.ts`
- Presentation templates in `src/templates/*.hbs` and compiled by `template.ts`.

##### README for additional insights
- Describes features: inline cost lenses on save, module/resource support, tree overview, and webview breakdown.
- Mentions “connect to Infracost Cloud” and use of local CLI for pricing data.
- Requires Terraform extension in VS Code and a workspace config file.

##### Final advice
- Be very detailed: list every UI provider, each major `.ts` module, and the external boundary.
- Asynchronous flows (e.g. CLI subprocess calls).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Systems
    subgraph "External Systems"
        direction TB
        TF["User Terraform Files"]:::external
        IC["Infracost CLI / Cloud API"]:::external
    end

    %% Core Logic
    subgraph "Core Logic" 
        direction TB
        Ext["Extension Activation"]:::core
        Cmd["Command Registration"]:::core
        Config["Configuration Loader"]:::data
        Scanner["Workspace Scanner & File Parser"]:::core
        Engine["Cost Engine (CLI/API Orchestrator)"]:::core
    end

    %% Data Models
    subgraph "Data Models & Context"
        direction TB
        Context["Context Manager"]:::data
        ProjectModel["Project Model"]:::data
    end

    %% UI Providers
    subgraph "UI Providers"
        direction TB
        Lens["Code Lens Provider"]:::ui
        Tree["Tree View Provider"]:::ui
        Status["Status Bar Item"]:::ui
        Webview["Webview Panel"]:::ui
        Templates["Handlebars Templates"]:::data
    end

    %% Data Files
    subgraph "Configuration & Assets"
        direction TB
        ConfigFile["infracost.yml"]:::data
    end

    %% Flows
    TF -->|"file save / change"| Scanner
    Scanner -->|"scan & parse"| ProjectModel
    Scanner --> ProjectModel
    ProjectModel --> Context
    ConfigFile --> Config
    Config --> Engine
    ProjectModel --> Engine
    Engine -->|"JSON cost data"| Context
    Ext --> Cmd
    Ext --> Config
    Ext --> Scanner
    Ext --> Lens
    Ext --> Tree
    Ext --> Status
    Ext --> Webview
    Cmd -->|"user action"| Engine
    Context --> Lens
    Context --> Tree
    Context --> Status
    Context --> Webview
    Templates --> Webview
    IC --> Engine

    %% Click Events
    click Ext "https://github.com/infracost/vscode-infracost/blob/master/src/extension.ts"
    click Cmd "https://github.com/infracost/vscode-infracost/blob/master/src/command.ts"
    click Config "https://github.com/infracost/vscode-infracost/blob/master/src/config.ts"
    click Scanner "https://github.com/infracost/vscode-infracost/blob/master/src/file.ts"
    click Scanner "https://github.com/infracost/vscode-infracost/blob/master/src/block.ts"
    click Scanner "https://github.com/infracost/vscode-infracost/blob/master/src/project.ts"
    click Scanner "https://github.com/infracost/vscode-infracost/blob/master/src/workspace.ts"
    click Engine "https://github.com/infracost/vscode-infracost/blob/master/src/cli.ts"
    click Context "https://github.com/infracost/vscode-infracost/blob/master/src/context.ts"
    click ProjectModel "https://github.com/infracost/vscode-infracost/blob/master/src/project.ts"
    click Lens "https://github.com/infracost/vscode-infracost/blob/master/src/lens.ts"
    click Tree "https://github.com/infracost/vscode-infracost/blob/master/src/tree.ts"
    click Status "https://github.com/infracost/vscode-infracost/blob/master/src/statusBar.ts"
    click Webview "https://github.com/infracost/vscode-infracost/blob/master/src/webview.ts"
    click Templates "https://github.com/infracost/vscode-infracost/blob/master/src/template.ts"
    %% Note: Templates directory for .hbs
    click Templates "https://github.com/infracost/vscode-infracost/tree/master/src/templates/"

    %% Styling
    classDef core fill:#AED6F1,stroke:#1B4F72,color:#1B2631
    classDef ui fill:#ABEBC6,stroke:#1D8348,color:#1B2631
    classDef external fill:#F5B041,stroke:#935116,color:#1B2631
    classDef data fill:#85C1E9,stroke:#1B4F72,color:#1B2631
```
