# leanprover/vscode-lean4 architecture

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

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

## Overview

##### Main Components

a. VS Code Extension ("vscode-lean4")
- This is the core component that integrates with the VS Code editor. It contains the entry point that launches the extension, handles configuration, and coordinates various features.
- It includes sub-features such as diagnostics, RPC communication with Lean processes, and command handling.

b. Lean Infoview and its Related API ("lean4-infoview" and "lean4-infoview-api")
- The "lean4-infoview" package is focused on the user interface aspects within the VS Code window. It likely uses modern front-end technologies (React via TypeScript, a rollup configuration is present) to render the live proof state and interactive elements.
- The "lean4-infoview-api" package provides an abstraction layer for communication between the Lean backend and the infoview. It defines types and methods for RPC sessions and LSP types.

c. Unicode Input Components ("lean4-unicode-input" and "lean4-unicode-input-component")
- These components deal with the abbreviations and Unicode character input features necessary for the Lean language. They handle rewriting and providing the input features so that users can enter mathematical/symbolic notation effectively.

d. Supporting Infrastructure and Tooling
- Configuration and build tools (e.g., .eslintrc.js, .prettierrc, tsconfig.json files) ensure code quality and consistency.
- Documentation (README, docs/manual, and dev guides in the docs/ folder) and test suites (within vscode-lean4/test) provide supporting material for development and quality assurance.
- Other directories such as .github (with workflows and issue templates) represent CI/CD and community guidelines.

##### Relationships and Interactions

c. For Unicode Input, show how the input components interact with the extension, possibly connected to the abstraction layer managing the rewriting of symbols for Lean code. This component feeds into the main extension’s input processing.

d. Shared configuration, utilities, and common libraries (e.g., the various tsconfig files, ESLint, Prettier configs, and utility modules under “vscode-lean4/src/utils”) should be marked as supporting elements that interact with all main components.

##### Architectural Patterns / Design Principles

a. Modularization: The project is divided into specialized packages. Mark these as separate nodes that interact via defined APIs.

b. Separation of concerns: The UI (infoview), the backend communication layer (infoview-api), and the input processing (unicode input) are clearly separated, which fits the single-responsibility principle.

##### Relevant Technologies and Frameworks

a. TypeScript is used across most components.

b. React (or JSX based tooling) is used in the infoview (as evidenced by .tsx files and rollup config).

c. ESLint, Prettier, and configurations for VS Code indicate adherence to coding standards.

d. Lerna is used as a monorepo tool, managing package versions and dependencies across components.

e. CI/CD workflows are defined under .github/workflows, which you may note as external services that continuously integrate, test, and deploy your extension.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Core Modules
    subgraph "Core Modules"
        A["VS Code Extension (vscode-lean4)"]:::ext
        B["Infoview UI (lean4-infoview)"]:::ui
        C["Infoview API (lean4-infoview-api)"]:::api
        D["Unicode Input Controller Part 1 (lean4-unicode-input)"]:::unicode
        E["Unicode Input Controller Part 2 (lean4-unicode-input-component)"]:::unicode
    end

    %% Supporting Infrastructure
    subgraph "Supporting Infrastructure"
        F["Configuration & Utilities"]:::infra
        G["CI/CD & Documentation"]:::infra
    end

    %% External Dependency
    H["Lean Backend (external)"]:::external

    %% Relationships between Core Modules and Supporting Infrastructure
    A -->|"launches"| B
    A -->|"integrates"| D
    A -->|"integrates"| E
    A -->|"configures"| F
    A -->|"triggers"| G

    B <-->|"bi-directional"| C
    C -->|"RPCcommunication"| H

    %% Additional support connections
    F -->|"supports"| A
    G -->|"supports"| A

    %% Styling Definitions
    classDef ext fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef ui fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef api fill:#FFA07A,stroke:#000,stroke-width:2px;
    classDef unicode fill:#DDA0DD,stroke:#000,stroke-width:2px;
    classDef infra fill:#F5F5F5,stroke:#000,stroke-width:2px;
    classDef external fill:#FFC0CB,stroke:#000,stroke-width:2px;

    %% Click Events for Component Mapping
    click A "https://github.com/leanprover/vscode-lean4/tree/master/vscode-lean4/"
    click B "https://github.com/leanprover/vscode-lean4/tree/master/lean4-infoview/"
    click C "https://github.com/leanprover/vscode-lean4/tree/master/lean4-infoview-api/"
    click D "https://github.com/leanprover/vscode-lean4/tree/master/lean4-unicode-input/"
    click E "https://github.com/leanprover/vscode-lean4/tree/master/lean4-unicode-input-component/"
```
