# msrsiddik/apicorex architecture

> Architecture diagram of the GitHub repository msrsiddik/apicorex, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/msrsiddik/apicorex
- Repository: https://github.com/msrsiddik/apicorex

## Overview

ApiCoreX is a stateless, multi-tenant HTTP API gateway whose main workflow is client request → device-token resolution through Identity → trusted tenant-context injection and authorization → protected streaming proxy to a registered plugin. Its separate control plane registers plugins and pulls manifests; additional capabilities include merged OpenAPI docs, an operator dashboard, tenant-domain routing, and observability/resilience. The graph uses README statements and shown source references for relationships; unsampled implementation details are represented only where the tree supports a subsystem path.

Main entry points: [`server/http.go`](https://github.com/msrsiddik/apicorex/blob/staging/server/http.go) (HTTP server), [`internal/controlplane/handlers.go`](https://github.com/msrsiddik/apicorex/blob/staging/internal/controlplane/handlers.go) (Registration handlers), [`internal/dispatcher/dispatcher.go`](https://github.com/msrsiddik/apicorex/blob/staging/internal/dispatcher/dispatcher.go) (Route and proxy), [`internal/middleware/auth.go`](https://github.com/msrsiddik/apicorex/blob/staging/internal/middleware/auth.go) (Token authentication)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_gateway["Gateway data plane"]
  node_http["HTTP server<br/>[http.go]"]
  node_tenant_domains["Tenant domain routing<br/>[domain_resolve.go]"]
  node_product_hosts["Product host routing<br/>[product_host.go]"]
  node_auth_middleware["Token authentication<br/>[auth.go]"]
  node_authz["Route authorization"]
  node_dispatcher["Route and proxy<br/>[dispatcher.go]"]
  node_protection["Resilience controls"]
end

subgraph group_control["Plugin control plane"]
  node_registry[("Plugin registry<br/>[registry.go]")]
  node_controlplane["Registration handlers<br/>[handlers.go]"]
  node_manifest["Plugin manifest<br/>[manifest.go]"]
end

subgraph group_operator["Operations and docs"]
  node_openapi["OpenAPI merger<br/>[injector.go]"]
  node_admin_ui["Admin dashboard UI<br/>[page.tsx]"]
  node_dashboard["Dashboard serving<br/>[dashboard.go]"]
end

subgraph group_runtime["Runtime services"]
  node_metrics["Metrics and health<br/>[metrics.go]"]
  node_tracing["Distributed tracing<br/>[tracing.go]"]
  node_tls_gate["On-demand TLS gate<br/>[ondemand.go]"]
  node_config["Runtime configuration<br/>[config.go]"]
end

node_client(("API client"))
node_identity["Identity service"]
node_plugin["HTTP plugin"]

node_client -->|"sends requests"| node_http
node_http -->|"applies auth"| node_auth_middleware
node_auth_middleware -->|"introspects tokens"| node_identity
node_auth_middleware -.->|"provides identity"| node_authz
node_http -->|"resolves domains"| node_tenant_domains
node_tenant_domains -->|"resolves domain"| node_identity
node_http -.->|"rewrites host paths"| node_product_hosts
node_http -->|"routes requests"| node_dispatcher
node_dispatcher -->|"streams requests"| node_plugin
node_dispatcher -->|"enforces limits"| node_protection
node_controlplane -->|"registers plugins"| node_registry
node_controlplane -->|"adds routes"| node_dispatcher
node_controlplane -->|"updates specs"| node_openapi
node_controlplane -->|"pulls manifest"| node_plugin
node_plugin -->|"registers and heartbeats"| node_controlplane
node_registry -->|"stores manifest"| node_manifest
node_http -->|"serves merged docs"| node_openapi
node_http -->|"serves dashboard"| node_dashboard
node_admin_ui -.->|"uses admin endpoints"| node_controlplane
node_http -->|"exposes metrics"| node_metrics
node_dispatcher -->|"starts proxy spans"| node_tracing
node_tls_gate -->|"checks host claims"| node_identity
node_config -.->|"configures limits"| node_protection

click node_http "https://github.com/msrsiddik/apicorex/blob/staging/server/http.go"
click node_tenant_domains "https://github.com/msrsiddik/apicorex/blob/staging/server/domain_resolve.go"
click node_product_hosts "https://github.com/msrsiddik/apicorex/blob/staging/server/product_host.go"
click node_auth_middleware "https://github.com/msrsiddik/apicorex/blob/staging/internal/middleware/auth.go"
click node_authz "https://github.com/msrsiddik/apicorex/tree/staging/internal/middleware"
click node_dispatcher "https://github.com/msrsiddik/apicorex/blob/staging/internal/dispatcher/dispatcher.go"
click node_protection "https://github.com/msrsiddik/apicorex/tree/staging/internal/protection"
click node_registry "https://github.com/msrsiddik/apicorex/blob/staging/internal/registry/registry.go"
click node_controlplane "https://github.com/msrsiddik/apicorex/blob/staging/internal/controlplane/handlers.go"
click node_manifest "https://github.com/msrsiddik/apicorex/blob/staging/internal/manifest/manifest.go"
click node_openapi "https://github.com/msrsiddik/apicorex/blob/staging/internal/openapi/injector.go"
click node_admin_ui "https://github.com/msrsiddik/apicorex/blob/staging/cmd/apicorex/admin/app/page.tsx"
click node_dashboard "https://github.com/msrsiddik/apicorex/blob/staging/cmd/apicorex/dashboard.go"
click node_metrics "https://github.com/msrsiddik/apicorex/blob/staging/internal/protection/metrics.go"
click node_tracing "https://github.com/msrsiddik/apicorex/blob/staging/internal/tracing/tracing.go"
click node_tls_gate "https://github.com/msrsiddik/apicorex/blob/staging/server/ondemand.go"
click node_config "https://github.com/msrsiddik/apicorex/blob/staging/internal/config/config.go"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_http,node_tenant_domains,node_product_hosts,node_auth_middleware,node_authz,node_dispatcher,node_protection,node_client toneBlue
class node_registry,node_controlplane,node_manifest toneAmber
class node_openapi,node_admin_ui,node_dashboard toneMint
class node_metrics,node_tracing,node_tls_gate,node_config toneRose
class node_identity,node_plugin toneIndigo
```

## Components

### Gateway data plane

- [HTTP server](https://github.com/msrsiddik/apicorex/blob/staging/server/http.go): `server/http.go`
- [Tenant domain routing](https://github.com/msrsiddik/apicorex/blob/staging/server/domain_resolve.go): `server/domain_resolve.go`
- [Product host routing](https://github.com/msrsiddik/apicorex/blob/staging/server/product_host.go): `server/product_host.go`
- [Token authentication](https://github.com/msrsiddik/apicorex/blob/staging/internal/middleware/auth.go): `internal/middleware/auth.go`
- [Route authorization](https://github.com/msrsiddik/apicorex/tree/staging/internal/middleware): `internal/middleware`
- [Route and proxy](https://github.com/msrsiddik/apicorex/blob/staging/internal/dispatcher/dispatcher.go): `internal/dispatcher/dispatcher.go`
- [Resilience controls](https://github.com/msrsiddik/apicorex/tree/staging/internal/protection): `internal/protection`

### Plugin control plane

- [Plugin registry](https://github.com/msrsiddik/apicorex/blob/staging/internal/registry/registry.go): `internal/registry/registry.go`
- [Registration handlers](https://github.com/msrsiddik/apicorex/blob/staging/internal/controlplane/handlers.go): `internal/controlplane/handlers.go`
- [Plugin manifest](https://github.com/msrsiddik/apicorex/blob/staging/internal/manifest/manifest.go): `internal/manifest/manifest.go`

### Operations and docs

- [OpenAPI merger](https://github.com/msrsiddik/apicorex/blob/staging/internal/openapi/injector.go): `internal/openapi/injector.go`
- [Admin dashboard UI](https://github.com/msrsiddik/apicorex/blob/staging/cmd/apicorex/admin/app/page.tsx): `cmd/apicorex/admin/app/page.tsx`
- [Dashboard serving](https://github.com/msrsiddik/apicorex/blob/staging/cmd/apicorex/dashboard.go): `cmd/apicorex/dashboard.go`

### Runtime services

- [Metrics and health](https://github.com/msrsiddik/apicorex/blob/staging/internal/protection/metrics.go): `internal/protection/metrics.go`
- [Distributed tracing](https://github.com/msrsiddik/apicorex/blob/staging/internal/tracing/tracing.go): `internal/tracing/tracing.go`
- [On-demand TLS gate](https://github.com/msrsiddik/apicorex/blob/staging/server/ondemand.go): `server/ondemand.go`
- [Runtime configuration](https://github.com/msrsiddik/apicorex/blob/staging/internal/config/config.go): `internal/config/config.go`

### Other components

- **API client**
- **Identity service**
- **HTTP plugin**

## Connections

- API client → HTTP server: sends requests
- HTTP server → Token authentication: applies auth (evidence: `server/http.go`)
- Token authentication → Identity service: introspects tokens
- Token authentication → Route authorization: provides identity
- HTTP server → Tenant domain routing: resolves domains (evidence: `server/http.go`)
- Tenant domain routing → Identity service: resolves domain (evidence: `server/domain_resolve.go`)
- HTTP server → Product host routing: rewrites host paths
- HTTP server → Route and proxy: routes requests (evidence: `server/http.go`)
- Route and proxy → HTTP plugin: streams requests
- Route and proxy → Resilience controls: enforces limits (evidence: `internal/dispatcher/dispatcher.go`)
- Registration handlers → Plugin registry: registers plugins (evidence: `internal/controlplane/handlers.go`)
- Registration handlers → Route and proxy: adds routes (evidence: `internal/controlplane/handlers.go`)
- Registration handlers → OpenAPI merger: updates specs (evidence: `internal/controlplane/handlers.go`)
- Registration handlers → HTTP plugin: pulls manifest (evidence: `internal/controlplane/handlers.go`)
- HTTP plugin → Registration handlers: registers and heartbeats
- Plugin registry → Plugin manifest: stores manifest (evidence: `internal/registry/registry.go`)
- HTTP server → OpenAPI merger: serves merged docs (evidence: `server/http.go`)
- HTTP server → Dashboard serving: serves dashboard (evidence: `server/http.go`)
- Admin dashboard UI → Registration handlers: uses admin endpoints
- HTTP server → Metrics and health: exposes metrics (evidence: `server/http.go`)
- Route and proxy → Distributed tracing: starts proxy spans (evidence: `internal/dispatcher/dispatcher.go`)
- On-demand TLS gate → Identity service: checks host claims (evidence: `server/ondemand.go`)
- Runtime configuration → Resilience controls: configures limits
