# instill-ai/api-gateway architecture

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

- Interactive diagram: https://gitdiagram.com/instill-ai/api-gateway
- Repository: https://github.com/instill-ai/api-gateway

## Overview

##### Main Components Identification

a) API Gateway Layer (Primary Focus)
- KrakenD Gateway (central component)
- Plugin System (multiple plugins identified in /plugins directory)
- Blob Plugin
- gRPC Proxy Plugin
- Multi-Auth Plugin
- Registry Plugin
- SSE Streaming Plugin

b) Configuration Management
- Base Configuration
- Environment-specific Settings
- Template System

##### Specific Component Details

- External client requests → API Gateway
- Gateway → Various Backend Services (through plugins)
- Configuration loading flow
- Plugin integration points

##### Implementation Details

Use these visual elements:
- Rectangles: Major components
- Hexagons: Plugins
- Diamonds: Decision points/routing logic

##### Additional Elements

Supporting components:
- Environment configuration flow
- Template processing system
- Security components (TLS, CORS, Auth)
- Monitoring components (metrics, debugging)

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        C[Client Requests]
    end

    subgraph Gateway
        KD[KrakenD Gateway]
        R[Request Router]
        SEC[Security Layer]
    end

    subgraph "Plugin System"
        direction TB
        MA[Multi-Auth Plugin]:::security
        GP[gRPC Proxy Plugin]:::network
        SS[SSE Streaming Plugin]:::network
        BP[Blob Plugin]:::storage
        RP[Registry Plugin]:::storage
    end

    subgraph "Configuration Management"
        direction TB
        BC[Base Configuration]
        ES[Environment Settings]
        TS[Template System]
        EC[Environment Config]
        SS_C[Shared Settings]
    end

    subgraph "Backend Services"
        BS1[Service 1]
        BS2[Service 2]
        BS3[Service 3]
    end

    C --> KD
    KD --> R
    R --> SEC
    SEC --> MA
    R --> GP
    R --> SS
    R --> BP
    R --> RP

    MA --> BS1
    GP --> BS2
    SS --> BS2
    BP --> BS3
    RP --> BS3

    BC --> KD
    ES --> KD
    TS --> KD
    EC --> KD
    SS_C --> KD

    %% Component Mappings
    click BC "https://github.com/instill-ai/api-gateway/blob/main/config/base.json"
    click ES "https://github.com/instill-ai/api-gateway/tree/main/config/settings-env"
    click TS "https://github.com/instill-ai/api-gateway/tree/main/config/share/templates"
    click MA "https://github.com/instill-ai/api-gateway/tree/main/plugins/multi-auth"
    click GP "https://github.com/instill-ai/api-gateway/tree/main/plugins/grpc-proxy"
    click SS "https://github.com/instill-ai/api-gateway/tree/main/plugins/sse-streaming"
    click BP "https://github.com/instill-ai/api-gateway/tree/main/plugins/blob"
    click RP "https://github.com/instill-ai/api-gateway/tree/main/plugins/registry"
    click EC "https://github.com/instill-ai/api-gateway/blob/main/config/.env"
    click SS_C "https://github.com/instill-ai/api-gateway/tree/main/config/share/settings-env"

    %% Styles
    classDef default fill:#f9f9f9,stroke:#333,stroke-width:2px
    classDef security fill:#ff9999,stroke:#333,stroke-width:2px
    classDef network fill:#9999ff,stroke:#333,stroke-width:2px
    classDef storage fill:#99ff99,stroke:#333,stroke-width:2px

    %% Legend
    subgraph Legend
        L1[Security Plugin]:::security
        L2[Network Plugin]:::network
        L3[Storage Plugin]:::storage
    end
```
