# kong/terraform-provider-konnect architecture

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

- Interactive diagram: https://gitdiagram.com/kong/terraform-provider-konnect
- Repository: https://github.com/kong/terraform-provider-konnect

## Overview

##### Main Components Identification

The system should be divided into these primary components:
- Provider Core
- Resource Management Layer
- SDK Layer
- External Integration (Kong Konnect API)

##### Detailed Architecture Breakdown

a) Core Provider Layer:
- Entry point through `main.go`
- Provider configuration handling
- Authentication management (PAT and system tokens)
- Regional server URL configuration

b) Resource Management Layer:
- Organized by domain categories:
- Gateway Manager resources
- Cloud Gateway resources
- Kong Gateway entities
- Mesh resources
- API Products
- Dev Portal
- Organization management

c) SDK Layer:
- Internal SDK implementation (`internal/sdk`)
- Models and operations
- API client functionality
- Error handling

**Top Level:**
**[Terraform Core] <---> [Konnect Provider] <---> [Kong Konnect API]**

**Second Level (Provider Internals):**
**[Provider Configuration]**

**[Resource Management Layer] <---> [Internal SDK]**

**[Validators & Plan Modifiers]**

##### Component Relationship Details

- Provider initialization flow
- Resource CRUD operations flow
- Authentication token handling
- API request/response cycle
- Validation and plan modification processes

##### Implementation Details

Specific components for:
- Resource types (from `internal/provider`)
- SDK models (from `internal/sdk/models`)
- Validators (from `internal/validators`)
- Plan modifiers (from `internal/planmodifiers`)

##### Notes Section

Notes about:
- Configuration requirements
- Environment variable usage
- Regional deployment considerations
- Resource dependency handling

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph TF["Terraform Core"]
        TC[Terraform Core]
    end

    subgraph Provider["Provider Layer"]
        PE["Provider Entry"]:::entry
        PC["Provider Config"]:::config
        click PE "https://github.com/Kong/terraform-provider-konnect/blob/main/main.go"
        click PC "https://github.com/Kong/terraform-provider-konnect/blob/main/internal/provider/provider.go"
    end

    subgraph Resources["Resource Management Layer"]
        direction TB
        GW["Gateway Resources"]:::gateway
        CG["Cloud Gateway Resources"]:::gateway
        AP["API Products"]:::api
        PR["Portal Resources"]:::portal
        MR["Mesh Resources"]:::mesh
        click GW "https://github.com/Kong/terraform-provider-konnect/tree/main/internal/provider/gateway"
        click CG "https://github.com/Kong/terraform-provider-konnect/tree/main/internal/provider/cloudgateway"
        click AP "https://github.com/Kong/terraform-provider-konnect/tree/main/internal/provider/apiproduct"
        click PR "https://github.com/Kong/terraform-provider-konnect/tree/main/internal/provider/portal"
        click MR "https://github.com/Kong/terraform-provider-konnect/tree/main/internal/provider/meshcontrolplane"
    end

    subgraph SDK["SDK Layer"]
        direction TB
        SC["SDK Core"]:::sdk
        SM["Models"]:::sdk
        SO["Operations"]:::sdk
        SE["Error Handling"]:::sdk
        click SC "https://github.com/Kong/terraform-provider-konnect/blob/main/internal/sdk/konnect.go"
        click SM "https://github.com/Kong/terraform-provider-konnect/tree/main/internal/sdk/models"
        click SO "https://github.com/Kong/terraform-provider-konnect/tree/main/internal/sdk/models/operations"
        click SE "https://github.com/Kong/terraform-provider-konnect/tree/main/internal/sdk/models/errors"
    end

    subgraph Validation["Validation Layer"]
        direction TB
        VL["Validators"]:::validation
        PM["Plan Modifiers"]:::validation
        click VL "https://github.com/Kong/terraform-provider-konnect/tree/main/internal/validators"
        click PM "https://github.com/Kong/terraform-provider-konnect/tree/main/internal/planmodifiers"
    end

    subgraph Documentation["Documentation"]
        direction TB
        RD["Resource Docs"]:::docs
        DD["Data Source Docs"]:::docs
        EX["Examples"]:::docs
        click RD "https://github.com/Kong/terraform-provider-konnect/tree/main/docs/resources"
        click DD "https://github.com/Kong/terraform-provider-konnect/tree/main/docs/data-sources"
        click EX "https://github.com/Kong/terraform-provider-konnect/tree/main/examples/resources"
    end

    subgraph Testing["Testing Layer"]
        E2E["E2E Tests"]:::test
        click E2E "https://github.com/Kong/terraform-provider-konnect/tree/main/tests/e2e"
    end

    subgraph External["External Systems"]
        KA["Kong Konnect API"]:::external
    end

    %% Connections
    TC <--> PE
    PE --> PC
    PC --> Resources
    Resources <--> SDK
    Resources <--> Validation
    SDK <--> KA
    Resources --> Documentation
    Resources --> Testing

    %% Styles
    classDef entry fill:#2d5986,color:white
    classDef config fill:#336699,color:white
    classDef gateway fill:#4d94ff,color:white
    classDef api fill:#00cc66,color:white
    classDef portal fill:#9933ff,color:white
    classDef mesh fill:#ff9933,color:white
    classDef sdk fill:#666699,color:white
    classDef validation fill:#ff6666,color:white
    classDef docs fill:#99cc00,color:white
    classDef test fill:#ff99cc,color:white
    classDef external fill:#808080,color:white

    %% Legend
    subgraph Legend
        L1["Entry Point"]:::entry
        L2["Configuration"]:::config
        L3["Gateway Components"]:::gateway
        L4["API Components"]:::api
        L5["Portal Components"]:::portal
        L6["Mesh Components"]:::mesh
        L7["SDK Components"]:::sdk
        L8["Validation Components"]:::validation
        L9["Documentation"]:::docs
        L10["Testing"]:::test
        L11["External Systems"]:::external
    end
```
