@cratis/pi 7.191.5 → 7.193.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package/corpus/harnesses/copilot/instructions/application-anatomy.instructions.md +143 -0
- package/package/corpus/harnesses/copilot/instructions/application-profile.instructions.md +1 -1
- package/package/corpus/harnesses/copilot/instructions/elixir.instructions.md +5 -0
- package/package/corpus/harnesses/copilot/instructions/specs.elixir.instructions.md +138 -0
- package/package/corpus/harnesses/copilot/instructions/specs.instructions.md +1 -0
- package/package/corpus/harnesses/copilot/instructions/vertical-slices.instructions.md +8 -1
- package/package/corpus/rules/application-anatomy.md +142 -0
- package/package/corpus/rules/application-profile.md +1 -1
- package/package/corpus/rules/elixir.md +5 -0
- package/package/corpus/rules/general.md +3 -3
- package/package/corpus/rules/specs.elixir.md +137 -0
- package/package/corpus/rules/specs.md +1 -0
- package/package/corpus/rules/vertical-slices.md +8 -1
- package/package/corpus/skills/cratis-application-growth/LICENSE +2 -0
- package/package/corpus/skills/cratis-application-growth/SKILL.md +124 -0
- package/package/corpus/skills/cratis-application-growth/references/rename-window.md +59 -0
- package/package/corpus/skills/cratis-application-growth/verification.json +14 -0
- package/package/corpus/skills/cratis-arc-authentication-authorization-and-identity/SKILL.md +2 -1
- package/package/corpus/skills/cratis-arc-authentication-authorization-and-identity/references/authorization.md +5 -0
- package/package/corpus/skills/cratis-arc-command/references/proxy-generation.md +18 -0
- package/package/corpus/skills/cratis-arc-elixir/references/commands-and-queries.md +20 -0
- package/package/corpus/skills/cratis-arc-elixir/references/proxies-and-vertical-slices.md +29 -0
- package/package/corpus/skills/cratis-chronicle-client-elixir/SKILL.md +10 -0
- package/package/corpus/skills/cratis-chronicle-configuration/references/client-options.md +1 -1
- package/package/corpus/skills/cratis-chronicle-read-model/SKILL.md +5 -2
- package/package/corpus/skills/cratis-chronicle-reducer/SKILL.md +4 -4
- package/package/corpus/skills/cratis-engineering-csharp-conventions/references/exceptions-logging-and-di.md +6 -1
- package/package/profile-catalog.json +6 -0
- package/package.json +1 -1
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
---
|
|
2
|
+
applyTo: "**/*.csproj,**/*.slnx,**/Directory.Build.props,**/Directory.Build.targets,**/Directory.Packages.props,**/package.json,**/tsconfig*.json"
|
|
3
|
+
profile: application
|
|
4
|
+
paths:
|
|
5
|
+
- "**/*.csproj"
|
|
6
|
+
- "**/*.slnx"
|
|
7
|
+
- "**/Directory.Build.props"
|
|
8
|
+
- "**/Directory.Build.targets"
|
|
9
|
+
- "**/Directory.Packages.props"
|
|
10
|
+
- "**/package.json"
|
|
11
|
+
- "**/tsconfig*.json"
|
|
12
|
+
---
|
|
13
|
+
<!-- cratis-ai: generated Copilot instructions. Do not edit; rules/ is the source. -->
|
|
14
|
+
|
|
15
|
+
<!-- Copyright (c) Cratis. All rights reserved. -->
|
|
16
|
+
<!-- Licensed under the MIT license. See LICENSE file in the project root for full license information. -->
|
|
17
|
+
|
|
18
|
+
# Application anatomy for growing systems
|
|
19
|
+
|
|
20
|
+
> **Application profile.** This is how the source tree of an application built on Cratis is shaped as it grows. It does **not** apply inside a Cratis framework repository (see [framework.md](./framework.instructions.md)). What goes in one behavior folder is [vertical-slices.md](./vertical-slices.instructions.md); the procedure for a move or a rename is the **cratis-application-growth** skill.
|
|
21
|
+
|
|
22
|
+
Lines are **[convention]** (house default; the framework does not check it) unless tagged **[contract]** (Arc, Chronicle or Fundamentals behave this way). Conventions hold only when the repository's own architecture gates enforce them; see *Gates* below.
|
|
23
|
+
|
|
24
|
+
An application's anatomy is a **path, not a choice made once.** Start at the smallest stage the product needs and grow when a signal says so. Skipping a stage is fine; building a later stage's structure before its signal appears is not.
|
|
25
|
+
|
|
26
|
+
## Words used here
|
|
27
|
+
|
|
28
|
+
- **Module**: one business capability (for example Billing or Support) with its own backend, frontend and specs.
|
|
29
|
+
- **Host**: the one project that composes and runs everything. Nothing references it.
|
|
30
|
+
- **Platform project**: code several modules need, or that no module owns. It never names a module.
|
|
31
|
+
- **Engine**: a platform project that holds reusable behavior with its own events and read models (a rules engine, a work queue). Modules plug into it; it knows no module.
|
|
32
|
+
- **Contracts project** (`<Module>.Contracts`): what a module lets others use: public events, grain or service interfaces, and the concepts they carry. No logic.
|
|
33
|
+
- **Seam**: a file that lives in one project's folder but is compiled into another project (a `<Compile Include="../Other/**" />`). It hides a dependency the project graph would reject.
|
|
34
|
+
|
|
35
|
+
## The stages
|
|
36
|
+
|
|
37
|
+
| Stage | Shape | What it buys |
|
|
38
|
+
| --- | --- | --- |
|
|
39
|
+
| **1. One project** | One backend project and one frontend package; behaviors are `<Feature>/<Slice>/` folders. | Least ceremony; one build; cohesive slices. |
|
|
40
|
+
| **2. Modules in one project** | Features grouped under named top-level folders (`<Module>/<Feature>/<Slice>/`), still one backend project. | Names the capability boundaries before paying for project boundaries. |
|
|
41
|
+
| **3. Module projects on a platform** | Each module is its own backend project and frontend package, composed by the host, on platform projects. | The compiler enforces boundaries: a module cannot use what it does not reference. |
|
|
42
|
+
| **4. Modules publish contracts** | A module others need exposes `<Module>.Contracts`. No module references another module's project. | Modules change and are owned independently. |
|
|
43
|
+
|
|
44
|
+
Separately deployed services are a further step; see **cratis-multi-service-architecture**.
|
|
45
|
+
|
|
46
|
+
## When to move up
|
|
47
|
+
|
|
48
|
+
Move when a signal is present *now*, not when it is imaginable:
|
|
49
|
+
|
|
50
|
+
- **1 → 2:** people name a group of features as a capability; features share vocabulary no other feature uses; navigation, settings or access group by capability.
|
|
51
|
+
- **2 → 3:** a module needs separate build, specs or ownership; code reaches into another module's internals and the folder rule alone is not holding; a capability is gated by entitlement or audience and must be provably absent for others.
|
|
52
|
+
- **3 → 4:** one module needs to ask another a question or react to its events. Add the contract at the first such need.
|
|
53
|
+
|
|
54
|
+
**Start at stage 2 or 3** when the shape is already known: several teams, clearly separate capabilities, entitlement or audience gating, or a product line that will gain modules. A prototype, a single-purpose service or one team with one capability starts at stage 1.
|
|
55
|
+
|
|
56
|
+
## The layers and what may reference what (stages 3 and 4)
|
|
57
|
+
|
|
58
|
+
| Layer | Examples | May reference |
|
|
59
|
+
| --- | --- | --- |
|
|
60
|
+
| Host | `Core` or `Host` | everything below; composes modules, integrations and engines |
|
|
61
|
+
| Modules | `Billing`, `Support` | other modules' `.Contracts`, engines' `.Contracts`, platform, Infrastructure, Components |
|
|
62
|
+
| Integration providers | `Integration.GitHub` | the `Integration` base and module `.Contracts` (ports) only |
|
|
63
|
+
| Engines and platform | `Notifications`, `Search`, `Integration`, `Mcp` | other platform `.Contracts`, Infrastructure, Components |
|
|
64
|
+
| Contracts | `Billing.Contracts`, `Tenancy.Contracts` | Infrastructure and other contracts only |
|
|
65
|
+
| Foundations | `Infrastructure`, `Components` | framework packages only; no domain concept, no module |
|
|
66
|
+
|
|
67
|
+
**References point down only.** If code compiles only with a reference that points up or sideways, the code is in the wrong project or the dependency must become a contract.
|
|
68
|
+
|
|
69
|
+
## Invariants at every stage
|
|
70
|
+
|
|
71
|
+
1. **Vertical slices.** The slice (command, events, projection, component, specs) is the unit at every stage. A stage changes what *groups* slices, never what a slice is. Never split by artifact type.
|
|
72
|
+
2. **No `InternalsVisibleTo`, no seams.** Both make a project boundary a folder name and nothing else. Code that needs either belongs in a lower project, or its dependency becomes a contract.
|
|
73
|
+
3. **No catch-all project.** A project named for its position rather than its purpose (`Global`, `Shared`, `Common`, `Base`) grows until it depends on the modules that depend on it. Every platform project has one purpose that its name states; a stage-1 `Common/` folder of concepts is fine.
|
|
74
|
+
4. **Every folder under the source root is a project or package with a `README.md`.** No loose code folders, no umbrella folders. The README states only what the code shows (template below).
|
|
75
|
+
5. **Specs live with their code** and are left out of analyzers and Release output by one shared pattern; see [fast-feedback.md](./fast-feedback.instructions.md).
|
|
76
|
+
6. **Namespaces follow projects and folders:** `<Company>.<Product>.<Project>.<folder path>`, so a namespace tells which project owns a type. That is the end state; while code is moving, namespaces stay put (see the next section). Project folders carry no product prefix (`Source/Billing`, not `Source/MyProduct.Billing`); the prefix lives in the root namespace, set once in `Directory.Build.props`.
|
|
77
|
+
7. **A namespace or assembly name is an identity, not a label.** See the next section before renaming either.
|
|
78
|
+
8. **Access is declared, never derived from a name.** Authorization, audience and admin-only rules sit on the code (an attribute, a policy, an assembly marker), never on a namespace prefix or folder; otherwise a rename silently changes who may read what.
|
|
79
|
+
|
|
80
|
+
## What a rename changes **[contract]**
|
|
81
|
+
|
|
82
|
+
| Identity | Derived from | Can it be pinned? |
|
|
83
|
+
| --- | --- | --- |
|
|
84
|
+
| Chronicle event type id | the type's **simple name** (namespace-independent) | yes: `[EventType("id")]` |
|
|
85
|
+
| Reactor, reducer and projection ids | the type's **full name** | yes: an explicit id on the attribute |
|
|
86
|
+
| Read model identifier | the type's **full name** | no: stored identifiers are rewritten, or the read model rebuilds |
|
|
87
|
+
| Arc model-bound command and query routes | the **namespace** (minus `SegmentsToSkipForRoute`) | no: every caller and proxy follows the new route |
|
|
88
|
+
| Generated proxy folders | the **namespace** (minus `CratisProxiesSegmentsToSkip`) | no |
|
|
89
|
+
| Stored grain state type names and job type names | full type names; job names are assembly-qualified | keep `AssemblyName` when a project is renamed; retire old names deliberately |
|
|
90
|
+
| Anything your code keys on a name | authorization prefixes, OpenAPI filters, build strip lists, settings keys | replace with explicit declarations first |
|
|
91
|
+
|
|
92
|
+
Consequences:
|
|
93
|
+
|
|
94
|
+
- **Moving a file is free; renaming its namespace is a migration.** While the structure moves, keep namespaces and assembly names, and record every folder whose namespace no longer matches in an allowlist that only shrinks. One exception: a job type that moves to another assembly changes its assembly-qualified stored name, so rewrite the stored names (or keep a type forwarder in the old assembly) in the same release.
|
|
95
|
+
- **Rename namespaces once, in one window**, with a repair that rewrites the stored identities (observer ids, read model identifiers, grain and job type names) before the new version starts. Without it every observer registers under a new id and replays from the first event: projections rebuild and reactors act on history again. Chronicle's `ArtifactIdentityDrift` setting reports likely renames; it does not repair them.
|
|
96
|
+
- **Event types:** an explicit id or an unchanged class name keeps the identity across any namespace change. Changing an event deliberately is **cratis-chronicle-event-type-migration**; removing a project removes its event types, which is also an event-store change.
|
|
97
|
+
|
|
98
|
+
## Module anatomy (stages 3 and 4)
|
|
99
|
+
|
|
100
|
+
- **One module declaration.** A single type (for example an `IModule` implementation) states the module's key, display name and **audience** (everyone, an entitled subset, internal). The key is an identity; keep it when the module's name changes.
|
|
101
|
+
- **One backend project and one frontend package** per module, plus `<Module>.Contracts` when others need it.
|
|
102
|
+
- **The module contributes its surfaces by convention:** routes, navigation, settings sections, tools for an MCP server, API endpoints, rule packs. The base that hosts a surface discovers contributions (through `IInstancesOf<>` or the equivalent) and never names a module; no central route table or menu list.
|
|
103
|
+
- **Audience and entitlement are enforced on the server** (commands and queries), not only by hiding navigation.
|
|
104
|
+
- **Ask through an interface, be told through an event.** A question or request is a grain or service interface in the owner's contracts; "tell me when" is a public event. A module never uses another module's commands, read models, reactors or internal concepts.
|
|
105
|
+
- **Ports for providers.** When a module needs something an external provider supplies, the module defines the port in its contracts and each provider project implements it. A module never names a provider; adding a provider is adding a project.
|
|
106
|
+
- **Frontend boundaries mirror the backend:** a package imports another module's package only through its public entry point (no deep paths), never in both directions, and the shared components package imports no module. Each backend project generates its proxies into its own package and maps referenced projects with `AssemblyToPackageMapping`, so a type is generated by its owner only.
|
|
107
|
+
- **Wiring is by convention:** the default `IFoo` → `Foo` binding and lifetime attributes. **[contract]** The convention binds only when the interface and its single implementation share a namespace, and it fills only service types nobody registered. An interface in `<Module>.Contracts` with its implementation in the module therefore needs an explicit (or generated) registration, applied after the explicit ones.
|
|
108
|
+
|
|
109
|
+
### README template
|
|
110
|
+
|
|
111
|
+
```markdown
|
|
112
|
+
# <Project or package>
|
|
113
|
+
|
|
114
|
+
<One paragraph: what it is for and who uses it.>
|
|
115
|
+
|
|
116
|
+
## Owns
|
|
117
|
+
- Namespaces and, for a module: its key and audience.
|
|
118
|
+
|
|
119
|
+
## Exposes
|
|
120
|
+
- Contracts, routes, settings sections and other contributions others may rely on.
|
|
121
|
+
|
|
122
|
+
## Depends on
|
|
123
|
+
- Project references and packages it imports, and why.
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## Gates
|
|
127
|
+
|
|
128
|
+
Prose does not hold a boundary; gates do. Write them as ordinary specs that read the project files and sources, so they run in the normal spec pass in seconds:
|
|
129
|
+
|
|
130
|
+
- no `InternalsVisibleTo` and no seam (no `Compile Include` reaching outside the project folder);
|
|
131
|
+
- only the host references a module project; nothing references the host;
|
|
132
|
+
- platform and Infrastructure name no module and no domain concept; a module names no integration provider;
|
|
133
|
+
- every source folder has a project or package and a `README.md`;
|
|
134
|
+
- namespace matches folder, except allowlisted entries;
|
|
135
|
+
- frontend: no two-way package imports, no deep imports past a package's entry point, the components package imports no module (an ESLint rule).
|
|
136
|
+
|
|
137
|
+
Each gate compares against a committed baseline that **only shrinks**. A change that removes coupling shrinks the baseline in the same commit; a change that grows it fails. Never raise a baseline to land a change. Count dependencies from project files or compiled assemblies, not `using` lines.
|
|
138
|
+
|
|
139
|
+
## See also
|
|
140
|
+
|
|
141
|
+
- **cratis-application-growth**: the procedure for each move and for the rename window.
|
|
142
|
+
- [vertical-slices.md](./vertical-slices.instructions.md), [application-profile.md](./application-profile.instructions.md), [react.md](./react.instructions.md), [components.md](./components.instructions.md).
|
|
143
|
+
- **cratis-multi-service-architecture**: when modules become separately deployed services.
|
|
@@ -24,7 +24,7 @@ profile: application
|
|
|
24
24
|
|
|
25
25
|
## Project Layout (Cratis Application convention)
|
|
26
26
|
|
|
27
|
-
The framework discovers commands and read models by attributes and static methods — **the folder shape is a convention, not a requirement.** The house default: the domain hierarchy lives directly under the app source root (**no top-level `Features/` wrapper**), cross-cutting concerns (`Common/` concepts, `Identity/`, shared components) at the top level, and one folder per behavior — `<Module>/<Feature>/<Slice>/` holding `<Slice>.cs`, the slice's `.tsx`, and its `when_*/` specs. **The slice is the invariant unit** — created, renamed, and deleted as one. Namespace mirrors the path under the source root, dropping any level that isn't present. The full tree and the split rules are in [vertical-slices.md](./vertical-slices.instructions.md).
|
|
27
|
+
The framework discovers commands and read models by attributes and static methods — **the folder shape is a convention, not a requirement.** The house default: the domain hierarchy lives directly under the app source root (**no top-level `Features/` wrapper**), cross-cutting concerns (`Common/` concepts, `Identity/`, shared components) at the top level, and one folder per behavior — `<Module>/<Feature>/<Slice>/` holding `<Slice>.cs`, the slice's `.tsx`, and its `when_*/` specs. **The slice is the invariant unit** — created, renamed, and deleted as one. Namespace mirrors the path under the source root, dropping any level that isn't present; once modules are their own projects it is `<Company>.<Product>.<Project>.<folder path>`, and renaming a namespace changes stored identities and routes (see [application-anatomy.md](./application-anatomy.instructions.md)). The full tree and the split rules are in [vertical-slices.md](./vertical-slices.instructions.md).
|
|
28
28
|
|
|
29
29
|
## Slice Types
|
|
30
30
|
|
|
@@ -104,6 +104,11 @@ Read the **cratis-arc-elixir** and **cratis-chronicle-client-elixir** skills bef
|
|
|
104
104
|
- **Third parties are integrations behind a behaviour**, with an in-memory stand-in for specs; only
|
|
105
105
|
reactors write to them.
|
|
106
106
|
|
|
107
|
+
Specs follow [specs.elixir.md](./specs.elixir.instructions.md): scripts in `for_*`/`when_*` folders beside the code, no
|
|
108
|
+
`_test` suffix, `should` assertions. Build read models with a projection, not a reducer, unless a projection
|
|
109
|
+
cannot express the transition, and enforce uniqueness with a Chronicle constraint, not a read before the append
|
|
110
|
+
(see the **cratis-arc-elixir** and **cratis-chronicle-client-elixir** skills).
|
|
111
|
+
|
|
107
112
|
Every `.ex` and `.exs` source file starts with:
|
|
108
113
|
|
|
109
114
|
```elixir
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
---
|
|
2
|
+
applyTo: "**/for_*/**/*.exs, **/when_*/**/*.exs"
|
|
3
|
+
paths:
|
|
4
|
+
- "**/for_*/**/*.exs"
|
|
5
|
+
- "**/when_*/**/*.exs"
|
|
6
|
+
---
|
|
7
|
+
<!-- cratis-ai: generated Copilot instructions. Do not edit; rules/ is the source. -->
|
|
8
|
+
|
|
9
|
+
<!-- Copyright (c) Cratis. All rights reserved. -->
|
|
10
|
+
<!-- Licensed under the MIT license. See LICENSE file in the project root for full license information. -->
|
|
11
|
+
|
|
12
|
+
# How to Write Elixir Specs
|
|
13
|
+
|
|
14
|
+
Extends the base [specs.md](./specs.instructions.md) with Elixir conventions. The philosophy is the same: a spec
|
|
15
|
+
describes a **behavior** in the language of the domain, the folder tree reads as a sentence, and one
|
|
16
|
+
scenario lives in one file. ExUnit is the runner; nothing else is needed.
|
|
17
|
+
|
|
18
|
+
## Specs are scripts beside the code, never in a release
|
|
19
|
+
|
|
20
|
+
A spec is an `.exs` file (a script). `mix compile` and `mix release` only ever build `.ex` files, so a spec
|
|
21
|
+
beside the code it specifies is **never part of a release**, the same outcome the C# build gets by removing
|
|
22
|
+
`when_*` files from Release builds and the TypeScript build gets by not importing them. Do not rename specs
|
|
23
|
+
to `.ex`. Shared helpers that must be compiled (a `Case` module) live in `test/support/*.ex`, which only the
|
|
24
|
+
`:test` environment adds to `elixirc_paths`.
|
|
25
|
+
|
|
26
|
+
**No `_test` suffix.** ExUnit's default pattern is `*_test.exs`, but the folder already says it is a spec
|
|
27
|
+
(`for_*`/`when_*`), exactly as in C# and TypeScript. Point `mix test` at the folders instead:
|
|
28
|
+
|
|
29
|
+
```elixir
|
|
30
|
+
# mix.exs: project/0
|
|
31
|
+
elixirc_paths: elixirc_paths(Mix.env()),
|
|
32
|
+
test_paths: ["lib"],
|
|
33
|
+
# A spec is any script in a `for_*` folder; `given/` holds shared contexts, which specs load themselves.
|
|
34
|
+
test_load_filters: [&(String.contains?(&1, "/for_") and not String.contains?(&1, "/given/"))],
|
|
35
|
+
|
|
36
|
+
defp elixirc_paths(:test), do: ["lib", "test/support"]
|
|
37
|
+
defp elixirc_paths(_env), do: ["lib"]
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
`test_load_filters` **replaces** the default `test_pattern`; do not set both. `test_helper.exs` (`ExUnit.start()`)
|
|
41
|
+
stays beside the specs, in the first of `test_paths`. Let `mix format` cover the scripts
|
|
42
|
+
(`inputs: ["{config,lib,test}/**/*.{ex,exs}"]`).
|
|
43
|
+
|
|
44
|
+
## Folder and file structure
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
<feature or slice>/
|
|
48
|
+
└── for_<unit>/ ← "For the unit..."
|
|
49
|
+
├── given/
|
|
50
|
+
│ └── a_<context>.exs ← shared context, loaded by the specs that need it (not a spec)
|
|
51
|
+
├── when_<behavior>/ ← "...when doing this..." (a folder when there are several outcomes)
|
|
52
|
+
│ ├── and_<condition>.exs ← one scenario per file
|
|
53
|
+
│ ├── with_<data>.exs
|
|
54
|
+
│ └── without_<requirement>.exs
|
|
55
|
+
└── when_<simple_behavior>.exs ← a single file for a single scenario
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
The unit is the module, command, read model, component or function under specification:
|
|
59
|
+
`for_rotate_secret`, `for_data_table`, `for_patterns`. Use the prepositions and the rules of
|
|
60
|
+
[specs.md](./specs.instructions.md) (`and_`, `with_`, `without_`, `having_`, `given_`), including: **never put `when` in a
|
|
61
|
+
file or non-`when_` folder name** (`and_ory_fails.exs`, not `when_ory_fails.exs`, under `when_adding/`).
|
|
62
|
+
|
|
63
|
+
Folder names are `snake_case`. A spec's **module name mirrors its path** below the application's namespace,
|
|
64
|
+
`PascalCase`, so it can never clash with the module it specifies and is never named `...Test`:
|
|
65
|
+
|
|
66
|
+
```elixir
|
|
67
|
+
# lib/access/credentials/adding_credentials/for_add_credential/when_adding/with_selected_vessels.exs
|
|
68
|
+
defmodule Prism.Access.Credentials.AddingCredentials.ForAddCredential.WhenAdding.WithSelectedVessels do
|
|
69
|
+
use ExUnit.Case, async: true
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## One scenario, several `should` assertions
|
|
73
|
+
|
|
74
|
+
The `setup` establishes the context and performs the behavior once per assertion (ExUnit runs `setup` for each
|
|
75
|
+
`test`); each `test` states one expectation and starts with **`should`**, so the file reads as a sentence:
|
|
76
|
+
|
|
77
|
+
```elixir
|
|
78
|
+
defmodule Prism.Access.ApiCredentials.ForState.WhenDerivingTheStatus do
|
|
79
|
+
use ExUnit.Case, async: true
|
|
80
|
+
|
|
81
|
+
alias Prism.Access.ApiCredentials.State
|
|
82
|
+
|
|
83
|
+
test "should be active by default" do
|
|
84
|
+
assert State.status(%State{id: "c", exists?: true}, ~U[2026-03-01 12:00:00Z]) == :active
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
- `test "should refuse a duplicate label"`, not `test "a duplicate label is refused"` and not
|
|
90
|
+
`test "refuses..."`. Name the expected result, not the call.
|
|
91
|
+
- A file with several unrelated scenarios is several files. Split `describe` blocks into
|
|
92
|
+
`when_<behavior>/<preposition>_<condition>.exs` files; do not use `describe` to group scenarios.
|
|
93
|
+
- Assert on the **contract**: the result, the events appended, what a collaborator was asked to do. Do not
|
|
94
|
+
assert on internals, and do not spec logging or trivial delegation.
|
|
95
|
+
- `doctest Module` belongs in its own spec (`when_building/with_the_documented_examples.exs`).
|
|
96
|
+
|
|
97
|
+
## Shared context: `given/`
|
|
98
|
+
|
|
99
|
+
Contexts that several specs share (a table of people, a started kernel) go in `for_<unit>/given/<name>.exs`
|
|
100
|
+
as a module, and a spec loads it by relative path. The filter above keeps `given/` out of the specs ExUnit
|
|
101
|
+
runs, so it is loaded once, by the spec that needs it:
|
|
102
|
+
|
|
103
|
+
```elixir
|
|
104
|
+
Code.require_file("../given/people.exs", __DIR__)
|
|
105
|
+
|
|
106
|
+
defmodule Prism.Access.Components.DataTable.ForDataTable.WhenFiltering.WithASingleFilter do
|
|
107
|
+
use ExUnit.Case, async: true
|
|
108
|
+
|
|
109
|
+
alias Prism.Access.Components.DataTable.ForDataTable.Given.People
|
|
110
|
+
import People, only: [names: 1, table: 1]
|
|
111
|
+
...
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
A context that needs a compiled module (a `Case` with `setup`, an in-memory stand-in) is a `test/support/*.ex`
|
|
115
|
+
module that the spec `use`s, like `Prism.Access.Case` in a Cratis application: it starts the in-memory
|
|
116
|
+
Chronicle kernel and gives `exec/3`, `facts/2` and the stand-ins.
|
|
117
|
+
|
|
118
|
+
## What to specify, by kind
|
|
119
|
+
|
|
120
|
+
| Kind | Run it through | Assert |
|
|
121
|
+
|---|---|---|
|
|
122
|
+
| Command | the real pipeline (`Cratis.Arc.Test.execute/3`, in-memory Chronicle) | result, events appended (types and data), what the integration was asked |
|
|
123
|
+
| Reactor / automation | the real reactor against the in-memory kernel | the command it ran, the event that records the outcome |
|
|
124
|
+
| Read model, projection | the events folded (`State`, projection function) | the document, never `Process.sleep` |
|
|
125
|
+
| Pure function | a direct call | return values; one file per rule |
|
|
126
|
+
| LiveView / component | `Phoenix.LiveViewTest` (`render_component/2`, `live/2`) | the markup that matters: structure, state classes, the events wired, not every attribute |
|
|
127
|
+
|
|
128
|
+
The in-memory Chronicle kernel does not run read-model queries; specs that need them use the development kernel
|
|
129
|
+
and say so in the file.
|
|
130
|
+
|
|
131
|
+
## Pitfalls
|
|
132
|
+
|
|
133
|
+
- A spec outside a `for_*` folder is **silently not run**. After adding the filter, check the count: `mix test`
|
|
134
|
+
must report at least what it did before.
|
|
135
|
+
- Do not name a spec `*_test.exs` while the filter is on: it is picked up only when it sits in a `for_*` folder.
|
|
136
|
+
- `Code.require_file` paths are relative to the spec (`__DIR__`), so moving a spec means fixing the path.
|
|
137
|
+
- Specs are scripts: aliases and imports go inside the module; the first line outside it is only for
|
|
138
|
+
`Code.require_file`.
|
|
@@ -150,4 +150,5 @@ This file is the shared base. For the concrete patterns:
|
|
|
150
150
|
- [specs.csharp.md](./specs.csharp.instructions.md) — C#: the universal `Cratis.Specifications` base + NSubstitute (both profiles; this is what framework/library specs use).
|
|
151
151
|
- [specs.scenarios.csharp.md](./specs.scenarios.csharp.instructions.md) — C# **application** profile: the in-process scenario family (`CommandScenario`, `EventScenario`, `ReadModelScenario`, `ReactorScenario`) + out-of-process Chronicle integration.
|
|
152
152
|
- [specs.typescript.md](./specs.typescript.instructions.md) — TypeScript framework-package specs (`given()` helper).
|
|
153
|
+
- [specs.elixir.md](./specs.elixir.instructions.md) — Elixir: `.exs` scripts in `for_*`/`when_*` folders with no `_test` suffix (never in a release), `should` assertions, `given/` contexts.
|
|
153
154
|
- [frontend-testing.md](./frontend-testing.instructions.md) — application frontend specs (view models, React components).
|
|
@@ -15,6 +15,8 @@ A vertical slice owns a single behavior: the command or query, the events it pro
|
|
|
15
15
|
|
|
16
16
|
This file is the reference for *what* goes in each part of a slice. Layout, slice types, workflow, and quality gates are in [general.md](../../../rules/general.md).
|
|
17
17
|
|
|
18
|
+
**In an application split into module projects**, a slice lives in the module that owns its behavior and uses another module only through that module's `.Contracts` project (an interface to ask, a public event to be told), never its commands, read models or project. Never add `InternalsVisibleTo` or compile a file into another project to make it build; [application-anatomy.md](./application-anatomy.instructions.md) has the layers and why a namespace is an identity.
|
|
19
|
+
|
|
18
20
|
**Model-first check.** Before changing a slice, look for it in the accepted `.play` model under the model root (opted in per `general.md` "Model first"; where `cratis-screenplay-modeling-lifecycle` is installed, run its `scripts/model-first-status.mjs` for the decision, root and drafts). If an accepted model covers it, change the model and render or gap-fill from it; never edit Stage-managed files. See Phase 0 in [application-profile.md](./application-profile.instructions.md).
|
|
19
21
|
|
|
20
22
|
## Technical stack
|
|
@@ -90,7 +92,7 @@ The command carries input from the caller. `Handle()` is defined directly on the
|
|
|
90
92
|
| Command-input / cross-field / pre-handler rule (incl. injected read-model/service/identity checks) | `CommandValidator<TCommand>` with `RuleFor(...)` |
|
|
91
93
|
| Handler needs fetched/computed data before it can build the event | `Provide()` — acquires inputs; only short-circuits when acquisition yields nothing usable. Validators own refusals |
|
|
92
94
|
| State-dependent rule that must hold **under concurrency** | Read protection `On`: the read model as a `CommandValidator<T>` constructor (or `Handle()`) parameter; a per-stream read model or `IStreamReads`/`StreamDecision` for one stream; an aggregate for a rich lifecycle. `[ProtectedDecision]` + `DecisionRead<T>` is the older per-command opt-in. Under `Off` (set explicitly, or the Arc 22 behavior) injection is a hint |
|
|
93
|
-
| Uniqueness | Chronicle `[Unique]` / `IConstraint` (race-safe) —
|
|
95
|
+
| Uniqueness (a value used once, a fact once per stream) | Chronicle `[Unique]` / `IConstraint` (race-safe) — **never** a read-model pre-check or a state read in `Provide()`/`Handle()`, which races and says nothing the kernel enforces. Elixir: `unique/2`, `unique_event_type/1` or a standalone `Constraint` module |
|
|
94
96
|
| Genuinely exceptional failure (bug, missing infra) | `throw` a domain exception |
|
|
95
97
|
|
|
96
98
|
**Do not throw for normal business rejection.** A thrown exception (from `Provide()` or `Handle()`) surfaces as an exception/HTTP 500, *not* a validation result. Recoverable, user-facing rejections are validation: `ValidationResult.Error(...)` via a validator or `Result<,>`. (For step-by-step business-rule placement, invoke the **cratis-arc-command-validation** skill.)
|
|
@@ -294,6 +296,10 @@ public record Author(AuthorId Id, AuthorName Name)
|
|
|
294
296
|
}
|
|
295
297
|
```
|
|
296
298
|
|
|
299
|
+
**[convention] Projections over reducers.** A read model is built by a **projection** by default (model-bound attributes, then fluent `IProjectionFor<T>`; in Elixir the `Cratis.Chronicle.Projections` DSL). Reach for a **reducer** only when a projection cannot express the transition (branching on prior state, calculations, guards) and say why in the read model's doc. A projection is declarative, so the kernel can replay, optimize and diagram it; a reducer is code you own and run.
|
|
300
|
+
|
|
301
|
+
**[convention] A read model owns its artifacts.** The read model, its projection (or, by exception, reducer) and its queries live together, in the slice folder of the read model and in one file named for it, not in files named for their technical function (`Queries`, `Reducer`, `Projection`). In Elixir that is one file with the read model's module containing its projection/reducer and its queries as nested modules, the way a command and its events share a file.
|
|
302
|
+
|
|
297
303
|
**[convention] No default values on `[ReadModel]` constructor parameters** — omit `= null`, `= default`, `= default!`, `= 0`, `= false`, `= ""`, `= []`. Chronicle writes the projected value on the first event, so a sentinel default is never correct and hides missing projection wiring. The only permitted defaults are enum variants that represent an explicit initial state and `[SetValue<T>]`-driven `bool` flags. Use `T?` for data genuinely absent before the relevant event fires.
|
|
298
304
|
|
|
299
305
|
**[convention] Read-model boundaries & naming.** Read models are shaped for consumers and command policies, not CRUD-style aggregate DTOs. Split one when it starts mixing unrelated lifecycles — the test is coupling (state that changes for different reasons), not size. The event log is already the canonical history/audit trail, so name a model `AuditLog`/`ActivityLog` only when it genuinely is an audit surface; for curated UI projections prefer names like `Timeline`, `WorkSurface`, `Summary`, `Detail`, or `Policy`. (This is "specialization over reuse" applied to read models.)
|
|
@@ -449,6 +455,7 @@ Frontend commands run through the Cratis dialogs — never a vendor or hand-roll
|
|
|
449
455
|
## See also
|
|
450
456
|
|
|
451
457
|
- [general.md](../../../rules/general.md) — layout, slice types, workflow, quality gates.
|
|
458
|
+
- [application-anatomy.md](./application-anatomy.instructions.md) — how the source tree grows from one project to modules and contracts; the slice stays the unit.
|
|
452
459
|
- [concepts.md](./concepts.instructions.md) — `ConceptAs<T>` / `EventSourceId<T>` full patterns.
|
|
453
460
|
- [reactors.md](./reactors.instructions.md) — reactor signatures and side-effect rules.
|
|
454
461
|
- [specs.md](./specs.instructions.md) — `CommandScenario` / `EventScenario` / `ReadModelScenario` / `ReactorScenario`.
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
---
|
|
2
|
+
applyTo: "**/*.csproj,**/*.slnx,**/Directory.Build.props,**/Directory.Build.targets,**/Directory.Packages.props,**/package.json,**/tsconfig*.json"
|
|
3
|
+
profile: application
|
|
4
|
+
paths:
|
|
5
|
+
- "**/*.csproj"
|
|
6
|
+
- "**/*.slnx"
|
|
7
|
+
- "**/Directory.Build.props"
|
|
8
|
+
- "**/Directory.Build.targets"
|
|
9
|
+
- "**/Directory.Packages.props"
|
|
10
|
+
- "**/package.json"
|
|
11
|
+
- "**/tsconfig*.json"
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
<!-- Copyright (c) Cratis. All rights reserved. -->
|
|
15
|
+
<!-- Licensed under the MIT license. See LICENSE file in the project root for full license information. -->
|
|
16
|
+
|
|
17
|
+
# Application anatomy for growing systems
|
|
18
|
+
|
|
19
|
+
> **Application profile.** This is how the source tree of an application built on Cratis is shaped as it grows. It does **not** apply inside a Cratis framework repository (see [framework.md](./framework.md)). What goes in one behavior folder is [vertical-slices.md](./vertical-slices.md); the procedure for a move or a rename is the **cratis-application-growth** skill.
|
|
20
|
+
|
|
21
|
+
Lines are **[convention]** (house default; the framework does not check it) unless tagged **[contract]** (Arc, Chronicle or Fundamentals behave this way). Conventions hold only when the repository's own architecture gates enforce them; see *Gates* below.
|
|
22
|
+
|
|
23
|
+
An application's anatomy is a **path, not a choice made once.** Start at the smallest stage the product needs and grow when a signal says so. Skipping a stage is fine; building a later stage's structure before its signal appears is not.
|
|
24
|
+
|
|
25
|
+
## Words used here
|
|
26
|
+
|
|
27
|
+
- **Module**: one business capability (for example Billing or Support) with its own backend, frontend and specs.
|
|
28
|
+
- **Host**: the one project that composes and runs everything. Nothing references it.
|
|
29
|
+
- **Platform project**: code several modules need, or that no module owns. It never names a module.
|
|
30
|
+
- **Engine**: a platform project that holds reusable behavior with its own events and read models (a rules engine, a work queue). Modules plug into it; it knows no module.
|
|
31
|
+
- **Contracts project** (`<Module>.Contracts`): what a module lets others use: public events, grain or service interfaces, and the concepts they carry. No logic.
|
|
32
|
+
- **Seam**: a file that lives in one project's folder but is compiled into another project (a `<Compile Include="../Other/**" />`). It hides a dependency the project graph would reject.
|
|
33
|
+
|
|
34
|
+
## The stages
|
|
35
|
+
|
|
36
|
+
| Stage | Shape | What it buys |
|
|
37
|
+
| --- | --- | --- |
|
|
38
|
+
| **1. One project** | One backend project and one frontend package; behaviors are `<Feature>/<Slice>/` folders. | Least ceremony; one build; cohesive slices. |
|
|
39
|
+
| **2. Modules in one project** | Features grouped under named top-level folders (`<Module>/<Feature>/<Slice>/`), still one backend project. | Names the capability boundaries before paying for project boundaries. |
|
|
40
|
+
| **3. Module projects on a platform** | Each module is its own backend project and frontend package, composed by the host, on platform projects. | The compiler enforces boundaries: a module cannot use what it does not reference. |
|
|
41
|
+
| **4. Modules publish contracts** | A module others need exposes `<Module>.Contracts`. No module references another module's project. | Modules change and are owned independently. |
|
|
42
|
+
|
|
43
|
+
Separately deployed services are a further step; see **cratis-multi-service-architecture**.
|
|
44
|
+
|
|
45
|
+
## When to move up
|
|
46
|
+
|
|
47
|
+
Move when a signal is present *now*, not when it is imaginable:
|
|
48
|
+
|
|
49
|
+
- **1 → 2:** people name a group of features as a capability; features share vocabulary no other feature uses; navigation, settings or access group by capability.
|
|
50
|
+
- **2 → 3:** a module needs separate build, specs or ownership; code reaches into another module's internals and the folder rule alone is not holding; a capability is gated by entitlement or audience and must be provably absent for others.
|
|
51
|
+
- **3 → 4:** one module needs to ask another a question or react to its events. Add the contract at the first such need.
|
|
52
|
+
|
|
53
|
+
**Start at stage 2 or 3** when the shape is already known: several teams, clearly separate capabilities, entitlement or audience gating, or a product line that will gain modules. A prototype, a single-purpose service or one team with one capability starts at stage 1.
|
|
54
|
+
|
|
55
|
+
## The layers and what may reference what (stages 3 and 4)
|
|
56
|
+
|
|
57
|
+
| Layer | Examples | May reference |
|
|
58
|
+
| --- | --- | --- |
|
|
59
|
+
| Host | `Core` or `Host` | everything below; composes modules, integrations and engines |
|
|
60
|
+
| Modules | `Billing`, `Support` | other modules' `.Contracts`, engines' `.Contracts`, platform, Infrastructure, Components |
|
|
61
|
+
| Integration providers | `Integration.GitHub` | the `Integration` base and module `.Contracts` (ports) only |
|
|
62
|
+
| Engines and platform | `Notifications`, `Search`, `Integration`, `Mcp` | other platform `.Contracts`, Infrastructure, Components |
|
|
63
|
+
| Contracts | `Billing.Contracts`, `Tenancy.Contracts` | Infrastructure and other contracts only |
|
|
64
|
+
| Foundations | `Infrastructure`, `Components` | framework packages only; no domain concept, no module |
|
|
65
|
+
|
|
66
|
+
**References point down only.** If code compiles only with a reference that points up or sideways, the code is in the wrong project or the dependency must become a contract.
|
|
67
|
+
|
|
68
|
+
## Invariants at every stage
|
|
69
|
+
|
|
70
|
+
1. **Vertical slices.** The slice (command, events, projection, component, specs) is the unit at every stage. A stage changes what *groups* slices, never what a slice is. Never split by artifact type.
|
|
71
|
+
2. **No `InternalsVisibleTo`, no seams.** Both make a project boundary a folder name and nothing else. Code that needs either belongs in a lower project, or its dependency becomes a contract.
|
|
72
|
+
3. **No catch-all project.** A project named for its position rather than its purpose (`Global`, `Shared`, `Common`, `Base`) grows until it depends on the modules that depend on it. Every platform project has one purpose that its name states; a stage-1 `Common/` folder of concepts is fine.
|
|
73
|
+
4. **Every folder under the source root is a project or package with a `README.md`.** No loose code folders, no umbrella folders. The README states only what the code shows (template below).
|
|
74
|
+
5. **Specs live with their code** and are left out of analyzers and Release output by one shared pattern; see [fast-feedback.md](./fast-feedback.md).
|
|
75
|
+
6. **Namespaces follow projects and folders:** `<Company>.<Product>.<Project>.<folder path>`, so a namespace tells which project owns a type. That is the end state; while code is moving, namespaces stay put (see the next section). Project folders carry no product prefix (`Source/Billing`, not `Source/MyProduct.Billing`); the prefix lives in the root namespace, set once in `Directory.Build.props`.
|
|
76
|
+
7. **A namespace or assembly name is an identity, not a label.** See the next section before renaming either.
|
|
77
|
+
8. **Access is declared, never derived from a name.** Authorization, audience and admin-only rules sit on the code (an attribute, a policy, an assembly marker), never on a namespace prefix or folder; otherwise a rename silently changes who may read what.
|
|
78
|
+
|
|
79
|
+
## What a rename changes **[contract]**
|
|
80
|
+
|
|
81
|
+
| Identity | Derived from | Can it be pinned? |
|
|
82
|
+
| --- | --- | --- |
|
|
83
|
+
| Chronicle event type id | the type's **simple name** (namespace-independent) | yes: `[EventType("id")]` |
|
|
84
|
+
| Reactor, reducer and projection ids | the type's **full name** | yes: an explicit id on the attribute |
|
|
85
|
+
| Read model identifier | the type's **full name** | no: stored identifiers are rewritten, or the read model rebuilds |
|
|
86
|
+
| Arc model-bound command and query routes | the **namespace** (minus `SegmentsToSkipForRoute`) | no: every caller and proxy follows the new route |
|
|
87
|
+
| Generated proxy folders | the **namespace** (minus `CratisProxiesSegmentsToSkip`) | no |
|
|
88
|
+
| Stored grain state type names and job type names | full type names; job names are assembly-qualified | keep `AssemblyName` when a project is renamed; retire old names deliberately |
|
|
89
|
+
| Anything your code keys on a name | authorization prefixes, OpenAPI filters, build strip lists, settings keys | replace with explicit declarations first |
|
|
90
|
+
|
|
91
|
+
Consequences:
|
|
92
|
+
|
|
93
|
+
- **Moving a file is free; renaming its namespace is a migration.** While the structure moves, keep namespaces and assembly names, and record every folder whose namespace no longer matches in an allowlist that only shrinks. One exception: a job type that moves to another assembly changes its assembly-qualified stored name, so rewrite the stored names (or keep a type forwarder in the old assembly) in the same release.
|
|
94
|
+
- **Rename namespaces once, in one window**, with a repair that rewrites the stored identities (observer ids, read model identifiers, grain and job type names) before the new version starts. Without it every observer registers under a new id and replays from the first event: projections rebuild and reactors act on history again. Chronicle's `ArtifactIdentityDrift` setting reports likely renames; it does not repair them.
|
|
95
|
+
- **Event types:** an explicit id or an unchanged class name keeps the identity across any namespace change. Changing an event deliberately is **cratis-chronicle-event-type-migration**; removing a project removes its event types, which is also an event-store change.
|
|
96
|
+
|
|
97
|
+
## Module anatomy (stages 3 and 4)
|
|
98
|
+
|
|
99
|
+
- **One module declaration.** A single type (for example an `IModule` implementation) states the module's key, display name and **audience** (everyone, an entitled subset, internal). The key is an identity; keep it when the module's name changes.
|
|
100
|
+
- **One backend project and one frontend package** per module, plus `<Module>.Contracts` when others need it.
|
|
101
|
+
- **The module contributes its surfaces by convention:** routes, navigation, settings sections, tools for an MCP server, API endpoints, rule packs. The base that hosts a surface discovers contributions (through `IInstancesOf<>` or the equivalent) and never names a module; no central route table or menu list.
|
|
102
|
+
- **Audience and entitlement are enforced on the server** (commands and queries), not only by hiding navigation.
|
|
103
|
+
- **Ask through an interface, be told through an event.** A question or request is a grain or service interface in the owner's contracts; "tell me when" is a public event. A module never uses another module's commands, read models, reactors or internal concepts.
|
|
104
|
+
- **Ports for providers.** When a module needs something an external provider supplies, the module defines the port in its contracts and each provider project implements it. A module never names a provider; adding a provider is adding a project.
|
|
105
|
+
- **Frontend boundaries mirror the backend:** a package imports another module's package only through its public entry point (no deep paths), never in both directions, and the shared components package imports no module. Each backend project generates its proxies into its own package and maps referenced projects with `AssemblyToPackageMapping`, so a type is generated by its owner only.
|
|
106
|
+
- **Wiring is by convention:** the default `IFoo` → `Foo` binding and lifetime attributes. **[contract]** The convention binds only when the interface and its single implementation share a namespace, and it fills only service types nobody registered. An interface in `<Module>.Contracts` with its implementation in the module therefore needs an explicit (or generated) registration, applied after the explicit ones.
|
|
107
|
+
|
|
108
|
+
### README template
|
|
109
|
+
|
|
110
|
+
```markdown
|
|
111
|
+
# <Project or package>
|
|
112
|
+
|
|
113
|
+
<One paragraph: what it is for and who uses it.>
|
|
114
|
+
|
|
115
|
+
## Owns
|
|
116
|
+
- Namespaces and, for a module: its key and audience.
|
|
117
|
+
|
|
118
|
+
## Exposes
|
|
119
|
+
- Contracts, routes, settings sections and other contributions others may rely on.
|
|
120
|
+
|
|
121
|
+
## Depends on
|
|
122
|
+
- Project references and packages it imports, and why.
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## Gates
|
|
126
|
+
|
|
127
|
+
Prose does not hold a boundary; gates do. Write them as ordinary specs that read the project files and sources, so they run in the normal spec pass in seconds:
|
|
128
|
+
|
|
129
|
+
- no `InternalsVisibleTo` and no seam (no `Compile Include` reaching outside the project folder);
|
|
130
|
+
- only the host references a module project; nothing references the host;
|
|
131
|
+
- platform and Infrastructure name no module and no domain concept; a module names no integration provider;
|
|
132
|
+
- every source folder has a project or package and a `README.md`;
|
|
133
|
+
- namespace matches folder, except allowlisted entries;
|
|
134
|
+
- frontend: no two-way package imports, no deep imports past a package's entry point, the components package imports no module (an ESLint rule).
|
|
135
|
+
|
|
136
|
+
Each gate compares against a committed baseline that **only shrinks**. A change that removes coupling shrinks the baseline in the same commit; a change that grows it fails. Never raise a baseline to land a change. Count dependencies from project files or compiled assemblies, not `using` lines.
|
|
137
|
+
|
|
138
|
+
## See also
|
|
139
|
+
|
|
140
|
+
- **cratis-application-growth**: the procedure for each move and for the rename window.
|
|
141
|
+
- [vertical-slices.md](./vertical-slices.md), [application-profile.md](./application-profile.md), [react.md](./react.md), [components.md](./components.md).
|
|
142
|
+
- **cratis-multi-service-architecture**: when modules become separately deployed services.
|
|
@@ -23,7 +23,7 @@ profile: application
|
|
|
23
23
|
|
|
24
24
|
## Project Layout (Cratis Application convention)
|
|
25
25
|
|
|
26
|
-
The framework discovers commands and read models by attributes and static methods — **the folder shape is a convention, not a requirement.** The house default: the domain hierarchy lives directly under the app source root (**no top-level `Features/` wrapper**), cross-cutting concerns (`Common/` concepts, `Identity/`, shared components) at the top level, and one folder per behavior — `<Module>/<Feature>/<Slice>/` holding `<Slice>.cs`, the slice's `.tsx`, and its `when_*/` specs. **The slice is the invariant unit** — created, renamed, and deleted as one. Namespace mirrors the path under the source root, dropping any level that isn't present. The full tree and the split rules are in [vertical-slices.md](./vertical-slices.md).
|
|
26
|
+
The framework discovers commands and read models by attributes and static methods — **the folder shape is a convention, not a requirement.** The house default: the domain hierarchy lives directly under the app source root (**no top-level `Features/` wrapper**), cross-cutting concerns (`Common/` concepts, `Identity/`, shared components) at the top level, and one folder per behavior — `<Module>/<Feature>/<Slice>/` holding `<Slice>.cs`, the slice's `.tsx`, and its `when_*/` specs. **The slice is the invariant unit** — created, renamed, and deleted as one. Namespace mirrors the path under the source root, dropping any level that isn't present; once modules are their own projects it is `<Company>.<Product>.<Project>.<folder path>`, and renaming a namespace changes stored identities and routes (see [application-anatomy.md](./application-anatomy.md)). The full tree and the split rules are in [vertical-slices.md](./vertical-slices.md).
|
|
27
27
|
|
|
28
28
|
## Slice Types
|
|
29
29
|
|
|
@@ -103,6 +103,11 @@ Read the **cratis-arc-elixir** and **cratis-chronicle-client-elixir** skills bef
|
|
|
103
103
|
- **Third parties are integrations behind a behaviour**, with an in-memory stand-in for specs; only
|
|
104
104
|
reactors write to them.
|
|
105
105
|
|
|
106
|
+
Specs follow [specs.elixir.md](./specs.elixir.md): scripts in `for_*`/`when_*` folders beside the code, no
|
|
107
|
+
`_test` suffix, `should` assertions. Build read models with a projection, not a reducer, unless a projection
|
|
108
|
+
cannot express the transition, and enforce uniqueness with a Chronicle constraint, not a read before the append
|
|
109
|
+
(see the **cratis-arc-elixir** and **cratis-chronicle-client-elixir** skills).
|
|
110
|
+
|
|
106
111
|
Every `.ex` and `.exs` source file starts with:
|
|
107
112
|
|
|
108
113
|
```elixir
|
|
@@ -35,7 +35,7 @@ When these instructions don't cover a situation, apply these values to make the
|
|
|
35
35
|
Every rule below is one of three kinds — know which, because they carry different weight:
|
|
36
36
|
|
|
37
37
|
- **Framework contract** — enforced by Arc/Chronicle source, analyzers, or runtime. Violating it breaks the build or behaves wrongly. (e.g. `[Command]` needs a public instance `Handle()`; model-bound queries are static methods on `[ReadModel]`; nullable event properties raise a Chronicle analyzer warning.)
|
|
38
|
-
- **Cratis Application convention** — the house default for maintainability and consistent generated code. The framework does **not** enforce it, but follow it for consistency. (e.g.
|
|
38
|
+
- **Cratis Application convention** — the house default for maintainability and consistent generated code. The framework does **not** enforce it, but follow it for consistency. (e.g. slice folder shape, declaration order.)
|
|
39
39
|
- **Product policy** — belongs in a downstream app's own `.cratis/ai/`, not this generic corpus. (e.g. specific roles, locales, design systems.)
|
|
40
40
|
|
|
41
41
|
Where a rule is convention rather than contract, this file says so. Do not claim "the framework requires this" for a convention.
|
|
@@ -126,7 +126,7 @@ Verify claims with build, spec, lint or observed-behavior signals, not confidenc
|
|
|
126
126
|
| --- | --- |
|
|
127
127
|
| Corpus profiles and configuration | `profiles.md` |
|
|
128
128
|
| **Contributing to a Cratis framework repo** (framework profile) | `framework.md`; creating a repository in the Cratis organization: `new-repository-intake.md` |
|
|
129
|
-
| Slice anatomy (commands, `Provide()`, validators, events, projections, read models, reactors, constraints, compliance, cross-slice) | `vertical-slices.md` |
|
|
129
|
+
| Slice anatomy (commands, `Provide()`, validators, events, projections, read models, reactors, constraints, compliance, cross-slice) | `vertical-slices.md`; modules, renames: `application-anatomy.md` |
|
|
130
130
|
| C# / TypeScript style and code-quality principles | `csharp.md`, `typescript.md`, `code-quality.md`, `code-quality.csharp.md`, `code-quality.typescript.md` |
|
|
131
131
|
| Kotlin / Java / Elixir style; Orleans grains; reactors; GitHub Actions workflows | `kotlin.md`, `java.md`, `elixir.md`, `orleans.md`, `reactors.md`, `github-actions.md` |
|
|
132
132
|
| Documentation structure, voice and examples | `documentation.md`, `documentation-structure-and-formatting.md`, `writing-cratis-docs.md`, `editing-cratis-docs.md`, `writing-correct-examples.md` |
|
|
@@ -134,7 +134,7 @@ Verify claims with build, spec, lint or observed-behavior signals, not confidenc
|
|
|
134
134
|
| Go | `go.md`; framework: `go-engineering.md`; product APIs: `cratis-chronicle-client-go`, `cratis-arc-go` and `cratis-fundamentals-concept-go` |
|
|
135
135
|
| React + Arc + Cratis Components + MVVM + dialogs | `react.md`, `components.md`, `dialogs.md` |
|
|
136
136
|
| Frontend engineering quality & testing | `frontend-quality.md`, `frontend-testing.md`, `storybook.md` |
|
|
137
|
-
| Spec patterns — universal `Specification` base (both profiles) | `specs.md`, `specs.csharp.md`, `specs.typescript.md` |
|
|
137
|
+
| Spec patterns — universal `Specification` base (both profiles) | `specs.md`, `specs.csharp.md`, `specs.typescript.md`, `specs.elixir.md` |
|
|
138
138
|
| Build and spec-run speed: parallel-safe specs, no per-spec startup, cheap analyzers | `fast-feedback.md` |
|
|
139
139
|
| Spec patterns — the four `*Scenario` helpers (application only) | `specs.scenarios.csharp.md` |
|
|
140
140
|
| Strongly-typed values (`ConceptAs<T>`, `EventSourceId<T>`); shared term definitions (event, projection, reducer, reactor, observer, DCB, …) | `concepts.md`; `glossary.md` |
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
---
|
|
2
|
+
applyTo: "**/for_*/**/*.exs, **/when_*/**/*.exs"
|
|
3
|
+
paths:
|
|
4
|
+
- "**/for_*/**/*.exs"
|
|
5
|
+
- "**/when_*/**/*.exs"
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
<!-- Copyright (c) Cratis. All rights reserved. -->
|
|
9
|
+
<!-- Licensed under the MIT license. See LICENSE file in the project root for full license information. -->
|
|
10
|
+
|
|
11
|
+
# How to Write Elixir Specs
|
|
12
|
+
|
|
13
|
+
Extends the base [specs.md](./specs.md) with Elixir conventions. The philosophy is the same: a spec
|
|
14
|
+
describes a **behavior** in the language of the domain, the folder tree reads as a sentence, and one
|
|
15
|
+
scenario lives in one file. ExUnit is the runner; nothing else is needed.
|
|
16
|
+
|
|
17
|
+
## Specs are scripts beside the code, never in a release
|
|
18
|
+
|
|
19
|
+
A spec is an `.exs` file (a script). `mix compile` and `mix release` only ever build `.ex` files, so a spec
|
|
20
|
+
beside the code it specifies is **never part of a release**, the same outcome the C# build gets by removing
|
|
21
|
+
`when_*` files from Release builds and the TypeScript build gets by not importing them. Do not rename specs
|
|
22
|
+
to `.ex`. Shared helpers that must be compiled (a `Case` module) live in `test/support/*.ex`, which only the
|
|
23
|
+
`:test` environment adds to `elixirc_paths`.
|
|
24
|
+
|
|
25
|
+
**No `_test` suffix.** ExUnit's default pattern is `*_test.exs`, but the folder already says it is a spec
|
|
26
|
+
(`for_*`/`when_*`), exactly as in C# and TypeScript. Point `mix test` at the folders instead:
|
|
27
|
+
|
|
28
|
+
```elixir
|
|
29
|
+
# mix.exs: project/0
|
|
30
|
+
elixirc_paths: elixirc_paths(Mix.env()),
|
|
31
|
+
test_paths: ["lib"],
|
|
32
|
+
# A spec is any script in a `for_*` folder; `given/` holds shared contexts, which specs load themselves.
|
|
33
|
+
test_load_filters: [&(String.contains?(&1, "/for_") and not String.contains?(&1, "/given/"))],
|
|
34
|
+
|
|
35
|
+
defp elixirc_paths(:test), do: ["lib", "test/support"]
|
|
36
|
+
defp elixirc_paths(_env), do: ["lib"]
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
`test_load_filters` **replaces** the default `test_pattern`; do not set both. `test_helper.exs` (`ExUnit.start()`)
|
|
40
|
+
stays beside the specs, in the first of `test_paths`. Let `mix format` cover the scripts
|
|
41
|
+
(`inputs: ["{config,lib,test}/**/*.{ex,exs}"]`).
|
|
42
|
+
|
|
43
|
+
## Folder and file structure
|
|
44
|
+
|
|
45
|
+
```
|
|
46
|
+
<feature or slice>/
|
|
47
|
+
└── for_<unit>/ ← "For the unit..."
|
|
48
|
+
├── given/
|
|
49
|
+
│ └── a_<context>.exs ← shared context, loaded by the specs that need it (not a spec)
|
|
50
|
+
├── when_<behavior>/ ← "...when doing this..." (a folder when there are several outcomes)
|
|
51
|
+
│ ├── and_<condition>.exs ← one scenario per file
|
|
52
|
+
│ ├── with_<data>.exs
|
|
53
|
+
│ └── without_<requirement>.exs
|
|
54
|
+
└── when_<simple_behavior>.exs ← a single file for a single scenario
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
The unit is the module, command, read model, component or function under specification:
|
|
58
|
+
`for_rotate_secret`, `for_data_table`, `for_patterns`. Use the prepositions and the rules of
|
|
59
|
+
[specs.md](./specs.md) (`and_`, `with_`, `without_`, `having_`, `given_`), including: **never put `when` in a
|
|
60
|
+
file or non-`when_` folder name** (`and_ory_fails.exs`, not `when_ory_fails.exs`, under `when_adding/`).
|
|
61
|
+
|
|
62
|
+
Folder names are `snake_case`. A spec's **module name mirrors its path** below the application's namespace,
|
|
63
|
+
`PascalCase`, so it can never clash with the module it specifies and is never named `...Test`:
|
|
64
|
+
|
|
65
|
+
```elixir
|
|
66
|
+
# lib/access/credentials/adding_credentials/for_add_credential/when_adding/with_selected_vessels.exs
|
|
67
|
+
defmodule Prism.Access.Credentials.AddingCredentials.ForAddCredential.WhenAdding.WithSelectedVessels do
|
|
68
|
+
use ExUnit.Case, async: true
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## One scenario, several `should` assertions
|
|
72
|
+
|
|
73
|
+
The `setup` establishes the context and performs the behavior once per assertion (ExUnit runs `setup` for each
|
|
74
|
+
`test`); each `test` states one expectation and starts with **`should`**, so the file reads as a sentence:
|
|
75
|
+
|
|
76
|
+
```elixir
|
|
77
|
+
defmodule Prism.Access.ApiCredentials.ForState.WhenDerivingTheStatus do
|
|
78
|
+
use ExUnit.Case, async: true
|
|
79
|
+
|
|
80
|
+
alias Prism.Access.ApiCredentials.State
|
|
81
|
+
|
|
82
|
+
test "should be active by default" do
|
|
83
|
+
assert State.status(%State{id: "c", exists?: true}, ~U[2026-03-01 12:00:00Z]) == :active
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
- `test "should refuse a duplicate label"`, not `test "a duplicate label is refused"` and not
|
|
89
|
+
`test "refuses..."`. Name the expected result, not the call.
|
|
90
|
+
- A file with several unrelated scenarios is several files. Split `describe` blocks into
|
|
91
|
+
`when_<behavior>/<preposition>_<condition>.exs` files; do not use `describe` to group scenarios.
|
|
92
|
+
- Assert on the **contract**: the result, the events appended, what a collaborator was asked to do. Do not
|
|
93
|
+
assert on internals, and do not spec logging or trivial delegation.
|
|
94
|
+
- `doctest Module` belongs in its own spec (`when_building/with_the_documented_examples.exs`).
|
|
95
|
+
|
|
96
|
+
## Shared context: `given/`
|
|
97
|
+
|
|
98
|
+
Contexts that several specs share (a table of people, a started kernel) go in `for_<unit>/given/<name>.exs`
|
|
99
|
+
as a module, and a spec loads it by relative path. The filter above keeps `given/` out of the specs ExUnit
|
|
100
|
+
runs, so it is loaded once, by the spec that needs it:
|
|
101
|
+
|
|
102
|
+
```elixir
|
|
103
|
+
Code.require_file("../given/people.exs", __DIR__)
|
|
104
|
+
|
|
105
|
+
defmodule Prism.Access.Components.DataTable.ForDataTable.WhenFiltering.WithASingleFilter do
|
|
106
|
+
use ExUnit.Case, async: true
|
|
107
|
+
|
|
108
|
+
alias Prism.Access.Components.DataTable.ForDataTable.Given.People
|
|
109
|
+
import People, only: [names: 1, table: 1]
|
|
110
|
+
...
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
A context that needs a compiled module (a `Case` with `setup`, an in-memory stand-in) is a `test/support/*.ex`
|
|
114
|
+
module that the spec `use`s, like `Prism.Access.Case` in a Cratis application: it starts the in-memory
|
|
115
|
+
Chronicle kernel and gives `exec/3`, `facts/2` and the stand-ins.
|
|
116
|
+
|
|
117
|
+
## What to specify, by kind
|
|
118
|
+
|
|
119
|
+
| Kind | Run it through | Assert |
|
|
120
|
+
|---|---|---|
|
|
121
|
+
| Command | the real pipeline (`Cratis.Arc.Test.execute/3`, in-memory Chronicle) | result, events appended (types and data), what the integration was asked |
|
|
122
|
+
| Reactor / automation | the real reactor against the in-memory kernel | the command it ran, the event that records the outcome |
|
|
123
|
+
| Read model, projection | the events folded (`State`, projection function) | the document, never `Process.sleep` |
|
|
124
|
+
| Pure function | a direct call | return values; one file per rule |
|
|
125
|
+
| LiveView / component | `Phoenix.LiveViewTest` (`render_component/2`, `live/2`) | the markup that matters: structure, state classes, the events wired, not every attribute |
|
|
126
|
+
|
|
127
|
+
The in-memory Chronicle kernel does not run read-model queries; specs that need them use the development kernel
|
|
128
|
+
and say so in the file.
|
|
129
|
+
|
|
130
|
+
## Pitfalls
|
|
131
|
+
|
|
132
|
+
- A spec outside a `for_*` folder is **silently not run**. After adding the filter, check the count: `mix test`
|
|
133
|
+
must report at least what it did before.
|
|
134
|
+
- Do not name a spec `*_test.exs` while the filter is on: it is picked up only when it sits in a `for_*` folder.
|
|
135
|
+
- `Code.require_file` paths are relative to the spec (`__DIR__`), so moving a spec means fixing the path.
|
|
136
|
+
- Specs are scripts: aliases and imports go inside the module; the first line outside it is only for
|
|
137
|
+
`Code.require_file`.
|
|
@@ -149,4 +149,5 @@ This file is the shared base. For the concrete patterns:
|
|
|
149
149
|
- [specs.csharp.md](./specs.csharp.md) — C#: the universal `Cratis.Specifications` base + NSubstitute (both profiles; this is what framework/library specs use).
|
|
150
150
|
- [specs.scenarios.csharp.md](./specs.scenarios.csharp.md) — C# **application** profile: the in-process scenario family (`CommandScenario`, `EventScenario`, `ReadModelScenario`, `ReactorScenario`) + out-of-process Chronicle integration.
|
|
151
151
|
- [specs.typescript.md](./specs.typescript.md) — TypeScript framework-package specs (`given()` helper).
|
|
152
|
+
- [specs.elixir.md](./specs.elixir.md) — Elixir: `.exs` scripts in `for_*`/`when_*` folders with no `_test` suffix (never in a release), `should` assertions, `given/` contexts.
|
|
152
153
|
- [frontend-testing.md](./frontend-testing.md) — application frontend specs (view models, React components).
|
|
@@ -14,6 +14,8 @@ A vertical slice owns a single behavior: the command or query, the events it pro
|
|
|
14
14
|
|
|
15
15
|
This file is the reference for *what* goes in each part of a slice. Layout, slice types, workflow, and quality gates are in [general.md](./general.md).
|
|
16
16
|
|
|
17
|
+
**In an application split into module projects**, a slice lives in the module that owns its behavior and uses another module only through that module's `.Contracts` project (an interface to ask, a public event to be told), never its commands, read models or project. Never add `InternalsVisibleTo` or compile a file into another project to make it build; [application-anatomy.md](./application-anatomy.md) has the layers and why a namespace is an identity.
|
|
18
|
+
|
|
17
19
|
**Model-first check.** Before changing a slice, look for it in the accepted `.play` model under the model root (opted in per `general.md` "Model first"; where `cratis-screenplay-modeling-lifecycle` is installed, run its `scripts/model-first-status.mjs` for the decision, root and drafts). If an accepted model covers it, change the model and render or gap-fill from it; never edit Stage-managed files. See Phase 0 in [application-profile.md](./application-profile.md).
|
|
18
20
|
|
|
19
21
|
## Technical stack
|
|
@@ -89,7 +91,7 @@ The command carries input from the caller. `Handle()` is defined directly on the
|
|
|
89
91
|
| Command-input / cross-field / pre-handler rule (incl. injected read-model/service/identity checks) | `CommandValidator<TCommand>` with `RuleFor(...)` |
|
|
90
92
|
| Handler needs fetched/computed data before it can build the event | `Provide()` — acquires inputs; only short-circuits when acquisition yields nothing usable. Validators own refusals |
|
|
91
93
|
| State-dependent rule that must hold **under concurrency** | Read protection `On`: the read model as a `CommandValidator<T>` constructor (or `Handle()`) parameter; a per-stream read model or `IStreamReads`/`StreamDecision` for one stream; an aggregate for a rich lifecycle. `[ProtectedDecision]` + `DecisionRead<T>` is the older per-command opt-in. Under `Off` (set explicitly, or the Arc 22 behavior) injection is a hint |
|
|
92
|
-
| Uniqueness | Chronicle `[Unique]` / `IConstraint` (race-safe) —
|
|
94
|
+
| Uniqueness (a value used once, a fact once per stream) | Chronicle `[Unique]` / `IConstraint` (race-safe) — **never** a read-model pre-check or a state read in `Provide()`/`Handle()`, which races and says nothing the kernel enforces. Elixir: `unique/2`, `unique_event_type/1` or a standalone `Constraint` module |
|
|
93
95
|
| Genuinely exceptional failure (bug, missing infra) | `throw` a domain exception |
|
|
94
96
|
|
|
95
97
|
**Do not throw for normal business rejection.** A thrown exception (from `Provide()` or `Handle()`) surfaces as an exception/HTTP 500, *not* a validation result. Recoverable, user-facing rejections are validation: `ValidationResult.Error(...)` via a validator or `Result<,>`. (For step-by-step business-rule placement, invoke the **cratis-arc-command-validation** skill.)
|
|
@@ -293,6 +295,10 @@ public record Author(AuthorId Id, AuthorName Name)
|
|
|
293
295
|
}
|
|
294
296
|
```
|
|
295
297
|
|
|
298
|
+
**[convention] Projections over reducers.** A read model is built by a **projection** by default (model-bound attributes, then fluent `IProjectionFor<T>`; in Elixir the `Cratis.Chronicle.Projections` DSL). Reach for a **reducer** only when a projection cannot express the transition (branching on prior state, calculations, guards) and say why in the read model's doc. A projection is declarative, so the kernel can replay, optimize and diagram it; a reducer is code you own and run.
|
|
299
|
+
|
|
300
|
+
**[convention] A read model owns its artifacts.** The read model, its projection (or, by exception, reducer) and its queries live together, in the slice folder of the read model and in one file named for it, not in files named for their technical function (`Queries`, `Reducer`, `Projection`). In Elixir that is one file with the read model's module containing its projection/reducer and its queries as nested modules, the way a command and its events share a file.
|
|
301
|
+
|
|
296
302
|
**[convention] No default values on `[ReadModel]` constructor parameters** — omit `= null`, `= default`, `= default!`, `= 0`, `= false`, `= ""`, `= []`. Chronicle writes the projected value on the first event, so a sentinel default is never correct and hides missing projection wiring. The only permitted defaults are enum variants that represent an explicit initial state and `[SetValue<T>]`-driven `bool` flags. Use `T?` for data genuinely absent before the relevant event fires.
|
|
297
303
|
|
|
298
304
|
**[convention] Read-model boundaries & naming.** Read models are shaped for consumers and command policies, not CRUD-style aggregate DTOs. Split one when it starts mixing unrelated lifecycles — the test is coupling (state that changes for different reasons), not size. The event log is already the canonical history/audit trail, so name a model `AuditLog`/`ActivityLog` only when it genuinely is an audit surface; for curated UI projections prefer names like `Timeline`, `WorkSurface`, `Summary`, `Detail`, or `Policy`. (This is "specialization over reuse" applied to read models.)
|
|
@@ -448,6 +454,7 @@ Frontend commands run through the Cratis dialogs — never a vendor or hand-roll
|
|
|
448
454
|
## See also
|
|
449
455
|
|
|
450
456
|
- [general.md](./general.md) — layout, slice types, workflow, quality gates.
|
|
457
|
+
- [application-anatomy.md](./application-anatomy.md) — how the source tree grows from one project to modules and contracts; the slice stays the unit.
|
|
451
458
|
- [concepts.md](./concepts.md) — `ConceptAs<T>` / `EventSourceId<T>` full patterns.
|
|
452
459
|
- [reactors.md](./reactors.md) — reactor signatures and side-effect rules.
|
|
453
460
|
- [specs.md](./specs.md) — `CommandScenario` / `EventScenario` / `ReadModelScenario` / `ReactorScenario`.
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: cratis-application-growth
|
|
3
|
+
description: Use when a Cratis application's source tree must grow from one project into modules or module projects, untangle a catch-all project, rename namespaces after moves, or decide whether a new application starts modular. Not for service splits (cratis-multi-service-architecture) or one slice's contents.
|
|
4
|
+
license: MIT
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
<!-- Copyright (c) Cratis. All rights reserved. -->
|
|
8
|
+
<!-- Licensed under the MIT license. See LICENSE file in the project root for full license information. -->
|
|
9
|
+
|
|
10
|
+
# Grow an application's anatomy
|
|
11
|
+
|
|
12
|
+
The stages, layers, invariants and identity table are the rule
|
|
13
|
+
[application-anatomy.md](../../rules/application-anatomy.md); read it first. This skill is the
|
|
14
|
+
procedure. The slice stays the unit throughout ([vertical-slices.md](../../rules/vertical-slices.md)).
|
|
15
|
+
|
|
16
|
+
The order is fixed: **decide, guard, move, untangle, rename, verify.** Each phase is done when its
|
|
17
|
+
check passes; do not start the next one before.
|
|
18
|
+
|
|
19
|
+
## 1. Decide
|
|
20
|
+
|
|
21
|
+
1. Name the current stage and the signal that justifies the next, in the rule's terms. No signal, no move.
|
|
22
|
+
2. A new application starts at stage 2 or 3 only for a rule-listed reason; otherwise stage 1.
|
|
23
|
+
3. Read the accepted decision records that describe the current structure. If the target contradicts one,
|
|
24
|
+
write the superseding record first (**cratis-engineering-decision-record**); a record binds until then.
|
|
25
|
+
4. Write down the target: the modules, the platform projects (each with one stated purpose), and
|
|
26
|
+
where every existing project goes.
|
|
27
|
+
|
|
28
|
+
Done when: the target is written and no accepted record contradicts it.
|
|
29
|
+
|
|
30
|
+
## 2. Guard before moving
|
|
31
|
+
|
|
32
|
+
1. Add the architecture gates from the rule's *Gates* section as specs, in a project of their own.
|
|
33
|
+
2. Record the current numbers as committed baselines: seams, `InternalsVisibleTo` grants, references between
|
|
34
|
+
modules, platform-to-module references, folders without project or README, namespace/folder
|
|
35
|
+
mismatches, frontend boundary violations.
|
|
36
|
+
3. Each gate fails when its baseline grows and asks for the baseline to shrink when coupling is removed.
|
|
37
|
+
|
|
38
|
+
Done when: the gates run in the normal spec pass and fail on a planted violation (add one grant, see red, remove it).
|
|
39
|
+
|
|
40
|
+
## 3. Move, and only move
|
|
41
|
+
|
|
42
|
+
Keep namespaces and assembly names while moving; moving a file changes no identity, a namespace change
|
|
43
|
+
does (rule, *What a rename changes*).
|
|
44
|
+
|
|
45
|
+
| Move | Steps (each a separate commit; build and run specs after each) |
|
|
46
|
+
| --- | --- |
|
|
47
|
+
| **1 → 2** | Create the module folder, `git mv` the related feature folders under it, add its `README.md`. |
|
|
48
|
+
| **2 → 3** | Create the module project and frontend package; `git mv` the module folder into them; reference only what the rule's layer table allows. Add the module declaration and register its routes, navigation and settings by convention. |
|
|
49
|
+
| **3 → 4** | At the first cross-module need, create `<Module>.Contracts` in the owning module and point the consumer at it. Replace the direct reference; never keep both. |
|
|
50
|
+
|
|
51
|
+
- `git mv` for files; no behavior change, rename or refactor in a move commit.
|
|
52
|
+
- When a project is renamed and stored names are assembly-qualified, keep its `AssemblyName`.
|
|
53
|
+
- A folder whose namespace no longer matches goes into the namespace allowlist until the rename window.
|
|
54
|
+
- Never add `InternalsVisibleTo` or a seam to make a move compile. A move that would need one waits
|
|
55
|
+
until step 4 has replaced the dependency.
|
|
56
|
+
- Large reshapes split into lanes: one worktree and branch per module or engine, each owning disjoint
|
|
57
|
+
folders, merged into one integration branch. Re-run every gate after each merge; when two lanes both
|
|
58
|
+
shrank a baseline, record the merged value, never the larger one.
|
|
59
|
+
|
|
60
|
+
Done when: build, specs and gates pass and every baseline is equal or smaller.
|
|
61
|
+
|
|
62
|
+
## 4. Untangle
|
|
63
|
+
|
|
64
|
+
For each dependency that points up or sideways, pick one fix:
|
|
65
|
+
|
|
66
|
+
| The dependency is | Fix |
|
|
67
|
+
| --- | --- |
|
|
68
|
+
| A question or request to another module | Grain or service interface in the owner's `.Contracts` |
|
|
69
|
+
| "Tell me when" | Public event in the owner's `.Contracts`; the consumer reacts |
|
|
70
|
+
| A module needing an external provider | Port in the module's `.Contracts`; each `Integration.<Provider>` project implements it |
|
|
71
|
+
| Platform code that knows a module | Discovery interface in the platform; the module implements it |
|
|
72
|
+
| Technical code with no domain | Move it to Infrastructure (or Components for UI) |
|
|
73
|
+
|
|
74
|
+
**Dissolving a catch-all project** (`Global`, `Shared`, `Common`): measure what other projects actually
|
|
75
|
+
import from it, folder by folder. Each cluster that several modules use becomes a platform project with
|
|
76
|
+
one purpose (shell and tenancy into the host or a `Tenancy.Contracts`, an engine into its own project
|
|
77
|
+
with contracts); everything else moves into the module that owns it. Delete the project when it is empty.
|
|
78
|
+
|
|
79
|
+
**Retiring a project that owns event types** removes those types: their stored events and registrations
|
|
80
|
+
need an event-store plan (**cratis-chronicle-event-type-migration**) before the project goes.
|
|
81
|
+
|
|
82
|
+
Done when: the seam baseline and the module-reference baseline reach zero.
|
|
83
|
+
|
|
84
|
+
## 5. Rename window
|
|
85
|
+
|
|
86
|
+
Rename namespaces to `<Company>.<Product>.<Project>.<folder path>` **once**, after the moves, as a
|
|
87
|
+
production rollout. Read [references/rename-window.md](references/rename-window.md) before starting it.
|
|
88
|
+
|
|
89
|
+
Done when: the namespace allowlist is empty and the stored-identity repair has passed its dry run and tests.
|
|
90
|
+
|
|
91
|
+
## 6. Verify
|
|
92
|
+
|
|
93
|
+
Run one phase at a time, each exiting 0 (use the repository's script names):
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
dotnet build
|
|
97
|
+
dotnet test
|
|
98
|
+
yarn tsc --noEmit
|
|
99
|
+
yarn lint
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Then boot the host and drive it end to end (integration specs over HTTP, then a walk of every screen).
|
|
103
|
+
Unit specs construct types directly; they do not see DI registration order, routes, generated proxies or
|
|
104
|
+
name-scoped filters, which is where structural changes break. Say which phases were not run.
|
|
105
|
+
|
|
106
|
+
## Pitfalls
|
|
107
|
+
|
|
108
|
+
| Symptom | Cause | Fix |
|
|
109
|
+
| --- | --- | --- |
|
|
110
|
+
| Observers replay from the start, side effects repeat | A namespace or type name changed an observer identity | Pin the id, or repair stored identities before starting the new version |
|
|
111
|
+
| `IFoo` not resolved, or the wrong implementation wins | Interface moved to `.Contracts`, so the same-namespace convention no longer binds; or extra bindings ran before explicit registrations | Register the pair explicitly; apply generated bindings once, after all explicit ones |
|
|
112
|
+
| 404 from the frontend or a script after a rename | Arc routes follow the namespace | Regenerate proxies; replace hard-coded routes; update reverse-proxy rewrites |
|
|
113
|
+
| A generated proxy lost members after a split | A project that only references a type emitted a copy over the owner's proxy | Generate each project into its own package; map referenced assemblies with `AssemblyToPackageMapping` (**cratis-arc-command**, proxy generation) |
|
|
114
|
+
| API docs, authorization or Release stripping silently stopped applying | Code keyed on a namespace or path | Replace name keys with explicit declarations or one shared pattern |
|
|
115
|
+
| Stored jobs fail to resume after a project rename or a move | Job type names are assembly-qualified | Keep `AssemblyName`; for a job type moved to another assembly, rewrite the stored names or leave a type forwarder |
|
|
116
|
+
| Module B does not compile without module A's internals | Hidden coupling | Contract or lower project; never `InternalsVisibleTo` |
|
|
117
|
+
| Gate baseline keeps growing | Moving and refactoring in one step | Split the commit; fix the dependency, not the baseline |
|
|
118
|
+
|
|
119
|
+
## Related
|
|
120
|
+
|
|
121
|
+
- **cratis-multi-service-architecture**: modules deployed as separate services.
|
|
122
|
+
- **cratis-chronicle-event-type-migration**: deliberate event identity or schema changes.
|
|
123
|
+
- **cratis-engineering-decision-record**: superseding the structure's accepted records.
|
|
124
|
+
- **cratis-application-slice-conformance**: a slice against its model after a move.
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
<!-- Copyright (c) Cratis. All rights reserved. -->
|
|
2
|
+
<!-- Licensed under the MIT license. See LICENSE file in the project root for full license information. -->
|
|
3
|
+
|
|
4
|
+
# The namespace rename window
|
|
5
|
+
|
|
6
|
+
A namespace rename is a change to stored identities, so it ships as one production rollout with a
|
|
7
|
+
repair, once, after the structural moves. The identity table is in
|
|
8
|
+
[application-anatomy.md](../../../rules/application-anatomy.md) (*What a rename changes*).
|
|
9
|
+
|
|
10
|
+
## 1. Prepare the code
|
|
11
|
+
|
|
12
|
+
1. **Replace name keys first, in their own commit:** authorization or audience rules keyed on a namespace
|
|
13
|
+
prefix become explicit markers (an attribute, an assembly-level marker, a policy); OpenAPI or filter
|
|
14
|
+
registrations scoped to one namespace take an explicit list; build steps that strip or include files by
|
|
15
|
+
path use one shared pattern. Add a spec that lists what each marker covers, so a later rename cannot
|
|
16
|
+
widen access unnoticed.
|
|
17
|
+
2. **Pin what can be pinned:** event types without an explicit id keep theirs while the class name stays.
|
|
18
|
+
Pin an observer id only when its stored state must survive and you will not repair it.
|
|
19
|
+
3. **Rename:** project folders lose the product prefix, every namespace becomes
|
|
20
|
+
`<Company>.<Product>.<Project>.<folder path>`, and `AssemblyName` stays unless the stored names are
|
|
21
|
+
repaired too. Set Arc's `SegmentsToSkipForRoute` (and `CratisProxiesSegmentsToSkip`) to the length of the
|
|
22
|
+
new prefix so routes and proxy folders do not grow it.
|
|
23
|
+
4. **Regenerate** every proxy, then search specs, scripts, documentation and reverse-proxy rewrites for
|
|
24
|
+
literal routes and compare each with the generated ones.
|
|
25
|
+
5. **Bindings:** interface/implementation pairs that no longer share a namespace get an explicit or
|
|
26
|
+
generated registration, applied after every explicit registration.
|
|
27
|
+
|
|
28
|
+
## 2. Build the repair
|
|
29
|
+
|
|
30
|
+
The repair renames stored identities from old full names to new ones before the new version starts:
|
|
31
|
+
|
|
32
|
+
| Stored identity | Typical location |
|
|
33
|
+
| --- | --- |
|
|
34
|
+
| Reactor, reducer and projection ids, observer state, failed partitions, replay state | the event store's system and per-namespace collections |
|
|
35
|
+
| Read model identifiers and definitions | the same collections; read model collections keep their names |
|
|
36
|
+
| Grain state type names | the Orleans storage |
|
|
37
|
+
| Job, job step and request type names | job storage |
|
|
38
|
+
|
|
39
|
+
Event types, events and read model content do not change.
|
|
40
|
+
|
|
41
|
+
The repair is a script with:
|
|
42
|
+
|
|
43
|
+
- a **mapping** generated from the old and new type catalogs, not typed by hand;
|
|
44
|
+
- a **test** that every changed identity maps to its new value and that pinned ids are untouched;
|
|
45
|
+
- a **dry run** that prints counts per collection, and a fuse that refuses to write above an expected count;
|
|
46
|
+
- **idempotence**: a second run changes nothing (prove it against a planted database);
|
|
47
|
+
- credentials read from an environment variable, never from the command line.
|
|
48
|
+
|
|
49
|
+
## 3. Run the window
|
|
50
|
+
|
|
51
|
+
1. Merge and publish the release; do not let it start against unrepaired storage.
|
|
52
|
+
2. Scale the application to zero, back up the affected collections, run the dry runs and compare their
|
|
53
|
+
counts with the expected ones.
|
|
54
|
+
3. Apply the repair, clear any cached registrations the event store kernel holds (restart it when it caches
|
|
55
|
+
them), then start the new version.
|
|
56
|
+
4. Check: no observer registered under a new id from position zero, no identity-drift warnings, every
|
|
57
|
+
screen loads, stored jobs resume.
|
|
58
|
+
|
|
59
|
+
Rollback is the backup plus the previous release; keep both until the checks pass.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"skill": "cratis-application-growth",
|
|
3
|
+
"input": "Our single-project Cratis app has a Billing capability gated by entitlement, a second team, and a Shared project every feature depends on. Plan moving Billing into a module project and renaming namespaces afterwards without breaking stored identities.",
|
|
4
|
+
"fixtures": [],
|
|
5
|
+
"assertions": [
|
|
6
|
+
{ "kind": "skill-contains", "value": "No signal, no move." },
|
|
7
|
+
{ "kind": "skill-contains", "value": "decide, guard, move, untangle, rename, verify." },
|
|
8
|
+
{ "kind": "skill-contains", "value": "Never add `InternalsVisibleTo` or a seam" },
|
|
9
|
+
{ "kind": "skill-contains", "value": "`<Module>.Contracts`" },
|
|
10
|
+
{ "kind": "skill-contains", "value": "Dissolving a catch-all project" },
|
|
11
|
+
{ "kind": "skill-contains", "value": "references/rename-window.md" },
|
|
12
|
+
{ "kind": "skill-contains", "value": "Then boot the host and drive it end to end" }
|
|
13
|
+
]
|
|
14
|
+
}
|
|
@@ -137,7 +137,8 @@ Current behavior:
|
|
|
137
137
|
and queries with no explicit declaration, on both hosts, and ASP.NET's
|
|
138
138
|
`FallbackPolicy` covers HTTP endpoints and MVC actions. They are separate:
|
|
139
139
|
neither covers what the other does, and neither protects an explicitly anonymous
|
|
140
|
-
endpoint.
|
|
140
|
+
endpoint. A baseline never decides from a namespace or folder name
|
|
141
|
+
([authorization](references/authorization.md#baselines-two-separate-mechanisms)).
|
|
141
142
|
- **Direct calls bypass authorization.** Calling `Handle()` or a query method
|
|
142
143
|
directly skips authorization, validation and filters; only the pipeline and
|
|
143
144
|
mapped endpoints enforce them. Server-side callers still need a principal
|
|
@@ -281,6 +281,11 @@ public class MembersByDefault : IFallbackAuthorizationEvaluator
|
|
|
281
281
|
resource-dependent rules.
|
|
282
282
|
- `IAuthorizationAttributeEvaluator` reports only **explicit** declarations from
|
|
283
283
|
another attribute family; it never becomes a baseline.
|
|
284
|
+
- **Never decide from a name.** An evaluator or filter that grants or denies by
|
|
285
|
+
namespace prefix, folder or route segment changes who may call what the day
|
|
286
|
+
code moves or a namespace is renamed. Decide from a declaration on the type or
|
|
287
|
+
its assembly (an attribute, an assembly-level marker, a named policy), and keep
|
|
288
|
+
a spec that lists what each declaration covers.
|
|
284
289
|
|
|
285
290
|
**ASP.NET Core `FallbackPolicy`** covers HTTP endpoints and MVC actions without
|
|
286
291
|
authorization metadata. It does **not** supply Arc's pipeline baseline, and
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
- Wiring
|
|
6
6
|
- MSBuild properties
|
|
7
|
+
- Several projects, several packages
|
|
7
8
|
- Route settings must match the host and the frontend
|
|
8
9
|
- Skipping generation
|
|
9
10
|
- What the generator extracts for client-side validation
|
|
@@ -86,6 +87,23 @@ inserted without configuration.
|
|
|
86
87
|
Item groups the target also forwards: `AssemblyToPackageMapping`,
|
|
87
88
|
`ExcludeType`, `ExcludeNamespace`, `NamespaceRoot`, and `TypeToTsType`.
|
|
88
89
|
|
|
90
|
+
## Several projects, several packages
|
|
91
|
+
|
|
92
|
+
The generator writes a TypeScript type for every type a project's commands and
|
|
93
|
+
queries use, **including types declared in referenced projects** (a contracts
|
|
94
|
+
project's concepts, another module's read model). Without a mapping, each
|
|
95
|
+
referencing project emits its own copy; when two projects write into the same
|
|
96
|
+
folder, the last writer wins and a partial copy can replace the owner's full
|
|
97
|
+
proxy.
|
|
98
|
+
|
|
99
|
+
- Give each backend project its own output root, inside its own frontend package.
|
|
100
|
+
- For every referenced project that has its own package, add
|
|
101
|
+
`<AssemblyToPackageMapping Include="billing" Assembly="<Assembly name>" Package="@<scope>/billing" />`
|
|
102
|
+
so its types are imported from that package instead of
|
|
103
|
+
regenerated. The owner generates a type; everyone else imports it.
|
|
104
|
+
- Routes and output folders follow the namespace, so a namespace rename changes
|
|
105
|
+
both; regenerate every package and search for literal routes afterwards.
|
|
106
|
+
|
|
89
107
|
## Route settings must match the host and the frontend
|
|
90
108
|
|
|
91
109
|
The route properties (`CratisProxiesApiPrefix`, `CratisProxiesSegmentsToSkip`,
|
|
@@ -24,6 +24,26 @@ once and is what Chronicle records.
|
|
|
24
24
|
|
|
25
25
|
Each callback runs only if the previous steps passed.
|
|
26
26
|
|
|
27
|
+
## Where each decision lives
|
|
28
|
+
|
|
29
|
+
A command's `handle/2` decides what to append from what `provide/2` loaded. Pick the mechanism by what the
|
|
30
|
+
decision is:
|
|
31
|
+
|
|
32
|
+
| Decision | Use |
|
|
33
|
+
| --- | --- |
|
|
34
|
+
| Shape or range of an input | `field` options (`required:`, `max_length:`), then a validator |
|
|
35
|
+
| State of the stream a rule needs (does it exist, is it suspended) | `provide/2` loading the folded state; `handle/2` refuses with a validation result |
|
|
36
|
+
| **Uniqueness**: a value used once, or a fact (an event type) once per stream | **A Chronicle constraint**, declared on the event type (`unique/2`, `unique_event_type/1`) or in a standalone `Cratis.Chronicle.Events.Constraint` module. The kernel checks it at append time, so it holds under concurrency. |
|
|
37
|
+
| A rule over many streams or a count (a tenant limit) | A read model or the integration, and accept that it can race; say so in the command's doc |
|
|
38
|
+
| An exceptional failure (a bug, missing infrastructure) | raise |
|
|
39
|
+
|
|
40
|
+
**Do not check uniqueness by reading first.** A `provide/2` that loads the stream or a read model to see "is
|
|
41
|
+
this taken" (`{:ok, %{exists?: true}} -> refuse(...)`) is a race: two commands both see it free, and both
|
|
42
|
+
append. Declare the constraint and let the append refuse. Arc turns the violation into a validation result with
|
|
43
|
+
reason `constraintViolation` (the constraint name in `reasonDetail`), so a client already handles it; give the
|
|
44
|
+
constraint a `:message` so the refusal reads well. Release a held value with `remove_constraint/1,2` on the event
|
|
45
|
+
that frees it. Read the Chronicle skill's `references/constraints.md` for the options.
|
|
46
|
+
|
|
27
47
|
## When Chronicle refuses
|
|
28
48
|
|
|
29
49
|
A constraint or concurrency rejection never raises. It is a validation result with reason
|
|
@@ -3,6 +3,13 @@
|
|
|
3
3
|
|
|
4
4
|
# Proxies and vertical slices
|
|
5
5
|
|
|
6
|
+
## Contents
|
|
7
|
+
|
|
8
|
+
- Vertical slices
|
|
9
|
+
- Group slices into sub-features, and keep an integration beside what it serves
|
|
10
|
+
- A read model owns its artifacts
|
|
11
|
+
- Name things by their ids
|
|
12
|
+
|
|
6
13
|
Proxy generation is opt-in. Add the compiler and every `mix compile` regenerates the
|
|
7
14
|
TypeScript for commands and queries:
|
|
8
15
|
|
|
@@ -46,6 +53,28 @@ The folder is the namespace: `Prism.Access.ApiCredentials.Secrets.RotatingSecret
|
|
|
46
53
|
sub-feature as a feature of its own, so the grouping is what readers and tools see. Keep
|
|
47
54
|
`segments_to_skip` equal to the segments above the module.
|
|
48
55
|
|
|
56
|
+
### A read model owns its artifacts
|
|
57
|
+
|
|
58
|
+
A view slice has one file, named for its read model, holding everything the read model needs:
|
|
59
|
+
|
|
60
|
+
```text
|
|
61
|
+
viewing/listing/
|
|
62
|
+
credential_listing.ex the read model, its projection (or reducer) and its queries
|
|
63
|
+
page.ex, page.html.heex the page that shows it
|
|
64
|
+
for_credential_listing/ its specs
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Inside, the read model's module nests what it needs (`Credential`, then its projection, then its `Queries`),
|
|
68
|
+
the way a command shares a file with its events. Do **not** make files or folders named for a technical function
|
|
69
|
+
(`queries.ex`, `reducer.ex`, `projection.ex`, `read_models/`): the folder is the slice and the file is the read
|
|
70
|
+
model, so a reader finds the whole view in one place and the event model draws one box.
|
|
71
|
+
|
|
72
|
+
**Prefer a projection over a reducer.** Build the read model with the `Cratis.Chronicle.Projections` DSL
|
|
73
|
+
(`from/2`, `join/2`, `children/2,3`, counters). Use a reducer (`Cratis.Chronicle.Reducers.Reducer`) only when a
|
|
74
|
+
projection cannot express the transition (branching on prior state, calculations, guards over the previous
|
|
75
|
+
document) and say why in the read model's `@moduledoc`. A reducer is code you own and run; a projection is
|
|
76
|
+
declarative and the kernel can replay and diagram it.
|
|
77
|
+
|
|
49
78
|
### Name things by their ids
|
|
50
79
|
|
|
51
80
|
A command is `use Cratis.Arc.Command, id: "rotate-secret"`, an event type has an `id:`, a reactor has an
|
|
@@ -252,6 +252,16 @@ A standalone projection is `use Cratis.Chronicle.Projections.Projection, model:
|
|
|
252
252
|
`reduce(event, model_or_nil, context) :: struct()`. **Reducers run in your
|
|
253
253
|
process**, so the reduction is Elixir code you own.
|
|
254
254
|
|
|
255
|
+
**Prefer a projection over a reducer.** Write a reducer only when a projection cannot express the transition
|
|
256
|
+
(branching on prior state, calculations, guards), and say why in its `@moduledoc`. Keep the read model, its
|
|
257
|
+
projection or reducer and its queries together in one file named for the read model; do not name files for
|
|
258
|
+
their technical function (`reducer.ex`, `queries.ex`).
|
|
259
|
+
|
|
260
|
+
**Uniqueness is a constraint, not a read.** To say "this value is used once" or "this event happens once per
|
|
261
|
+
stream", declare `unique/2` or `unique_event_type/1` (or a standalone constraint module) and let the append
|
|
262
|
+
refuse; do not load the stream or a read model first to look. A read-then-append check races. See
|
|
263
|
+
[references/constraints.md](references/constraints.md).
|
|
264
|
+
|
|
255
265
|
#### Variants — mutually exclusive read models for one entity's lifecycle
|
|
256
266
|
|
|
257
267
|
Requires `cratis_chronicle` `3.4.0` or later. `variant_of/2` requires `:key`; a variant with no `enters_on` raises `Cratis.Chronicle.Projections.VariantMustDeclareEntersOnEvent` at registration.
|
|
@@ -28,7 +28,7 @@ event store name is required and has no default.
|
|
|
28
28
|
| `SkipCompatibilityCheck` | `false` | Connecting deliberately to a kernel version the client does not declare compatible. Leave on otherwise. |
|
|
29
29
|
| `UnitOfWorkLifecyclePolicy` | `Compatibility` | `Strict` to fail on units of work that are never completed. |
|
|
30
30
|
| `EventGenerationDelivery` | `Compatibility` | Opting into the newer event generation delivery behavior. |
|
|
31
|
-
| `ArtifactIdentityDrift` | `Warn` | `
|
|
31
|
+
| `ArtifactIdentityDrift` | `Warn` | `Fail` in CI or staging to stop registration on likely reactor or event type renames (values: `Warn`, `Fail`, `Ignore`). It detects drift; it does not repair stored identities. |
|
|
32
32
|
| `DefaultSinkTypeId` | MongoDB | Read models should default to another sink type. |
|
|
33
33
|
| `ClaimsBasedNamespaceResolverClaimType` | `tenant_id` | The identity provider carries the tenant in another claim. |
|
|
34
34
|
| `EnableEventTypeGenerationValidation` | `false` | Only a development kernel honors this; a production kernel always enforces migration-chain validation. |
|
|
@@ -107,8 +107,11 @@ For application code, work down this ladder:
|
|
|
107
107
|
2. **Fluent `IProjectionFor<T>`** when the definition needs structure or an
|
|
108
108
|
attribute-free contract. Counters, joins, children and composite keys remain
|
|
109
109
|
projection features; fluent lambdas are not arbitrary per-event code.
|
|
110
|
-
3. **Reducer code** when
|
|
111
|
-
|
|
110
|
+
3. **Reducer code** only when a projection cannot express the transition:
|
|
111
|
+
branching on prior state, calculations or guards that mappings, counters,
|
|
112
|
+
joins and children cannot say. **Prefer a projection over a reducer**; a
|
|
113
|
+
reducer needs a reason you can name, and it is the exception, not an equal
|
|
114
|
+
choice.
|
|
112
115
|
For new .NET code default to a **self-reducing model**: public static
|
|
113
116
|
`Reduce(TEvent @event, TSelf? current[, EventContext context])` on the model,
|
|
114
117
|
returning `TSelf`/`TSelf?` or `Task` of it. No marker or model activation.
|
|
@@ -7,10 +7,10 @@ license: MIT
|
|
|
7
7
|
# Chronicle reducers
|
|
8
8
|
|
|
9
9
|
A reducer builds a read model as "current state plus event produces next state",
|
|
10
|
-
with real C# control flow.
|
|
11
|
-
`IProjectionFor<T>` when mappings need
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
with real C# control flow. **We prefer projections over reducers.** Start with
|
|
11
|
+
model-bound attributes, use fluent `IProjectionFor<T>` when mappings need
|
|
12
|
+
structure, and choose a reducer only when a projection cannot express the
|
|
13
|
+
transition (branching on prior state, calculations or guards). For the application-code ladder and PDL's
|
|
14
14
|
outside-code role, read [choosing a style](../cratis-chronicle-read-model/SKILL.md#step-3--choose-a-projection-or-a-reducer).
|
|
15
15
|
|
|
16
16
|
Requires Chronicle 19.58.0 for self-reducing read models.
|
|
@@ -81,7 +81,12 @@ registration is the exception, not the rule.
|
|
|
81
81
|
collaborators — that is the service-locator anti-pattern.
|
|
82
82
|
- Mark a singleton with the `[Singleton]` attribute rather than registering it
|
|
83
83
|
explicitly.
|
|
84
|
-
- A convention-based `IFoo → Foo` pair needs no registration.
|
|
84
|
+
- A convention-based `IFoo → Foo` pair needs no registration. The convention
|
|
85
|
+
binds only when `IFoo` and `Foo` share a namespace and `Foo` is the single
|
|
86
|
+
implementation, and it skips any service type already registered. An
|
|
87
|
+
interface in a contracts project with its implementation elsewhere is not
|
|
88
|
+
covered: register it explicitly, and apply any generated bindings after the
|
|
89
|
+
explicit registrations so they only fill gaps.
|
|
85
90
|
- Command and query `Handle()` parameters resolve from DI by type.
|
|
86
91
|
|
|
87
92
|
```csharp
|
|
@@ -106,6 +106,7 @@
|
|
|
106
106
|
"cratis/specifications/typescript"
|
|
107
107
|
],
|
|
108
108
|
"availableTargets": [
|
|
109
|
+
"cratis-application-growth",
|
|
109
110
|
"cratis-observability"
|
|
110
111
|
],
|
|
111
112
|
"languages": [
|
|
@@ -127,6 +128,7 @@
|
|
|
127
128
|
"cratis/specifications/dotnet"
|
|
128
129
|
],
|
|
129
130
|
"availableTargets": [
|
|
131
|
+
"cratis-application-growth",
|
|
130
132
|
"cratis-observability"
|
|
131
133
|
],
|
|
132
134
|
"languages": [
|
|
@@ -142,6 +144,7 @@
|
|
|
142
144
|
"cratis/specifications/dotnet"
|
|
143
145
|
],
|
|
144
146
|
"availableTargets": [
|
|
147
|
+
"cratis-application-growth",
|
|
145
148
|
"cratis-observability"
|
|
146
149
|
],
|
|
147
150
|
"languages": [
|
|
@@ -158,6 +161,7 @@
|
|
|
158
161
|
"cratis/specifications/dotnet"
|
|
159
162
|
],
|
|
160
163
|
"availableTargets": [
|
|
164
|
+
"cratis-application-growth",
|
|
161
165
|
"cratis-observability"
|
|
162
166
|
],
|
|
163
167
|
"languages": [
|
|
@@ -178,6 +182,7 @@
|
|
|
178
182
|
"cratis/specifications/typescript"
|
|
179
183
|
],
|
|
180
184
|
"availableTargets": [
|
|
185
|
+
"cratis-application-growth",
|
|
181
186
|
"cratis-observability"
|
|
182
187
|
],
|
|
183
188
|
"languages": [
|
|
@@ -242,6 +247,7 @@
|
|
|
242
247
|
"cratis/specifications/typescript"
|
|
243
248
|
],
|
|
244
249
|
"availableTargets": [
|
|
250
|
+
"cratis-application-growth",
|
|
245
251
|
"cratis-observability"
|
|
246
252
|
],
|
|
247
253
|
"languages": [
|