# bookang869/plexon architecture

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

- Interactive diagram: https://gitdiagram.com/bookang869/plexon
- Repository: https://github.com/bookang869/plexon
- Video tour (about a minute): https://gitdiagram.com/bookang869/plexon/video

## Overview

Plexon is a FastAPI LLM gateway: team clients submit OpenAI-compatible chat requests, which are authenticated, rate- and budget-checked, enriched, routed to a provider, and returned with spend reconciliation. Operators also manage teams and limits. README capabilities include streaming, fallback and circuit breaking, health checks, hot configuration, and observability. The graph includes those documented branches; unsampled implementation links are omitted or marked unverified. External telemetry destinations are shown only where the README identifies them.

Main entry points: [`gateway/routes.py`](https://github.com/bookang869/plexon/blob/main/gateway/routes.py) (Chat API), [`gateway/config/loader.py`](https://github.com/bookang869/plexon/blob/main/gateway/config/loader.py) (Gateway configuration), [`gateway/resilience/orchestrator.py`](https://github.com/bookang869/plexon/blob/main/gateway/resilience/orchestrator.py) (Retry and fallback), [`gateway/admin/routes.py`](https://github.com/bookang869/plexon/blob/main/gateway/admin/routes.py) (Admin API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_request["Request gateway"]
  node_request_api["Chat API<br/>[routes.py]"]
  node_team_auth["Team authentication<br/>[team_auth.py]"]
  node_canonical["Chat schemas<br/>[schemas.py]"]
  node_enrich["Request enrichment<br/>[enrich.py]"]
  node_filter["Content filtering<br/>[content_filter.py]"]
  node_stream["Streaming delivery<br/>[streaming.py]"]
end

subgraph group_providers["Provider execution"]
  node_registry["Provider selection<br/>[registry.py]"]
  node_provider_adapters["Provider adapters"]
  node_resilience["Retry and fallback<br/>[orchestrator.py]"]
  node_breaker["Circuit breaker<br/>[circuit_breaker.py]"]
  node_fallback["Fallback chains<br/>[fallback.py]"]
  node_health["Provider health checks<br/>[health_check.py]"]
end

subgraph group_state["State and policy"]
  node_limiter["Rate limiting<br/>[limiter.py]"]
  node_bucket["Token bucket<br/>[token_bucket.py]"]
  node_budget["Budget enforcement<br/>[budget.py]"]
  node_redis[("Redis state<br/>[redis_client.py]")]
  node_postgres[("PostgreSQL pool<br/>[db.py]")]
  node_config["Gateway configuration<br/>[loader.py]"]
end

subgraph group_admin["Administration"]
  node_admin_auth["Admin authentication<br/>[admin_auth.py]"]
  node_admin_api["Admin API<br/>[routes.py]"]
end

subgraph group_observe["Observability"]
  node_tracing["Tracing<br/>[tracing.py]"]
  node_metrics["Metrics<br/>[metrics.py]"]
  node_alert_eval["Alert evaluation<br/>[alert_evaluator.py]"]
  node_alerts["Alert delivery<br/>[alerts.py]"]
  node_tempo[("Tempo")]
  node_prometheus[("Prometheus")]
  node_slack["Slack"]
end

node_team(("Team client"))
node_operator(("Operator"))

node_team -->|"submits request"| node_request_api
node_request_api -->|"authenticates via"| node_team_auth
node_team_auth -->|"looks up key"| node_postgres
node_request_api -->|"checks limits"| node_limiter
node_limiter -->|"consumes tokens"| node_bucket
node_limiter -->|"uses state"| node_redis
node_request_api -->|"checks and records spend"| node_budget
node_budget -->|"reads and updates"| node_redis
node_budget -->|"writes ledger"| node_postgres
node_request_api -->|"enriches request"| node_enrich
node_enrich -->|"applies rules"| node_filter
node_request_api -->|"resolves provider"| node_registry
node_registry -->|"selects adapter"| node_provider_adapters
node_request_api -->|"dispatches call"| node_resilience
node_resilience -->|"checks and records"| node_breaker
node_resilience -.->|"resolves candidates"| node_fallback
node_resilience -->|"attempts provider"| node_provider_adapters
node_request_api -.->|"delivers stream"| node_stream
node_request_api -->|"accepts and returns"| node_canonical
node_config -->|"configures providers"| node_registry
node_resilience -->|"uses policy"| node_config
node_limiter -->|"reads tier settings"| node_config
node_enrich -->|"reads defaults"| node_config
node_health -->|"checks health"| node_provider_adapters
node_health -.->|"stores status"| node_redis
node_operator -->|"manages gateway"| node_admin_api
node_admin_api -->|"authenticates via"| node_admin_auth
node_admin_api -->|"reads and updates"| node_postgres
node_admin_api -->|"checks live limits"| node_redis
node_admin_api -->|"reloads settings"| node_config
node_request_api -->|"records spans"| node_tracing
node_request_api -->|"records metrics"| node_metrics
node_alert_eval -->|"reads thresholds"| node_config
node_alert_eval -->|"sends alerts"| node_alerts
node_budget -->|"sends budget warning"| node_alerts
node_tracing -->|"exports traces"| node_tempo
node_prometheus -->|"scrapes endpoint"| node_metrics
node_alerts -->|"notifies"| node_slack

click node_request_api "https://github.com/bookang869/plexon/blob/main/gateway/routes.py"
click node_team_auth "https://github.com/bookang869/plexon/blob/main/gateway/auth/team_auth.py"
click node_canonical "https://github.com/bookang869/plexon/blob/main/gateway/schemas.py"
click node_enrich "https://github.com/bookang869/plexon/blob/main/gateway/enrichment/enrich.py"
click node_filter "https://github.com/bookang869/plexon/blob/main/gateway/enrichment/content_filter.py"
click node_stream "https://github.com/bookang869/plexon/blob/main/gateway/streaming.py"
click node_registry "https://github.com/bookang869/plexon/blob/main/gateway/providers/registry.py"
click node_provider_adapters "https://github.com/bookang869/plexon/tree/main/gateway/providers"
click node_resilience "https://github.com/bookang869/plexon/blob/main/gateway/resilience/orchestrator.py"
click node_breaker "https://github.com/bookang869/plexon/blob/main/gateway/resilience/circuit_breaker.py"
click node_fallback "https://github.com/bookang869/plexon/blob/main/gateway/resilience/fallback.py"
click node_health "https://github.com/bookang869/plexon/blob/main/gateway/resilience/health_check.py"
click node_limiter "https://github.com/bookang869/plexon/blob/main/gateway/ratelimit/limiter.py"
click node_bucket "https://github.com/bookang869/plexon/blob/main/gateway/ratelimit/token_bucket.py"
click node_budget "https://github.com/bookang869/plexon/blob/main/gateway/ratelimit/budget.py"
click node_redis "https://github.com/bookang869/plexon/blob/main/gateway/redis_client.py"
click node_postgres "https://github.com/bookang869/plexon/blob/main/gateway/db.py"
click node_config "https://github.com/bookang869/plexon/blob/main/gateway/config/loader.py"
click node_admin_auth "https://github.com/bookang869/plexon/blob/main/gateway/auth/admin_auth.py"
click node_admin_api "https://github.com/bookang869/plexon/blob/main/gateway/admin/routes.py"
click node_tracing "https://github.com/bookang869/plexon/blob/main/gateway/observability/tracing.py"
click node_metrics "https://github.com/bookang869/plexon/blob/main/gateway/observability/metrics.py"
click node_alert_eval "https://github.com/bookang869/plexon/blob/main/gateway/observability/alert_evaluator.py"
click node_alerts "https://github.com/bookang869/plexon/blob/main/gateway/observability/alerts.py"

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_request_api,node_team_auth,node_canonical,node_enrich,node_filter,node_stream,node_team toneBlue
class node_registry,node_provider_adapters,node_resilience,node_breaker,node_fallback,node_health toneAmber
class node_limiter,node_bucket,node_budget,node_redis,node_postgres,node_config toneMint
class node_admin_auth,node_admin_api toneRose
class node_tracing,node_metrics,node_alert_eval,node_alerts,node_tempo,node_prometheus,node_slack,node_operator toneIndigo
```

## Components

### Request gateway

- [Chat API](https://github.com/bookang869/plexon/blob/main/gateway/routes.py): `gateway/routes.py`
- [Team authentication](https://github.com/bookang869/plexon/blob/main/gateway/auth/team_auth.py): `gateway/auth/team_auth.py`
- [Chat schemas](https://github.com/bookang869/plexon/blob/main/gateway/schemas.py): `gateway/schemas.py`
- [Request enrichment](https://github.com/bookang869/plexon/blob/main/gateway/enrichment/enrich.py): `gateway/enrichment/enrich.py`
- [Content filtering](https://github.com/bookang869/plexon/blob/main/gateway/enrichment/content_filter.py): `gateway/enrichment/content_filter.py`
- [Streaming delivery](https://github.com/bookang869/plexon/blob/main/gateway/streaming.py): `gateway/streaming.py`

### Provider execution

- [Provider selection](https://github.com/bookang869/plexon/blob/main/gateway/providers/registry.py): `gateway/providers/registry.py`
- [Provider adapters](https://github.com/bookang869/plexon/tree/main/gateway/providers): `gateway/providers`
- [Retry and fallback](https://github.com/bookang869/plexon/blob/main/gateway/resilience/orchestrator.py): `gateway/resilience/orchestrator.py`
- [Circuit breaker](https://github.com/bookang869/plexon/blob/main/gateway/resilience/circuit_breaker.py): `gateway/resilience/circuit_breaker.py`
- [Fallback chains](https://github.com/bookang869/plexon/blob/main/gateway/resilience/fallback.py): `gateway/resilience/fallback.py`
- [Provider health checks](https://github.com/bookang869/plexon/blob/main/gateway/resilience/health_check.py): `gateway/resilience/health_check.py`

### State and policy

- [Rate limiting](https://github.com/bookang869/plexon/blob/main/gateway/ratelimit/limiter.py): `gateway/ratelimit/limiter.py`
- [Token bucket](https://github.com/bookang869/plexon/blob/main/gateway/ratelimit/token_bucket.py): `gateway/ratelimit/token_bucket.py`
- [Budget enforcement](https://github.com/bookang869/plexon/blob/main/gateway/ratelimit/budget.py): `gateway/ratelimit/budget.py`
- [Redis state](https://github.com/bookang869/plexon/blob/main/gateway/redis_client.py): `gateway/redis_client.py`
- [PostgreSQL pool](https://github.com/bookang869/plexon/blob/main/gateway/db.py): `gateway/db.py`
- [Gateway configuration](https://github.com/bookang869/plexon/blob/main/gateway/config/loader.py): `gateway/config/loader.py`

### Administration

- [Admin authentication](https://github.com/bookang869/plexon/blob/main/gateway/auth/admin_auth.py): `gateway/auth/admin_auth.py`
- [Admin API](https://github.com/bookang869/plexon/blob/main/gateway/admin/routes.py): `gateway/admin/routes.py`

### Observability

- [Tracing](https://github.com/bookang869/plexon/blob/main/gateway/observability/tracing.py): `gateway/observability/tracing.py`
- [Metrics](https://github.com/bookang869/plexon/blob/main/gateway/observability/metrics.py): `gateway/observability/metrics.py`
- [Alert evaluation](https://github.com/bookang869/plexon/blob/main/gateway/observability/alert_evaluator.py): `gateway/observability/alert_evaluator.py`
- [Alert delivery](https://github.com/bookang869/plexon/blob/main/gateway/observability/alerts.py): `gateway/observability/alerts.py`
- **Tempo**
- **Prometheus**
- **Slack**

### Other components

- **Team client**
- **Operator**

## Connections

- Team client → Chat API: submits request
- Chat API → Team authentication: authenticates via (evidence: `gateway/routes.py`)
- Team authentication → PostgreSQL pool: looks up key (evidence: `gateway/auth/team_auth.py`)
- Chat API → Rate limiting: checks limits (evidence: `gateway/routes.py`)
- Rate limiting → Token bucket: consumes tokens (evidence: `gateway/ratelimit/limiter.py`)
- Rate limiting → Redis state: uses state (evidence: `gateway/ratelimit/limiter.py`)
- Chat API → Budget enforcement: checks and records spend (evidence: `gateway/routes.py`)
- Budget enforcement → Redis state: reads and updates (evidence: `gateway/ratelimit/budget.py`)
- Budget enforcement → PostgreSQL pool: writes ledger (evidence: `gateway/ratelimit/budget.py`)
- Chat API → Request enrichment: enriches request (evidence: `gateway/routes.py`)
- Request enrichment → Content filtering: applies rules (evidence: `gateway/enrichment/enrich.py`)
- Chat API → Provider selection: resolves provider (evidence: `gateway/routes.py`)
- Provider selection → Provider adapters: selects adapter (evidence: `gateway/providers/registry.py`)
- Chat API → Retry and fallback: dispatches call (evidence: `gateway/routes.py`)
- Retry and fallback → Circuit breaker: checks and records (evidence: `gateway/resilience/orchestrator.py`)
- Retry and fallback → Fallback chains: resolves candidates (evidence: `gateway/resilience/orchestrator.py`)
- Retry and fallback → Provider adapters: attempts provider (evidence: `gateway/resilience/orchestrator.py`)
- Chat API → Streaming delivery: delivers stream (evidence: `gateway/routes.py`)
- Chat API → Chat schemas: accepts and returns (evidence: `gateway/routes.py`)
- Gateway configuration → Provider selection: configures providers (evidence: `gateway/providers/registry.py`)
- Retry and fallback → Gateway configuration: uses policy (evidence: `gateway/resilience/orchestrator.py`)
- Rate limiting → Gateway configuration: reads tier settings (evidence: `gateway/ratelimit/limiter.py`)
- Request enrichment → Gateway configuration: reads defaults
- Provider health checks → Provider adapters: checks health (evidence: `gateway/resilience/health_check.py`)
- Provider health checks → Redis state: stores status (evidence: `gateway/resilience/health_check.py`)
- Operator → Admin API: manages gateway
- Admin API → Admin authentication: authenticates via (evidence: `gateway/admin/routes.py`)
- Admin API → PostgreSQL pool: reads and updates (evidence: `gateway/admin/routes.py`)
- Admin API → Redis state: checks live limits (evidence: `gateway/admin/routes.py`)
- Admin API → Gateway configuration: reloads settings (evidence: `gateway/admin/routes.py`)
- Chat API → Tracing: records spans (evidence: `gateway/routes.py`)
- Chat API → Metrics: records metrics (evidence: `gateway/routes.py`)
- Alert evaluation → Gateway configuration: reads thresholds (evidence: `gateway/observability/alert_evaluator.py`)
- Alert evaluation → Alert delivery: sends alerts (evidence: `gateway/observability/alert_evaluator.py`)
- Budget enforcement → Alert delivery: sends budget warning (evidence: `gateway/ratelimit/budget.py`)
- Tracing → Tempo: exports traces
- Prometheus → Metrics: scrapes endpoint
- Alert delivery → Slack: notifies
