Architecture
Crate Dependency Graph
Visual dependency graph of all Rust crates in the OGuardAI workspace
The OGuardAI runtime is built from a workspace of focused Rust crates. Each crate has a single responsibility. This page shows how they depend on each other.
| Crate | Purpose |
|---|
guardai-core | Shared types, error definitions, entity model, runtime kernel. Most crates depend on this; a few self-contained utility crates (auth, large-text, streaming, prompt-security, document-ingest) do not. |
guardai-api-types | Request/response contracts (serde structs) for the HTTP API. |
| Crate | Purpose |
|---|
guardai-detector-builtins | Rust regex-based entity detectors (email, phone, SSN, IBAN, etc.). |
guardai-detector-client | HTTP bridge to the Python NER detector service. Falls back to builtins. |
| Crate | Purpose |
|---|
guardai-runtime | Protection kernel: composes tokenize, policy, transform, seal, and rehydrate into one transactional flow shared by the server and proxy. |
guardai-tokenizer | Generates semantic tokens ({{type:id:cap}}) from detected entities. |
guardai-transformer | Orchestrates detect + tokenize + policy to produce safe text. |
guardai-rehydrate | Restores tokens in LLM output using session state and policy. |
guardai-policy | Loads and evaluates policy YAML (entity rules, output channels, restore modes). |
guardai-session | Session backends: sealed (encrypted client-side blob), memory (in-process), and Redis (encrypted at rest, wired via session.backend=redis for shared cross-replica sessions). Redis also backs the durable revocation and replay stores. |
| Crate | Purpose |
|---|
guardai-token-robustness | 3-stage token repair (strict, repair, fuzzy) for LLM-mangled tokens. |
guardai-output-guard | Second-pass detection on LLM output to catch newly generated PII. |
guardai-prompt-security | Prompt injection defense and system preamble generation. |
| Crate | Purpose |
|---|
guardai-large-text | Chunking, batching, and span management for large documents. |
guardai-streaming | SSE streaming for transform and rehydrate operations. |
guardai-provider-strategy | Per-LLM-provider context-verbosity profiles (how much entity_context metadata is sent). |
guardai-document-ingest | Document ingestion pipeline for RAG workflows. |
guardai-ocr | OCR text extraction with entity detection. |
| Crate | Purpose |
|---|
guardai-auth | Authentication middleware (API key, static JWT, and OIDC/JWKS). |
guardai-observability | Shared PII-safe audit events and Prometheus metrics for the runtime and proxy. |
| Crate | Purpose |
|---|
oguardai-server | Axum HTTP server. Depends on nearly all crates. |
oguardai-cli | CLI binary for transform, rehydrate, detect, config, and server management. |
oguardai-proxy | Transparent API proxy that auto-masks requests to LLM providers. |
guardai-core depends on nothing internal. It is the foundation.
- Pipeline crates depend on
core and optionally on each other following the data flow: detect, tokenize, transform, rehydrate.
- Application crates (
server, cli, proxy) are leaf nodes. They depend on library crates but no library crate depends on them.
- No circular dependencies. The graph is a DAG.
- New crates must declare their position in this graph before implementation.