# 3mre0s/ai-firewall architecture

> Architecture diagram of the GitHub repository 3mre0s/ai-firewall, 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/3mre0s/ai-firewall
- Repository: https://github.com/3mre0s/ai-firewall

## Overview

Anonmyz is a local-first DLP gateway: clients send model requests through its proxy, sensitive values are replaced before upstream forwarding, and placeholders are restored locally in responses. The graph covers CLI/Codex and IDE entry points, explicit and optional transparent proxy modes, request-scoped inspection, provider routing, and local audit/metrics. Edges are limited to README statements and shown source references/calls; unsampled subsystems are included only where documented, so some internal links are omitted.

Main entry points: [`proxy/proxy.go`](https://github.com/3mre0s/ai-firewall/blob/main/proxy/proxy.go) (HTTP proxy), [`main.go`](https://github.com/3mre0s/ai-firewall/blob/main/main.go) (CLI and server), [`mitm/proxy.go`](https://github.com/3mre0s/ai-firewall/blob/main/mitm/proxy.go) (TLS MITM proxy), [`extensions/vscode/src/extension.js`](https://github.com/3mre0s/ai-firewall/blob/main/extensions/vscode/src/extension.js) (VS Code extension)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_clients["Client Integrations"]
  node_cli["CLI and server<br/>[main.go]"]
  node_codex_launcher["Codex launcher<br/>[codex.go]"]
  node_vscode["VS Code extension<br/>[extension.js]"]
  node_vscode_lifecycle["Process lifecycle"]
  node_vscode_binary["Binary resolver<br/>[binary.js]"]
  node_jetbrains["JetBrains plugin<br/>[FirewallPlugin.kt]"]
  node_jetbrains_binary["Binary resolver<br/>[BinaryResolver.kt]"]
  node_demo["Local privacy demo<br/>[demo.go]"]
end

subgraph group_gateway["Gateway Modes"]
  node_explicit_proxy["HTTP proxy<br/>[proxy.go]"]
  node_mitm_proxy["TLS MITM proxy<br/>[proxy.go]"]
  node_ca["Certificate authority<br/>[ca.go]"]
end

subgraph group_inspection["Inspection Core"]
  node_dlp_engine["Exchange lifecycle<br/>[engine.go]"]
  node_stream_restore["Stream restoration<br/>[stream.go]"]
  node_masker["Detection and masking<br/>[masker.go]"]
  node_patterns["Sensitive patterns<br/>[patterns.go]"]
  node_vault[("Request secret vault<br/>[vault.go]")]
  node_config["Runtime configuration<br/>[config.go]"]
end

subgraph group_upstream["Provider Routing"]
  node_provider_adapters["Provider adapters<br/>[provider.go]"]
end

subgraph group_observability["Local Observability"]
  node_audit[("Audit metadata<br/>[audit.go]")]
  node_metrics["Metrics<br/>[metrics.go]"]
  node_securitylog["Security events<br/>[log.go]"]
end

node_user(("Local user"))
node_coding_client(("Coding client"))
node_ai_provider(("Configured AI provider"))

node_user -->|"runs"| node_cli
node_coding_client -->|"sends requests"| node_explicit_proxy
node_cli -->|"loads"| node_config
node_cli -->|"creates"| node_vault
node_cli -->|"starts"| node_explicit_proxy
node_cli -->|"starts optionally"| node_mitm_proxy
node_cli -->|"dispatches"| node_codex_launcher
node_cli -->|"dispatches"| node_demo
node_codex_launcher -->|"starts"| node_explicit_proxy
node_codex_launcher -->|"reads evidence"| node_audit
node_vscode -->|"manages process"| node_vscode_lifecycle
node_vscode -->|"resolves executable"| node_vscode_binary
node_vscode -->|"starts binary"| node_cli
node_jetbrains -->|"resolves executable"| node_jetbrains_binary
node_jetbrains -.->|"launches binary"| node_cli
node_explicit_proxy -->|"prepares exchange"| node_dlp_engine
node_mitm_proxy -->|"creates engine"| node_dlp_engine
node_dlp_engine -->|"scopes masking"| node_masker
node_masker -->|"analyzes text"| node_patterns
node_masker -->|"stores mappings"| node_vault
node_explicit_proxy -->|"selects provider"| node_provider_adapters
node_explicit_proxy -->|"forwards sanitized request"| node_ai_provider
node_ai_provider -->|"returns response"| node_explicit_proxy
node_explicit_proxy -->|"restores stream"| node_stream_restore
node_mitm_proxy -->|"forwards sanitized request"| node_ai_provider
node_ai_provider -->|"returns response"| node_mitm_proxy
node_mitm_proxy -->|"uses certificates"| node_ca
node_explicit_proxy -->|"records metadata"| node_audit
node_explicit_proxy -->|"records counters"| node_metrics
node_explicit_proxy -->|"emits events"| node_securitylog
node_mitm_proxy -->|"emits events"| node_securitylog
node_demo -->|"exercises pipeline"| node_explicit_proxy
node_demo -->|"uses mock upstream"| node_ai_provider

click node_cli "https://github.com/3mre0s/ai-firewall/blob/main/main.go"
click node_codex_launcher "https://github.com/3mre0s/ai-firewall/blob/main/codex.go"
click node_vscode "https://github.com/3mre0s/ai-firewall/blob/main/extensions/vscode/src/extension.js"
click node_vscode_lifecycle "https://github.com/3mre0s/ai-firewall/blob/main/extensions/vscode/src/process-lifecycle.js"
click node_vscode_binary "https://github.com/3mre0s/ai-firewall/blob/main/extensions/vscode/src/binary.js"
click node_jetbrains "https://github.com/3mre0s/ai-firewall/blob/main/extensions/jetbrains/src/main/kotlin/com/localai/firewall/FirewallPlugin.kt"
click node_jetbrains_binary "https://github.com/3mre0s/ai-firewall/blob/main/extensions/jetbrains/src/main/kotlin/com/localai/firewall/BinaryResolver.kt"
click node_explicit_proxy "https://github.com/3mre0s/ai-firewall/blob/main/proxy/proxy.go"
click node_mitm_proxy "https://github.com/3mre0s/ai-firewall/blob/main/mitm/proxy.go"
click node_ca "https://github.com/3mre0s/ai-firewall/blob/main/mitm/ca.go"
click node_dlp_engine "https://github.com/3mre0s/ai-firewall/blob/main/dlp/engine.go"
click node_stream_restore "https://github.com/3mre0s/ai-firewall/blob/main/dlp/stream.go"
click node_masker "https://github.com/3mre0s/ai-firewall/blob/main/masker/masker.go"
click node_patterns "https://github.com/3mre0s/ai-firewall/blob/main/patterns/patterns.go"
click node_vault "https://github.com/3mre0s/ai-firewall/blob/main/vault/vault.go"
click node_config "https://github.com/3mre0s/ai-firewall/blob/main/config/config.go"
click node_provider_adapters "https://github.com/3mre0s/ai-firewall/blob/main/providers/provider.go"
click node_audit "https://github.com/3mre0s/ai-firewall/blob/main/audit/audit.go"
click node_metrics "https://github.com/3mre0s/ai-firewall/blob/main/metrics/metrics.go"
click node_securitylog "https://github.com/3mre0s/ai-firewall/blob/main/securitylog/log.go"
click node_demo "https://github.com/3mre0s/ai-firewall/blob/main/demo.go"

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_cli,node_codex_launcher,node_vscode,node_vscode_lifecycle,node_vscode_binary,node_jetbrains,node_jetbrains_binary,node_demo,node_user,node_coding_client toneBlue
class node_explicit_proxy,node_mitm_proxy,node_ca toneAmber
class node_dlp_engine,node_stream_restore,node_masker,node_patterns,node_vault,node_config toneMint
class node_provider_adapters toneRose
class node_audit,node_metrics,node_securitylog,node_ai_provider toneIndigo
```

## Components

### Client Integrations

- [CLI and server](https://github.com/3mre0s/ai-firewall/blob/main/main.go): `main.go`
- [Codex launcher](https://github.com/3mre0s/ai-firewall/blob/main/codex.go): `codex.go`
- [VS Code extension](https://github.com/3mre0s/ai-firewall/blob/main/extensions/vscode/src/extension.js): `extensions/vscode/src/extension.js`
- [Process lifecycle](https://github.com/3mre0s/ai-firewall/blob/main/extensions/vscode/src/process-lifecycle.js): `extensions/vscode/src/process-lifecycle.js`
- [Binary resolver](https://github.com/3mre0s/ai-firewall/blob/main/extensions/vscode/src/binary.js): `extensions/vscode/src/binary.js`
- [JetBrains plugin](https://github.com/3mre0s/ai-firewall/blob/main/extensions/jetbrains/src/main/kotlin/com/localai/firewall/FirewallPlugin.kt): `extensions/jetbrains/src/main/kotlin/com/localai/firewall/FirewallPlugin.kt`
- [Binary resolver](https://github.com/3mre0s/ai-firewall/blob/main/extensions/jetbrains/src/main/kotlin/com/localai/firewall/BinaryResolver.kt): `extensions/jetbrains/src/main/kotlin/com/localai/firewall/BinaryResolver.kt`
- [Local privacy demo](https://github.com/3mre0s/ai-firewall/blob/main/demo.go): `demo.go`

### Gateway Modes

- [HTTP proxy](https://github.com/3mre0s/ai-firewall/blob/main/proxy/proxy.go): `proxy/proxy.go`
- [TLS MITM proxy](https://github.com/3mre0s/ai-firewall/blob/main/mitm/proxy.go): `mitm/proxy.go`
- [Certificate authority](https://github.com/3mre0s/ai-firewall/blob/main/mitm/ca.go): `mitm/ca.go`

### Inspection Core

- [Exchange lifecycle](https://github.com/3mre0s/ai-firewall/blob/main/dlp/engine.go): `dlp/engine.go`
- [Stream restoration](https://github.com/3mre0s/ai-firewall/blob/main/dlp/stream.go): `dlp/stream.go`
- [Detection and masking](https://github.com/3mre0s/ai-firewall/blob/main/masker/masker.go): `masker/masker.go`
- [Sensitive patterns](https://github.com/3mre0s/ai-firewall/blob/main/patterns/patterns.go): `patterns/patterns.go`
- [Request secret vault](https://github.com/3mre0s/ai-firewall/blob/main/vault/vault.go): `vault/vault.go`
- [Runtime configuration](https://github.com/3mre0s/ai-firewall/blob/main/config/config.go): `config/config.go`

### Provider Routing

- [Provider adapters](https://github.com/3mre0s/ai-firewall/blob/main/providers/provider.go): `providers/provider.go`

### Local Observability

- [Audit metadata](https://github.com/3mre0s/ai-firewall/blob/main/audit/audit.go): `audit/audit.go`
- [Metrics](https://github.com/3mre0s/ai-firewall/blob/main/metrics/metrics.go): `metrics/metrics.go`
- [Security events](https://github.com/3mre0s/ai-firewall/blob/main/securitylog/log.go): `securitylog/log.go`

### Other components

- **Local user**
- **Coding client**
- **Configured AI provider**

## Connections

- Local user → CLI and server: runs (evidence: `README.md`)
- Coding client → HTTP proxy: sends requests (evidence: `README.md`)
- CLI and server → Runtime configuration: loads (evidence: `main.go`)
- CLI and server → Request secret vault: creates (evidence: `main.go`)
- CLI and server → HTTP proxy: starts (evidence: `main.go`)
- CLI and server → TLS MITM proxy: starts optionally (evidence: `main.go`)
- CLI and server → Codex launcher: dispatches (evidence: `main.go`)
- CLI and server → Local privacy demo: dispatches (evidence: `main.go`)
- Codex launcher → HTTP proxy: starts (evidence: `codex.go`)
- Codex launcher → Audit metadata: reads evidence (evidence: `codex.go`)
- VS Code extension → Process lifecycle: manages process (evidence: `extensions/vscode/src/extension.js`)
- VS Code extension → Binary resolver: resolves executable (evidence: `extensions/vscode/src/extension.js`)
- VS Code extension → CLI and server: starts binary (evidence: `extensions/vscode/src/extension.js`)
- JetBrains plugin → Binary resolver: resolves executable (evidence: `extensions/jetbrains/src/main/kotlin/com/localai/firewall/FirewallPlugin.kt`)
- JetBrains plugin → CLI and server: launches binary
- HTTP proxy → Exchange lifecycle: prepares exchange (evidence: `proxy/proxy.go`)
- TLS MITM proxy → Exchange lifecycle: creates engine (evidence: `mitm/proxy.go`)
- Exchange lifecycle → Detection and masking: scopes masking (evidence: `dlp/engine.go`)
- Detection and masking → Sensitive patterns: analyzes text (evidence: `masker/masker.go`)
- Detection and masking → Request secret vault: stores mappings (evidence: `masker/masker.go`)
- HTTP proxy → Provider adapters: selects provider (evidence: `proxy/proxy.go`)
- HTTP proxy → Configured AI provider: forwards sanitized request (evidence: `README.md`)
- Configured AI provider → HTTP proxy: returns response (evidence: `README.md`)
- HTTP proxy → Stream restoration: restores stream (evidence: `proxy/proxy.go`)
- TLS MITM proxy → Configured AI provider: forwards sanitized request (evidence: `mitm/proxy.go`)
- Configured AI provider → TLS MITM proxy: returns response (evidence: `mitm/proxy.go`)
- TLS MITM proxy → Certificate authority: uses certificates
- HTTP proxy → Audit metadata: records metadata (evidence: `proxy/proxy.go`)
- HTTP proxy → Metrics: records counters (evidence: `proxy/proxy.go`)
- HTTP proxy → Security events: emits events (evidence: `proxy/proxy.go`)
- TLS MITM proxy → Security events: emits events (evidence: `mitm/proxy.go`)
- Local privacy demo → HTTP proxy: exercises pipeline (evidence: `demo.go`)
- Local privacy demo → Configured AI provider: uses mock upstream (evidence: `demo.go`)
