Expand description
§Cruxi
A minimal, transport-agnostic hexagonal architecture framework for Rust.
Cruxi implements the Ports & Adapters pattern with a 4-layer architecture:
┌──────────────────────────────────────┐
│ INBOUND TRANSPORTS │
│ (HTTP, gRPC, MQTT, TCP) │
└──────────────────────────────────────┘
↓
┌──────────────────────────────────────┐
│ HANDLER (Inbound Adapter) │
│ • Receives requests │
│ • Validates transport format │
│ • Delegates to Service │
└──────────────────────────────────────┘
↓
┌──────────────────────────────────────┐
│ SERVICE (Application Layer) │
│ • Business logic orchestration │
│ • Authorization checks │
│ • Coordinates Repositories │
└──────────────────────────────────────┘
↓
┌──────────────────────────────────────┐
│ REPOSITORY (Domain Layer) │
│ • Domain validation │
│ • Transactional integrity │
│ • Calls Providers │
└──────────────────────────────────────┘
↓
┌──────────────────────────────────────┐
│ PROVIDER (Infrastructure) │
│ • Database I/O │
│ • HTTP API calls │
│ • Message queues │
└──────────────────────────────────────┘§Design Principles
- Zero external dependencies in the core (only std + thiserror)
- Generic type safety via trait generics on Req/Resp
- Pattern matching for all control flow and error handling
- No
.unwrap()- explicit error handling throughout
§Collaborators
A collaborator is a required dependency that a composite delegates to, provided at construction time.
ValidatingHandlercollaborators: validator and serviceValidatingRepositorycollaborators: validator, provider, and transaction
Intentional no-op behavior is still explicit composition:
- use
PassValidatorfor no-op validation - use
NoTransactionfor no-op transaction wrapping
§Features
async- Enables async trait variants (requiresasync-trait)
Structs§
- Cancellation
Handle - Shared cancellation handle for a context runtime.
- Coded
Error - A structured error with a machine-readable code.
- Context
- Request-scoped context carrying cancellation, deadline, and extension data.
- Context
Builder - Builder for constructing
Contextinstances. - Error
Mapping Context - Transport-agnostic mapping context derived from a
CodedError. - Extensions
- Type-safe storage for arbitrary values in a context.
- Fail
Validator - A validator that always fails with the given error.
- Handler
Fn - Adapts a function to the
Handlertrait. - NoTransaction
- A no-op transaction that just executes the function directly.
- Pass
Validator - A validator that always passes.
- Principal
- Typed principal metadata value.
- Provider
Fn - Adapts a function to the
Providertrait. - Repository
Fn - Adapts a function to the
Repositorytrait. - Request
Id - Typed request-id metadata value.
- Scopes
- Typed scopes metadata value.
- Service
Fn - Adapts a function to the
Servicetrait. - Tenant
- Typed tenant metadata value.
- TraceId
- Typed trace-id metadata value.
- Urn
- A Unified Resource Name for stable resource references.
- Validating
Handler - A handler that validates requests before delegating to a service.
- Validating
Repository - A repository that validates input and wraps provider calls in a transaction collaborator.
- Validation
Error - A field-level validation error.
- Validator
Fn - Adapts a function to the
Validatortrait.
Enums§
- Cruxi
Error - Sentinel errors for common framework conditions.
- Done
Reason - Completion reason for context lifecycle.
- Error
Class - Transport-agnostic error classification for adapter mapping.
- Message
Exposure - Whether an adapter can safely expose the user-facing error message.
- Retryability
Hint - Retryability hint for policy engines and adapters.
- TxError
- Error combining transaction failures with inner operation failures.
- UrnError
- Errors that can occur when parsing or constructing URNs.
- Validating
Handler Error - Error type for
ValidatingHandler. - Validating
Repository Error - Error type for
ValidatingRepository.
Traits§
- Error
Class Mapper - Contract for adapter-facing error mapping.
- Handler
- Receives inbound requests and delegates to a service.
- Provider
- Performs infrastructure I/O operations.
- Repository
- Validates data and enforces transactional integrity.
- Service
- Orchestrates business logic and coordinates repositories.
- Transaction
- Wraps operations in a unit of work.
- Transport
As - Helper trait for type-safe transport payload extraction.
- Validator
- Validates input and returns its configured error type on failure.
Functions§
- map_
coded_ error - Maps a
CodedErrorto an adapter decision via anErrorClassMapper.