# microsoft/kiota architecture

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

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

## Overview

##### Main components
- Core Libraries (blue):
– Kiota.Builder (C#): the heart of the code generator. It contains:
- CodeDOM model (CodeElement, CodeClass, etc.)
- Generation logic (KiotaBuilder, KiotaSearcher)
- Language-specific CodeRenderers (TypeScript, CSharp, Java, Go, Python, etc.)
– Abstractions (folder “abstractions” and “authentication”): a common HTTP & serialization abstraction layer and authentication providers.
– HTTP/Serialization (folders “http” and “serialization”): HTTP transport, format serializers (JSON, multipart, text, form).
– SearchProviders: modules to fetch OpenAPI specs (GitHub, APIsGuru, OpenApiSpec).
– Plugin system: PluginsGenerationService, plugin walkers, plugin auth.

- CLI / Host (green):
– CLI Host (“src/kiota”): Program.cs, command handlers (AddHandler, GenerateHandler, SearchHandler, etc.), configuration extensions, RPC server (Rpc folder).
– Telemetry (AppInsights/OpenTelemetry): TelemetryConfig, Instrumentation.
– Kiota.Generated: small project to generate version and settings at build time.
– Dockerfile, CI pipelines: build & release orchestration.

- Editor & Language Integrations (orange):
– VS Code Extension (“vscode/microsoft-kiota”): TypeScript extension invoking the CLI over RPC or child‐process, deepLink, handlers, tree providers.
– NPM wrapper (“vscode/npm-package”): TS library that shells out to the Kiota CLI, exposes JS API for generateClient, searchDescription, migrate, updateClients, etc.
– IntelliJ Plugin (“intellij”): Java plugin using KiotaGenerationLanguage and GenerateClientHandler to integrate code generation into IntelliJ.
– Other “it” test harnesses for C#, Java, Go, Dart, Python, Ruby, TS.

##### Relationships and data flows
– User or IDE issues a command (VS Code command palette, IntelliJ menu, or NPM JS call).
– The integration invokes the Kiota CLI Host via:
- RPC channel (WebSocket/IPC) or
- Child‐process CLI (dotnet kiota.exe).
– CLI Host parses command → routes to a specific CommandHandler.
– Handler uses:
- SearchProviders to locate or download the OpenAPI description.
- Abstractions + HTTP libs to fetch or validate the spec.
- Kiota.Builder to build a CodeDOM and generate code:
– KiotaBuilder orchestrates parsing, refinement (Refiners), rendering (CodeRenderers).
– The generated code is written via Writers modules to the target language directory.
– Plugin system may augment generation or post‐process output.
– Telemetry events are sent to AppInsights/OpenTelemetry.

##### Architectural patterns & principles
– Layered Architecture: separation of core code-generation logic, host orchestration, and client integrations.
– Plugin/Handler Pattern: command handlers decouple CLI verbs from implementation; PluginsGenerationService decouples extension points.
– Strategy Pattern: language-specific writers (ICodeElementWriter + ConventionService) plugged into Kiota.Builder.
– Dependency Inversion: abstractions for HTTP, serialization, authentication, search providers.
– RPC & IPC: supports editor extensions without embedding C#.

##### Final checklist
– Clearly separate layers.
– Annotate key framework/technology (C#, dotnet CLI, TypeScript, Java, HTTP clients, RPC).
– Capture essential modules: SearchProviders, Abstractions, Kiota.Builder, Command Handlers, CodeRenderers, Writers, Plugins, Telemetry, Integrations.
– Keep it detailed enough to see extension points and module boundaries but simple enough to read at a glance.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Spec Sources
    GitHub("GitHub API"):::external
    APIsGuru("APIsGuru"):::external
    LocalFiles("Local Files"):::external

    %% Core Libraries Layer
    subgraph "Core Libraries" 
        direction TB
        KiotaBuilder["Kiota.Builder"]:::core
        CodeDOM["CodeDOM Model"]:::core
        BuilderLogic["KiotaBuilder.cs"]:::core
        SearcherLogic["KiotaSearcher.cs"]:::core
        CodeRenderers["CodeRenderers"]:::core
        Abstractions["abstractions/"]:::core
        Authentication["authentication/"]:::core
        HTTP["http/"]:::core
        Serialization["serialization/"]:::core
        SearchProviders["SearchProviders"]:::core
        Plugins["PluginsGenerationService"]:::core
        Writers["Writers"]:::core
        Output["Generated Code Output"]:::core
    end

    %% CLI / Host Layer
    subgraph "CLI / Host" 
        direction TB
        CLI["Program & Commands"]:::host
        Handlers["Command Handlers"]:::host
        RPC["RPC Server"]:::host
        TelemetryHost["Telemetry Config & Instrumentation"]:::host
        KiotaGenerated["Kiota.Generated"]:::host
        DockerfileNode["Dockerfile"]:::host
        Pipelines["CI Pipelines"]:::host
    end

    %% Editor & IDE Integrations Layer
    subgraph "Editor & IDE Integrations"
        direction TB
        VSCode["VS Code Extension"]:::int
        NPM["NPM Wrapper"]:::int
        IntelliJ["IntelliJ Plugin"]:::int
        ITTests["Integration Test Harness"]:::int
    end

    %% Telemetry Endpoint
    TelemetryEndpoint["Telemetry Endpoint"]:::external

    %% Relationships
    GitHub -->|fetch spec| SearchProviders
    APIsGuru -->|fetch spec| SearchProviders
    LocalFiles -->|load spec| SearchProviders

    SearchProviders -->|spec data| HTTP
    Abstractions -->|HTTP client| KiotaBuilder
    Authentication -->|auth providers| KiotaBuilder
    HTTP -->|transport| KiotaBuilder
    Serialization -->|format serializers| KiotaBuilder

    KiotaBuilder -->|build model| CodeDOM
    CodeDOM -->|render AST| CodeRenderers
    CodeRenderers -->|write code| Writers
    Writers -->|output files| Output
    Plugins -.->|extend| KiotaBuilder

    CLI -->|invokes| Handlers
    Handlers -->|uses| SearchProviders
    Handlers -->|uses| Abstractions
    Handlers -->|uses| KiotaBuilder
    CLI -->|RPC calls| RPC
    CLI -->|child-process| KiotaBuilder
    CLI -->|emit telemetry| TelemetryHost
    TelemetryHost -->|send| TelemetryEndpoint
    CLI -->|build metadata| KiotaGenerated
    CLI -->|docker| DockerfileNode
    CLI -->|CI| Pipelines

    VSCode -->|RPC/process| CLI
    NPM -->|child-process| CLI
    IntelliJ -->|RPC/process| CLI
    ITTests -->|uses CLI| CLI

    %% Click Events
    click KiotaBuilder "https://github.com/microsoft/kiota/blob/main/src/Kiota.Builder"
    click CodeDOM "https://github.com/microsoft/kiota/tree/main/src/Kiota.Builder/CodeDOM"
    click BuilderLogic "https://github.com/microsoft/kiota/blob/main/src/Kiota.Builder/KiotaBuilder.cs"
    click SearcherLogic "https://github.com/microsoft/kiota/blob/main/src/Kiota.Builder/KiotaSearcher.cs"
    click CodeRenderers "https://github.com/microsoft/kiota/tree/main/src/Kiota.Builder/CodeRenderers"
    click Abstractions "https://github.com/microsoft/kiota/tree/main/abstractions/"
    click Authentication "https://github.com/microsoft/kiota/tree/main/authentication/"
    click HTTP "https://github.com/microsoft/kiota/tree/main/http/"
    click Serialization "https://github.com/microsoft/kiota/tree/main/serialization/"
    click SearchProviders "https://github.com/microsoft/kiota/tree/main/src/Kiota.Builder/SearchProviders"
    click Plugins "https://github.com/microsoft/kiota/tree/main/src/Kiota.Builder/Plugins"
    click Writers "https://github.com/microsoft/kiota/tree/main/src/Kiota.Builder/Writers"
    click CLI "https://github.com/microsoft/kiota/blob/main/src/kiota/Program.cs"
    click Handlers "https://github.com/microsoft/kiota/tree/main/src/kiota/Handlers"
    click RPC "https://github.com/microsoft/kiota/tree/main/src/kiota/Rpc"
    click TelemetryHost "https://github.com/microsoft/kiota/tree/main/src/kiota/Telemetry"
    click KiotaGenerated "https://github.com/microsoft/kiota/blob/main/src/Kiota.Generated"
    click DockerfileNode "https://github.com/microsoft/kiota/tree/main/Dockerfile"
    click Pipelines "https://github.com/microsoft/kiota/blob/main/.azure-pipelines/ci-build.yml"
    click VSCode "https://github.com/microsoft/kiota/tree/main/vscode/microsoft-kiota"
    click NPM "https://github.com/microsoft/kiota/tree/main/vscode/npm-package"
    click IntelliJ "https://github.com/microsoft/kiota/tree/main/intellij"
    click ITTests "https://github.com/microsoft/kiota/tree/main/it/"

    %% Styles
    classDef core fill:#bbdefb,stroke:#0d47a1,color:#0d47a1
    classDef host fill:#c8e6c9,stroke:#1b5e20,color:#1b5e20
    classDef int fill:#ffe0b2,stroke:#e65100,color:#e65100
    classDef external fill:#e0e0e0,stroke:#424242,color:#424242
```
