Production infrastructure for AI agents
Website · Documentation · Guides · Core · Template · Discord
systemprompt-models
Foundation data models for systemprompt.io AI governance infrastructure. Shared DTOs, config, and domain types consumed by every layer of the MCP governance pipeline. Includes API models, authentication types, configuration, database models, and service-layer error handling.
Layer: Shared — foundational types/traits with no dependencies on other layers. Part of the systemprompt-core workspace.
Overview
This crate provides common data models, error types, and repository patterns used throughout systemprompt.io. It includes API models, authentication types, configuration, database models, and service-layer error handling.
Architecture
api — API Response Models
Standard JSON API response structures.
auth — Authentication Models
User identity, roles, and auth error types.
config — Configuration Models
Config struct and provider integration.
errors — Error Handling
Layered error types with automatic conversions:
RepositoryError → ServiceError → ApiError → HTTP Response
repository — Repository Patterns
Service lifecycle trait, WhereClause query builder, and repository macros.
execution — Execution Context
RequestContext and related types for request-scoped state propagation.
Usage
[]
= "0.2.1"
api — API Response Models
use ;
let response = success;
let error = not_found;
auth — Authentication Models
use ;
let user = AuthenticatedUser ;
config — Configuration Models
use Config;
use ConfigProvider;
let config = from_env?;
let db_url = config.database_url; // ConfigProvider trait
errors — Error Handling
RepositoryError — Database/repository layer errors:
use RepositoryError;
let err = NotFound;
// Automatically converts to ApiError
let api_err: ApiError = err.into;
ServiceError — Business logic layer errors:
use ServiceError;
let err = Validation;
let api_err: ApiError = err.into; // Converts to HTTP 400
repository — Repository Patterns
Service Lifecycle Trait:
use ServiceLifecycle;
Query Builder:
use WhereClause;
let = new
.eq
.is_not_null
.build;
let query = format!;
Repository Macros:
use impl_repository_base;
impl_repository_base!;
// Expands to:
// impl Repository for MyRepository {
// type Pool = DbPool;
// type Error = RepositoryError;
// fn pool(&self) -> &Self::Pool { &self.db_pool }
// }
execution — Execution Context
use RequestContext;
let req_ctx = RequestContext ;
AgentConfig
use AgentConfig;
Error Handling Pattern
systemprompt.io uses a layered error handling approach:
Layer 1: Repository (Database)
use RepositoryError;
async
Layer 2: Service (Business Logic)
use ServiceError;
async
Layer 3: API (HTTP)
use ApiError;
async
Repository Pattern
All repositories should implement the Repository trait from systemprompt-traits:
use ;
use DbPool;
const GET_USER_QUERY: &str = "SELECT * FROM users WHERE id = ?";
Query Helpers
WhereClause Builder
use WhereClause;
let = new
.eq
.is_not_null
.like
.in_list
.build;
// clause = "WHERE status = ? AND deleted_at IS NOT NULL AND name LIKE ? AND role IN (?, ?)"
// params = vec!["active", "%john%", "admin", "user"]
Repository Macros
// Base trait implementation
impl_repository_base!;
// Query execution
let users = repository_query!?;
// Execute statement
repository_execute!?;
Module Models
use ;
let module = Module ;
Feature Flags
| Feature | Default | Description |
|---|---|---|
web |
No | Axum IntoResponse implementations |
Dependencies
serde/serde_json— Serializationanyhow/thiserror— Error handlingchrono/uuid— Common typesaxum— Request types (optional, withwebfeature)async-trait— Async traitssystemprompt-traits— Core trait definitionssystemprompt-identifiers— Typed identifierssystemprompt-extension— Extension frameworksystemprompt-provider-contracts— Provider trait definitions
Best Practices
1. Use Shared Error Types
// Good
async
// Avoid
async
2. Layer Your Errors
// Repository layer
// Service layer
// API layer
3. Use Query Builders
// Good
let = new.eq.build;
// Avoid — SQL injection risk
let clause = format!;
4. Implement Repository Trait
// Good — consistent pattern
// Avoid — no trait, inconsistent
Testing
Mock repositories using traits:
License
BSL-1.1 (Business Source License). Source-available for evaluation, testing, and non-production use. Production use requires a commercial license. Each version converts to Apache 2.0 four years after publication. See LICENSE.
systemprompt.io · Documentation · Guides · Live Demo · Template · crates.io · docs.rs · Discord
Shared layer · Own how your organization uses AI.