# devarajan8/aegis-proxy architecture

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

- Interactive diagram: https://gitdiagram.com/devarajan8/aegis-proxy
- Repository: https://github.com/devarajan8/aegis-proxy

## Overview

#### Purpose and Public Entry Point
Aegis Proxy is a containerized privacy gateway intended to sit between a client and an OpenAI/Groq-compatible LLM endpoint. Its public API is served by the Go gateway: health at `GET /healthz` and chat at `POST /v1/chat/completions`. Main entry point: `services/gateway/main.go`.

#### Gateway Service
The Go gateway is the only host-exposed service (port 8080). It accepts client chat-completion requests and is the intended orchestration boundary for PII sanitization, LLM forwarding, and response restoration. Its module and container build are defined in `services/gateway/go.mod` and `services/gateway/Dockerfile`; runtime behavior begins in `services/gateway/main.go`.

#### PII Processing Service
The Python/FastAPI PII engine is an internal service intended to detect sensitive values and replace them with tokens before prompts leave the private network, then reverse tokens in returned model text. Its service implementation and dependency boundary are `services/pii-engine/app.py` and `services/pii-engine/requirements.txt`; image construction is `services/pii-engine/Dockerfile`.

#### Token Vault Boundary
Redis is the intended in-memory vault for token-to-original-value mappings. The PII engine should own interaction with this store so the gateway and external LLM do not require direct access to raw mappings. Redis persistence is deliberately ephemeral: mappings are discarded when the stack restarts. Service wiring, including the Redis URL and internal topology, is centralized in `docker-compose.yml`.

#### Primary Request/Response Flow
1. A client sends a chat request to the gateway on port 8080.
2. The gateway sends prompt content to the internal PII engine.
3. The PII engine identifies/tokenizes PII and stores mappings in Redis.
4. The gateway forwards only tokenized content to the configured external LLM endpoint.
5. The returned LLM response is passed back through the PII engine for detokenization.
6. The gateway returns natural-language content to the client.

The external LLM boundary is controlled by `LLM_ENDPOINT` and `GROQ_API_KEY`; the target defaults to Groq’s chat-completions API.

#### Deployment and Network Topology
`docker-compose.yml` defines the three-service stack: gateway, PII engine, and Redis vault. Services communicate over the private Docker bridge network `aegis-net`; only gateway port 8080 is published to the host. Docker image boundaries are represented by `services/gateway/Dockerfile` and `services/pii-engine/Dockerfile`.

#### Current Maturity and Extension Points
The repository is explicitly Phase 1/skeleton-oriented. The intended architectural stages—actual NER-based PII recognition, complete proxy/detokenization behavior, streaming, authentication, rate limiting, and audit logging—are not guaranteed implemented merely by the current layout. The principal implementation anchors for those future stages are `services/gateway/main.go` and `services/pii-engine/app.py`.

