Skip to main content

Crate mediaschema

Crate mediaschema 

Source
Expand description

Product-agnostic media-primitive schema.

The architectural hub is the hand-written domain layer; every backend — protobuf wire (under [buffa]), sqlx row mappers (under [sqlx]), MongoDB (under [mongodb]) — is a thin lossless conversion to/from the domain. Locked schema docs live under schema/*.md; they are the specification the implementation tracks.

Encode-side bridges (From<&Domain> for Backend) are infallible — the domain is the validated side. Decode-side bridges (TryFrom<Backend> for Domain) route through the same try_new + with_* builders application code uses, so every invariant is re-enforced at the wire/storage edge.

§Aggregate clusters

§Feature flags

Three independent capability tiers (alloc / std, both additive), three medium-aggregate gates (video / audio / subtitle), plus optional backend features. Defaults are std + video + audio + subtitle.

flagroledepends on
noneno-std + no-alloc; stack-only types only
allocno-std + alloc; adds heap-using domain types
std (default)adds jiff-using aggregates + Uuid::now_v7
video (default)compiles the Video / VideoTrack / Scene / Keyframe aggregate tree + its backendsa heap tier
audio (default)compiles the Audio / AudioTrack / AudioSegment aggregate tree + its backendsa heap tier
subtitle (default)compiles the Subtitle / SubtitleTrack / SubtitleCue aggregate tree + its backendsa heap tier
buffaproto3 wire layer (under [buffa])std or alloc
jsonwire JSON via serdestd + buffa
arbitraryArbitrary derives for property testsstd + buffa
mongodbbson backend (under [mongodb])std + json
sqlx-postgres / sqlx-mysql / sqlx-sqlitesql backends (under [sqlx])std

The three medium gates are independent on/off flags: a consumer that only needs the video aggregate tree can opt out of the audio / subtitle trees (and all their backend bridges) with default-features = false + features = ["std", "video"]. The cross-cutting aggregates (Media, MediaFile, Person, Speaker, WatchedLocation, UserTag, SceneAnnotation) plus the Identified<Id, D> transport envelope are always available when a heap tier is on.

§Regenerating wire code

The buffa-generated wire layer (src/generated/) is produced from the .proto files in proto/. Regenerate with cargo run -p xtask -- gen. Do not hand-edit the generated files.

Re-exports§

pub use crate::domain::Identified;

Modules§

domain
Hand-written domain layer — the architectural hub. App logic programs against mediaschema::domain::*; the buffa-generated wire types at the crate root (re-exported from generated::media::v1::*, available with feature = "std") are the serialization edge. Domain ⇄ wire conversions are added incrementally as each aggregate lands (with domain → wire → domain round-trip property tests). See schema/*.md for the locked specifications. Hand-written domain layer — the architectural hub for mediaschema.