Shared backend
boilerplate
for any Rust app.
Configured clients and primitives — Postgres, Redis, crypto, storage, LLM, knowledge graph — feature-gated, logic-free. A library, not a server. You pick features; logic stays in your app.
One crate. Thirteen features.
Each concern is behind its own cargo feature. A db-only consumer never compiles the LLM or crypto graphs. Change one module, unrelated consumers don't rebuild.
db defaultPostgres pool
connect_from_env() — a configured sqlx PgPool with sane defaults, sslmode support, and application_name.
tracing defaultStructured logging
telemetry::init() — tracing-subscriber honouring RUST_LOG; human or LOG_FORMAT=json.
cacheRedis client
connect_from_env() — multiplexed, auto-reconnecting ConnectionManager; thin GET/SET/SETEX/DEL/EXPIRE helpers.
cryptoCrypto primitives
AES-256-GCM encrypt/decrypt, Argon2id password hashing, HKDF-SHA256, HMAC-SHA256, SHA-256. Caller supplies all parameters.
storage-s3AWS S3 storage
StorageClient::from_env() — configured S3 (or S3-compatible) handle; thin get/put/delete.
storage-azureAzure Blob storage
StorageClient::from_env() — configured Azure Blob handle; same thin API as storage-s3.
llmAnthropic LLM client
LlmClient::from_env() — typed MessagesRequest/MessagesResponse + token usage. No retry, no prompt logic.
kgKnowledge graph
Upsert nodes/edges, one-hop neighbor traversal, pgvector cosine-distance similarity search. No embedding generation.
httpHTTP client
client() — a reqwest::Client with rustls TLS and sane default timeouts (30s request, 10s connect).
signalGraceful shutdown
shutdown_signal() — await Ctrl-C (SIGINT) or SIGTERM. Pure plumbing; does not log.
configEnv helpers
require_env / env_or / env_parse — tiny typed env-var helpers with clear error messages.
errorsSafe DB errors
redact_db_error — a client-safe message for a sqlx::Error. No SQL text, no bound params, no PII.
testingTest harness
TestDb::create_from_env() — an isolated, auto-dropped Postgres database per test. Self-cleaning even on panic.
A library you use.
Not a service you run.
There is no binary, no daemon, no HTTP port. You add soma-infra as a Cargo dependency, select features, and call into configured clients from your own code.
soma-infra
Pool builder, TLS setup, AES-256-GCM wire format, Argon2id PHC strings, HKDF/HMAC/SHA-256 math, object-store auth wiring, Anthropic wire protocol, pgvector query helpers, SIGTERM plumbing. Decision-free operations a service would otherwise hand-roll.
Your service
KDF salt/info strings, which fields to encrypt, SQLSTATE→domain-error mapping, migration schema and advisory lock key, prompt construction and retry logic, object key naming, rate-limit backoff strategy, embedding generation, what to log on shutdown.
Pick features. Call helpers.
Three representative snippets. See CONSUMING.md for the full per-module guide.