Main entry points: [`services/gateway/main.go`](https://github.com/devarajan8/aegis-proxy/blob/main/services/gateway/main.go) (Go gateway), [`services/pii-engine/app.py`](https://github.com/devarajan8/aegis-proxy/blob/main/services/pii-engine/app.py) (PII engine), [`docker-compose.yml`](https://github.com/devarajan8/aegis-proxy/blob/main/docker-compose.yml) (Compose topology), [`services/gateway/Dockerfile`](https://github.com/devarajan8/aegis-proxy/blob/main/services/gateway/Dockerfile) (Gateway image)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_stack["Docker stack"]
  node_gateway["Go gateway<br/>host-exposed service<br/>[main.go]"]
  node_gateway_build["Gateway image<br/>container build"]
  node_pii_engine["PII engine<br/>internal FastAPI service<br/>[app.py]"]
  node_pii_build["PII engine image<br/>container build"]
  node_pii_dependencies["PII dependencies<br/>Python dependency boundary<br/>[requirements.txt]"]
  node_redis_vault[("Redis token vault<br/>ephemeral mapping store")]
  node_compose["Compose topology<br/>deployment orchestration<br/>[docker-compose.yml]"]
  node_private_network{{"aegis-net<br/>private Docker network"}}
end

subgraph group_external["External boundary"]
  node_client(("Client<br/>API consumer"))
  node_llm_config["LLM credentials<br/>runtime configuration"]
  node_external_llm["OpenAI/Groq-compatible LLM<br/>external chat endpoint"]
end

node_client -->|"POST /v1/chat/completions"| node_gateway
node_client -.->|"GET /healthz"| node_gateway
node_gateway_build -.->|"builds"| node_gateway
node_pii_build -.->|"builds"| node_pii_engine
node_pii_dependencies -.->|"provides dependencies"| node_pii_engine
node_gateway -->|"tokenize prompt"| node_pii_engine
node_pii_engine -->|"store and resolve mappings"| node_redis_vault
node_pii_engine -->|"detokenized response"| node_gateway
node_gateway -->|"forward tokenized chat"| node_external_llm
node_external_llm -->|"model response"| node_gateway
node_llm_config -.->|"configures upstream"| node_gateway
node_compose -.->|"runs; publishes 8080"| node_gateway
node_compose -.->|"runs internally"| node_pii_engine
node_compose -.->|"runs ephemeral vault"| node_redis_vault
node_gateway -.->|"internal access"| node_private_network
node_pii_engine -.->|"internal access"| node_private_network
node_redis_vault -.->|"internal access"| node_private_network

click node_gateway "https://github.com/devarajan8/aegis-proxy/blob/main/services/gateway/main.go"
click node_gateway_build "https://github.com/devarajan8/aegis-proxy/blob/main/services/gateway/Dockerfile"
click node_pii_engine "https://github.com/devarajan8/aegis-proxy/blob/main/services/pii-engine/app.py"
click node_pii_build "https://github.com/devarajan8/aegis-proxy/blob/main/services/pii-engine/Dockerfile"
click node_pii_dependencies "https://github.com/devarajan8/aegis-proxy/blob/main/services/pii-engine/requirements.txt"
click node_compose "https://github.com/devarajan8/aegis-proxy/blob/main/docker-compose.yml"

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_gateway,node_gateway_build,node_pii_engine,node_pii_build,node_pii_dependencies,node_redis_vault,node_compose,node_private_network toneBlue
class node_client,node_llm_config,node_external_llm toneAmber
```

## Components

### Docker stack

Private aegis-net deployment.

- [Go gateway](https://github.com/devarajan8/aegis-proxy/blob/main/services/gateway/main.go): host-exposed service · Only service published on port 8080. · `services/gateway/main.go`
- [Gateway image](https://github.com/devarajan8/aegis-proxy/blob/main/services/gateway/Dockerfile): container build · `services/gateway/Dockerfile`
- [PII engine](https://github.com/devarajan8/aegis-proxy/blob/main/services/pii-engine/app.py): internal FastAPI service · Owns tokenization and detokenization. · `services/pii-engine/app.py`
- [PII engine image](https://github.com/devarajan8/aegis-proxy/blob/main/services/pii-engine/Dockerfile): container build · `services/pii-engine/Dockerfile`
- [PII dependencies](https://github.com/devarajan8/aegis-proxy/blob/main/services/pii-engine/requirements.txt): Python dependency boundary · `services/pii-engine/requirements.txt`
- **Redis token vault**: ephemeral mapping store · Mappings are discarded when the stack restarts.
- [Compose topology](https://github.com/devarajan8/aegis-proxy/blob/main/docker-compose.yml): deployment orchestration · Defines services, Redis URL, and aegis-net. · `docker-compose.yml`
- **aegis-net**: private Docker network · Internal service communication boundary.

### External boundary

- **Client**: API consumer
- **LLM credentials**: runtime configuration · LLM_ENDPOINT and GROQ_API_KEY select and authorize the upstream.
- **OpenAI/Groq-compatible LLM**: external chat endpoint · Receives tokenized prompts only.

## Connections

- Client → Go gateway: POST /v1/chat/completions
- Client → Go gateway: GET /healthz
- Gateway image → Go gateway: builds
- PII engine image → PII engine: builds
- PII dependencies → PII engine: provides dependencies
- Go gateway → PII engine: tokenize prompt
- PII engine → Redis token vault: store and resolve mappings
- PII engine → Go gateway: detokenized response
- Go gateway → OpenAI/Groq-compatible LLM: forward tokenized chat
- OpenAI/Groq-compatible LLM → Go gateway: model response
- LLM credentials → Go gateway: configures upstream
- Compose topology → Go gateway: runs; publishes 8080
- Compose topology → PII engine: runs internally
- Compose topology → Redis token vault: runs ephemeral vault
- Go gateway → aegis-net: internal access
- PII engine → aegis-net: internal access
- Redis token vault → aegis-net: internal access
