Backend projects
The backend is a layered set of .NET projects under backend/src/. Two protocol libraries under
services/adapter-protocol/ are shared with the out-of-process adapters. MSBuild targets in
backend/Directory.Build.targets enforce the layering: a project reference a layer has not declared fails that
project's build.
The workflow engine (ReeveWorkflow.*), the workload engine (Reeve.Workloads.*) and the cluster and locking
libraries (Reeve.Cluster.*, Reeve.EntityFrameworkCore.AdvisoryLocks) are NuGet packages built in their own
repositories. They are listed in Directory.Packages.props and are never referenced as projects.
The projects
| Project | Owns | May reference | Notable contents |
|---|---|---|---|
Reeve.Contracts |
Every DTO on the wire: REST request and response shapes, realtime event payloads, validation attributes, serializer options. | no project (packages ReeveWorkflow.Abstractions, Reeve.Workloads.Abstractions) |
Devices/, Cameras/, Automations/, Workloads/, Serialization/, Validation/ |
Reeve.Domain |
Entities, aggregate invariants, the permission catalog, the authorization policy evaluator. | Contracts | Entities/, Authorization/, Permissions/, Alerts/, Workloads/ |
Reeve.Application |
Use cases: service interfaces, command and query objects, validation, per-feature exceptions, the audit-writer abstraction. | Domain, Contracts, PluginAbstractions | one folder per feature area, for example Devices/, Automations/, Plugins/, Workloads/, Security/ |
Reeve.Infrastructure |
Every implementation: EF Core persistence and migrations, identity, MQTT, the plugin host, the workflow engine integration, object storage, cluster locks, health checks, telemetry writes. | Application, Domain, Contracts, PluginAbstractions, PluginAuthoring, Discovery.Contracts, the two protocol libraries | Persistence/, Migrations/, Plugins/, Automations/, Cluster/, Locks/, ObjectStorage/, HealthChecks/ |
Reeve.Api |
The HTTP and realtime entry point: controllers, hubs, authentication handlers, rate limiting, exception-to-ProblemDetails mapping, the cluster pipeline (UseReeveCluster runs first, after request logging, security headers and CORS) and its error writer in ClusterHost/, and the composition root. |
Application, Infrastructure, Contracts, Discovery.Contracts | Controllers/, Hubs/, Realtime/, RateLimiting/, ExceptionHandling/, Swagger/ |
Reeve.Api.E2E |
The end-to-end test surface: the anonymous api/test controller, the settable clock, the plugin release-asset fixture, and the module that registers them. Only the E2E image contains it; the host loads it under the E2E environment. |
Api | none |
Reeve.PluginAbstractions |
The device plugin SDK: every interface, attribute and base type a plugin implements. The workflow block SDK is the ReeveWorkflow.Abstractions package. |
Contracts, Adapters.Protocol | Devices/, Discovery/, Configuration/, Cameras/, Actions/ |
Reeve.PluginAuthoring |
Helpers for plugin authors: inbound vendor-to-canonical value maps, unit converters, typed canonical-device builders, outbound command maps. | Contracts | Inbound/, Commands/, Units/, Values/, Building/ |
Reeve.Discovery.Contracts |
Discovered-device records and provider and matcher types shared with out-of-process adapters. | nothing | none |
Reeve.Ble.Decoding |
Transport-agnostic BLE advertisement decoding: encrypted MiBeacon and unencrypted BTHome v2 payloads, a rotating-telemetry accumulator and a raw GAP parser. | nothing | none |
ContractsCodegen (backend/contracts-codegen) |
The generator that writes the frontend's Zod mirrors of the contract types into frontend/src/contracts/generated/. CI fails when the committed files differ from its output. |
Contracts | Areas/, Zod/ |
Reeve.Adapters.Protocol |
The wire protocol between the host and an out-of-process adapter. | nothing | services/adapter-protocol/ |
Reeve.MatterBridge.Protocol |
The wire protocol between the host and the Matter bridge sidecar. | Adapters.Protocol, Contracts | services/adapter-protocol/ |
Reeve.Adapters.Protocol.MockGateway |
Mock workload-gateway conformance fixtures for adapter and sidecar session clients, for plugin repositories' tests. | Adapters.Protocol | services/adapter-protocol/ |
The repository also holds projects outside the backend solution folders: tools/Reeve.PluginDev (the plugin
development CLI), the benchmark and conformance generator tools under tools/, the HelloWorld plugin under
examples/ and the mobile projects under mobile/. mobile/Reeve.Mobile and mobile/Reeve.MatterAndroid.Bindings
are Android workload projects and are not part of Reeve.slnx; see mobile.md.
Layering rules
- Application never references Infrastructure. Dependencies point inward: Infrastructure implements Application's interfaces and is wired in Api's composition root. A use case that needs a new capability gets a new abstraction in Application, not a reference the other way.
- PluginAbstractions is a compatibility surface. It ships as a package that plugins compile against, so a
signature change, including adding a member to a
record(which changes the generated constructor), breaks every plugin binary built against the earlier shape. A public API analyzer tracks the surface; review each change against the existing plugins. - Domain carries no persistence concerns. No EF Core attributes or annotations; mapping lives in
Infrastructure's
Persistence/. - Plugins never see Application or Domain. The plugin host loads native plugins into collectible assembly load contexts and hands them only PluginAbstractions and Contracts types.
- Vendor translation is a plugin concern. The host holds no vendor-protocol code; see the constraints.
Notes
- Contracts is the shared vocabulary of four consumers. The backend, the web SPA (
frontend/src/contracts/, TypeScript generated bybackend/contracts-codegen), the mobile app (a project reference) and third-party plugins all read it. A breaking DTO change touches all four. - Domain references Contracts. It reads contract enums and value types so that a canonical capability has one spelling. It takes no dependency on EF Core, ASP.NET or any database provider.
- Nine projects ship as packages: Contracts, PluginAbstractions, PluginAuthoring, Discovery.Contracts,
Ble.Decoding, Adapters.Protocol, MatterBridge.Protocol, Adapters.Protocol.MockGateway and the
Reeve.PluginDevtool. The list is the set the release workflow packs (.github/workflows/release.yml). Reeve.Ble.Decodingis a standalone package. The backend does not reference it; the ESPHome and Bluetooth plugins do.- PluginAuthoring is a convenience, not a trust boundary. The host validates everything a plugin produces regardless of which helper built it.
- Infrastructure references
services/adapter-protocol/directly rather than through a package, so a protocol change is compiled against the host in the same build. - Api's
Controllers/is grouped by feature, not versioned by folder. Device routes live underapi/devices/*. A sharedReeveControllerBasecarries the common pieces, and unmatched or bodiless error responses are normalised toapplication/problem+jsonwith a trace id. - The test-support controller under
api/testlives inReeve.Api.E2E, which only the E2E image carries. See e2e-testing.md.
Test projects
| Project | Tier | Needs |
|---|---|---|
Reeve.Domain.Tests, Reeve.Application.Tests, Reeve.Api.Tests, Reeve.Api.E2E.Tests, Reeve.Infrastructure.Tests, Reeve.Ble.Decoding.Tests, ContractsCodegen.Tests, Reeve.PluginAuthoring.Tests, Reeve.Adapters.Protocol.Tests, Reeve.MatterBridge.Protocol.Tests, Reeve.PluginDev.Tests |
unit | nothing external; parts run on the in-memory persistence provider |
Reeve.Api.IntegrationTests |
integration | containerised PostgreSQL/TimescaleDB, Redis and MQTT (Docker). The ClusterAcceptance collection runs three replicas against one database to exercise failover, rolling restarts and cross-replica requests |
Reeve.Infrastructure.IntegrationTests |
integration | a throwaway database per test with the real migration applied (Docker) |
Reeve.PluginDev.IntegrationTests |
integration | Docker |
backend/tests/Fixtures/ holds small plugin projects that the plugin-host tests load. Reeve.TestInfrastructure
is the shared test harness.
Run the cluster acceptance tests alone with --filter FullyQualifiedName~Reeve.Api.IntegrationTests.ClusterAcceptance..
Each acceptance scenario carries a History trait, for example --filter History=Failover.
A model-shape change compiles and passes the unit tier while breaking the real database; only the integration tiers verify it. See the testing rules.
Database migrations
EF Core migrations for the host live in backend/src/Reeve.Infrastructure/Migrations/, together with the model
snapshot. Scaffold them with the pinned tool (dotnet tool restore, then dotnet ef), never a global dotnet-ef
of another major version. The snapshot names the last migration (LastMigrationId), so two branches that each add
one conflict on that line: drop yours and its Designer, take the other branch's snapshot and scaffold yours again.
The workflow, workload and cluster libraries own their own migration histories. The boot order is the cluster runner, the workflow library's migrator, the host's chain, then workloads.
The directory holds one migration, InitialSchema, applied at boot. A few of its operations are written by hand
because EF Core cannot express them, and a regeneration must keep them: the unique lower() indexes on
plugin_installations, plugin_auto_update_subscriptions and rooms, the retention policy on the
device_telemetry_hourly aggregate, the two foreign keys into automation.workflows, the two journal indexes on
the workflow library's execution tables, and the dashboards.view grant to the Household Member role. Every column
default is declared in the model, so a regeneration keeps them.
Raw SQL in a migration
The idempotent-script generator wraps every migrationBuilder.Sql() body in a PL/pgSQL block, where a bare
SELECT is illegal. The TimescaleDB provider compensates by rewriting any line whose first token is SELECT to
PERFORM, unless the body starts with CREATE, ALTER or DROP. Neither step parses SQL, so:
- a
SELECTthat belongs to a larger statement (anINSERT ... SELECT, a CTE, a subquery) must not start its own line; - a standalone
SELECT some_function(...)must not share aSql()body with leading DDL.
The idempotent-script test checks both.
Builds in a rolling window
A migration that drops, renames or tightens something the previous build reads is a contract step. It carries a
// CONTRACT (expand X.Y.Z) comment, and its release raises ReeveRollFrom above that core version. See
the overlap rule.
Workflow context tooling
dotnet ef --context WorkflowDbContext with the Api startup project needs a reachable Redis, and the error of a
non-migrating boot can name Redis before the database.