Architecture: the layers and why they exist
services (or a YAML, via cmd/hyrule-serve)
↓
behaviors (audit, searchsync, events — reusable hooks)
↓
rest (Resource, Schema, Service, API, Adapter — the HTTP contract)
↓
platform (mongodb, postgres, config, auth, search, pubsub, redis, health, server)
Each layer only knows the one below it. platform never imports
rest or behaviors, even when that would save a line — that's how
platform/mongodb.Store can satisfy rest.Store without
the mongodb package knowing rest exists (the interface's methods
only use bson/stdlib types, not rest-owned structs; see
store.md). Inverting that direction — platform importing
rest — would create a structural dependency from a low-level
module to a high-level one even without a real import cycle, and would
confuse any future reader.
One exception, by design: restpostgres is the single package
allowed to import both rest and platform/postgres — it's the
bridge, not a new layer, implementing rest.Adapter
(see adapter.md) the same way mongoAdapter does
inside rest itself for platform/mongodb. A Resource picks one of
the two by setting Adapter (restpostgres.NewAdapter(...)) or
Store (platform/mongodb.NewStore(...), which rest wraps in a
mongoAdapter automatically) — never both.
A behaviors/* package (e.g. events, which wires outbox into
rest.Hooks) can depend on both rest and platform — that's
exactly what it's there for, to be the glue between the two.
Decisions that shape the framework
- Storage and events share a local transaction. Mongo resources use
outbox; Postgres resources useoutboxpostgreswith the same pool/context. Shared hooks depend on the Adder contract, but atomicity never spans two databases or an external publisher. See outbox. - Storage portability is the interface, not the query language.
rest.Storestayed exactlybson.M/bson.D-typed, Mongo-shaped, never generified (ADR-0002) — a real second backend needed a different seam in front of it, not a newStoreimplementation:rest.Adapter(seeadapter.md), withrestpostgresimplementing it overplatform/postgresfor the first real Postgres-backed resource (examples/blog-apis/services/comments-api). Each backend still keeps its own query language and error semantics —where=/sort=staybson.M/bson.Dfor Mongo and apostgres.Querycompiled byplatform/postgresfor Postgres, never a shared filter AST. - YAML covers data, not code.
declarativeexpresses everything that's already plain data inrest.Schema/Field/Resource;Field.Check,Resource.Validate,Resource.Datasourceand every kind ofHookscarry arbitrary behavior and are left out on purpose — seeresources-yaml.md.
See both backend integrations and the review/evidence for current bootstrap behavior and limits.