Model-bound queries
Put query methods beside their read model so you can find state and selection logic together. The model remains an ordinary named struct: no base type, constructor, service-provider field or hidden framework state.
Use unnamed namespace methods as the static-equivalent
convention. Directed top-level functions are equally supported. Register the
model only when you need shared identity, path or authorization overrides;
otherwise queries.Register[M] uses its type name and the registry namespace.
Shared Arc and Chronicle rules
Section titled “Shared Arc and Chronicle rules”One struct can serve both frameworks. These are the agreed shared type rules, not a claim that Arc executes Chronicle projections:
- Disjoint metadata. Arc owns
arc:"…"and//arc:; Chronicle ownschronicle:"…"and//chronicle:. Neither interprets the other’s metadata; both tolerate other tag keys. Arc validates unknown options within its own tags. - Explicit wire names. Use explicit
jsontags. Queries, proxies, projection paths, read-model schemas and indexes must agree on the exact serialized name. Do not rely on different framework default naming policies, especially initialisms. - Exported state only. Only exported serializable fields participate.
json:"-"fields are invisible to both and cannot carry Chronicle mappings. - Pointer nullability.
*Tmeans nullable/absent.omitemptyandomitzeroaffect serialization only; they do not change projection semantics. - Concepts. Domain values can implement Fundamentals.Go
concepts.Concept[T].concepts.Underlyingrecognizes the scalar representation andCheckJSONchecks codec shape. Plain named primitives need no extra marker. Query text binding usesUnmarshalText, not private concept state. - Separate keys. Chronicle’s read-model key is
chronicle:"key", withID/Idfallback. Arc identity isarc:"identity"; argument declarations remain separate. These declarations may reference the same field but neither implies a command key or a Chronicle event-source identity. - Separate registration. Register the same type independently with each
framework: Arc registrations/adapters and Chronicle read models/projections.
There is no shared global registry and no
initregistration.
This shared declaration excerpt uses primitives only:
type Item struct { ID int `json:"id" arc:"identity" chronicle:"key"` Name string `json:"name"` Note *string `json:"note,omitempty"`}Namespace methods are ignored by serialization and projection field inspection. Chronicle owns FromEvent/SetFrom-equivalent declarations. Arc registration implies neither projection ownership nor command-side model injection; projection ownership must not require Arc registration or invoke query methods.
The Chronicle integration includes a shared model registered with both frameworks and a kernel test that projects events and serves the result through Arc. Query registration alone demonstrates no persistence.
Pin public identity deliberately
Section titled “Pin public identity deliberately”queries.NewRegistry(queries.RegistryOptions{Namespace: "Shop.Inventory"})
sets a logical namespace, never one derived from an import path or folder.
RegisterReadModel[M] accepts WithModelIdentity, WithModelPath and
WithModelAuthorization. Explicit query descriptors remain available for migrations.
For nongenerated declarations, a single blank metadata field can use
json:"-" arc:"readmodel,name=Item,namespace=Shop"; authorization uses the shared
metadata grammar. Type renaming changes the default public identity: pin it before
moving or renaming a model consumed by clients.
Continue with namespace methods and functions or method-over-model authorization.