MATIH Platform is in active MVP development. Documentation reflects current implementation status.
2. Architecture
Gateway Architecture

Gateway Architecture

Production - Kong 3.5.0 - DB-less mode, 3 custom Lua plugins

The API Gateway is the single point of entry for all external traffic into the MATIH platform. Built on Kong 3.5.0 in DB-less (declarative) mode, it handles request routing, JWT authentication, tenant context injection, per-tenant rate limiting, and security filtering. Every request from a browser, CLI tool, or external API client passes through this gateway.


2.3.E.1Kong Configuration

ParameterValueRationale
Database modeDB-less (declarative YAML)GitOps-compatible, no external DB dependency
Proxy port8080Main traffic entry point
Admin port8444 (internal only)Management API not exposed externally
Status port8100Health check endpoint for Kubernetes probes
Worker countAuto (CPU cores)NGINX worker processes
SSL terminationAt load balancer / ingressGateway handles HTTP internally

Why DB-less Mode

DB-less mode means Kong reads its entire configuration from a YAML file at startup. There is no PostgreSQL database for Kong itself (unlike the standard Kong deployment). This choice provides:

  1. Immutability -- Configuration is version-controlled alongside application code
  2. Reproducibility -- Every environment gets the exact same gateway configuration
  3. Speed -- No database dependency means faster startup (sub-second) and failover
  4. GitOps compatibility -- Configuration changes go through the same PR review process as code
  5. Reduced surface area -- No Kong admin API to secure against unauthorized changes

2.3.E.2Custom Lua Plugins

Three custom Lua plugins extend Kong's built-in functionality:

JWT Claims Extraction Plugin

Extracts tenant_id, user_id, and roles from the validated JWT and injects them as HTTP headers:

Incoming Request:
  Authorization: Bearer eyJhbGci...

After Plugin:
  Authorization: Bearer eyJhbGci...  (preserved)
  X-Tenant-ID: acme-corp             (from JWT tenant_id claim)
  X-User-ID: user-123                (from JWT sub claim)
  X-User-Roles: data_analyst,viewer  (from JWT roles claim)
  X-Request-ID: req-abc-456          (generated if missing)
  X-Correlation-ID: cor-def-789      (generated if missing)

Tenant Rate Limiting Plugin

Enforces per-tenant rate limits stored in Redis:

Tenant TierRequests/MinRequests/HourBurst Limit
Free601,00010
Professional60020,000100
Enterprise6,000200,0001,000

Rate counters use Redis sliding window: ratelimit:{tenant_id}:{window_start}.

When exceeded: 429 Too Many Requests with Retry-After header.

Request Validation Plugin

Input validation at the gateway edge:

CheckResponse on Failure
Content-Type on POST/PUT400 Bad Request
Content-Length within 10MB413 Payload Too Large
Path traversal (../, %2e%2e)400 Bad Request
SQL injection patterns in query params400 Bad Request
Null bytes in URL or headers400 Bad Request
Authorization header on protected routes401 Unauthorized

2.3.E.3Routing Table

Control Plane Routes

Path PrefixUpstreamPortAuth
/api/v1/auth/loginiam-service8081Public
/api/v1/auth/registeriam-service8081Public
/api/v1/auth/refreshiam-service8081Refresh token
/api/v1/auth/*iam-service8081JWT
/api/v1/users/*iam-service8081JWT
/api/v1/tenants/*tenant-service8082JWT
/api/v1/config/*config-service8888JWT
/api/v1/notifications/*notification-service8085JWT
/api/v1/audit/*audit-service8086JWT
/api/v1/billing/*billing-service8087JWT
/api/v1/observability/*observability-api8088JWT
/api/v1/infrastructure/*infrastructure-service8089JWT
/api/v1/registry/*platform-registry8084JWT

Data Plane Routes

Path PrefixUpstreamPortAuth
/api/v1/query/*query-engine8080JWT
/api/v1/catalog/*catalog-service8086JWT
/api/v1/semantic/*semantic-layer8086JWT
/api/v1/bi/*bi-service8084JWT
/api/v1/ai/*ai-service8000JWT
/api/v1/ai/chat/streamai-service8000JWT (SSE)
/api/v1/ml/*ml-service8000JWT
/api/v1/pipelines/*pipeline-service8092JWT
/api/v1/quality/*data-quality-service8000JWT
/api/v1/ontology/*ontology-service8101JWT
/api/v1/governance/*governance-service8080JWT
/api/v1/render/*render-service8098JWT

2.3.E.4Streaming Support

Server-Sent Events (SSE)

Used by the AI service for streaming chat responses:

Client --> POST /api/v1/ai/chat/stream
  Accept: text/event-stream

Gateway configuration:
  - proxy_buffering: off
  - proxy_read_timeout: 300s
  - proxy_send_timeout: 300s
  - keepalive_timeout: 300s

WebSocket Upgrade

Used for real-time dashboard updates:

Client --> GET /api/v1/bi/ws
  Connection: Upgrade
  Upgrade: websocket

Gateway:
  - Validates JWT before upgrade
  - Upgrades connection to WebSocket
  - Proxies frames bidirectionally
  - Idle timeout: 300s

2.3.E.5Gateway Metrics

Kong exports Prometheus metrics:

MetricDescription
kong_http_requests_totalTotal requests by service, method, status
kong_request_latency_msGateway processing time
kong_upstream_latency_msUpstream response time
kong_bandwidth_bytesRequest/response bandwidth
kong_rate_limiting_totalRate limit hits by tenant

Average gateway overhead: 2-5ms for authenticated requests, 1-2ms for public routes.


Related Sections