shared-framework
Reusable building blocks for HTTP services in Rust: routing and controllers on Hyper, a SeaORM data layer with repositories and explicit relation hydration, request validation, live OpenAPI 3.1 docs with a bundled Swagger UI, background jobs, RabbitMQ consumers, Redis/in-memory caching, and resilience helpers (retries, circuit breakers, rate limiting).
Quick start
use Arc;
use ;
;
async
Handlers receive only a CorrelationContext; the body, headers, query
parameters, and multipart files travel on it:
// JSON or form DTO, deserialized and validated in place:
let input: CreateUser = ctx.body?;
// Raw payloads (text/plain routes):
let raw: String = ctx.body_string?;
// Headers, query, files:
let token = ctx.header;
let search = ctx.query_param_or;
let avatars = ctx.files_for;
Booting a full service
GenericStartup::bootstrap wires everything optional registrars provide —
static assets, controllers (plus the docs controller), the Basilisk gateway,
jobs, consumers, and socket configuration — and exposes the results for manual
wiring of anything you skip:
use Arc;
use ;
let startup = bootstrap
.await?;
startup.serve.await?;
Registrars build their pieces from the startup state (registrant(),
gateway_client(), redis_client(), server_addr()), and jobs run on demand
via startup.run_jobs().await.
Data
use ;
let repo = new;
// Paginated reads; options combine request state with caller overrides.
let page = repo
.get_paginated_view
.await?;
// Explicit relation hydration: one batched query per relation, no N+1.
let with_orders = repo
.get_all_traversed
.await?;
Validation
use ;
Returning ctx.body::<CreateUser>() in a handler runs this automatically and
answers 400 on the first failure.
API documentation
Routes self-document through RouteDescription (groups, bodies via
DocumentableDTO, response examples, headers, params, rate limits, file
uploads). After mounting, GET /docs serves the generated OpenAPI 3.1 JSON
and / serves the bundled Swagger UI — hidden in production unless external
docs mode is enabled.
Background work
- Jobs (
job):ServiceJobwith periodic, exact-time, or combined schedules, run byJobRegistry. - Queues (
queue): RabbitMQ consumers with retry (.retry) and dead-letter (.dlq) queues plus a message producer, onlapin. - Cache (
data::cache): region-based in-memory and Redis storage with a sharedStorageAccessinterface. - Resilience (
retry,service,middleware::rate): exponential-backoff retries, per-provider circuit breakers, and fixed-window rate limiting (in-memory or Redis-backed).
Configuration
Loaded once from .env (or a given file) plus the process environment.
Required keys: SERVICE_NAME, SERVICE_VERSION, BUILD_NUMBER,
ENVIRONMENT_KIND (DEVELOPMENT/DEBUG/STAGING/PRODUCTION),
SERVER_PORT, SERVICE_URL, POSTGRESQL_URL, REDIS_URL, RABBITMQ_URL,
MONGODB_URL. Useful defaults are applied for the rest (PROCESS_ROLE,
SERVER_COUNT, WORKER_COUNT, SOCKET_COUNT, SOCKET_PORT, … — see
AppEnvironment). Gateway registration additionally needs BASILISK_HOST,
BASILISK_BUS_PORT, BASILISK_TOKEN, BASILISK_GATEWAY_URL,
BASILISK_SERVICE_ID, and SERVICE_KEY.
Layout
app/ GenericStartup, StartupOptions, registrar traits
controller/ RouteController, Router, RouteDescription, server bootstrap
middleware/ composable handlers: identification, rate limiting, monitoring
data/ BaseEntity, QueryData, RepositoryOptions, PersistentRepository,
relation hydration (traverse), cache, seeding, connectors
validation/ Validate trait + constraint helpers
logging/ CorrelationContext, loggers (tracing-based)
response/ ServiceResult, ErrorResult, typed results
service/ provider chains with circuit breakers
queue/ RabbitMQ consumers and producers
job/ scheduled background jobs
doc/ OpenAPI generation, docs controller, bundled Swagger UI
gateway/ service registration and event bus client
retry/ backoff retry strategies
types/ shared value types (geo, ranges, batches)
utils/ crypto, dates, HTTP client, multipart parsing, helpers
env/ environment loading and validation
config/ server configuration re-export
monitoring/ monitoring event plumbing
Building