This document provides a comprehensive overview of the NeuralBudget project structure, module responsibilities, and service interactions.
NeuralBudget is a Rust-first SLO (Service Level Objective) toolkit with Python interoperability. It provides deterministic reliability analytics for service, ML, and GenAI workloads through:
- A strongly-typed Rust core (
src/) - Native Python bindings via PyO3 (
python/neuralbudget/) - Convenience helpers for notebooks and pipelines
- Integration with Prometheus, OpenTelemetry, and webhook alerting systems
NeuralBudget/
├── src/ # Rust core implementation
│ ├── lib.rs # Module declarations and public exports
│ ├── core.rs # Core SLO models and calculations
│ ├── exporter.rs # Prometheus metrics exporter
│ ├── otlp.rs # OpenTelemetry Protocol integration
│ ├── python.rs # Python/PyO3 FFI bindings
│ └── bin/ # CLI binary
│ ├── main.rs # CLI entry point
│ └── commands/ # CLI subcommands
│
├── python/
│ ├── neuralbudget/ # Native extension package
│ │ ├── __init__.py # Package exports
│ │ ├── client.py # High-level NeuralBudgetClient facade
│ │ ├── convenience.py # Ergonomic helper layer
│ │ └── alerting.py # Webhook alert dispatcher
│ │
│ └── neuralbudget_convenience/ # (Python-only convenience module)
│
├── tests/ # Test suites
│ ├── functional_tests.rs # Rust functional tests
│ ├── integration_tests.rs # Rust integration tests
│ ├── cli_integration_tests.rs # CLI integration tests
│ ├── python_client_tests.py # NeuralBudgetClient tests
│ ├── python_alerting_tests.py # Alerting integration tests
│ └── python_convenience_tests.py # Convenience layer tests
│
├── benches/ # Performance benchmarks
│ └── composite_slo_dag.rs # DAG evaluation performance tests
│
├── examples/ # Example configurations and scripts
│ ├── python/ # Python usage examples
│ ├── kubernetes/ # K8s deployment manifests
│ ├── grafana/ # Grafana dashboard templates
│ ├── slo_http.yaml # HTTP service SLO example
│ ├── slo_ml.yaml # ML service SLO example
│ └── sample_http.json # Sample metrics JSON
│
├── docs/ # Project documentation
│ ├── guides/ # User guides and walkthroughs
│ ├── reference/ # API and component references
│ ├── cli/ # CLI documentation
│ ├── internal/ # Internal design docs
│ └── plans/ # Project planning
│
├── Cargo.toml # Rust dependencies and build config
├── pyproject.toml # Python package metadata
└── Dockerfile # Docker build for CLI
- Purpose: Declares all submodules and re-exports public API
- Responsibility: Maintains the public interface contract
- Exports: All types and functions needed by Python bindings and end-users
- Purpose: Defines all fundamental SLO types and calculation logic
- Key Types:
SloConfig— SLO metadata (target, window, schema versioning)ErrorBudget— Budget remaining and burn velocityTimeWindow— Rolling vs. calendar-aligned time windowsHistogramSample,HistogramBucket— Latency distribution samplesHttpSlo— Stateless HTTP/gRPC SLO (latency percentile + availability)StatefulSlo— Stateful service evaluation (replication lag, queue depth, pool saturation)MlSlo— ML serving hybrid SLO (latency score + drift score with weighted formula)GenAiSlo— LLM workload SLO (throughput, TTFT, semantic similarity)CompositeSlo— Dependency DAG evaluation with failure propagation
- Responsibility: Stateless computation; all business logic lives here
- Key Properties:
- Deterministic (same inputs = same outputs, every time)
- No external I/O dependencies
- Thoroughly tested for correctness
- Purpose: Converts SLO evaluation results into Prometheus exposition format
- Responsibility:
- Renders SLO metrics as Prometheus TEXT format
- Handles label mapping and metric naming conventions
- Use Cases: Direct scraping by Prometheus, custom Prometheus client integration
- Purpose: Ingests OpenTelemetry Protocol histogram samples
- Responsibility:
- Parses OTLP JSON payloads (delta and cumulative formats)
- Converts OTLP histograms to NeuralBudget HistogramSample
- Handles format conversions (delta ↔ cumulative)
- Use Cases: Direct integration with OTLP collectors, Grafana Loki, observability platforms
- Purpose: Exposes Rust types and functions to Python
- Responsibility:
- PyO3 type conversions (Rust ↔ Python objects)
- Error mapping from Rust to Python exceptions
- Helper extraction functions for dict/TypedDict conversion
- Python wrapper classes (e.g.,
PySloConfig,PyTimeWindow)
- Design: Thin FFI layer; all logic remains in Rust
- Purpose: Command-line interface for SLO operations
- Subcommands:
eval— Evaluate SLO against sample metricsgen-rules— Generate Prometheus alerting rulescheck— Validate SLO configurationsserve— HTTP server (future)
- Design: Modular subcommand architecture with error handling
- Purpose: Stable, ergonomic entry point for notebooks and CI/CD pipelines
- Key Methods:
NeuralBudgetClient.load_config(path)— Load YAML/JSON SLO configsclient.evaluate(metric_data)— Evaluate metrics against loaded config
- Responsibilities:
- Config parsing and validation
- Mode dispatch (http, stateful, ml, genai, composite)
- Optional return dataclass conversion
- Alert dispatching on SLO violations
- Design Pattern: Configuration object → evaluation strategy dispatch
- Purpose: Thin, low-boilerplate helpers around native API
- Key Functions:
availability_snapshot()— One-shot availability checkevaluate_http_once()— Single HTTP histogram evaluationevaluate_stateful_once()— Single stateful service evaluationevaluate_ml_once()— Single ML SLO evaluationevaluate_genai_once()— Single GenAI SLO evaluation
- Design Philosophy:
- Minimal logic; delegates calculations to Rust
- Preserves deterministic behavior
- Dataclass result types for type safety
- Profile System: Pre-configured parameter sets (e.g., "aggressive", "conservative") for common scenarios
- Purpose: Sends SLO violation notifications to external systems
- Supported Providers:
- Slack: Incoming webhooks with rich formatting
- PagerDuty: Events API v2 for incident creation
- Opsgenie: Alerts API v2 for multi-channel routing
- Key Features:
- Private network detection (prevents leaking internal metrics)
- Payload size limits (64 KB cap)
- Structured error reporting
- Security: Environment-variable-based credential management
- Purpose: Re-exports public API from submodules
- Exports:
NeuralBudgetClient, convenience functions, alert dispatcher
┌──────────────────────────────────┐
│ Metric Input (YAML/JSON/Dict) │
│ - Prometheus histogram │
│ - OTLP payload │
│ - Raw request/stateful metrics │
└──────────────────┬───────────────┘
│
▼
┌──────────────────────┐
│ NeuralBudgetClient │
│ (config dispatch) │
└──────────┬───────────┘
│
┌─────────┴─────────┐
│ │
▼ ▼
┌────────────┐ ┌──────────────┐
│Convenience │ │Native (Rust) │
│ Layer │ │ Core API │
└────────────┘ └──────────────┘
│ │
└─────────┬─────────┘
│
▼
┌──────────────────────┐
│ SLO Calculation │
│ (core.rs logic) │
└──────────┬───────────┘
│
▼
┌──────────────────────┐
│ Evaluation Result │
│ (dataclass/dict) │
└──────────┬───────────┘
│
┌─────────┴─────────┐
│ │
▼ ▼
┌──────────┐ ┌────────────┐
│ Return │ │ Alert │
│ to User │ │ Dispatch │
│ │ │ (alerting) │
└──────────┘ └────────────┘
- User provides YAML/JSON config
- Client parses config →
ClientConfigFileTypedDict - Schema version validation (prevents breaking changes)
- Mode-specific parameter extraction
- Rust core initialized with extracted config
- Evaluation ready
- Service nodes provide local SLO scores
- Dependency edges define failure propagation
- DAG runner (in
core.rs):- Performs topological sort with cycle detection
- Propagates failures down dependency chain with weighted penalties
- Computes global System SLO score
- Result: Service-level and system-level pass/fail decisions
- PyO3 (0.24.2): Language binding framework
- Serde + serde_yaml/serde_json: Serialization for configs
- Criterion: Benchmarking framework (dev-only)
- Clap: CLI argument parsing
- Anyhow: Error handling for CLI
neuralbudget(native extension built from Rust core)pathlib,dataclasses,json,urllib(stdlib)
- Prometheus: For metrics scraping and alerting
- OpenTelemetry: For distributed trace context and histogram ingestion
- Slack/PagerDuty/Opsgenie: For webhook-based alerting
- Docker: For containerized distribution
| Test Suite | Location | Purpose |
|---|---|---|
| Functional (Rust) | tests/functional_tests.rs |
Core SLO calculation correctness |
| Integration (Rust) | tests/integration_tests.rs |
Multi-component interaction |
| CLI Integration (Rust) | tests/cli_integration_tests.rs |
CLI subcommand behavior |
| Client (Python) | tests/python_client_tests.py |
Config loading and dispatch |
| Convenience (Python) | tests/python_convenience_tests.py |
Helper ergonomics and results |
| Alerting (Python) | tests/python_alerting_tests.py |
Webhook dispatch behavior |
| Benchmarks (Rust) | benches/composite_slo_dag.rs |
Composite DAG performance |
- All calculations are pure functions
- No randomness, no external state
- Identical inputs always produce identical outputs
- Rust
derive(Serialize, Deserialize)for schema - Python
TypedDictfor config validation - Comprehensive type hints in Python API
- Python convenience functions are thin wrappers
- All heavy lifting stays in Rust
- Simplifies maintenance and preserves correctness
- YAML/JSON configs version-controlled
- Schema versioning prevents silent incompatibilities
- Environment-variable interpolation for secrets (alerting)
- Core = Calculation logic
- Exporter = Format conversion (Prometheus)
- OTLP = Input format conversion (OpenTelemetry)
- CLI = Command-line interface
- Python = Language binding
- Client = Facade and orchestration
- Convenience = Ergonomics and profiles
- Alerting = Webhook dispatch
- Define struct in
core.rswith#[derive(Serialize, Deserialize)] - Implement evaluation method
- Add PyO3 wrapper in
python.rs - Add convenience helper in
convenience.py - Add test case in appropriate test file
- Add provider logic to
alerting.pyAlertDispatcher.send_violation() - Define payload format for the provider's API
- Add tests to
python_alerting_tests.py - Document in user guide
- Extend
CompositeSlomodel incore.rs - Update cycle detection and topological sort if needed
- Update result types in
convenience.py - Add benchmark to
benches/composite_slo_dag.rs
- Define new variant in
Commandsenum insrc/bin/main.rs - Create new module in
src/bin/commands/ - Implement subcommand logic
- Add integration tests to
tests/cli_integration_tests.rs - Document in
docs/cli/USER_GUIDE.md
- User Guide:
docs/guides/getting-started.md - CLI Guide:
docs/cli/USER_GUIDE.md - CLI Development:
docs/cli/DEVELOPMENT.md - Production Deployment:
docs/guides/production-deployment.md - API References:
- Python API:
docs/reference/api.md— Complete Python extension and convenience layer reference - Composite SLO DAG:
docs/reference/composite-slo-dag.md— Dependency graph schemas and scoring - Convenience Layer:
docs/reference/convenience-layer.md— Helper functions and profile presets
- Python API: