# mr-ans-2006/carta-zta architecture

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

- Interactive diagram: https://gitdiagram.com/mr-ans-2006/carta-zta
- Repository: https://github.com/mr-ans-2006/carta-zta

## Overview

CARTA-ZTA is a native Python zero-trust framework. Client requests pass through JWT verification, risk-aware policy decisions, and the protected application; asynchronously recorded telemetry feeds a frozen-model detector whose risk and health state inform later requests. The repository also provides traffic simulators, a live console, and benchmark/reporting tools. Edges follow shown calls or README descriptions; unsampled service wiring is identified by documentation rather than source inspection.

Main entry points: [`pep_gateway/proxy.py`](https://github.com/mr-ans-2006/carta-zta/blob/main/pep_gateway/proxy.py) (PEP gateway), [`common/state_store.py`](https://github.com/mr-ans-2006/carta-zta/blob/main/common/state_store.py) (JSON runtime state), [`ai_engine/detector.py`](https://github.com/mr-ans-2006/carta-zta/blob/main/ai_engine/detector.py) (Risk detector), [`runner.py`](https://github.com/mr-ans-2006/carta-zta/blob/main/runner.py) (System runner)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_enforcement["Request enforcement"]
  node_pep["PEP gateway<br/>[proxy.py]"]
  node_pdp["OPA policy<br/>[policy.rego]"]
  node_fallback["Python PDP fallback<br/>[pdp_fallback.py]"]
  node_policy_logic["Reference policy logic<br/>[policy_logic.py]"]
  node_target["Protected API<br/>[main.py]"]
end

subgraph group_risk["Risk assessment"]
  node_features["Window features<br/>[features.py]"]
  node_training["Frozen model training<br/>[train.py]"]
  node_detector["Risk detector<br/>[detector.py]"]
end

subgraph group_state["Shared state"]
  node_store[("JSON runtime state<br/>[state_store.py]")]
  node_config["Shared configuration<br/>[config.py]"]
end

subgraph group_operations["Operations and demos"]
  node_runner["System runner<br/>[runner.py]"]
  node_console["Web console server<br/>[server.py]"]
  node_dashboard["Dashboard UI<br/>[dashboard.html]"]
  node_jwt["JWT issuer<br/>[generate_jwt.py]"]
  node_normal["Normal traffic<br/>[normal_traffic.py]"]
  node_attacks["Attack scenarios"]
end

subgraph group_evaluation["Evaluation and research"]
  node_benchmarks["Benchmark runner<br/>[run_benchmarks.py]"]
  node_plots["Result plots<br/>[plot_results.py]"]
  node_paper["Paper renderer<br/>[render_paper.py]"]
end

node_client(("API client"))
node_pdp_service["PDP service"]

node_client -->|"sends requests"| node_pep
node_pep -->|"reads risk and health"| node_store
node_pep -->|"queries decisions"| node_pdp_service
node_pdp_service -.->|"evaluates policy"| node_pdp
node_pdp_service -.->|"uses if unavailable"| node_fallback
node_pep -->|"falls back locally"| node_policy_logic
node_fallback -->|"uses rules"| node_policy_logic
node_pep -->|"forwards allowed requests"| node_target
node_target -->|"returns response"| node_pep
node_pep -->|"appends telemetry asynchronously"| node_store
node_detector -->|"extracts windows"| node_features
node_detector -->|"scores with hybrid models"| node_training
node_detector -->|"writes risk and heartbeat"| node_store
node_store -->|"provides telemetry stream"| node_detector
node_training -->|"trains on baseline data"| node_features
node_pep -->|"uses service settings"| node_config
node_target -->|"uses internal secret"| node_config
node_console -->|"serves interface"| node_dashboard
node_console -->|"reads live state"| node_store
node_console -->|"launches traffic"| node_normal
node_console -->|"launches scenarios"| node_attacks
node_normal -.->|"issues tokens"| node_jwt
node_attacks -->|"issues tokens"| node_jwt
node_normal -.->|"sends demo requests"| node_pep
node_attacks -->|"sends attack requests"| node_pep
node_runner -.->|"starts service"| node_pep
node_runner -.->|"starts service"| node_detector
node_runner -.->|"starts service"| node_pdp_service
node_runner -.->|"starts service"| node_target
node_benchmarks -->|"runs attack scenarios"| node_attacks
node_benchmarks -->|"measures normal traffic"| node_normal
node_benchmarks -->|"reads risk and health"| node_store
node_benchmarks -.->|"produces result inputs"| node_plots
node_plots -.->|"supports paper output"| node_paper

click node_pep "https://github.com/mr-ans-2006/carta-zta/blob/main/pep_gateway/proxy.py"
click node_pdp "https://github.com/mr-ans-2006/carta-zta/blob/main/policy_engine/policy.rego"
click node_fallback "https://github.com/mr-ans-2006/carta-zta/blob/main/policy_engine/pdp_fallback.py"
click node_policy_logic "https://github.com/mr-ans-2006/carta-zta/blob/main/common/policy_logic.py"
click node_target "https://github.com/mr-ans-2006/carta-zta/blob/main/target_app/main.py"
click node_features "https://github.com/mr-ans-2006/carta-zta/blob/main/ai_engine/features.py"
click node_training "https://github.com/mr-ans-2006/carta-zta/blob/main/ai_engine/train.py"
click node_detector "https://github.com/mr-ans-2006/carta-zta/blob/main/ai_engine/detector.py"
click node_store "https://github.com/mr-ans-2006/carta-zta/blob/main/common/state_store.py"
click node_config "https://github.com/mr-ans-2006/carta-zta/blob/main/common/config.py"
click node_runner "https://github.com/mr-ans-2006/carta-zta/blob/main/runner.py"
click node_console "https://github.com/mr-ans-2006/carta-zta/blob/main/gui/server.py"
click node_dashboard "https://github.com/mr-ans-2006/carta-zta/blob/main/gui/dashboard.html"
click node_jwt "https://github.com/mr-ans-2006/carta-zta/blob/main/simulator/generate_jwt.py"
click node_normal "https://github.com/mr-ans-2006/carta-zta/blob/main/simulator/normal_traffic.py"
click node_attacks "https://github.com/mr-ans-2006/carta-zta/blob/main/simulator/attack_scenarios.py"
click node_benchmarks "https://github.com/mr-ans-2006/carta-zta/blob/main/evaluation/run_benchmarks.py"
click node_plots "https://github.com/mr-ans-2006/carta-zta/blob/main/evaluation/plot_results.py"
click node_paper "https://github.com/mr-ans-2006/carta-zta/blob/main/evaluation/render_paper.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_pep,node_pdp,node_fallback,node_policy_logic,node_target,node_client toneBlue
class node_features,node_training,node_detector toneAmber
class node_store,node_config toneMint
class node_runner,node_console,node_dashboard,node_jwt,node_normal,node_attacks toneRose
class node_benchmarks,node_plots,node_paper,node_pdp_service toneIndigo
```

## Components

### Request enforcement

- [PEP gateway](https://github.com/mr-ans-2006/carta-zta/blob/main/pep_gateway/proxy.py): `pep_gateway/proxy.py`
- [OPA policy](https://github.com/mr-ans-2006/carta-zta/blob/main/policy_engine/policy.rego): `policy_engine/policy.rego`
- [Python PDP fallback](https://github.com/mr-ans-2006/carta-zta/blob/main/policy_engine/pdp_fallback.py): `policy_engine/pdp_fallback.py`
- [Reference policy logic](https://github.com/mr-ans-2006/carta-zta/blob/main/common/policy_logic.py): `common/policy_logic.py`
- [Protected API](https://github.com/mr-ans-2006/carta-zta/blob/main/target_app/main.py): `target_app/main.py`

### Risk assessment

- [Window features](https://github.com/mr-ans-2006/carta-zta/blob/main/ai_engine/features.py): `ai_engine/features.py`
- [Frozen model training](https://github.com/mr-ans-2006/carta-zta/blob/main/ai_engine/train.py): `ai_engine/train.py`
- [Risk detector](https://github.com/mr-ans-2006/carta-zta/blob/main/ai_engine/detector.py): `ai_engine/detector.py`

### Shared state

- [JSON runtime state](https://github.com/mr-ans-2006/carta-zta/blob/main/common/state_store.py): `common/state_store.py`
- [Shared configuration](https://github.com/mr-ans-2006/carta-zta/blob/main/common/config.py): `common/config.py`

### Operations and demos

- [System runner](https://github.com/mr-ans-2006/carta-zta/blob/main/runner.py): `runner.py`
- [Web console server](https://github.com/mr-ans-2006/carta-zta/blob/main/gui/server.py): `gui/server.py`
- [Dashboard UI](https://github.com/mr-ans-2006/carta-zta/blob/main/gui/dashboard.html): `gui/dashboard.html`
- [JWT issuer](https://github.com/mr-ans-2006/carta-zta/blob/main/simulator/generate_jwt.py): `simulator/generate_jwt.py`
- [Normal traffic](https://github.com/mr-ans-2006/carta-zta/blob/main/simulator/normal_traffic.py): `simulator/normal_traffic.py`
- [Attack scenarios](https://github.com/mr-ans-2006/carta-zta/blob/main/simulator/attack_scenarios.py): `simulator/attack_scenarios.py`

### Evaluation and research

- [Benchmark runner](https://github.com/mr-ans-2006/carta-zta/blob/main/evaluation/run_benchmarks.py): `evaluation/run_benchmarks.py`
- [Result plots](https://github.com/mr-ans-2006/carta-zta/blob/main/evaluation/plot_results.py): `evaluation/plot_results.py`
- [Paper renderer](https://github.com/mr-ans-2006/carta-zta/blob/main/evaluation/render_paper.py): `evaluation/render_paper.py`

### Other components

- **API client**
- **PDP service**

## Connections

- API client → PEP gateway: sends requests (evidence: `pep_gateway/proxy.py`)
- PEP gateway → JSON runtime state: reads risk and health (evidence: `pep_gateway/proxy.py`)
- PEP gateway → PDP service: queries decisions (evidence: `pep_gateway/proxy.py`)
- PDP service → OPA policy: evaluates policy (evidence: `README.md`)
- PDP service → Python PDP fallback: uses if unavailable (evidence: `README.md`)
- PEP gateway → Reference policy logic: falls back locally (evidence: `pep_gateway/proxy.py`)
- Python PDP fallback → Reference policy logic: uses rules (evidence: `policy_engine/pdp_fallback.py`)
- PEP gateway → Protected API: forwards allowed requests (evidence: `pep_gateway/proxy.py`)
- Protected API → PEP gateway: returns response (evidence: `pep_gateway/proxy.py`)
- PEP gateway → JSON runtime state: appends telemetry asynchronously (evidence: `pep_gateway/proxy.py`)
- Risk detector → Window features: extracts windows (evidence: `ai_engine/detector.py`)
- Risk detector → Frozen model training: scores with hybrid models (evidence: `ai_engine/detector.py`)
- Risk detector → JSON runtime state: writes risk and heartbeat (evidence: `ai_engine/detector.py`)
- JSON runtime state → Risk detector: provides telemetry stream (evidence: `ai_engine/detector.py`)
- Frozen model training → Window features: trains on baseline data (evidence: `ai_engine/train.py`)
- PEP gateway → Shared configuration: uses service settings (evidence: `pep_gateway/proxy.py`)
- Protected API → Shared configuration: uses internal secret (evidence: `target_app/main.py`)
- Web console server → Dashboard UI: serves interface (evidence: `gui/server.py`)
- Web console server → JSON runtime state: reads live state (evidence: `gui/server.py`)
- Web console server → Normal traffic: launches traffic (evidence: `gui/server.py`)
- Web console server → Attack scenarios: launches scenarios (evidence: `gui/server.py`)
- Normal traffic → JWT issuer: issues tokens (evidence: `README.md`)
- Attack scenarios → JWT issuer: issues tokens (evidence: `simulator/attack_scenarios.py`)
- Normal traffic → PEP gateway: sends demo requests (evidence: `README.md`)
- Attack scenarios → PEP gateway: sends attack requests (evidence: `simulator/attack_scenarios.py`)
- System runner → PEP gateway: starts service (evidence: `README.md`)
- System runner → Risk detector: starts service (evidence: `README.md`)
- System runner → PDP service: starts service (evidence: `README.md`)
- System runner → Protected API: starts service (evidence: `README.md`)
- Benchmark runner → Attack scenarios: runs attack scenarios (evidence: `evaluation/run_benchmarks.py`)
- Benchmark runner → Normal traffic: measures normal traffic (evidence: `evaluation/run_benchmarks.py`)
- Benchmark runner → JSON runtime state: reads risk and health (evidence: `evaluation/run_benchmarks.py`)
- Benchmark runner → Result plots: produces result inputs (evidence: `README.md`)
- Result plots → Paper renderer: supports paper output (evidence: `README.md`)
