# amosehiguese/tyk architecture

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

- Interactive diagram: https://gitdiagram.com/amosehiguese/tyk
- Repository: https://github.com/amosehiguese/tyk

## Overview

##### Project type and purpose
- This is Tyk API Gateway—a high-performance, open-source API Gateway written in Go.
- It supports REST, GraphQL, gRPC and TCP protocols, and is extensible via middleware and plugins.
- It can run as a standalone Go service (main.go), in Docker/Kubernetes, and integrates with Redis, Consul, Vault, tracing backends, etc.

##### File structure
- Top-level “main.go” kicks off the Gateway process.
- “gateway/” package contains core HTTP/gRPC/TCP server, request routing, middleware chain, store adapters and analytics.
- “apidef/” package implements the API-definition adapters for OpenAPI, GraphQL, asyncAPI, etc.
- “config/” loads runtime configuration (config file, env vars, tracing, external services).
- “storage/”, “rpc/”, “dnscache/”, “redis/” etc. implement pluggable backends for rate-limit, sessions, discovery.
- “ee/” holds enterprise-only middleware (streams, OAuth, upstream auth, etc.).
- “cli/” provides command-line utilities (linter, importer, bundler).
- “coprocess/” provides the plugin engine via gRPC/protobuf for Go/Python/Java/Lua plugins.
- “trace/” integrates with Jaeger and Zipkin.

##### README for additional insights
- Tyk Gateway is “batteries-included” and provides features like rate limiting, quotas, transformations, analytics, service discovery, hitless reloads, and plug-in architecture.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "API Ingress Layer"
        Ingress["API Ingress Layer"]:::core
    end
    click Ingress "https://github.com/amosehiguese/tyk/blob/master/gateway/server.go"

    subgraph "Configuration Loader"
        Config["Configuration Loader"]:::adapters
    end
    click Config "https://github.com/amosehiguese/tyk/blob/master/config/config.go"

    subgraph "API Definition Engine"
        DefEngine["API Definition Engine"]:::adapters
    end
    click DefEngine "https://github.com/amosehiguese/tyk/tree/master/apidef/"

    subgraph "Core Gateway"
        Middleware["Middleware Chain"]:::core
        RateLimit["Policy & Rate-Limit Engine"]:::core
    end
    click Middleware "https://github.com/amosehiguese/tyk/blob/master/gateway/middleware.go"
    click RateLimit "https://github.com/amosehiguese/tyk/tree/master/internal/policy/"

    subgraph "Plugin/Coprocess Engine"
        Plugins["Plugin Engine"]:::plugins
    end
    click Plugins "https://github.com/amosehiguese/tyk/tree/master/coprocess/"

    subgraph "Upstream Proxy & Service Discovery"
        Proxy["Upstream Proxy"]:::core
        Discovery["Service Discovery"]:::core
    end
    click Proxy "https://github.com/amosehiguese/tyk/blob/master/gateway/reverse_proxy.go"
    click Discovery "https://github.com/amosehiguese/tyk/blob/master/rpc/dns_monitor.go"

    subgraph "Analytics & Logging"
        Analytics["Analytics & Logging"]:::core
        Tracing["Tracing Integration"]:::adapters
    end
    click Analytics "https://github.com/amosehiguese/tyk/blob/master/gateway/analytics.go"
    click Tracing "https://github.com/amosehiguese/tyk/tree/master/trace/"

    subgraph "Storage Backends"
        Redis[(Redis)]:::backend
        Consul[(Consul)]:::backend
        Vault[(Vault)]:::backend
    end
    click Redis "https://github.com/amosehiguese/tyk/blob/master/storage/redis_cluster.go"
    click Consul "https://github.com/amosehiguese/tyk/tree/master/storage/"
    click Vault "https://github.com/amosehiguese/tyk/tree/master/storage/"

    subgraph "Enterprise Extensions (EE)"
        EEComp["Enterprise Extensions"]:::ee
    end
    click EEComp "https://github.com/amosehiguese/tyk/tree/master/ee/"

    subgraph "CLI Tools"
        CLI["CLI Tools"]:::cli
    end
    click CLI "https://github.com/amosehiguese/tyk/tree/master/cli/"

    subgraph "External Systems"
        Jaeger(("Jaeger")):::external
        Zipkin(("Zipkin")):::external
        K8s(("Kubernetes API")):::external
        Docker(("Docker")):::external
        CICD(("CI Pipeline")):::external
    end

    Ingress -->|"reads"| Config
    Ingress -->|"parses definitions"| DefEngine
    Ingress -->|"forwards request"| Middleware
    DefEngine -->|"models API"| Middleware
    Config -->|"provides config"| Middleware
    Middleware -->|"enforces policies"| RateLimit
    RateLimit -->|"stores/retrieves"| Redis
    RateLimit -->|"stores/retrieves"| Consul
    RateLimit -->|"stores/retrieves"| Vault
    Middleware -->|"invokes plugins"| Plugins
    Plugins -->|"returns result"| Middleware
    Middleware -->|"proxies request"| Proxy
    Proxy -->|"discovers services"| Discovery
    Proxy -->|"calls upstream"| K8s
    Middleware -->|"logs metrics"| Analytics
    Analytics -->|"exports spans"| Jaeger
    Analytics -->|"exports spans"| Zipkin
    Tracing -->|"sends traces"| Jaeger
    Tracing -->|"sends traces"| Zipkin

    classDef core fill:#D0E6FF,stroke:#036;
    classDef adapters fill:#DFFFE0,stroke:#060;
    classDef backend fill:#FFE6CC,stroke:#E60;
    classDef plugins fill:#EEDFF7,stroke:#963;
    classDef ee fill:#FDE2E4,stroke:#D33;
    classDef cli fill:#FFF4C1,stroke:#DD0;
    classDef external fill:#E0E0E0,stroke:#888;
```
