# microsoft/inshellisense architecture

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

- Interactive diagram: https://gitdiagram.com/microsoft/inshellisense
- Repository: https://github.com/microsoft/inshellisense

## Overview

##### Main Components

a. Core Runtime Layer:
- Located in `/src/runtime`
- Components for parsing, suggestion generation, and template handling
- Interaction with the autocomplete specs system

b. Shell Integration Layer:
- Located in `/src/isterm`
- PTY (Pseudo Terminal) handling
- Shell-specific integration components

c. UI Management Layer:
- Located in `/src/ui`
- Suggestion management and UI utilities
- Connection to the runtime layer

d. Command Management:
- Located in `/src/commands`
- Command hierarchy (root, init, doctor, etc.)

**┌─────────────────────────────────────────────┐**
- Shell Interface              │
- (bash/zsh/fish/pwsh/powershell/cmd/etc.)  │
- ┬─────────────────────────┘
- ↕
**┌───────────────────┴─────────────────────────┐**
- Shell Integration Layer           │
- (PTY & Command Management)           │
- ┬─────────────────────────┘
- ↕
**┌───────────────────┴─────────────────────────┐**
- Runtime Layer                  │
- (Parser, Generator, Suggestion Engine)    │
- ┬─────────────────────────┘
- ↕
**┌───────────────────┴─────────────────────────┐**
- UI Management Layer              │
- (Suggestion Display & Interaction)      │
- ┘

##### Key Interactions to Highlight

a. Data Flow:
- How user input flows from shell → PTY → parser → suggestion engine
- How completions flow back to the UI
- Demonstrate configuration file interaction

b. Control Flow:
- Initialization sequence
- Command execution paths
- Keybinding interaction paths

##### Implementation Details

- Node.js runtime dependency
- Autocomplete spec integration
- Shell-specific initialization scripts
- Configuration file paths and processing

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Shell Interface"
        SI["Shell (bash/zsh/fish/pwsh/cmd)"]
    end

    subgraph "Shell Integration Layer"
        PTY["PTY Handler"]:::shell
        CM["Command Manager"]:::shell
        SIS["Shell Integration Scripts"]:::shell
    end

    subgraph "Core Runtime Layer"
        Parser["Parser"]:::runtime
        SugEng["Suggestion Engine"]:::runtime
        TempH["Template Handler"]:::runtime
        Gen["Generator"]:::runtime
        RT["Runtime Core"]:::runtime
    end

    subgraph "UI Management Layer"
        SugMgr["Suggestion Manager"]:::ui
        UIUtils["UI Utilities"]:::ui
        DoctorUI["Doctor UI"]:::ui
        RootUI["Root UI"]:::ui
        UninstUI["Uninstall UI"]:::ui
    end

    subgraph "Command Management"
        RootCmd["Root Command"]:::cmd
        InitCmd["Init Command"]:::cmd
        DoctorCmd["Doctor Command"]:::cmd
        CompleteCmd["Complete Command"]:::cmd
        UninstallCmd["Uninstall Command"]:::cmd
        SpecsCmd["Specs Commands"]:::cmd
    end

    subgraph "Utility Components"
        Config["Configuration"]:::util
        ShellUtils["Shell Utils"]:::util
        Logging["Logging"]:::util
        ANSI["ANSI Handling"]:::util
        Version["Version Management"]:::util
    end

    SI --> PTY
    PTY --> CM
    CM --> SIS

    PTY --> Parser
    Parser --> SugEng
    SugEng --> TempH
    TempH --> Gen
    Gen --> RT

    RT --> SugMgr
    SugMgr --> UIUtils
    UIUtils --> DoctorUI
    UIUtils --> RootUI
    UIUtils --> UninstUI

    CM --> RootCmd
    RootCmd --> InitCmd
    RootCmd --> DoctorCmd
    RootCmd --> CompleteCmd
    RootCmd --> UninstallCmd
    RootCmd --> SpecsCmd

    Config --> RT
    ShellUtils --> CM
    Logging --> RT
    ANSI --> UIUtils
    Version --> RootCmd

    %% Click events for component mapping
    click Parser "https://github.com/microsoft/inshellisense/blob/main/src/runtime/parser.ts"
    click SugEng "https://github.com/microsoft/inshellisense/blob/main/src/runtime/suggestion.ts"
    click TempH "https://github.com/microsoft/inshellisense/blob/main/src/runtime/template.ts"
    click Gen "https://github.com/microsoft/inshellisense/blob/main/src/runtime/generator.ts"
    click RT "https://github.com/microsoft/inshellisense/blob/main/src/runtime/runtime.ts"
    click PTY "https://github.com/microsoft/inshellisense/blob/main/src/isterm/pty.ts"
    click CM "https://github.com/microsoft/inshellisense/blob/main/src/isterm/commandManager.ts"
    click SIS "https://github.com/microsoft/inshellisense/blob/main/shell/shellIntegration.bash"
    click SugMgr "https://github.com/microsoft/inshellisense/blob/main/src/ui/suggestionManager.ts"
    click UIUtils "https://github.com/microsoft/inshellisense/blob/main/src/ui/utils.ts"
    click DoctorUI "https://github.com/microsoft/inshellisense/blob/main/src/ui/ui-doctor.ts"
    click RootUI "https://github.com/microsoft/inshellisense/blob/main/src/ui/ui-root.ts"
    click UninstUI "https://github.com/microsoft/inshellisense/blob/main/src/ui/ui-uninstall.ts"
    click RootCmd "https://github.com/microsoft/inshellisense/blob/main/src/commands/root.ts"
    click InitCmd "https://github.com/microsoft/inshellisense/blob/main/src/commands/init.ts"
    click DoctorCmd "https://github.com/microsoft/inshellisense/blob/main/src/commands/doctor.ts"
    click CompleteCmd "https://github.com/microsoft/inshellisense/blob/main/src/commands/complete.ts"
    click UninstallCmd "https://github.com/microsoft/inshellisense/blob/main/src/commands/uninstall.ts"
    click SpecsCmd "https://github.com/microsoft/inshellisense/blob/main/src/commands/specs/root.ts"
    click Config "https://github.com/microsoft/inshellisense/blob/main/src/utils/config.ts"
    click ShellUtils "https://github.com/microsoft/inshellisense/blob/main/src/utils/shell.ts"
    click Logging "https://github.com/microsoft/inshellisense/blob/main/src/utils/log.ts"
    click ANSI "https://github.com/microsoft/inshellisense/blob/main/src/utils/ansi.ts"
    click Version "https://github.com/microsoft/inshellisense/blob/main/src/utils/version.ts"

    %% Styling
    classDef shell fill:#3498db,stroke:#2980b9,color:white
    classDef runtime fill:#2ecc71,stroke:#27ae60,color:white
    classDef ui fill:#e67e22,stroke:#d35400,color:white
    classDef cmd fill:#9b59b6,stroke:#8e44ad,color:white
    classDef util fill:#95a5a6,stroke:#7f8c8d,color:white

    %% Legend
    subgraph Legend
        L1["Shell Integration"]:::shell
        L2["Runtime Components"]:::runtime
        L3["UI Components"]:::ui
        L4["Command Components"]:::cmd
        L5["Utility Components"]:::util
    end
```
