rivet-core
rivet-core is the runtime kernel for rivet composition and dispatch.
Build Lifecycle Order
ApplicationBuilder::build() executes stages in a deterministic order:
- Configure modules (
RivetModule::configure). - Collect providers from modules.
- Register all providers.
- Boot all providers.
- Collect routes from modules.
- Collect middleware from modules.
If any stage fails, build stops immediately and later stages do not run.
Middleware Order Semantics
Middleware runs in registration order on the way in and reverse order on the way out.
Given middleware [A, B], execution order is:
A.beforeB.before- terminal dispatch
B.afterA.after
A middleware can short-circuit by returning a response without calling next.
Build Failure Behavior
Build-time failures return RivetError with deterministic messages.
Primary categories are:
- configure/module failures
- provider register/boot failures
- route collection failures (including duplicates)
The builder is fail-fast and does not attempt partial recovery.
Dispatch Contract For Adapters
Adapters should treat Dispatcher::dispatch(Request) -> Response as the only dispatch boundary.
Current dispatch behavior:
- matched route:
200 - no route path match:
404 - path match + method mismatch:
405withallowheader HEADfalls back toGETand clears body when no explicitHEADroute exists
Adapter responsibilities remain transport-specific concerns such as timeout, panic boundaries, IO buffering, and protocol translation.
Observability
Core emits structured tracing events for build stages, route outcomes, middleware execution, and dispatch completion.
Request body contents are intentionally not logged.
Examples
Run the minimal example:
Run the modular provider example:
modular_provider_app shows a module exposing a service provider that initializes a service in the container during build.
Run the Laravel-style builder example:
laravel_style_app demonstrates the fluent bootstrap API:
ApplicationBuilder::configure(..., config)->with_routing(...)->with_middleware(...)->with_exceptions(...)->with_schedule(...)->build().
The simplified API surface used by examples:
Builder::with_defaults()for in-memory container/config bootstrapping.Application::make::<T>()for typed service resolution from the app container.ProviderFactory+with_providers(&[...])for compile-time static provider registries.