Motivation
Instance-to-instance relationship roles have no compile-time contract today. We want a structural declaration — what roles this Instance kind may participate in, and with what target kind — introspectable at runtime, the same way parties/0 and places/0 are today.
Enforcement (validating that only declared roles are used, auto-wiring in build_after, multiplicity constraints) is behaviour and is out of scope until the expectations model is settled.
Proposed DSL
```elixir
provider do
relationships do
relationship :provides, MyApp.BackboneService
relationship :requires, MyApp.AccessService
relationship_ref :peer, MyApp.AccessService # reference — no direct edge
end
end
```
Scope
RelationshipDeclaration struct (name, instance_type, reference)
PersistRelationships — bakes relationships/0 and relationship/1 onto the module
VerifyRelationships — compile-time: no duplicate role names, target is a BaseInstance-derived resource
instance_transformer_test.exs coverage
AGENTS.md and usage-rules.md updated
Explicitly deferred
- Enforcement via
relate_instance/2 or VerifyBehaviour
- Auto-wiring in
build_after
- Multiplicity constraints
- Reverse-side declaration (target-side
instances do equivalent)
Motivation
Instance-to-instance relationship roles have no compile-time contract today. We want a structural declaration — what roles this Instance kind may participate in, and with what target kind — introspectable at runtime, the same way
parties/0andplaces/0are today.Enforcement (validating that only declared roles are used, auto-wiring in
build_after, multiplicity constraints) is behaviour and is out of scope until the expectations model is settled.Proposed DSL
```elixir
provider do
relationships do
relationship :provides, MyApp.BackboneService
relationship :requires, MyApp.AccessService
relationship_ref :peer, MyApp.AccessService # reference — no direct edge
end
end
```
Scope
RelationshipDeclarationstruct (name,instance_type,reference)PersistRelationships— bakesrelationships/0andrelationship/1onto the moduleVerifyRelationships— compile-time: no duplicate role names, target is aBaseInstance-derived resourceinstance_transformer_test.exscoverageAGENTS.mdandusage-rules.mdupdatedExplicitly deferred
relate_instance/2orVerifyBehaviourbuild_afterinstances doequivalent)