@oxface/modular-monolith-patterns 0.0.0-stage → 0.1.1
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/CHANGELOG.md +17 -0
- package/LICENSE +201 -0
- package/README.md +99 -2
- package/SKILL.md +29 -0
- package/bootstrap.md +117 -0
- package/dist/cli.js +137 -0
- package/dist/skill/CHANGELOG.md +17 -0
- package/dist/skill/README.md +100 -0
- package/dist/skill/SKILL.md +29 -0
- package/dist/skill/bootstrap.md +117 -0
- package/dist/skill/bundle.json +25 -0
- package/dist/skill/dotnet-react-vite.md +244 -0
- package/dist/skill/entity-work.md +93 -0
- package/dist/skill/first-module.md +135 -0
- package/dist/skill/gloaming.md +69 -0
- package/dist/skill/kafka.md +142 -0
- package/dist/skill/messaging.md +89 -0
- package/dist/skill/modules.md +75 -0
- package/dist/skill/postgres-wakeups.md +96 -0
- package/dist/skill/structure.md +81 -0
- package/dist/skill/verification.md +81 -0
- package/dotnet-react-vite.md +244 -0
- package/entity-work.md +93 -0
- package/first-module.md +135 -0
- package/gloaming.md +69 -0
- package/kafka.md +142 -0
- package/messaging.md +89 -0
- package/modules.md +75 -0
- package/package.json +39 -4
- package/postgres-wakeups.md +96 -0
- package/structure.md +81 -0
- package/verification.md +81 -0
package/gloaming.md
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# Select Gloaming capabilities
|
|
2
|
+
|
|
3
|
+
These patterns work with native .NET composition. Add a Gloaming capability only where its
|
|
4
|
+
documented guarantee removes a technical obligation in the consuming application.
|
|
5
|
+
The package README is authoritative for the version in use.
|
|
6
|
+
|
|
7
|
+
## Package integration
|
|
8
|
+
|
|
9
|
+
Select published Gloaming packages from NuGet.org and pin the roots the application needs.
|
|
10
|
+
Keep dependency locks and check the selected package's target framework, native dependencies
|
|
11
|
+
and public contract. Keep application project references inside the application; consume
|
|
12
|
+
technical libraries as packages.
|
|
13
|
+
|
|
14
|
+
For changes to Gloaming itself, use native SDK candidate packing and the
|
|
15
|
+
[package-only proofs](https://github.com/oxface/gloaming/blob/main/eng/release/README.md).
|
|
16
|
+
The first public release starts at 0.1.0; use an actually published version in an application.
|
|
17
|
+
|
|
18
|
+
### Distribution boundary
|
|
19
|
+
|
|
20
|
+
[Release operations](https://github.com/oxface/gloaming/blob/main/docs/releases.md) describes
|
|
21
|
+
hosted NuGet/npm delivery. Applications own their package pins, locks, migrations and upgrade
|
|
22
|
+
acceptance. A temporary candidate folder is useful for testing unpublished changes; it is not
|
|
23
|
+
required application infrastructure. Rebuilding source need not reproduce an existing archive's
|
|
24
|
+
bytes. Never replace an already published version with changed source.
|
|
25
|
+
|
|
26
|
+
### Read contracts for the adopted version
|
|
27
|
+
|
|
28
|
+
Start with the README included in the chosen package. Its nuspec repository commit identifies
|
|
29
|
+
the corresponding source revision. The source links in these patterns point to main for
|
|
30
|
+
navigation; inspect the selected revision when applying an older package's contract. A built
|
|
31
|
+
skill pins those links to its own source revision. Later changes on main do not change the
|
|
32
|
+
package or the consuming application's selected version.
|
|
33
|
+
|
|
34
|
+
For one protected EF/PostgreSQL operation, the [first-module walkthrough](first-module.md)
|
|
35
|
+
identifies the selected packages and executable examples.
|
|
36
|
+
|
|
37
|
+
| Requirement | Contract and selection |
|
|
38
|
+
| --- | --- |
|
|
39
|
+
| Actor/initiator attribution | [ActorIdentity](https://github.com/oxface/gloaming/blob/main/src/Gloaming.ActorIdentity/README.md), with optional native HTTP establishment |
|
|
40
|
+
| Selected tenant/tenantless context | [Tenancy](https://github.com/oxface/gloaming/blob/main/src/Gloaming.Tenancy/README.md), independent of actor identity |
|
|
41
|
+
| Ownership/protected saves and optional RLS | [Persistence](https://github.com/oxface/gloaming/blob/main/src/Gloaming.Persistence/README.md) |
|
|
42
|
+
| Ordered native save preparation/validation | [EntityFrameworkCore](https://github.com/oxface/gloaming/blob/main/src/Gloaming.EntityFrameworkCore/README.md) |
|
|
43
|
+
| Event-sourced aggregate writes/replay | [EventSourcing](https://github.com/oxface/gloaming/blob/main/src/Gloaming.EventSourcing/README.md) |
|
|
44
|
+
| Stable JSON event names/upcasting/history | [Events](https://github.com/oxface/gloaming/blob/main/src/Gloaming.Events/README.md) |
|
|
45
|
+
| Local fact capture/reactions | [EventReactions](https://github.com/oxface/gloaming/blob/main/src/Gloaming.EventReactions/README.md) |
|
|
46
|
+
| Explicit accepted-change audit | [Auditing](https://github.com/oxface/gloaming/blob/main/src/Gloaming.Auditing/README.md) |
|
|
47
|
+
| Logical action/result retention | [CommandReceipts](https://github.com/oxface/gloaming/blob/main/src/Gloaming.CommandReceipts/README.md) |
|
|
48
|
+
| Durable inbox/outbox and selected continuations | [Messaging](https://github.com/oxface/gloaming/blob/main/src/Gloaming.Messaging/README.md) |
|
|
49
|
+
|
|
50
|
+
## Integration obligations
|
|
51
|
+
|
|
52
|
+
Bind registrations and model/save configuration to the same typed context. For every selected
|
|
53
|
+
capability, account for native sync and async saving, required transaction isolation,
|
|
54
|
+
failure disposal and its supported mapping constraints. Use the save coordinator where its
|
|
55
|
+
ordered phases help; it does not create a generic transaction middleware or silently commit.
|
|
56
|
+
|
|
57
|
+
Establish required immutable actor/tenant context before resolving protected scoped persistence.
|
|
58
|
+
HTTP and worker ingress have different admission paths. RLS also requires native policies,
|
|
59
|
+
restricted credentials and transaction-local setup for reads as well as writes.
|
|
60
|
+
|
|
61
|
+
Keep explicit mappings, connection/credential roles, migrations and deployment ordering in the
|
|
62
|
+
application. Library scope or tenant metadata does not authorize access. Select transport-specific
|
|
63
|
+
packages only for the routes that need them.
|
|
64
|
+
|
|
65
|
+
## Reference application
|
|
66
|
+
|
|
67
|
+
[Wholesale](https://github.com/oxface/gloaming/blob/main/samples/Wholesale/README.md) shows native
|
|
68
|
+
composition across Access, Sales and Inventory. Use its wiring and proof boundaries as examples;
|
|
69
|
+
application users, grants, stock rules, SQL roles and exact module graph are its own policy.
|
package/kafka.md
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
# Native Kafka delivery with PostgreSQL inbox/outbox
|
|
2
|
+
|
|
3
|
+
Compose Kafka through the existing `IMessagePublisher` and typed PostgreSQL inbox/outbox
|
|
4
|
+
interfaces. The application owns the native Confluent client, routing, wire contract,
|
|
5
|
+
trusted producer mapping, consumer group, bootstrap position and poison-record policy.
|
|
6
|
+
This recipe adds no Gloaming package, runtime or reusable library mechanism.
|
|
7
|
+
|
|
8
|
+
The executable [package-only consumer](https://github.com/oxface/gloaming/blob/main/eng/release/consumers/Kafka/README.md) demonstrates
|
|
9
|
+
one sequential intake loop with Confluent.Kafka 2.16.0, Kafka 4.3.1 and PostgreSQL 18.6.
|
|
10
|
+
Its record format, table names and sample effects are consumer-owned examples.
|
|
11
|
+
|
|
12
|
+
## Publish retained intent
|
|
13
|
+
|
|
14
|
+
Enqueue `OutgoingMessage` in the producer module's ordinary native transaction. Save business
|
|
15
|
+
state and outbox work, then commit. Dispatch runs independently and claims work before invoking
|
|
16
|
+
the publisher; no producer database transaction spans Kafka I/O. See the
|
|
17
|
+
[PostgreSQL messaging contract](https://github.com/oxface/gloaming/blob/main/src/Gloaming.Messaging/Gloaming.Messaging.EntityFrameworkCore.Postgres/README.md).
|
|
18
|
+
|
|
19
|
+
The host owns a native `IProducer<byte[], byte[]>` configured with `Acks.All` and
|
|
20
|
+
`EnableIdempotence = true`. Supply it to the consumer's
|
|
21
|
+
[KafkaPublisher](https://github.com/oxface/gloaming/blob/main/eng/release/consumers/Kafka/KafkaAdapter.cs) and reuse it for its selected
|
|
22
|
+
lifetime. Keep credentials/TLS, native timeouts and disposal in host composition.
|
|
23
|
+
`PublishAsync` validates the selected route, serializes the retained envelope and awaits
|
|
24
|
+
`ProduceAsync`. It returns normally only when the report says `PersistenceStatus.Persisted`.
|
|
25
|
+
Failed or unconfirmed acceptance throws. Cancellation does not prove broker rejection.
|
|
26
|
+
The example's wire codec allows one wrapper around the core's 64-level JSON payload (65 total).
|
|
27
|
+
Keep application payload admission and transport byte/depth budgets consistent before durable
|
|
28
|
+
staging; another transport contract may impose stricter consumer-owned limits.
|
|
29
|
+
|
|
30
|
+
Keep MessageId unchanged across dispatch attempts. A producer session's idempotence does not
|
|
31
|
+
deduplicate a fresh producer after process loss. Broker acceptance can precede recorded outbox
|
|
32
|
+
completion; receiving intake must still deduplicate. The example's Kafka key is an item key;
|
|
33
|
+
it is neither delivery identity nor an authorization credential. Kafka partition order does not
|
|
34
|
+
establish domain causality or FIFO from an independently scheduled outbox.
|
|
35
|
+
|
|
36
|
+
## Commit intake before advancing a position
|
|
37
|
+
|
|
38
|
+
Select a native consumer group and bootstrap/reset policy explicitly. The fixture uses classic
|
|
39
|
+
groups, Range assignment and earliest reset for its new isolated topics; that is not a production
|
|
40
|
+
retention/replay decision. Disable **both** `EnableAutoCommit` and `EnableAutoOffsetStore`.
|
|
41
|
+
Native prefetch may continue internally, but the application accepts one delivered record at a
|
|
42
|
+
time. See the native client's [offset-management guidance](https://docs.confluent.io/kafka-clients/dotnet/current/overview.html).
|
|
43
|
+
|
|
44
|
+
For each record:
|
|
45
|
+
|
|
46
|
+
1. Decode the selected wire contract and map its trusted native route to the application's
|
|
47
|
+
stable producer namespace. MessageId, message alias/version and business metadata come from
|
|
48
|
+
the validated envelope. An asserted producer name or TenantKey alone grants no authority.
|
|
49
|
+
2. Create a fresh scope and receiving DbContext. Begin an explicit native ReadCommitted
|
|
50
|
+
transaction, call `IInbox<TContext>.ReceiveAsync`, then commit.
|
|
51
|
+
3. After committed intake, call `consumer.Commit(record)`. Both `Queued` and `AlreadyReceived`
|
|
52
|
+
permit this acknowledgement. An unobserved/failed database commit does not.
|
|
53
|
+
4. Dispose the operation scope before accepting more work. Local business processing runs
|
|
54
|
+
separately through `IInboxProcessor<TContext>` with its own fresh scopes and atomic local
|
|
55
|
+
effects/completion. Do not hold Kafka intake across slow external work.
|
|
56
|
+
|
|
57
|
+
The [native adapter](https://github.com/oxface/gloaming/blob/main/eng/release/consumers/Kafka/KafkaAdapter.cs) contains the complete
|
|
58
|
+
receive/commit composition. Both native EF save forms call the selected guards in the
|
|
59
|
+
[consumer mappings](https://github.com/oxface/gloaming/blob/main/eng/release/consumers/Kafka/Database.cs). Production schema placement,
|
|
60
|
+
migrations, grants, tenant admission and reader permissions stay with the application.
|
|
61
|
+
|
|
62
|
+
If intake fails, stop that consumer attempt or deliberately seek/retry the same record before
|
|
63
|
+
reading further. Do not catch a failure, continue and later commit a higher position in that
|
|
64
|
+
partition. Kafka commits a next position; it does not acknowledge arbitrary independent records.
|
|
65
|
+
This recipe supplies no parallel-intake watermark, batch acknowledgement or partition scheduler.
|
|
66
|
+
|
|
67
|
+
Intake commit followed by offset-commit failure can redeliver. Reconcile through retained intake
|
|
68
|
+
in a fresh scope; do not repeat business work directly from the broker record. Ownership-loss
|
|
69
|
+
errors such as Local_State or UnknownMemberId do not roll back the committed receipt. They must
|
|
70
|
+
not become a blanket policy that ignores every Kafka exception. The host owns fail-stop/restart,
|
|
71
|
+
backoff and readiness; the proof observes an actual live group handoff and rejected stale commit.
|
|
72
|
+
|
|
73
|
+
## Reject or retain poison work deliberately
|
|
74
|
+
|
|
75
|
+
Malformed or conflicting records have not entered accepted intake. The library's
|
|
76
|
+
[inbox dead letters](https://github.com/oxface/gloaming/blob/main/src/Gloaming.Messaging/docs/inbox-recovery.md) instead describe failures
|
|
77
|
+
after accepted intake; they cannot dispose an undecodable Kafka record.
|
|
78
|
+
|
|
79
|
+
The executable example first proves fail-stop at a conflicting offset while later valid work
|
|
80
|
+
remains unacknowledged. It then selects a different explicit policy: commit a receiver-owned
|
|
81
|
+
quarantine record before committing that position. Its controlled reasons distinguish invalid
|
|
82
|
+
envelopes and identity/content conflicts. Database/storage failures still propagate.
|
|
83
|
+
|
|
84
|
+
Quarantine retains a source-incarnation key, topic, partition, position, raw key/value bytes,
|
|
85
|
+
ordered headers and broker timestamp. Repeating disposition checks retained content rather than
|
|
86
|
+
overwriting it. Use a new admitted source incarnation after relevant cluster/topic recreation;
|
|
87
|
+
topic name plus numeric offset is not permanent source identity. The fixture uses unique topics
|
|
88
|
+
and never recreates one under its existing incarnation.
|
|
89
|
+
|
|
90
|
+
This is example policy and schema, not a Gloaming quarantine store. Applications choose operator
|
|
91
|
+
authority, disclosure, retention and repair/replay. Retained payloads/headers may contain sensitive
|
|
92
|
+
data. No replay UI, automatic discard, automatic evidence expiry or application admission follows
|
|
93
|
+
from this recipe.
|
|
94
|
+
|
|
95
|
+
## Lifetime and recovery
|
|
96
|
+
|
|
97
|
+
Bound native publication and operation budgets. Cancel a native `Consume` call cooperatively,
|
|
98
|
+
await it, then close/dispose its consumer; do not use that consumer concurrently from another
|
|
99
|
+
thread during close. Stop new work before shutdown. A pending database/offset boundary remains
|
|
100
|
+
uncertain under process loss; fresh operation scopes and retained delivery identity own recovery.
|
|
101
|
+
Producer delivery timers, native session limits and external process termination are separate
|
|
102
|
+
policies. No wrapper here bounds arbitrary user code or supplies a supervisor.
|
|
103
|
+
|
|
104
|
+
The host also owns source retention and receipt evidence lifetime. Deleting a processed receipt
|
|
105
|
+
ends its deduplication/content evidence; replay may execute old work again. A new group cannot
|
|
106
|
+
recover broker records removed by retention. Separate query projection rebuilds from historical
|
|
107
|
+
email, inference and other external effects. Kafka producer transactions do not atomically commit
|
|
108
|
+
PostgreSQL effects.
|
|
109
|
+
|
|
110
|
+
## Verification and limits
|
|
111
|
+
|
|
112
|
+
From the Gloaming repository root, with the pinned SDK, Node and a Docker-compatible engine:
|
|
113
|
+
|
|
114
|
+
```sh
|
|
115
|
+
npm ci --prefix eng/release --ignore-scripts
|
|
116
|
+
npm run verify:kafka -- --feed .artifacts/packages --version 0.1.0
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Pack candidates with the native SDK as described in the [package guide](https://github.com/oxface/gloaming/blob/main/eng/release/README.md).
|
|
120
|
+
The [runner](https://github.com/oxface/gloaming/blob/main/eng/release/verify-kafka.ts) consumes the selected package folder/version and restores an external
|
|
121
|
+
consumer through source mapping into a fresh cache, verifies its exact four-package Gloaming
|
|
122
|
+
closure and zero ProjectReferences, then uses Testcontainers to provision an isolated broker and
|
|
123
|
+
PostgreSQL. It retains redacted logs, selected package identities, per-scenario outcomes and cleanup
|
|
124
|
+
evidence. See the [consumer guide](https://github.com/oxface/gloaming/blob/main/eng/release/consumers/Kafka/README.md)
|
|
125
|
+
for rootless Podman setup.
|
|
126
|
+
The [Native Kafka package adoption check](https://github.com/oxface/gloaming/blob/main/.github/workflows/ci.yml)
|
|
127
|
+
owns this profile. The ordinary package command uses PostgreSQL.
|
|
128
|
+
|
|
129
|
+
The selected proofs cover process death before/after intake commit, accepted publication before
|
|
130
|
+
outbox completion, duplicate effects, native local rollback, conflicting/malformed disposition,
|
|
131
|
+
live max-poll ownership loss, dropped native Produce acknowledgements, broker restart, cancelled
|
|
132
|
+
consume/close and an owned literal v1 record. The database uncertainty case throws through a
|
|
133
|
+
native post-commit observer; it proves an unobserved committed result, not a TCP-level PostgreSQL
|
|
134
|
+
response fault. The frame proxy and process barriers are test-owned and absent from the recipe
|
|
135
|
+
adapter.
|
|
136
|
+
|
|
137
|
+
The tested topology is Linux x64, one combined broker/controller, one partition per topic, classic
|
|
138
|
+
groups and local plaintext. Replication-factor-one acceptance is no broker-availability claim.
|
|
139
|
+
Managed-service TLS/ACLs, cooperative/new consumer protocols, multiple partitions, parallel intake,
|
|
140
|
+
throughput, real production migrations and cross-released-client compatibility require their own
|
|
141
|
+
selected evidence. The initial literal v1 fixture does not certify two released library versions.
|
|
142
|
+
No Share Groups dependency or new Gloaming root runtime is introduced.
|
package/messaging.md
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# Add durable handoff and logical command receipts
|
|
2
|
+
|
|
3
|
+
Select this document when the requested behavior needs work to survive process loss,
|
|
4
|
+
independent module commits or ambiguous command completion. Modules alone do not imply messaging.
|
|
5
|
+
|
|
6
|
+
## Define the boundary
|
|
7
|
+
|
|
8
|
+
Name the sender, receiver, wire contract, admitted scope, logical action and failure behavior.
|
|
9
|
+
Decide whether delivery is a native local adapter or an external transport.
|
|
10
|
+
The application owns routes, queues/subscriptions, credentials, identity admission and workers.
|
|
11
|
+
|
|
12
|
+
Keep these identities distinct:
|
|
13
|
+
|
|
14
|
+
| Identity | Meaning |
|
|
15
|
+
| --- | --- |
|
|
16
|
+
| Entity/aggregate ID | Business resource |
|
|
17
|
+
| Logical command ID | One accepted action, reused after an uncertain response |
|
|
18
|
+
| Delivery MessageId | One retained outgoing/incoming envelope |
|
|
19
|
+
| Correlation/causation | Conversation and immediate cause |
|
|
20
|
+
|
|
21
|
+
## Outbox and inbox
|
|
22
|
+
|
|
23
|
+
The sender stages an immutable outgoing envelope with its business changes in the same
|
|
24
|
+
module context/transaction, then saves and commits. Install the required native outbox guards.
|
|
25
|
+
|
|
26
|
+
A separately invoked dispatcher publishes retained messages outside the claim transaction.
|
|
27
|
+
Transport acceptance can be uncertain; delivery can repeat. Database fencing cannot recall an
|
|
28
|
+
external provider effect.
|
|
29
|
+
|
|
30
|
+
The receiver validates transport/wire/scope admission, durably retains intake and commits before
|
|
31
|
+
acknowledging transport. Its independently invoked inbox processor commits local effects,
|
|
32
|
+
completion and any next outgoing message together. The selected processor owns that bounded
|
|
33
|
+
transaction; follow its savepoint, failure-accounting and cancellation contract.
|
|
34
|
+
|
|
35
|
+
Use the callable storage/dispatch/processing roles directly or select the separate Hosting
|
|
36
|
+
package. The application decides polling, supervision and process restart.
|
|
37
|
+
|
|
38
|
+
For optional PostgreSQL notifications around callable roles, follow
|
|
39
|
+
[the native wakeup recipe](postgres-wakeups.md). Preserve independent polling, fresh scopes and
|
|
40
|
+
terminal completion/accounting supervision; notification payloads never select business work.
|
|
41
|
+
Broker-free adapters must still preserve retained intent, stable identity, admitted intake and
|
|
42
|
+
recoverable response delivery. A direct independently committing method call alone does not.
|
|
43
|
+
|
|
44
|
+
Done: native tests prove producer rollback, receiver deduplication, redelivery after uncertain
|
|
45
|
+
acceptance, competing processing and recovery after process death.
|
|
46
|
+
|
|
47
|
+
For different deliveries targeting one entity, compose the native
|
|
48
|
+
[entity-work exclusion recipe](entity-work.md). It keeps a complete consumer key locked through
|
|
49
|
+
the original transaction; it does not supply FIFO, retained deduplication or business authority.
|
|
50
|
+
|
|
51
|
+
## Logical command receipts
|
|
52
|
+
|
|
53
|
+
Use receipts for an explicitly selected action whose accepted result must be recovered after a
|
|
54
|
+
lost response. The client/operator retains the action ID before sending and reuses it for that
|
|
55
|
+
same intent. A deliberate new action uses a new ID.
|
|
56
|
+
|
|
57
|
+
Authorize before exposing a retained result. In one fresh ReadCommitted context/transaction,
|
|
58
|
+
acquire the full scope/operation/action key and compare stable consumer-selected input.
|
|
59
|
+
An existing result is decoded with a compatible reader; a new accepted decision retains its
|
|
60
|
+
result/reference with the business and outgoing changes before save/commit.
|
|
61
|
+
|
|
62
|
+
The consumer owns comparison meaning, result format and readers, permissions, retention and
|
|
63
|
+
migration. Retain evidence for module lifetime under the current contract; explicit removal ends
|
|
64
|
+
duplicate protection. Unknown result formats must fail without re-executing the action.
|
|
65
|
+
|
|
66
|
+
Done: equal concurrent attempts commit one effect, changed input conflicts, rollback leaves
|
|
67
|
+
no completed receipt, and a fresh authorized retry recovers an uncertain committed result.
|
|
68
|
+
|
|
69
|
+
## Longer processes
|
|
70
|
+
|
|
71
|
+
Select the optional continuation runner only for its supported saved-method/request-reply model.
|
|
72
|
+
Business branching, compensation, response validation and operator authority stay in the module.
|
|
73
|
+
One pending request is supported. For parallel named replies, select the separate
|
|
74
|
+
[technical contribution protocol](https://github.com/oxface/gloaming/blob/main/src/Gloaming.Messaging/docs/contributions.md) and explicitly
|
|
75
|
+
choose participant/count policy and outcome messages. Business approval, strict deadline policy
|
|
76
|
+
and human-workflow assignment remain module decisions; no parallel workflow graph is supplied.
|
|
77
|
+
|
|
78
|
+
A due-time signal is an invitation to reconsider current business state, not authority to
|
|
79
|
+
complete a task. Generation/current-state checks remain necessary after cancellation or reassignment.
|
|
80
|
+
Select [finite due-time intents](https://github.com/oxface/gloaming/blob/main/src/Gloaming.Messaging/docs/due-intents.md) when a module
|
|
81
|
+
needs retained occurrence identity, suppression and bounded outbox handoff. The module still
|
|
82
|
+
owns its clock, source rules, transaction/save/commit and polling. This finite mechanism does
|
|
83
|
+
not supply a calendar, human assignment or workflow deadline policy.
|
|
84
|
+
|
|
85
|
+
Select the optional [recurrence module](https://github.com/oxface/gloaming/blob/main/src/Gloaming.Messaging/Gloaming.Messaging.Recurrence.EntityFrameworkCore.Postgres/README.md)
|
|
86
|
+
when repeated technical work needs retained planning progress. Pin and verify calendar inputs,
|
|
87
|
+
choose Skip/Coalesce/bounded CatchUp explicitly, and keep current-generation relevance in the
|
|
88
|
+
module. The module invokes planning/stopping in fresh native transactions; recurrence does not
|
|
89
|
+
install a worker or select business recipients and holidays.
|
package/modules.md
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# Add modules and aggregate roots
|
|
2
|
+
|
|
3
|
+
Use [structure](structure.md) for project boundaries. Interpret persistence per aggregate from
|
|
4
|
+
the request; ordinary EF state is the default. A module can use more than one persistence style
|
|
5
|
+
while retaining one clear native transaction owner.
|
|
6
|
+
|
|
7
|
+
## Common module steps
|
|
8
|
+
|
|
9
|
+
1. Create the named implementation and its needed Contracts. Define the requested aggregate
|
|
10
|
+
roots and a small application-facing command/query API. Keep business inputs/results free
|
|
11
|
+
from EF and persistence implementation types.
|
|
12
|
+
2. Add a scoped native DbContext with module-owned mappings, schema and migrations.
|
|
13
|
+
Configure a distinct migrations history/schema for modules sharing a database.
|
|
14
|
+
Host connection options are supplied to explicit module registration.
|
|
15
|
+
3. Implement current resource permission checks in the application operation. Use the
|
|
16
|
+
application-admitted actor and tenant; neither replaces resource authorization.
|
|
17
|
+
4. Make public commands return after their chosen local transaction commits. The module
|
|
18
|
+
application service normally owns the native transaction, save/commit and failure disposal.
|
|
19
|
+
If the application deliberately selects caller-owned staging instead, expose that contract
|
|
20
|
+
explicitly and keep commit ownership visible in its adapter.
|
|
21
|
+
5. Map HTTP/worker ingress through the module's Contracts. Native endpoint style and status
|
|
22
|
+
mapping belong to the host. Inter-module calls use Contracts and preserve module ownership.
|
|
23
|
+
6. Add migrations and meaningful operation/isolation/rollback tests before considering the
|
|
24
|
+
module ready. Update the application's module map.
|
|
25
|
+
|
|
26
|
+
An operation performs its accepted business changes and selected audit/outbox/receipt writes
|
|
27
|
+
in the same owning transaction. On failure or uncertain commit, dispose the transaction/context
|
|
28
|
+
and reconcile from fresh state. Independent module commits have independent recovery obligations.
|
|
29
|
+
|
|
30
|
+
## State-stored aggregates
|
|
31
|
+
|
|
32
|
+
Use ordinary domain classes or immutable state/candidates with native EF mappings.
|
|
33
|
+
Keep invariants, complete-candidate validation and optimistic versions in the module.
|
|
34
|
+
A generic repository, universal entity base and CQRS dispatcher are not required.
|
|
35
|
+
|
|
36
|
+
Choose native concurrency tokens for contested writes. Check expected versions at the business
|
|
37
|
+
boundary and handle save-time concurrency as well. Validate the complete accepted change before
|
|
38
|
+
mutating persisted state. Child/value mappings remain application decisions.
|
|
39
|
+
|
|
40
|
+
For multitenant data, select [ownership/save protection](gloaming.md) and include tenant identity
|
|
41
|
+
in all relevant keys/predicates. A query filter alone does not protect detached updates,
|
|
42
|
+
relationships or raw SQL. Use native constraints and selected RLS where the threat model requires.
|
|
43
|
+
|
|
44
|
+
Done: create/load and the selected mutation preserve invariants, ownership and versions;
|
|
45
|
+
stale/invalid changes and rollback leave committed state unchanged.
|
|
46
|
+
|
|
47
|
+
## Event-sourced aggregates
|
|
48
|
+
|
|
49
|
+
Select Gloaming's EventSourcing core and native EF store, then read their exact current contracts.
|
|
50
|
+
Use consumer-owned immutable state/facts and pure evolution. Stable event names/schema versions
|
|
51
|
+
and JSON encoding belong to the module; persisted CLR names are not the event contract.
|
|
52
|
+
|
|
53
|
+
Configure the complete stream key, event/header mappings and one required inline aggregate
|
|
54
|
+
state. Registered aggregate writes stage the accepted events, head and inline state together.
|
|
55
|
+
Install every required sync/async save validation. Save/commit stays with the selected operation
|
|
56
|
+
owner; the store is not an automatic unit of work.
|
|
57
|
+
|
|
58
|
+
Ordinary aggregate loading uses validated inline state at the current head.
|
|
59
|
+
Explicit history reading and complete regeneration are separate operations; production reads
|
|
60
|
+
do not silently rebuild or emit historical side effects. Payload upcasting is independently
|
|
61
|
+
selected. Reducer changes that affect persisted state require a deliberate repair/rollout plan.
|
|
62
|
+
|
|
63
|
+
For the initial example, use the named aggregate's smallest create/load lifecycle with an
|
|
64
|
+
explicit creation fact. Add business decisions only from actual requirements.
|
|
65
|
+
|
|
66
|
+
Done: native tests prove contiguous facts, consistent event/head/inline-state versions,
|
|
67
|
+
optimistic conflicts, complete rollback and replay of retained literal data when compatibility
|
|
68
|
+
is promised. State-stored aggregates in other modules take no event-sourcing dependency.
|
|
69
|
+
|
|
70
|
+
## Cross-module behavior
|
|
71
|
+
|
|
72
|
+
Same-process invocation is enough only when its failure/commit behavior meets the requirement.
|
|
73
|
+
If one module commits and the caller can die before recording the result, select a durable
|
|
74
|
+
handoff or explicitly prove a shared native transaction. Follow [messaging](messaging.md) when
|
|
75
|
+
durable progress is required; compensations remain business decisions.
|
package/package.json
CHANGED
|
@@ -1,6 +1,41 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oxface/modular-monolith-patterns",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Installable agent guidance for consumer-owned .NET modular monoliths.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"author": "oxface",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/oxface/gloaming.git",
|
|
11
|
+
"directory": "modular-monolith-patterns"
|
|
12
|
+
},
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": ">=24.21.0 <25"
|
|
15
|
+
},
|
|
16
|
+
"bin": {
|
|
17
|
+
"modular-monolith-patterns": "dist/cli.js"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist/",
|
|
21
|
+
"*.md",
|
|
22
|
+
"LICENSE"
|
|
23
|
+
],
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public",
|
|
26
|
+
"provenance": true
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "node eng/bundle.ts",
|
|
30
|
+
"typecheck": "tsc --noEmit -p tsconfig.check.json",
|
|
31
|
+
"format:check": "prettier --check 'src/*.ts' 'eng/*.ts' 'tests/*.ts' '*.json' 'SKILL.md'",
|
|
32
|
+
"test": "npm run build && node --test tests/*.test.ts",
|
|
33
|
+
"check": "npm run typecheck && npm run format:check && npm test",
|
|
34
|
+
"prepack": "npm run build"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@types/node": "24.19.2",
|
|
38
|
+
"prettier": "3.10.1",
|
|
39
|
+
"typescript": "7.0.2"
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# Optional PostgreSQL queue wakeups
|
|
2
|
+
|
|
3
|
+
Use notifications to shorten an application worker's idle wait while keeping periodic polling
|
|
4
|
+
authoritative. This is native application composition using existing typed Gloaming inbox/outbox
|
|
5
|
+
operations, Npgsql and bounded channels. It establishes **no new reusable library mechanism** and
|
|
6
|
+
adds no dependency to the provider-free hosting package. The standard polling hosts remain useful
|
|
7
|
+
without this optional recipe.
|
|
8
|
+
|
|
9
|
+
## Native session and startup
|
|
10
|
+
|
|
11
|
+
The application owns a dedicated direct PostgreSQL connection, independent of all business/
|
|
12
|
+
processing contexts. Use `Pooling=false`, `Multiplexing=false`, `Enlist=false`, an explicit endpoint,
|
|
13
|
+
bounded connection/command timeouts and a reconnect delay. A listener must retain one server
|
|
14
|
+
session; do not use transaction-pooled endpoints. The executable proof uses direct PostgreSQL18
|
|
15
|
+
with Npgsql10.0.3. Other proxies/topologies have no execution certificate here.
|
|
16
|
+
|
|
17
|
+
Attach `Notification` before issuing fixed reviewed `LISTEN` commands. Commit registration outside
|
|
18
|
+
a business/ambient transaction, then force each selected worker to poll durable state. A notification
|
|
19
|
+
may be consumed while processing an ordinary command before a later `WaitAsync`; the callback must
|
|
20
|
+
retain a hint. Never assume the next wait replays an already consumed event.
|
|
21
|
+
|
|
22
|
+
Give the inbox and outbox worker **separate capacity-one signals**. The callback only performs a
|
|
23
|
+
nonblocking signal write; it runs no handler, query or publication. Bursts coalesce with bounded
|
|
24
|
+
memory. The proved composition has one reader per signal; additional workers need their own signals
|
|
25
|
+
or an explicitly selected application fan-out policy. A signal is neither work nor authority.
|
|
26
|
+
|
|
27
|
+
Run one exclusive native receive pump. On connection failure, dispose that session, report degraded
|
|
28
|
+
wakeups, wait the selected reconnect delay, open/register again and force fresh polls. Worker polling
|
|
29
|
+
continues independently throughout listener outages. Hints lost during disconnect are harmless to
|
|
30
|
+
correctness. Cancel and await the pump before disposing its connection; never command or close a
|
|
31
|
+
connection concurrently with its wait. Cancellation/keepalive may break a session: discard it.
|
|
32
|
+
|
|
33
|
+
Npgsql's integer `WaitAsync(timeout, token)` needs a positive bounded millisecond timeout when
|
|
34
|
+
bounded waiting is intended;0/-1 mean indefinite. Multiplexing is unsupported. Driver pooled reset
|
|
35
|
+
removes LISTEN registrations; a new/reopened session always registers again. Each held listener
|
|
36
|
+
consumes a database connection even when no queue work exists.
|
|
37
|
+
|
|
38
|
+
## Two ordinary callers
|
|
39
|
+
|
|
40
|
+
For each inbox poll, create a fresh established scope and call
|
|
41
|
+
`IInboxProcessor<ModuleDatabase>.ProcessNextAsync(selectedSubscription, token)`. For each outbox
|
|
42
|
+
poll, independently create a fresh scope and call
|
|
43
|
+
`IOutboxDispatcher<ModuleDatabase>.DispatchNextAsync(token)`. Dispose each operation scope before
|
|
44
|
+
idling. After `NoWork`, consume its retained hint or wait for a hint **or a positive fallback delay**,
|
|
45
|
+
then poll again. A hint never selects a message, tenant, subscription or acknowledgment.
|
|
46
|
+
|
|
47
|
+
Use a cancelled-and-awaited losing read, not an abandoned `Task.WhenAny` read that could steal the
|
|
48
|
+
next hint. The executable recipe uses a linked cancellation source with the fallback deadline and
|
|
49
|
+
awaits its channel read to completion. Eligibility, retry availability and lease expiry can change
|
|
50
|
+
solely with time; insert/update notifications cannot replace that fallback.
|
|
51
|
+
|
|
52
|
+
The consumer supervises listener and workers together. Unexpected worker completion or any thrown
|
|
53
|
+
processing/publication/accounting fault reaches the host and cancels the other tasks. Listener
|
|
54
|
+
connection errors only degrade wakeups; they must not convert fatal `InboxFailureAccountingException`,
|
|
55
|
+
`OutboxFailureAccountingException` or `OutboxCompletionException` into ordinary retries. Cancellation
|
|
56
|
+
and cleanup have independent budgets; preserve original failures. The recipe selects terminal
|
|
57
|
+
supervision for thrown worker errors. Backoff, restarts, logging and readiness remain application
|
|
58
|
+
policy; no universal retry loop or Gloaming runtime is introduced.
|
|
59
|
+
|
|
60
|
+
## Additive migration and grants
|
|
61
|
+
|
|
62
|
+
The consumer installs reviewed `AFTER INSERT` triggers on its selected inbox/outbox tables. A fixed
|
|
63
|
+
`SECURITY INVOKER` function calls qualified `pg_catalog.pg_notify` with a constant channel and **empty
|
|
64
|
+
payload**, using a trusted fixed search path. Schema/table/function ownership stays with migration
|
|
65
|
+
credentials. Runtime credentials need normal queue/handler grants plus database CONNECT; they do not
|
|
66
|
+
need schema CREATE, function ownership, trigger changes or deletion. Prove actual grants, including
|
|
67
|
+
any locally revoked native function privileges. Notifications do not change RLS or admission policy.
|
|
68
|
+
|
|
69
|
+
Pause/coordinate native DDL as appropriate to the application's migration process. Install additively
|
|
70
|
+
over retained rows; the initial post-registration poll drains pre-trigger work. Unchanged older
|
|
71
|
+
writers signal through the database trigger. Removing triggers leaves ordinary polling functional.
|
|
72
|
+
Keep owned table mappings, migrations and compiled old/new writers; no library release compatibility
|
|
73
|
+
claim follows merely from compiling the current source twice.
|
|
74
|
+
|
|
75
|
+
Notifications commit with the producer transaction and are not durable offline delivery. Identical
|
|
76
|
+
hints within one transaction can fold; spurious/untrusted hints may cause an extra poll. Notifications
|
|
77
|
+
are visible to database users, so channels/payloads must contain no secrets. A saturated native
|
|
78
|
+
notification queue can fail the notifying transaction's **commit**; selecting a trigger therefore
|
|
79
|
+
adds a producer failure mode. Monitor native queue usage and transaction duration, and recover failed
|
|
80
|
+
producer decisions through their existing fresh-context transaction protocol. There is no external
|
|
81
|
+
exactly-once, FIFO, zero-latency or always-available-listener guarantee.
|
|
82
|
+
|
|
83
|
+
## Executable owners
|
|
84
|
+
|
|
85
|
+
The [native application fixture](https://github.com/oxface/gloaming/blob/main/src/Gloaming.Messaging/tests/Fixtures/Wakeups/README.md) contains
|
|
86
|
+
the complete pump, typed callers and fault supervisor. [Provider tests](https://github.com/oxface/gloaming/blob/main/src/Gloaming.Messaging/tests/OutboxPostgresTests/WakeupTests.cs)
|
|
87
|
+
cover actual queue processing, disconnected fallback/reconnect, cancellation, pooled reset,
|
|
88
|
+
notification-before-wait, bounded coalescing, restricted grants and separately compiled earlier
|
|
89
|
+
writes across trigger installation/removal. The [independent package consumer](https://github.com/oxface/gloaming/blob/main/eng/release/consumers/Wakeups.cs)
|
|
90
|
+
uses both real callable roles and native notifications from NuGet packages without Hosting.
|
|
91
|
+
|
|
92
|
+
Native semantics are described in [PostgreSQL LISTEN](https://www.postgresql.org/docs/18/sql-listen.html),
|
|
93
|
+
[NOTIFY](https://www.postgresql.org/docs/18/sql-notify.html) and
|
|
94
|
+
[Npgsql notification waiting](https://www.npgsql.org/doc/wait.html). The application chooses whether
|
|
95
|
+
the reduced idle latency justifies session/notification overhead; no throughput benchmark or
|
|
96
|
+
production latency objective is certified by these bounded proofs.
|
package/structure.md
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# Application structure
|
|
2
|
+
|
|
3
|
+
Use module boundaries as the main organization. Within a module, begin with one implementation
|
|
4
|
+
project and a Contracts project when the host or another module needs its business API.
|
|
5
|
+
Use folders inside the implementation for domain, application operations and persistence.
|
|
6
|
+
|
|
7
|
+
~~~text
|
|
8
|
+
<Application>.slnx
|
|
9
|
+
global.json
|
|
10
|
+
Directory.Build.props
|
|
11
|
+
Directory.Packages.props
|
|
12
|
+
orchestration/
|
|
13
|
+
local/
|
|
14
|
+
<Application>.Local.AppHost.csproj
|
|
15
|
+
src/
|
|
16
|
+
<Application>.Server/
|
|
17
|
+
<Application>.Worker/
|
|
18
|
+
<Application>.Migrator/
|
|
19
|
+
<Application>.ServiceDefaults/
|
|
20
|
+
Modules/
|
|
21
|
+
X/
|
|
22
|
+
<Application>.X.Contracts/
|
|
23
|
+
<Application>.X/
|
|
24
|
+
Domain/
|
|
25
|
+
Application/
|
|
26
|
+
Persistence/
|
|
27
|
+
Migrations/
|
|
28
|
+
Y/
|
|
29
|
+
<Application>.Y.Contracts/
|
|
30
|
+
<Application>.Y/
|
|
31
|
+
tests/
|
|
32
|
+
<Application>.ArchitectureTests/
|
|
33
|
+
<Application>.IntegrationTests/
|
|
34
|
+
docs/
|
|
35
|
+
architecture.md
|
|
36
|
+
~~~
|
|
37
|
+
|
|
38
|
+
Create folders when they contain implementation. Worker and service-default projects have
|
|
39
|
+
their selected lifecycle responsibilities; document or omit an unnecessary host rather than
|
|
40
|
+
inventing recurring jobs. Existing repositories may use a different layout while keeping the
|
|
41
|
+
same ownership boundaries.
|
|
42
|
+
Add `orchestration/e2e`, `orchestration/shared` and a publishing AppHost only when used.
|
|
43
|
+
The [browser stack profile](dotnet-react-vite.md) adds `apps/`, private workspace `packages/`
|
|
44
|
+
and `eng/` helpers for its selected frontend and verification tools.
|
|
45
|
+
|
|
46
|
+
## Dependencies
|
|
47
|
+
|
|
48
|
+
- Contracts exposes business operations, inputs and results. Keep EF rows, DbContexts,
|
|
49
|
+
event-store internals and implementation DTOs inside the module implementation.
|
|
50
|
+
- A module implementation references its Contracts, selected technical libraries and another
|
|
51
|
+
module's Contracts when needed. It does not reference another module implementation.
|
|
52
|
+
- Server/Worker composition roots reference implementations to register native services.
|
|
53
|
+
Business endpoints and cross-module calls use Contracts.
|
|
54
|
+
- Migrator invokes explicit module setup entry points for their migrations and grants.
|
|
55
|
+
AppHost references executable hosts for local orchestration.
|
|
56
|
+
- Business modules have no dependency on Server, Worker, Migrator, AppHost or Aspire.
|
|
57
|
+
- Domain objects contain their own invariants. State-stored aggregates need no shared domain
|
|
58
|
+
base. Event-sourced aggregates may select Gloaming bookkeeping without moving rules into it.
|
|
59
|
+
|
|
60
|
+
Use names from the target application. Wholesale's Access/Sales/Inventory language is example
|
|
61
|
+
policy and is not a prescribed set of modules.
|
|
62
|
+
|
|
63
|
+
## Persistence ownership
|
|
64
|
+
|
|
65
|
+
Give every module a native DbContext, owned schema, migration history and named connection.
|
|
66
|
+
A shared physical PostgreSQL instance/database is a deliberate deployment choice; it does not
|
|
67
|
+
create a shared context or cross-module unit of work. Separate databases/roles are appropriate
|
|
68
|
+
when the application's isolation requirements call for them.
|
|
69
|
+
Keep native `IEntityTypeConfiguration<T>` mappings with the module alongside migrations.
|
|
70
|
+
Hosts supply configuration and select setup operations; modules own schema-specific SQL.
|
|
71
|
+
|
|
72
|
+
Use business IDs in another module's data rather than cross-module EF navigation or database
|
|
73
|
+
foreign keys. Query another module through its Contracts or maintain an explicitly owned
|
|
74
|
+
receiving view. Same-process calls that commit independently do not create atomicity.
|
|
75
|
+
|
|
76
|
+
## Record the result
|
|
77
|
+
|
|
78
|
+
The target architecture document lists each module, aggregate roots, persistence mode,
|
|
79
|
+
schema/database, connection/credential roles, public Contracts and transaction owner.
|
|
80
|
+
It also records chosen hosts, identity/tenant admission and any durable delivery boundary.
|
|
81
|
+
Keep library API details in their owning library contracts.
|