# insaneodyssey26/what-the-code architecture

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

- Interactive diagram: https://gitdiagram.com/insaneodyssey26/what-the-code
- Repository: https://github.com/insaneodyssey26/what-the-code

## Overview

##### Project type and purpose
- This is a VS Code extension written in TypeScript.
- It provides three main features:
- Natural-language Q&A on your code via a Gemini AI API
- Dead-code discovery and removal (unused imports, functions, variables)
- Snapshot/restore of files before modifications

##### File structure
- Top-level:
- package.json / tsconfig.json / eslint.config.mjs – project config & dependencies
- .vscode / .vscodeignore – VS Code packaging settings
- src/: all business logic, e.g.:
- extension.ts – activation/deactivation, command registration
- *Providers (aiProviders, mainActionsProvider, resultsDisplay, etc.) – modules responsible for VS Code UI webviews and tree views
- codeCollector.ts, getProjectFiles.ts – scanning project files
- analyzeDeadCode.ts, deadCodeFinder.ts, deadCodeRemover.ts – dead-code analysis & edits
- snapshotProvider.ts – save/restore file state
- types.ts, uiPresets.ts – shared types, UI styling presets

##### README for additional insights
- Confirms use of Gemini API for Q&A
- Describes three distinct features (chat, dead-code, snapshots)
- Usage via a command (`Ctrl+Shift+Alt+K`) and a sidebar

1. VS Code Host
- Command Palette
- Sidebar / Webview Container
- Editor / Text Documents
2. Extension Core (our code)
- Activation Module (extension.ts)
- UI Controllers (searchInput, resultsDisplay, mainActionsProvider)
- Services:
- AIService (aiProviders.ts)
- DeadCodeService (analyzeDeadCode, deadCodeFinder, deadCodeRemover)
- SnapshotService (snapshotProvider)
- FileSystemService (codeCollector, getProjectFiles)
3. External Gemini API (Google AI Studio)
- User triggers command in VS Code → Extension Activation Module
- Activation Module → registers Command Handlers & Tree/Webview Providers
- UI Controllers render input form / result tree → user enters query or clicks “Find Dead Code”
- On query: UI Controller → AIService → Gemini API → AIService receives response → UI Controller updates Webview
- On “Find Dead Code”: UI Controller → FileSystemService scans files → DeadCodeService analyzes → DeadCodeService returns suggestions → UI Controller shows code actions → user applies fix → DeadCodeService applies edits via VS Code API
- On any operation: SnapshotService optionally saves or restores file state
c. Architectural patterns & design principles
- Modular “Provider” pattern to separate UI from business logic
- Single Responsibility: each service (AI, DeadCode, Snapshot, FileSystem) encapsulates its own domain
- Event-driven flow: user actions → commands → providers → services → VS Code editor
d. Key technologies, frameworks, libraries
- TypeScript & Node.js
- VS Code Extension API
- Google Gemini REST API
- ESLint config for linting

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% VS Code Host Layer
    subgraph "VS Code Host"
        CP["Command Palette"]:::ui
        Sidebar["Sidebar/Webview Container"]:::ui
        Editor["Editor/Text Documents"]:::ui
    end

    %% Extension Core Layer
    subgraph "Extension Core"
        %% Activation Module
        Activation["Activation Module"]:::core

        %% UI Controllers
        subgraph "UI Controllers"
            SearchInput["Search Input Webview"]:::core
            MainActions["Main Actions Tree Provider"]:::core
            ResultsDisplay["Results Display Webview"]:::core
            DeadCodeActions["Dead Code Actions Provider"]:::core
            SearchResults["Search Results Tree Provider"]:::core
        end

        %% Services
        subgraph "Services"
            %% AI Service
            AIService["AIService"]:::service

            %% File System Service
            subgraph "FileSystemService"
                Scanner["codeCollector"]:::service
                Lister["getProjectFiles"]:::service
            end

            %% Dead Code Service
            subgraph "DeadCodeService"
                DCEntry["analyzeDeadCode"]:::service
                DCFinder["deadCodeFinder"]:::service
                DCRemover["deadCodeRemover"]:::service
            end

            %% Snapshot Service
            Snapshot["SnapshotService"]:::service
        end
    end

    %% External API
    External["Gemini API"]:::external

    %% Connections
    CP -->|"invokes command"| Activation
    Activation -->|"registers handlers"| SearchInput
    Activation -->|"registers handlers"| MainActions
    Activation -->|"registers handlers"| ResultsDisplay
    Activation -->|"registers handlers"| DeadCodeActions
    Activation -->|"registers handlers"| SearchResults

    %% Chat Flow
    SearchInput -->|"query request"| AIService
    AIService -->|"POST code snippet"| External
    External -->|"response"| AIService
    AIService -->|"results"| SearchInput

    %% Dead Code Flow
    DeadCodeActions -->|"scan project"| Scanner
    Scanner -->|"list files"| Lister
    Lister -->|"project files"| DCEntry
    DCEntry -->|"find dead code"| DCFinder
    DCFinder -->|"suggestions"| DeadCodeActions
    DeadCodeActions -->|"apply fix"| DCRemover
    DCRemover -->|"apply TextEdit"| Editor

    %% Snapshot Flow (optional on operations)
    SearchInput -->|"snapshot before"| Snapshot
    DeadCodeActions -->|"snapshot before"| Snapshot

    %% Layout tweaks
    Activation --> Editor

    %% Click Events
    click Activation "https://github.com/insaneodyssey26/what-the-code/blob/main/src/extension.ts"
    click AIService "https://github.com/insaneodyssey26/what-the-code/blob/main/src/aiProviders.ts"
    click DCEntry "https://github.com/insaneodyssey26/what-the-code/blob/main/src/analyzeDeadCode.ts"
    click DCFinder "https://github.com/insaneodyssey26/what-the-code/blob/main/src/deadCodeFinder.ts"
    click DCRemover "https://github.com/insaneodyssey26/what-the-code/blob/main/src/deadCodeRemover.ts"
    click Snapshot "https://github.com/insaneodyssey26/what-the-code/blob/main/src/snapshotProvider.ts"
    click Scanner "https://github.com/insaneodyssey26/what-the-code/blob/main/src/codeCollector.ts"
    click Lister "https://github.com/insaneodyssey26/what-the-code/blob/main/src/getProjectFiles.ts"
    click SearchInput "https://github.com/insaneodyssey26/what-the-code/blob/main/src/searchInput.ts"
    click MainActions "https://github.com/insaneodyssey26/what-the-code/blob/main/src/mainActionsProvider.ts"
    click ResultsDisplay "https://github.com/insaneodyssey26/what-the-code/blob/main/src/resultsDisplay.ts"
    click DeadCodeActions "https://github.com/insaneodyssey26/what-the-code/blob/main/src/deadCodeActionsProvider.ts"
    click SearchResults "https://github.com/insaneodyssey26/what-the-code/blob/main/src/searchResultsProvider.ts"
    click Types "https://github.com/insaneodyssey26/what-the-code/blob/main/src/types.ts"
    click UIPresets "https://github.com/insaneodyssey26/what-the-code/blob/main/src/uiPresets.ts"

    %% Styles
    classDef ui fill:#ADD8E6,stroke:#000;
    classDef core fill:#90EE90,stroke:#000;
    classDef service fill:#98FB98,stroke:#000;
    classDef external fill:#FFD580,stroke:#000;
```
