SentrySentry
Architecture

High-Level Architecture

Sentry's pipeline, layers and design principles

High-Level Architecture

Sentry is organized into three plugin layers (Sources, Core, Actions) on top of a persistence layer. Every plugin implements a common trait, allowing new sources and actions to be added without recompiling the core.

Design principles

  1. Source trait: every plugin implements fn stream_events(&self) -> impl Stream<Item = RawEvent>. Adding nginx = implementing the trait.
  2. Action trait: fn execute(&self, decision: &Decision) -> Result<()>. Block, Challenge, Alert, etc.
  3. Normalized Event: a single struct Event regardless of source. The core never knows whether it came from nginx or TCP.
  4. Asynchronous pipeline: tokio + channels. Each stage is an actor/fan-out.
  5. Declarative configuration: sentry.toml defines active sources, active actions, thresholds.

Tech stack

LayerCrate / TechnologyRationale
Async runtimetokioDe facto standard, cross-platform
CLIclap (derive) + ratatui for live TUIErgonomics, subcommands, live panel
Configserde + toml + figment (env+file merge)Env-var override in prod
Logs/Tracingtracing + tracing-subscriberStructured logging, per-request spans
nginx parsernom or regex + serdeCustom access_log line format
HTTP clientreqwest (rustls)Cloudflare API, webhooks, geolookup
Local ML/AIort (ONNX Runtime) + candle fallbackLocal inference without external API dependency
LLM (optional)LlmProvider trait + adapters: OpenRouter (routes to any model), async-openai, ollama-rsComplex payload analysis on demand, provider-agnostic
Storagesqlx with Postgres default (sqlx migrations), optional SQLite via feature flagSame schema, switch via feature flag; Postgres supports HA and multiple nodes from day one
Geolookupmaxminddb (local DB)No external call per event
IPC/Embeddablecore as a lib crate (sentry-core)Future dashboard consumes the same lib
Serializationserde + serde_jsonEvents, export, future API
Errorsthiserror (lib) + color-eyre (bin)Ergonomics + readable backtraces
Testsproptest + insta (snapshots) + wiremockMalicious payloads, log fixtures
Build/Releasecargo-dist or crossMulti-OS binaries

Crate structure (workspace)

sentry/
├── Cargo.toml                    # workspace
├── crates/
│   ├── sentry-core/              # lib: Event, traits, pipeline, scoring
│   ├── sentry-source-nginx/      # plugin Source: nginx log tail
│   ├── sentry-source-http/       # plugin Source: proxy middleware (future)
│   ├── sentry-source-tcp/        # plugin Source: pcap (future)
│   ├── sentry-source-cloudflare/ # plugin Source: pull CF logs
│   ├── sentry-ai/                # ONNX + LLM provider trait
│   ├── sentry-action-cloudflare/ # plugin Action
│   ├── sentry-action-webhook/    # plugin Action
│   ├── sentry-action-blocklist/  # plugin Action
│   ├── sentry-storage/           # sqlx SQLite/Postgres
│   ├── sentry-geo/               # maxminddb wrapper
│   └── sentry-cli/               # binary: clap + ratatui + entrypoint
├── models/                       # versioned ONNX models
├── config/sentry.example.toml
├── tests/                        # integration tests
└── docs/

On this page