# dgexplores/aegis-gateway architecture

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

- Interactive diagram: https://gitdiagram.com/dgexplores/aegis-gateway
- Repository: https://github.com/dgexplores/aegis-gateway

## Overview

AEGIS is a FastAPI gateway that screens tenant requests before sending them to configured AI providers, then returns results with audit evidence. Its main path runs from caller authentication and limits through prompt safety, routing and provider failover to response handling; tenant-scoped retrieval can supply grounded context. Separate branches cover operator controls, audit records and the browser console. The graph preserves documented capabilities and central modules; some links rely on README or SOURCE INDEX references rather than sampled call sites.

Main entry points: [`src/aegis/api/routes.py`](https://github.com/dgexplores/aegis-gateway/blob/main/src/aegis/api/routes.py) (HTTP routes), [`src/aegis/gateway.py`](https://github.com/dgexplores/aegis-gateway/blob/main/src/aegis/gateway.py) (Gateway orchestration), [`src/aegis/rag/service.py`](https://github.com/dgexplores/aegis-gateway/blob/main/src/aegis/rag/service.py) (RAG service), [`src/aegis/providers/registry.py`](https://github.com/dgexplores/aegis-gateway/blob/main/src/aegis/providers/registry.py) (Provider failover)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and console"]
  node_routes["HTTP routes<br/>[routes.py]"]
  node_dashboard["Browser console<br/>[dashboard.js]"]
  node_middleware["Request middleware<br/>[middleware.py]"]
end

subgraph group_policy["Request policy"]
  node_auth["Tenant authentication<br/>[auth.py]"]
  node_ratelimit["Rate limits<br/>[ratelimit.py]"]
  node_budget["Tenant budgets<br/>[budget.py]"]
  node_gateway["Gateway orchestration<br/>[gateway.py]"]
  node_injection["Injection screening<br/>[injection.py]"]
  node_pii["PII masking<br/>[pii.py]"]
end

subgraph group_providers["Provider execution"]
  node_router["Model routing<br/>[router.py]"]
  node_registry["Provider failover<br/>[registry.py]"]
  node_provider["Provider contracts<br/>[base.py]"]
end

subgraph group_retrieval["Tenant retrieval"]
  node_ragservice["RAG service<br/>[service.py]"]
  node_ingest["Document chunking<br/>[ingest.py]"]
  node_retriever["Hybrid retrieval<br/>[retriever.py]"]
  node_embeddings["Embedding providers<br/>[embeddings.py]"]
  node_ragdb[("RAG persistence<br/>[db.py]")]
end

subgraph group_ops["Audit and operations"]
  node_audit[("Tamper-evident audit<br/>[audit.py]")]
  node_admin["Operator controls<br/>[opscontrol.py]"]
  node_adminsession["Admin sessions<br/>[admin_session.py]"]
  node_metrics["Metrics<br/>[metrics.py]"]
  node_evaldata["Evaluation datasets<br/>[dataset.py]"]
  node_evalrunner["Evaluation runner<br/>[runner.py]"]
  node_evaljudges["Evaluation judges<br/>[judges.py]"]
end

node_app(("Client application"))

node_app -->|"sends requests"| node_routes
node_routes -->|"uses middleware"| node_middleware
node_routes -->|"authenticates callers"| node_auth
node_routes -->|"checks limits"| node_ratelimit
node_routes -->|"checks budgets"| node_budget
node_routes -->|"dispatches requests"| node_gateway
node_gateway -->|"screens prompts"| node_injection
node_gateway -->|"masks data"| node_pii
node_gateway -->|"selects tier"| node_router
node_gateway -->|"requests completion"| node_registry
node_registry -->|"dispatches completion"| node_provider
node_registry -.->|"returns completion"| node_gateway
node_gateway -->|"records decisions"| node_audit
node_routes -->|"requests retrieval"| node_ragservice
node_ragservice -->|"chunks documents"| node_ingest
node_ragservice -->|"retrieves context"| node_retriever
node_ragservice -->|"persists chunks"| node_ragdb
node_retriever -->|"uses vectors"| node_embeddings
node_ragservice -.->|"supplies context"| node_gateway
node_routes -->|"checks sessions"| node_adminsession
node_routes -.->|"exposes controls"| node_admin
node_routes -->|"serves audit records"| node_audit
node_gateway -->|"records metrics"| node_metrics
node_app -.->|"uses console"| node_dashboard
node_evalrunner -->|"loads cases"| node_evaldata
node_evalrunner -->|"uses judges"| node_evaljudges

click node_routes "https://github.com/dgexplores/aegis-gateway/blob/main/src/aegis/api/routes.py"
click node_dashboard "https://github.com/dgexplores/aegis-gateway/blob/main/src/aegis/static/dashboard.js"
click node_middleware "https://github.com/dgexplores/aegis-gateway/blob/main/src/aegis/api/middleware.py"
click node_auth "https://github.com/dgexplores/aegis-gateway/blob/main/src/aegis/security/auth.py"
click node_ratelimit "https://github.com/dgexplores/aegis-gateway/blob/main/src/aegis/ratelimit.py"
click node_budget "https://github.com/dgexplores/aegis-gateway/blob/main/src/aegis/budget.py"
click node_gateway "https://github.com/dgexplores/aegis-gateway/blob/main/src/aegis/gateway.py"
click node_injection "https://github.com/dgexplores/aegis-gateway/blob/main/src/aegis/security/injection.py"
click node_pii "https://github.com/dgexplores/aegis-gateway/blob/main/src/aegis/security/pii.py"
click node_router "https://github.com/dgexplores/aegis-gateway/blob/main/src/aegis/router.py"
click node_registry "https://github.com/dgexplores/aegis-gateway/blob/main/src/aegis/providers/registry.py"
click node_provider "https://github.com/dgexplores/aegis-gateway/blob/main/src/aegis/providers/base.py"
click node_ragservice "https://github.com/dgexplores/aegis-gateway/blob/main/src/aegis/rag/service.py"
click node_ingest "https://github.com/dgexplores/aegis-gateway/blob/main/src/aegis/rag/ingest.py"
click node_retriever "https://github.com/dgexplores/aegis-gateway/blob/main/src/aegis/rag/retriever.py"
click node_embeddings "https://github.com/dgexplores/aegis-gateway/blob/main/src/aegis/rag/embeddings.py"
click node_ragdb "https://github.com/dgexplores/aegis-gateway/blob/main/src/aegis/store/db.py"
click node_audit "https://github.com/dgexplores/aegis-gateway/blob/main/src/aegis/security/audit.py"
click node_admin "https://github.com/dgexplores/aegis-gateway/blob/main/src/aegis/opscontrol.py"
click node_adminsession "https://github.com/dgexplores/aegis-gateway/blob/main/src/aegis/security/admin_session.py"
click node_metrics "https://github.com/dgexplores/aegis-gateway/blob/main/src/aegis/metrics.py"
click node_evaldata "https://github.com/dgexplores/aegis-gateway/blob/main/src/aegis/evals/dataset.py"
click node_evalrunner "https://github.com/dgexplores/aegis-gateway/blob/main/src/aegis/evals/runner.py"
click node_evaljudges "https://github.com/dgexplores/aegis-gateway/blob/main/src/aegis/evals/judges.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_routes,node_dashboard,node_middleware,node_app toneBlue
class node_auth,node_ratelimit,node_budget,node_gateway,node_injection,node_pii toneAmber
class node_router,node_registry,node_provider toneMint
class node_ragservice,node_ingest,node_retriever,node_embeddings,node_ragdb toneRose
class node_audit,node_admin,node_adminsession,node_metrics,node_evaldata,node_evalrunner,node_evaljudges toneIndigo
```

## Components

### API and console

- [HTTP routes](https://github.com/dgexplores/aegis-gateway/blob/main/src/aegis/api/routes.py): `src/aegis/api/routes.py`
- [Browser console](https://github.com/dgexplores/aegis-gateway/blob/main/src/aegis/static/dashboard.js): `src/aegis/static/dashboard.js`
- [Request middleware](https://github.com/dgexplores/aegis-gateway/blob/main/src/aegis/api/middleware.py): `src/aegis/api/middleware.py`

### Request policy

- [Tenant authentication](https://github.com/dgexplores/aegis-gateway/blob/main/src/aegis/security/auth.py): `src/aegis/security/auth.py`
- [Rate limits](https://github.com/dgexplores/aegis-gateway/blob/main/src/aegis/ratelimit.py): `src/aegis/ratelimit.py`
- [Tenant budgets](https://github.com/dgexplores/aegis-gateway/blob/main/src/aegis/budget.py): `src/aegis/budget.py`
- [Gateway orchestration](https://github.com/dgexplores/aegis-gateway/blob/main/src/aegis/gateway.py): `src/aegis/gateway.py`
- [Injection screening](https://github.com/dgexplores/aegis-gateway/blob/main/src/aegis/security/injection.py): `src/aegis/security/injection.py`
- [PII masking](https://github.com/dgexplores/aegis-gateway/blob/main/src/aegis/security/pii.py): `src/aegis/security/pii.py`

### Provider execution

- [Model routing](https://github.com/dgexplores/aegis-gateway/blob/main/src/aegis/router.py): `src/aegis/router.py`
- [Provider failover](https://github.com/dgexplores/aegis-gateway/blob/main/src/aegis/providers/registry.py): `src/aegis/providers/registry.py`
- [Provider contracts](https://github.com/dgexplores/aegis-gateway/blob/main/src/aegis/providers/base.py): `src/aegis/providers/base.py`

### Tenant retrieval

- [RAG service](https://github.com/dgexplores/aegis-gateway/blob/main/src/aegis/rag/service.py): `src/aegis/rag/service.py`
- [Document chunking](https://github.com/dgexplores/aegis-gateway/blob/main/src/aegis/rag/ingest.py): `src/aegis/rag/ingest.py`
- [Hybrid retrieval](https://github.com/dgexplores/aegis-gateway/blob/main/src/aegis/rag/retriever.py): `src/aegis/rag/retriever.py`
- [Embedding providers](https://github.com/dgexplores/aegis-gateway/blob/main/src/aegis/rag/embeddings.py): `src/aegis/rag/embeddings.py`
- [RAG persistence](https://github.com/dgexplores/aegis-gateway/blob/main/src/aegis/store/db.py): `src/aegis/store/db.py`

### Audit and operations

- [Tamper-evident audit](https://github.com/dgexplores/aegis-gateway/blob/main/src/aegis/security/audit.py): `src/aegis/security/audit.py`
- [Operator controls](https://github.com/dgexplores/aegis-gateway/blob/main/src/aegis/opscontrol.py): `src/aegis/opscontrol.py`
- [Admin sessions](https://github.com/dgexplores/aegis-gateway/blob/main/src/aegis/security/admin_session.py): `src/aegis/security/admin_session.py`
- [Metrics](https://github.com/dgexplores/aegis-gateway/blob/main/src/aegis/metrics.py): `src/aegis/metrics.py`
- [Evaluation datasets](https://github.com/dgexplores/aegis-gateway/blob/main/src/aegis/evals/dataset.py): `src/aegis/evals/dataset.py`
- [Evaluation runner](https://github.com/dgexplores/aegis-gateway/blob/main/src/aegis/evals/runner.py): `src/aegis/evals/runner.py`
- [Evaluation judges](https://github.com/dgexplores/aegis-gateway/blob/main/src/aegis/evals/judges.py): `src/aegis/evals/judges.py`

### Other components

- **Client application**

## Connections

- Client application → HTTP routes: sends requests
- HTTP routes → Request middleware: uses middleware (evidence: `src/aegis/api/routes.py`)
- HTTP routes → Tenant authentication: authenticates callers (evidence: `src/aegis/api/routes.py`)
- HTTP routes → Rate limits: checks limits (evidence: `src/aegis/api/routes.py`)
- HTTP routes → Tenant budgets: checks budgets (evidence: `src/aegis/api/routes.py`)
- HTTP routes → Gateway orchestration: dispatches requests (evidence: `src/aegis/api/routes.py`)
- Gateway orchestration → Injection screening: screens prompts (evidence: `src/aegis/gateway.py`)
- Gateway orchestration → PII masking: masks data (evidence: `src/aegis/gateway.py`)
- Gateway orchestration → Model routing: selects tier (evidence: `src/aegis/gateway.py`)
- Gateway orchestration → Provider failover: requests completion (evidence: `src/aegis/gateway.py`)
- Provider failover → Provider contracts: dispatches completion (evidence: `src/aegis/providers/registry.py`)
- Provider failover → Gateway orchestration: returns completion (evidence: `src/aegis/gateway.py`)
- Gateway orchestration → Tamper-evident audit: records decisions (evidence: `src/aegis/gateway.py`)
- HTTP routes → RAG service: requests retrieval (evidence: `src/aegis/api/routes.py`)
- RAG service → Document chunking: chunks documents (evidence: `src/aegis/rag/service.py`)
- RAG service → Hybrid retrieval: retrieves context (evidence: `src/aegis/rag/service.py`)
- RAG service → RAG persistence: persists chunks (evidence: `src/aegis/rag/service.py`)
- Hybrid retrieval → Embedding providers: uses vectors (evidence: `src/aegis/rag/retriever.py`)
- RAG service → Gateway orchestration: supplies context
- HTTP routes → Admin sessions: checks sessions (evidence: `src/aegis/api/routes.py`)
- HTTP routes → Operator controls: exposes controls
- HTTP routes → Tamper-evident audit: serves audit records (evidence: `src/aegis/api/routes.py`)
- Gateway orchestration → Metrics: records metrics (evidence: `src/aegis/gateway.py`)
- Client application → Browser console: uses console
- Evaluation runner → Evaluation datasets: loads cases (evidence: `src/aegis/evals/runner.py`)
- Evaluation runner → Evaluation judges: uses judges (evidence: `src/aegis/evals/runner.py`)
