serverless-ircd 0.4.0 → 0.6.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/.github/workflows/ci.yml +34 -2
- package/.github/workflows/deploy-aws.yml +1 -2
- package/.github/workflows/deploy-cf-tcp.yml +1 -5
- package/.github/workflows/deploy-cf.yml +1 -2
- package/CHANGELOG.md +435 -0
- package/README.md +206 -27
- package/apps/aws-stack/README.md +37 -3
- package/apps/aws-stack/package.json +1 -1
- package/apps/aws-stack/src/aws-stack.ts +106 -13
- package/apps/aws-stack/tests/coverage-command.test.ts +155 -0
- package/apps/aws-stack/tests/stack.test.ts +49 -3
- package/apps/aws-stack/tests/synth-no-bundle.test.ts +129 -0
- package/apps/aws-stack/tests/vitest.setup.ts +18 -0
- package/apps/aws-stack/vitest.config.ts +3 -0
- package/apps/cf-tcp-container/package.json +1 -1
- package/apps/cf-tcp-container/src/config-loader.ts +6 -7
- package/apps/cf-tcp-container/src/container-server.ts +3 -0
- package/apps/cf-tcp-container/tests/config-loader.test.ts +10 -3
- package/apps/cf-tcp-container/wrangler.toml +1 -1
- package/apps/cf-worker/package.json +2 -1
- package/apps/cf-worker/vitest.config.ts +1 -1
- package/apps/cf-worker/wrangler.toml +5 -3
- package/apps/local-cli/package.json +1 -1
- package/apps/local-cli/src/config-loader.ts +6 -6
- package/apps/local-cli/src/main.ts +20 -0
- package/apps/local-cli/src/server.ts +138 -28
- package/apps/local-cli/tests/e2e.test.ts +113 -29
- package/apps/local-cli/tests/tcp.test.ts +71 -19
- package/apps/local-cli/tests/ws-subprotocol.test.ts +262 -0
- package/biome.json +1 -0
- package/docs/ADR-001-pure-reducers-and-effect-system.md +74 -0
- package/docs/ADR-002-location-of-authority.md +82 -0
- package/docs/ADR-003-durable-object-sharding.md +110 -0
- package/docs/ADR-004-dynamodb-schema.md +96 -0
- package/docs/ADR-005-wss-only-transport-v1.md +83 -0
- package/docs/ADR-006-sasl-mechanism-scope.md +96 -0
- package/docs/ADR-007-deterministic-ports.md +82 -0
- package/docs/ADR-008-monorepo-tooling.md +60 -0
- package/docs/ADR-009-dual-transport-wss-and-irc-tls.md +138 -0
- package/docs/ADR-Index.md +15 -0
- package/docs/AWS-Adapter-Architecture.md +496 -0
- package/docs/AWS-Deployment.md +1275 -0
- package/docs/AWS-TCP-Deployment.md +410 -0
- package/docs/Cloudflare-Deployment-Guide.md +719 -0
- package/docs/Cloudflare-TCP-Deployment.md +510 -0
- package/docs/Home.md +15 -0
- package/docs/Observability.md +87 -0
- package/docs/PlanExtensions.md +812 -0
- package/docs/PlanIRCv3Websocket.md +503 -0
- package/docs/PlanWebClient.md +451 -0
- package/docs/Release-Process.md +443 -0
- package/package.json +2 -2
- package/packages/aws-adapter/package.json +1 -1
- package/packages/aws-adapter/src/aws-runtime.ts +69 -0
- package/packages/aws-adapter/src/handlers/connect.ts +36 -5
- package/packages/aws-adapter/src/handlers/default.ts +66 -5
- package/packages/aws-adapter/src/handlers/index.ts +41 -2
- package/packages/aws-adapter/src/handlers/nlb-stream.ts +18 -0
- package/packages/aws-adapter/src/index.ts +2 -0
- package/packages/aws-adapter/src/serialize.ts +40 -2
- package/packages/aws-adapter/src/stats.ts +80 -0
- package/packages/aws-adapter/tests/account-store-dynamo.test.ts +49 -8
- package/packages/aws-adapter/tests/account-store.test.ts +4 -7
- package/packages/aws-adapter/tests/aws-harness.ts +5 -2
- package/packages/aws-adapter/tests/aws-integration.test.ts +8 -4
- package/packages/aws-adapter/tests/aws-runtime.test.ts +140 -0
- package/packages/aws-adapter/tests/config-loader.test.ts +11 -2
- package/packages/aws-adapter/tests/connect.test.ts +100 -4
- package/packages/aws-adapter/tests/disconnect-fanout.test.ts +3 -4
- package/packages/aws-adapter/tests/global-setup.ts +55 -30
- package/packages/aws-adapter/tests/gone-exception.test.ts +4 -9
- package/packages/aws-adapter/tests/handlers.test.ts +238 -4
- package/packages/aws-adapter/tests/message-store.test.ts +6 -5
- package/packages/aws-adapter/tests/nlb-stream.test.ts +62 -8
- package/packages/aws-adapter/tests/stats.test.ts +317 -0
- package/packages/cf-adapter/package.json +6 -1
- package/packages/cf-adapter/src/cf-runtime.ts +66 -1
- package/packages/cf-adapter/src/channel-do.ts +2 -2
- package/packages/cf-adapter/src/connection-do.ts +185 -54
- package/packages/cf-adapter/src/env.ts +25 -6
- package/packages/cf-adapter/src/index.ts +2 -0
- package/packages/cf-adapter/src/registry-do.ts +22 -3
- package/packages/cf-adapter/src/serialize.ts +25 -4
- package/packages/cf-adapter/src/sharding.ts +1 -2
- package/packages/cf-adapter/src/stats.ts +65 -0
- package/packages/cf-adapter/tests/cf-harness.ts +1 -1
- package/packages/cf-adapter/tests/cf-integration.test.ts +4 -4
- package/packages/cf-adapter/tests/cf-runtime.test.ts +307 -2
- package/packages/cf-adapter/tests/channel-do.test.ts +119 -2
- package/packages/cf-adapter/tests/config-loader.test.ts +49 -0
- package/packages/cf-adapter/tests/connection-do-channel-registration.test.ts +2 -2
- package/packages/cf-adapter/tests/connection-do-no-batching-reservation.test.ts +2 -2
- package/packages/cf-adapter/tests/connection-do-pure.test.ts +91 -0
- package/packages/cf-adapter/tests/connection-do-ws-spec-contract.test.ts +289 -0
- package/packages/cf-adapter/tests/connection-do-ws-subprotocol.test.ts +184 -0
- package/packages/cf-adapter/tests/connection-do.test.ts +27 -2
- package/packages/cf-adapter/tests/d1-account-store.test.ts +48 -0
- package/packages/cf-adapter/tests/registry-do.test.ts +108 -4
- package/packages/cf-adapter/tests/serialize.test.ts +308 -0
- package/packages/cf-adapter/tests/sharding.test.ts +1 -1
- package/packages/cf-adapter/tests/stats.test.ts +120 -0
- package/packages/cf-adapter/tests/worker/main.ts +7 -7
- package/packages/cf-adapter/tests/worker/stubs/channel-stub.ts +2 -2
- package/packages/cf-adapter/tests/worker/stubs/registry-stub.ts +8 -2
- package/packages/cf-adapter/vitest.config.ts +1 -1
- package/packages/cf-adapter/wrangler.test.toml +7 -0
- package/packages/in-memory-runtime/package.json +1 -1
- package/packages/in-memory-runtime/src/in-memory-runtime.ts +39 -0
- package/packages/in-memory-runtime/tests/in-memory-runtime.test.ts +259 -0
- package/packages/irc-core/package.json +1 -1
- package/packages/irc-core/src/admission.ts +16 -15
- package/packages/irc-core/src/caps/capabilities.ts +38 -4
- package/packages/irc-core/src/caps/index.ts +1 -0
- package/packages/irc-core/src/caps/sts.ts +84 -0
- package/packages/irc-core/src/commands/account-notify.ts +53 -0
- package/packages/irc-core/src/commands/away.ts +9 -3
- package/packages/irc-core/src/commands/cap.ts +23 -5
- package/packages/irc-core/src/commands/chathistory.ts +40 -11
- package/packages/irc-core/src/commands/index.ts +42 -0
- package/packages/irc-core/src/commands/invite.ts +2 -4
- package/packages/irc-core/src/commands/isupport.ts +59 -2
- package/packages/irc-core/src/commands/kick.ts +2 -4
- package/packages/irc-core/src/commands/kill.ts +127 -0
- package/packages/irc-core/src/commands/list.ts +1 -1
- package/packages/irc-core/src/commands/lusers.ts +204 -0
- package/packages/irc-core/src/commands/mode.ts +12 -9
- package/packages/irc-core/src/commands/monitor.ts +327 -0
- package/packages/irc-core/src/commands/multiline.ts +256 -0
- package/packages/irc-core/src/commands/names.ts +3 -5
- package/packages/irc-core/src/commands/part.ts +2 -4
- package/packages/irc-core/src/commands/pre-away.ts +112 -0
- package/packages/irc-core/src/commands/privmsg.ts +19 -12
- package/packages/irc-core/src/commands/read-marker.ts +108 -0
- package/packages/irc-core/src/commands/registration.ts +8 -0
- package/packages/irc-core/src/commands/rehash.ts +119 -0
- package/packages/irc-core/src/commands/sasl.ts +24 -1
- package/packages/irc-core/src/commands/setname.ts +109 -0
- package/packages/irc-core/src/commands/stats.ts +152 -0
- package/packages/irc-core/src/commands/tagmsg.ts +71 -1
- package/packages/irc-core/src/commands/topic.ts +2 -4
- package/packages/irc-core/src/commands/trace.ts +137 -0
- package/packages/irc-core/src/commands/wallops.ts +118 -0
- package/packages/irc-core/src/commands/whois.ts +5 -0
- package/packages/irc-core/src/config.ts +72 -10
- package/packages/irc-core/src/effects.ts +41 -1
- package/packages/irc-core/src/index.ts +2 -0
- package/packages/irc-core/src/ports.ts +568 -0
- package/packages/irc-core/src/protocol/index.ts +14 -0
- package/packages/irc-core/src/protocol/labeled-response.ts +133 -0
- package/packages/irc-core/src/protocol/numerics.ts +57 -11
- package/packages/irc-core/src/protocol/outbound.ts +36 -4
- package/packages/irc-core/src/protocol/standard-replies.ts +277 -0
- package/packages/irc-core/src/state/connection.ts +32 -1
- package/packages/irc-core/src/types.ts +120 -1
- package/packages/irc-core/src/ws-framing.ts +132 -0
- package/packages/irc-core/src/ws-subprotocol.ts +66 -0
- package/packages/irc-core/stryker.commands.conf.json +1 -2
- package/packages/irc-core/tests/admission.test.ts +18 -0
- package/packages/irc-core/tests/away-store.test.ts +73 -0
- package/packages/irc-core/tests/caps/capabilities.test.ts +119 -2
- package/packages/irc-core/tests/caps/sts.test.ts +123 -0
- package/packages/irc-core/tests/commands/account-notify.test.ts +171 -0
- package/packages/irc-core/tests/commands/away.test.ts +85 -2
- package/packages/irc-core/tests/commands/cap.test.ts +165 -0
- package/packages/irc-core/tests/commands/chathistory.test.ts +148 -1
- package/packages/irc-core/tests/commands/echo-message.test.ts +9 -3
- package/packages/irc-core/tests/commands/isupport.test.ts +80 -0
- package/packages/irc-core/tests/commands/kill.test.ts +243 -0
- package/packages/irc-core/tests/commands/lusers.test.ts +368 -0
- package/packages/irc-core/tests/commands/mode.test.ts +129 -0
- package/packages/irc-core/tests/commands/monitor.test.ts +411 -0
- package/packages/irc-core/tests/commands/multiline.test.ts +428 -0
- package/packages/irc-core/tests/commands/pre-away.test.ts +241 -0
- package/packages/irc-core/tests/commands/privmsg.test.ts +154 -3
- package/packages/irc-core/tests/commands/read-marker.test.ts +211 -0
- package/packages/irc-core/tests/commands/registration.test.ts +64 -0
- package/packages/irc-core/tests/commands/rehash.test.ts +171 -0
- package/packages/irc-core/tests/commands/sasl.test.ts +116 -2
- package/packages/irc-core/tests/commands/setname.test.ts +225 -0
- package/packages/irc-core/tests/commands/stats.test.ts +294 -0
- package/packages/irc-core/tests/commands/tagmsg.test.ts +357 -0
- package/packages/irc-core/tests/commands/trace.test.ts +282 -0
- package/packages/irc-core/tests/commands/wallops.test.ts +231 -0
- package/packages/irc-core/tests/commands/whois.test.ts +34 -0
- package/packages/irc-core/tests/config.test.ts +103 -13
- package/packages/irc-core/tests/dropped-s2s-and-obsolete-verbs.test.ts +90 -0
- package/packages/irc-core/tests/effects.test.ts +14 -0
- package/packages/irc-core/tests/labeled-response.test.ts +181 -0
- package/packages/irc-core/tests/message-tags.test.ts +114 -0
- package/packages/irc-core/tests/monitor-store.test.ts +200 -0
- package/packages/irc-core/tests/numerics.test.ts +90 -0
- package/packages/irc-core/tests/outbound.test.ts +51 -0
- package/packages/irc-core/tests/ports.test.ts +22 -0
- package/packages/irc-core/tests/raw-modules.d.ts +11 -0
- package/packages/irc-core/tests/read-marker-store.test.ts +108 -0
- package/packages/irc-core/tests/standard-replies.test.ts +412 -0
- package/packages/irc-core/tests/stats-store.test.ts +222 -0
- package/packages/irc-core/tests/types.test.ts +27 -0
- package/packages/irc-core/tests/ws-framing.test.ts +213 -0
- package/packages/irc-core/tests/ws-subprotocol.test.ts +111 -0
- package/packages/irc-server/package.json +1 -1
- package/packages/irc-server/src/actor.ts +699 -19
- package/packages/irc-server/src/dispatch.ts +109 -16
- package/packages/irc-server/src/routing.ts +3 -0
- package/packages/irc-server/src/runtime.ts +31 -0
- package/packages/irc-server/src/transport.ts +10 -7
- package/packages/irc-server/tests/actor.test.ts +2523 -42
- package/packages/irc-server/tests/dispatch.test.ts +300 -2
- package/packages/irc-server/tests/raw-modules.d.ts +11 -0
- package/packages/irc-server/tests/routing.test.ts +1 -0
- package/packages/irc-server/tests/runtime.test.ts +7 -0
- package/packages/irc-test-support/package.json +1 -1
- package/packages/irc-test-support/src/index.ts +6 -0
- package/packages/irc-test-support/src/scenarios.ts +9 -1
- package/packages/irc-test-support/src/test-config.ts +54 -0
- package/packages/irc-test-support/tests/in-memory-scenarios.test.ts +1 -1
- package/packages/irc-test-support/tests/test-config.test.ts +51 -0
- package/pnpm-workspace.yaml +1 -0
- package/tools/ci-hardening/package.json +1 -1
- package/tools/ci-hardening/tests/ddb-local.test.ts +82 -0
- package/tools/load-test/package.json +33 -0
- package/tools/load-test/src/client.ts +351 -0
- package/tools/load-test/src/config.ts +313 -0
- package/tools/load-test/src/harness.ts +116 -0
- package/tools/load-test/src/main.ts +120 -0
- package/tools/load-test/src/metrics.ts +168 -0
- package/tools/load-test/src/report.ts +106 -0
- package/tools/load-test/tests/client.test.ts +212 -0
- package/tools/load-test/tests/config.test.ts +152 -0
- package/tools/load-test/tests/framing.test.ts +37 -0
- package/tools/load-test/tests/harness.test.ts +165 -0
- package/tools/load-test/tests/metrics.test.ts +174 -0
- package/tools/load-test/tests/report.test.ts +161 -0
- package/tools/load-test/tests/smoke.test.ts +67 -0
- package/tools/load-test/tsconfig.build.json +12 -0
- package/tools/load-test/tsconfig.test.json +10 -0
- package/tools/load-test/vitest.config.ts +29 -0
- package/tools/package.json +6 -1
- package/tools/seed-cf-accounts.ts +4 -1
- package/tools/tcp-ws-forwarder/package.json +1 -1
- package/tools/tcp-ws-forwarder/src/forwarder.ts +57 -9
- package/tools/tcp-ws-forwarder/tests/forwarder.test.ts +34 -1
- package/tools/tcp-ws-forwarder/tests/framing.test.ts +65 -1
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# ADR-003: Cloudflare Durable Object sharding strategy
|
|
2
|
+
|
|
3
|
+
**Date:** 2025-02-01 (Phase 3)
|
|
4
|
+
**Status:** Accepted
|
|
5
|
+
**Supersedes:** —
|
|
6
|
+
**Superseded by:** —
|
|
7
|
+
|
|
8
|
+
## Context
|
|
9
|
+
|
|
10
|
+
Cloudflare Durable Objects (DOs) are single-threaded per-instance: all
|
|
11
|
+
requests to a given DO instance are serialized. This is ideal for enforcing
|
|
12
|
+
uniqueness invariants (two racing requests land on the same DO, one after the
|
|
13
|
+
other), but a single DO instance is a throughput ceiling. ServerlessIRCd needs
|
|
14
|
+
three DO classes:
|
|
15
|
+
|
|
16
|
+
1. **ConnectionDO** — one per WebSocket connection. Keyed by `connectionId`.
|
|
17
|
+
No sharding needed: each connection is its own instance.
|
|
18
|
+
2. **ChannelDO** — one per channel. Keyed by lowercased channel name.
|
|
19
|
+
No sharding needed: one DO per channel is the natural unit; a hot channel
|
|
20
|
+
(1k+ members) is bounded by DO fanout latency, not by DO count.
|
|
21
|
+
3. **RegistryDO** — holds the global nick → connectionId map. If this were a
|
|
22
|
+
single DO, every nick registration on the entire server would serialize
|
|
23
|
+
through one instance. That is an unacceptable bottleneck for any non-trivial
|
|
24
|
+
deployment.
|
|
25
|
+
|
|
26
|
+
The open question (PLAN §9): *"Channel DO sharding granularity (one DO per
|
|
27
|
+
channel vs. bucketed)?"* and *"Registry DO: how to shard?"*
|
|
28
|
+
|
|
29
|
+
## Decision
|
|
30
|
+
|
|
31
|
+
**ConnectionDO:** one instance per connection (`idFromName(connectionId)`).
|
|
32
|
+
No sharding.
|
|
33
|
+
|
|
34
|
+
**ChannelDO:** one instance per channel
|
|
35
|
+
(`idFromName(lowercasedChannelName)`). No bucketing. If a hot channel exceeds
|
|
36
|
+
DO throughput limits, the mitigation is fanout batching (one `stub()` call
|
|
37
|
+
carrying multiple lines) rather than splitting the channel across DOs. A
|
|
38
|
+
single channel's roster and modes live in one DO so that all mutations are
|
|
39
|
+
serialized correctly.
|
|
40
|
+
|
|
41
|
+
**RegistryDO:** sharded by `hash(lowercased(nick)) % N`, where `N` defaults
|
|
42
|
+
to **32** (`DEFAULT_REGISTRY_SHARDS`). The hash function is FNV-1a 32-bit,
|
|
43
|
+
chosen for its uniform distribution, deterministic output (no randomness),
|
|
44
|
+
and trivial implementation.
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
shard = fnv1a32(nick.toLowerCase()) % N
|
|
48
|
+
key = `s${shard}` // e.g. "s7", "s31"
|
|
49
|
+
stub = env.REGISTRY_DO.get(env.REGISTRY_DO.idFromName(key))
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Two clients racing on the same nick always land on the same shard (because
|
|
53
|
+
lowercasing collapses case variants), so the single-shard uniqueness check
|
|
54
|
+
covers all case variants. Different nicks spread across shards, so
|
|
55
|
+
registration throughput scales with the fleet size.
|
|
56
|
+
|
|
57
|
+
Cross-shard nick changes (old nick and new nick hash to different shards)
|
|
58
|
+
use a two-phase reserve-new-then-release-old. The new-nick shard wins the
|
|
59
|
+
race; the old-nick shard is released only after the new reservation succeeds.
|
|
60
|
+
|
|
61
|
+
`N` is configurable via the `REGISTRY_SHARDS` environment variable. Changing
|
|
62
|
+
`N` in production requires a migration (re-sharding every existing nick entry
|
|
63
|
+
to its new shard).
|
|
64
|
+
|
|
65
|
+
## Consequences
|
|
66
|
+
|
|
67
|
+
**Positive:**
|
|
68
|
+
- Nick uniqueness is race-free within the DO model. No conditional writes,
|
|
69
|
+
no optimistic concurrency — the DO's serial execution is the lock.
|
|
70
|
+
- Registration throughput scales horizontally: 32 shards handle 32× the
|
|
71
|
+
single-DO throughput for distinct nicks.
|
|
72
|
+
- One DO per channel keeps channel semantics simple: JOIN/PART/MODE/KICK all
|
|
73
|
+
serialize through the same instance.
|
|
74
|
+
|
|
75
|
+
**Negative:**
|
|
76
|
+
- Changing `N` (the shard count) requires migrating every existing nick to
|
|
77
|
+
its new shard. This is an offline migration, not a live reshard. The shard
|
|
78
|
+
count should be chosen conservatively at deployment time.
|
|
79
|
+
- The channel registry problem: there is no DO that "knows" all channels
|
|
80
|
+
(LIST, TICKET-073). A dedicated registry DO or KV index is needed — this is
|
|
81
|
+
a known gap tracked in TICKET-073.
|
|
82
|
+
- Hot-nick collisions (many nicks hashing to the same shard) are possible but
|
|
83
|
+
statistically rare with FNV-1a and `N = 32` for typical populations.
|
|
84
|
+
|
|
85
|
+
### Outbound batching scope (TICKET-087)
|
|
86
|
+
|
|
87
|
+
The fanout batching decided above is implemented **per call**:
|
|
88
|
+
`ConnectionDO.deliver()` joins every line of one ChannelDO broadcast into a
|
|
89
|
+
single `WebSocket.send()`, and the actor's `send` handler does the same for
|
|
90
|
+
all lines of one frame's response. A speculative **cross-call** coalescing
|
|
91
|
+
optimization (queueing lines from independent `deliver`/`send` invocations
|
|
92
|
+
within one microtask and flushing them as one write) was reserved as a
|
|
93
|
+
commented-out field in `ConnectionDO` and subsequently **dropped**: it would
|
|
94
|
+
add a drain queue and a `queueMicrotask` scheduler, introduce ordering
|
|
95
|
+
hazards between independent fan-out calls, and yield no measured benefit —
|
|
96
|
+
nothing in the TICKET-049 load-test report or the ChannelDO fan-out path
|
|
97
|
+
shows WS round-trips as a bottleneck. The AWS adapter batches at a different
|
|
98
|
+
layer (per-invocation `outbound: string[]` accumulated then posted once), so
|
|
99
|
+
no shared abstraction is worth extracting. Revisit only if WS round-trips
|
|
100
|
+
become a demonstrated bottleneck.
|
|
101
|
+
|
|
102
|
+
## References
|
|
103
|
+
|
|
104
|
+
- PLAN §9 — open question: "Channel DO sharding granularity"
|
|
105
|
+
- PLAN §6.1 — `RegistryDO` sharded by `hash(nick) % N`
|
|
106
|
+
- `packages/cf-adapter/src/sharding.ts` — `shardNick`, `registryKeyForNick`,
|
|
107
|
+
`DEFAULT_REGISTRY_SHARDS = 32`
|
|
108
|
+
- `packages/cf-adapter/src/registry-do.ts` — per-shard registry authority
|
|
109
|
+
- TICKET-034 — RegistryDO implementation
|
|
110
|
+
- TICKET-073 — CF runtime stubbed lookups (channel registry gap)
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# ADR-004: AWS DynamoDB schema
|
|
2
|
+
|
|
3
|
+
**Date:** 2025-02-15 (Phase 4)
|
|
4
|
+
**Status:** Accepted
|
|
5
|
+
**Supersedes:** —
|
|
6
|
+
**Superseded by:** —
|
|
7
|
+
|
|
8
|
+
## Context
|
|
9
|
+
|
|
10
|
+
The AWS adapter runs IRC state on DynamoDB (single table family, not
|
|
11
|
+
single-table design). Unlike Cloudflare Durable Objects, DynamoDB does not
|
|
12
|
+
serialize access to a record by default — concurrent writes can interleave.
|
|
13
|
+
Nick uniqueness, channel membership atomicity, and gone-connection cleanup
|
|
14
|
+
all require explicit concurrency control.
|
|
15
|
+
|
|
16
|
+
The schema must support: connection records, channel metadata, channel
|
|
17
|
+
membership (roster), nick registry, and SASL account credentials. It must
|
|
18
|
+
also handle the Lambda invocation model: each `$default` invocation is a
|
|
19
|
+
fresh process that reads state, runs a reducer, and writes back — there is no
|
|
20
|
+
in-memory state between invocations.
|
|
21
|
+
|
|
22
|
+
## Decision
|
|
23
|
+
|
|
24
|
+
Five tables, each with a clear partition-key boundary:
|
|
25
|
+
|
|
26
|
+
| Table | Partition Key | Sort Key | TTL | Purpose |
|
|
27
|
+
|---|---|---|---|---|
|
|
28
|
+
| `Connections` | `connectionId` | — | `idleSince` | Per-connection state: nick, user, host, caps, joined channels, away |
|
|
29
|
+
| `ChannelMeta` | `channelName` | — | — | Topic, modes, key, limit |
|
|
30
|
+
| `ChannelMembers` | `channelName` | `connectionId` | — | Roster: membership + prefix flags (op/voice) |
|
|
31
|
+
| `Nicks` | `nickLower` | — | — | Nick → connectionId registry |
|
|
32
|
+
| `Accounts` | `account` | — | — | SASL credentials (scrypt-hashed, never plaintext) |
|
|
33
|
+
|
|
34
|
+
**Concurrency invariants:**
|
|
35
|
+
- **Nick uniqueness:** enforced via conditional `PutItem`
|
|
36
|
+
(`ConditionExpression: attribute_not_exists(nickLower)`). Two racing
|
|
37
|
+
Puts for the same nick — exactly one succeeds; the other gets a
|
|
38
|
+
`ConditionalCheckFailedException` → `433 ERR_NICKNAMEINUSE`.
|
|
39
|
+
- **Membership atomicity:** `TransactWriteItems` spans `Connections`
|
|
40
|
+
(update `joinedChannels`) and `ChannelMembers` (add/remove member) in a
|
|
41
|
+
single atomic transaction. Concurrent JOIN/PART by the same connection
|
|
42
|
+
cannot leave inconsistent state.
|
|
43
|
+
- **Gone connections:** `ApiGatewayManagementApi.postToConnection` throws
|
|
44
|
+
`GoneException` for a stale connection. The handler catches this, triggers
|
|
45
|
+
lazy cleanup (removes the `Connections` row + `ChannelMembers` rows), and
|
|
46
|
+
broadcasts QUIT to peers (TICKET-074). A sweeper Lambda reaps rows whose
|
|
47
|
+
`idleSince` TTL has expired.
|
|
48
|
+
- **Environment isolation:** physical table names are environment-prefixed
|
|
49
|
+
(`<Env>Connections`, e.g. `StagingConnections`) so staging and production
|
|
50
|
+
can coexist in the same account + region (TICKET-066).
|
|
51
|
+
|
|
52
|
+
**SASL credentials** (`Accounts`): stored as scrypt `HashedAccountCredential`
|
|
53
|
+
rows (`{ account, algorithm, salt, hash }`, base64-encoded). The Lambda
|
|
54
|
+
pre-loads all rows at cold start into an in-memory `DynamoAccountStore`; the
|
|
55
|
+
reducer's `AccountStore.verify()` stays synchronous (reducers are pure — no
|
|
56
|
+
async). Seed tooling (`tools/seed-aws-accounts.ts`) writes hashed rows; never
|
|
57
|
+
plaintext.
|
|
58
|
+
|
|
59
|
+
## Consequences
|
|
60
|
+
|
|
61
|
+
**Positive:**
|
|
62
|
+
- Clear separation of concerns: each table is one authority (matches
|
|
63
|
+
ADR-002). A channel's metadata, membership, and each member's connection
|
|
64
|
+
record are independently addressable.
|
|
65
|
+
- Conditional writes + `TransactWriteItems` give race-free semantics without
|
|
66
|
+
locks — the natural fit for DynamoDB.
|
|
67
|
+
- `idleSince` TTL auto-reaps idle connections even if the sweeper misses a
|
|
68
|
+
tick; the sweeper is a belt-and-suspenders cleanup, not the only path.
|
|
69
|
+
- Pay-per-request billing means idle tables cost nothing; the schema does not
|
|
70
|
+
over-provision.
|
|
71
|
+
|
|
72
|
+
**Negative:**
|
|
73
|
+
- Five tables (vs. a single-table design) means more `TransactWriteItems`
|
|
74
|
+
spanning multiple partitions. `TransactWriteItems` consumes more RCUs than
|
|
75
|
+
individual writes and has a 100-item-per-transaction cap. Membership
|
|
76
|
+
transactions are 2 items (well within limits), but a future feature that
|
|
77
|
+
touches many channels in one command could approach the cap.
|
|
78
|
+
- No cross-table GSI for "all channels a connection is in" — the
|
|
79
|
+
`Connections` row stores `joinedChannels` as a set, which must be updated
|
|
80
|
+
on every JOIN/PART. This duplicates membership data between `Connections`
|
|
81
|
+
and `ChannelMembers`, kept consistent by the transaction.
|
|
82
|
+
- `Accounts` pre-loading at cold start means every Lambda cold start scans
|
|
83
|
+
the table. For deployments with thousands of accounts, this adds latency.
|
|
84
|
+
Mitigated by Lambda reuse (warm starts skip the scan); a cache layer or
|
|
85
|
+
on-demand lookup is a documented follow-up.
|
|
86
|
+
|
|
87
|
+
## References
|
|
88
|
+
|
|
89
|
+
- PLAN §4 — state model & authoritative ownership
|
|
90
|
+
- PLAN §6.2 — DynamoDB tables
|
|
91
|
+
- `packages/aws-adapter/src/cdk-table-defs.ts` — `TABLE_DEFS` (source of truth)
|
|
92
|
+
- `packages/aws-adapter/src/aws-runtime.ts` — `AwsRuntime` implementation
|
|
93
|
+
- TICKET-039 — CDK stack
|
|
94
|
+
- TICKET-041 — DynamoDB transactions for membership
|
|
95
|
+
- TICKET-066 — environment-name prefixing
|
|
96
|
+
- TICKET-072 — `Accounts` table scrypt-hashed `AccountStore`
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# ADR-005: wss-only transport in v1 (no raw TCP)
|
|
2
|
+
|
|
3
|
+
**Date:** 2025-01-15 (Phase 1)
|
|
4
|
+
**Status:** Superseded by ADR-009 (Phase 7 — TICKET-052)
|
|
5
|
+
**Supersedes:** —
|
|
6
|
+
|
|
7
|
+
## Context
|
|
8
|
+
|
|
9
|
+
IRC is traditionally spoken over raw TCP (port 6667 plaintext, 6697 TLS).
|
|
10
|
+
WebSocket Secure (wss) is a framing layer over TLS that adds an HTTP upgrade
|
|
11
|
+
handshake. Serverless compute platforms have fundamentally different support
|
|
12
|
+
for these two transports:
|
|
13
|
+
|
|
14
|
+
- **Cloudflare Workers** can accept WebSocket upgrades but **cannot accept raw
|
|
15
|
+
TCP**. Spectrum (Enterprise tier) can terminate TLS and proxy to an origin,
|
|
16
|
+
but Workers itself is request-response.
|
|
17
|
+
- **AWS API Gateway WebSocket API** provides persistent WebSocket connections
|
|
18
|
+
with per-message Lambda invocation. Raw TCP requires a Network Load Balancer
|
|
19
|
+
+ Lambda streaming (invoke mode) — a fundamentally different integration.
|
|
20
|
+
|
|
21
|
+
The v1 goal is a clean serverless story: one codebase, two adapters, zero
|
|
22
|
+
stateful origin servers. Raw TCP on either platform requires additional,
|
|
23
|
+
non-serverless infrastructure (a long-running container on CF; NLB + Lambda
|
|
24
|
+
streaming on AWS).
|
|
25
|
+
|
|
26
|
+
Additionally, wss carries one IRC message per WebSocket text frame, which
|
|
27
|
+
simplifies framing: the server does not need to implement a stateful
|
|
28
|
+
byte-stream line buffer. The parser still tolerates `\r\n`-joined frames
|
|
29
|
+
(multiple messages in one text frame) for robustness, but the common case is
|
|
30
|
+
one-message-per-frame.
|
|
31
|
+
|
|
32
|
+
## Decision
|
|
33
|
+
|
|
34
|
+
v1 ships **wss-only**. No plaintext TCP listener, no `irc://` scheme, no
|
|
35
|
+
port 6667/6697. Clients connect via `wss://server.tld/` and speak IRC inside
|
|
36
|
+
WebSocket text frames.
|
|
37
|
+
|
|
38
|
+
Rationale:
|
|
39
|
+
1. Both target platforms support wss natively without additional
|
|
40
|
+
infrastructure.
|
|
41
|
+
2. wss is TLS-terminated at the edge (CF) or at API Gateway (AWS) — the
|
|
42
|
+
Lambda/Worker never sees plaintext credentials.
|
|
43
|
+
3. One-message-per-frame eliminates the need for a TCP-style line-framing
|
|
44
|
+
buffer in the core (though the parser tolerates joined frames).
|
|
45
|
+
4. The serverless cost/ops model is clean: no long-running origin, no TCP
|
|
46
|
+
keepalive management.
|
|
47
|
+
|
|
48
|
+
The `ConnectionActor` transport seam accepts WebSocket text frames directly.
|
|
49
|
+
A `Transport` interface is not abstracted in v1 — the actor's
|
|
50
|
+
`receiveTextFrame(text)` is the only entry point.
|
|
51
|
+
|
|
52
|
+
## Consequences
|
|
53
|
+
|
|
54
|
+
**Positive:**
|
|
55
|
+
- Zero infrastructure beyond the serverless platform. No TCP listener, no
|
|
56
|
+
origin server, no port management.
|
|
57
|
+
- TLS everywhere — no accidental plaintext exposure.
|
|
58
|
+
- Simple framing: WebSocket text frames are message-delimited by definition.
|
|
59
|
+
- Lower operational burden for v1.
|
|
60
|
+
|
|
61
|
+
**Negative:**
|
|
62
|
+
- RFC 1459/2812 clients that only speak raw TCP cannot connect. WeeChat and
|
|
63
|
+
HexChat support WebSocket; some older clients and bots do not.
|
|
64
|
+
- The WebSocket overhead (HTTP upgrade, per-frame masking) adds ~2–10 bytes
|
|
65
|
+
per message vs. raw TCP. Negligible for IRC's small message sizes.
|
|
66
|
+
- Some IRCv3 extensions assume a TCP transport (e.g. SASL EXTERNAL via client
|
|
67
|
+
certs over TLS passthrough). Without raw TCP, mTLS must be done at the edge
|
|
68
|
+
(CF API Shield, API Gateway custom domain), which changes the cert
|
|
69
|
+
verification surface.
|
|
70
|
+
|
|
71
|
+
**Superseded:** Phase 7 (TICKET-052) reverses this decision for v1.x: a
|
|
72
|
+
dual-transport model (wss stays the default; `irc+tls` on :6697 is added via
|
|
73
|
+
Cloudflare Spectrum + Container origin, and AWS NLB + Lambda streaming). This
|
|
74
|
+
ADR documents the original v1 rationale; the superseding ADR covers the
|
|
75
|
+
reversal and per-platform TCP+TLS mapping.
|
|
76
|
+
|
|
77
|
+
## References
|
|
78
|
+
|
|
79
|
+
- PLAN §3 — "No plaintext TCP in v1 (wss only)"
|
|
80
|
+
- PLAN §9 — "Framing: wss-only"
|
|
81
|
+
- TICKET-052 — superseding ADR: dual wss + irc+tls
|
|
82
|
+
- `packages/irc-server/src/actor.ts` — `receiveTextFrame(text)` (single
|
|
83
|
+
transport entry point in v1)
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# ADR-006: SASL mechanism scope (PLAIN always; EXTERNAL mTLS-conditional)
|
|
2
|
+
|
|
3
|
+
**Date:** 2025-01-20 (Phase 1) · revised 2025-07-27 (TICKET-079)
|
|
4
|
+
**Status:** Superseded (TICKET-079)
|
|
5
|
+
**Supersedes:** —
|
|
6
|
+
**Superseded by:** —
|
|
7
|
+
|
|
8
|
+
## Context
|
|
9
|
+
|
|
10
|
+
IRCv3 SASL (`CAP sasl`) lets a client authenticate during registration,
|
|
11
|
+
before the welcome sequence. The server advertises supported mechanisms in
|
|
12
|
+
the `sasl` cap value (e.g. `sasl=PLAIN,EXTERNAL`). Each mechanism has
|
|
13
|
+
different infrastructure requirements:
|
|
14
|
+
|
|
15
|
+
- **PLAIN:** the client sends `AUTHENTICATE PLAIN`, then a base64 payload of
|
|
16
|
+
`\0username\0password`. The server verifies the credentials against an
|
|
17
|
+
`AccountStore`. No client certificates, no TLS-passthrough — works over
|
|
18
|
+
any transport, including wss with edge-terminated TLS.
|
|
19
|
+
- **EXTERNAL:** the server authenticates the client based on an external
|
|
20
|
+
identity, typically a client certificate verified via mutual TLS (mTLS).
|
|
21
|
+
This requires the TLS handshake to present the client cert to the
|
|
22
|
+
application layer. On serverless platforms with edge-terminated TLS
|
|
23
|
+
(Cloudflare, API Gateway), the application does not see the raw client
|
|
24
|
+
cert — it must be configured at the edge (API Shield mTLS, custom-domain
|
|
25
|
+
mTLS trust store). That infrastructure does not exist in v1 (ADR-005:
|
|
26
|
+
wss-only, no raw TCP; mTLS passthrough is Phase 7, TICKET-054).
|
|
27
|
+
|
|
28
|
+
## Decision
|
|
29
|
+
|
|
30
|
+
The server ships **SASL PLAIN** as the always-available mechanism and
|
|
31
|
+
**SASL EXTERNAL** as an mTLS-conditional mechanism:
|
|
32
|
+
|
|
33
|
+
- When **no** `MtlsIdentityProvider` is bound to the connection (the default
|
|
34
|
+
for non-mTLS deployments), the `sasl` cap advertises `PLAIN` only and
|
|
35
|
+
`AUTHENTICATE EXTERNAL` returns `908 ERR_SASLMECHS` listing `PLAIN` as the
|
|
36
|
+
sole available mechanism.
|
|
37
|
+
- When an `MtlsIdentityProvider` **is** bound (the operator configured mTLS
|
|
38
|
+
at the edge — CF API Shield mTLS or AWS custom-domain mTLS), the `sasl` cap
|
|
39
|
+
advertises `PLAIN,EXTERNAL` and `AUTHENTICATE EXTERNAL` proceeds through
|
|
40
|
+
the full handshake: the verified client-cert subject is resolved via the
|
|
41
|
+
provider and verified against the `AccountStore`.
|
|
42
|
+
|
|
43
|
+
This means EXTERNAL advertisement and functionality are driven entirely by
|
|
44
|
+
whether mTLS is configured — operators enable EXTERNAL by configuring edge
|
|
45
|
+
mTLS, with no code change required. The `saslCapValue(hasMtls)` helper in
|
|
46
|
+
`caps/capabilities.ts` and the `supportedMechs(ctx)` helper in
|
|
47
|
+
`commands/sasl.ts` are the single sources of truth for the advertised value.
|
|
48
|
+
|
|
49
|
+
`AccountStore` is a port in `irc-core` consumed by the SASL reducer. The
|
|
50
|
+
`verify(mechanism, payload)` method is **synchronous** — adapters pre-load
|
|
51
|
+
credentials at boot so the reducer stays pure (ADR-001). PLAIN verification
|
|
52
|
+
decodes the base64 payload, extracts username + password, and matches
|
|
53
|
+
against the store. EXTERNAL verification resolves the cert subject via the
|
|
54
|
+
`MtlsIdentityProvider` and matches it against the store.
|
|
55
|
+
|
|
56
|
+
## Consequences
|
|
57
|
+
|
|
58
|
+
**Positive:**
|
|
59
|
+
- PLAIN works end-to-end with no special infrastructure. The
|
|
60
|
+
`AccountStore` port abstracts the credential store; adapters seed it from
|
|
61
|
+
config (in-memory), DynamoDB (AWS), or a persistent backend (D1/DO for CF,
|
|
62
|
+
TICKET-093).
|
|
63
|
+
- EXTERNAL is fully functional when mTLS is configured (TICKET-054) and
|
|
64
|
+
correctly unadvertised when it is not — clients never waste a round-trip
|
|
65
|
+
on a mechanism that cannot succeed.
|
|
66
|
+
- The mTLS-conditional advertisement is driven by the `MtlsIdentityProvider`
|
|
67
|
+
binding, so operators enable EXTERNAL by configuring edge mTLS with no
|
|
68
|
+
code change.
|
|
69
|
+
- The synchronous `AccountStore.verify()` keeps the reducer pure and
|
|
70
|
+
deterministic. Async credential lookups (DynamoDB) are resolved at cold
|
|
71
|
+
start or via pre-loading, not inside the reducer.
|
|
72
|
+
|
|
73
|
+
**Negative:**
|
|
74
|
+
- Deployments without mTLS (the common case) cannot offer EXTERNAL. This is
|
|
75
|
+
inherent — EXTERNAL requires client-certificate verification at the TLS
|
|
76
|
+
layer, which is only available via edge mTLS configuration.
|
|
77
|
+
- PLAIN sends the password base64-encoded (not encrypted) inside the wss
|
|
78
|
+
frame. wss provides the TLS layer, so the password is encrypted in transit
|
|
79
|
+
— but PLAIN is still weaker than EXTERNAL (no mutual auth).
|
|
80
|
+
- The synchronous `AccountStore` contract means the adapter must pre-load all
|
|
81
|
+
credentials. For deployments with many accounts, cold-start latency grows
|
|
82
|
+
linearly with account count. A lazy/async lookup variant is a documented
|
|
83
|
+
follow-up but would require an async-reducer or effect-based credential
|
|
84
|
+
query — a significant architecture change.
|
|
85
|
+
|
|
86
|
+
## References
|
|
87
|
+
|
|
88
|
+
- PLAN §3 — "sasl (mechanisms: PLAIN, EXTERNAL reserved for later with mTLS)"
|
|
89
|
+
- PLAN §9 — SASL mechanism scope
|
|
90
|
+
- TICKET-026 — SASL reducer implementation
|
|
91
|
+
- TICKET-071 — AccountStore wiring into ConnectionActor
|
|
92
|
+
- TICKET-072 — AWS DynamoDB AccountStore (scrypt hashing)
|
|
93
|
+
- TICKET-079 — SASL EXTERNAL: implement or stop advertising (interim decision)
|
|
94
|
+
- TICKET-054 — mTLS support (Phase 7, enables functional EXTERNAL)
|
|
95
|
+
- `packages/irc-core/src/commands/sasl.ts` — `authenticateReducer`
|
|
96
|
+
- `packages/irc-core/src/ports.ts` — `AccountStore` port
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# ADR-007: Deterministic ports for time and ID generation
|
|
2
|
+
|
|
3
|
+
**Date:** 2025-01-15 (Phase 1)
|
|
4
|
+
**Status:** Accepted
|
|
5
|
+
**Supersedes:** —
|
|
6
|
+
**Superseded by:** —
|
|
7
|
+
|
|
8
|
+
## Context
|
|
9
|
+
|
|
10
|
+
IRC protocol behaviour is time-sensitive: idle/PING timers, WHOIS signon
|
|
11
|
+
time, `server-time` tags (ISO-8601 timestamps on every message), SASL nonce
|
|
12
|
+
generation, chathistory message IDs. A traditional ircd calls `Date.now()`
|
|
13
|
+
and `crypto.randomUUID()` directly in handlers. This makes tests
|
|
14
|
+
non-deterministic: the same input produces different output on every run,
|
|
15
|
+
depending on when the test executed.
|
|
16
|
+
|
|
17
|
+
Non-determinism is fatal for the parametrized contract suite (TICKET-032),
|
|
18
|
+
which runs identical scenarios across in-memory, CF, and AWS runtimes. If a
|
|
19
|
+
reducer embeds `Date.now()`, the expected `@time=` tag changes every
|
|
20
|
+
millisecond and the assertion cannot be written.
|
|
21
|
+
|
|
22
|
+
## Decision
|
|
23
|
+
|
|
24
|
+
Time and ID generation are **injected ports**, not global calls:
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
interface Clock {
|
|
28
|
+
now(): number; // epoch milliseconds
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
interface IdFactory {
|
|
32
|
+
nonce(): string; // unique message ID for message-tags/chathistory
|
|
33
|
+
traceId(): string; // per-request trace ID for observability
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Both are passed through `Ctx` to every reducer. Reducers read `ctx.clock.now()`
|
|
38
|
+
and `ctx.ids.nonce()` — never `Date.now()` or `Math.random()`.
|
|
39
|
+
|
|
40
|
+
Concrete implementations:
|
|
41
|
+
- **`FakeClock`** (tests): returns a fixed value set at construction.
|
|
42
|
+
Deterministic: `new FakeClock(10_000)` always reports `now() === 10_000`.
|
|
43
|
+
- **`SystemClock`** (production): wraps `Date.now()`.
|
|
44
|
+
- **`SequentialIdFactory`** (tests): returns `id-0`, `id-1`, `id-2`, …
|
|
45
|
+
Deterministic: the same sequence of calls produces the same IDs.
|
|
46
|
+
- **`RandomIdFactory`** (production): wraps `crypto.randomUUID()`.
|
|
47
|
+
|
|
48
|
+
## Consequences
|
|
49
|
+
|
|
50
|
+
**Positive:**
|
|
51
|
+
- Reducer tests are fully deterministic. The same `(state, message, ctx)`
|
|
52
|
+
triple always produces the same `{ state, effects }`. No flaky tests.
|
|
53
|
+
- The contract suite can assert exact wire output including `@time=` tags
|
|
54
|
+
and `msgid=` tags, because the fake clock and ID factory are pinned.
|
|
55
|
+
- Time travel is trivial in tests: advance the `FakeClock` between messages
|
|
56
|
+
to test idle/PING logic, flood-control refill, and chathistory bounds.
|
|
57
|
+
- The reducer purity contract (ADR-001) is enforceable: a reducer that calls
|
|
58
|
+
`Date.now()` is simply not using the injected port, and the test will fail
|
|
59
|
+
because the output is wrong.
|
|
60
|
+
|
|
61
|
+
**Negative:**
|
|
62
|
+
- Every call site that needs time or an ID must thread `ctx` — there is no
|
|
63
|
+
shortcut. This is a small constant cost per reducer.
|
|
64
|
+
- The `Clock` and `IdFactory` must be consistent across the actor's lifetime.
|
|
65
|
+
The actor pins them at construction; switching mid-connection would
|
|
66
|
+
produce inconsistent timestamps. This is enforced by the actor's readonly
|
|
67
|
+
fields.
|
|
68
|
+
- `Date.now()` resolution is milliseconds; sub-millisecond ordering is not
|
|
69
|
+
possible with this port. This has not been a problem for IRC (message
|
|
70
|
+
ordering is preserved by connection/channel authority serialization, not
|
|
71
|
+
by timestamp).
|
|
72
|
+
|
|
73
|
+
## References
|
|
74
|
+
|
|
75
|
+
- PLAN §9 — "Time/IDs: injected ports (Clock, IdFactory) for deterministic
|
|
76
|
+
tests"
|
|
77
|
+
- PLAN §8 — "Determinism rules: inject a Clock and deterministic ID/nonce
|
|
78
|
+
ports. No real timers/random in reducers."
|
|
79
|
+
- ADR-001 — pure reducers (why determinism matters)
|
|
80
|
+
- `packages/irc-core/src/ports.ts` — `Clock`, `IdFactory`, `FakeClock`,
|
|
81
|
+
`SequentialIdFactory`, `SystemClock`, `RandomIdFactory`
|
|
82
|
+
- `packages/irc-core/src/types.ts` — `Ctx.clock`, `Ctx.ids`
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# ADR-008: Monorepo and tooling stack
|
|
2
|
+
|
|
3
|
+
**Date:** 2025-01-10 (Phase 0)
|
|
4
|
+
**Status:** Accepted
|
|
5
|
+
**Supersedes:** —
|
|
6
|
+
**Superseded by:** —
|
|
7
|
+
|
|
8
|
+
## Context
|
|
9
|
+
|
|
10
|
+
ServerlessIRCd is a multi-package TypeScript project: a platform-agnostic
|
|
11
|
+
core (`irc-core`), an orchestration layer (`irc-server`), a reference runtime
|
|
12
|
+
(`in-memory-runtime`), two cloud adapters (`cf-adapter`, `aws-adapter`), and
|
|
13
|
+
several apps (`local-cli`, `cf-worker`, `aws-stack`). The toolchain must
|
|
14
|
+
support cross-package type checking, incremental builds, a unified test
|
|
15
|
+
runner, and CI that enforces coverage gates per package.
|
|
16
|
+
|
|
17
|
+
## Decision
|
|
18
|
+
|
|
19
|
+
| Concern | Choice | Rationale |
|
|
20
|
+
|---|---|---|
|
|
21
|
+
| Package manager | **pnpm** (workspaces) | Fast, disk-efficient, first-class monorepo support |
|
|
22
|
+
| Build orchestration | **turbo** (caching) | Incremental builds, remote cache, task dependency graph |
|
|
23
|
+
| TypeScript | Project references + `tsconfig.base.json` | Strict mode, `exactOptionalPropertyTypes`, `noUncheckedIndexedAccess` |
|
|
24
|
+
| Test runner | **vitest** | ESM-native, fast, integrates with Workers (`vitest-pool-workers`), built-in coverage |
|
|
25
|
+
| Coverage | v8 provider, gate ≥90% (100% on `irc-core`) | Enforced in CI (`.github/workflows/ci.yml`) |
|
|
26
|
+
| Lint/format | **Biome** | Single tool (replaces ESLint + Prettier), fast, zero config drift |
|
|
27
|
+
| CF bundler | **wrangler** (esbuild internally) | Native Workers toolchain |
|
|
28
|
+
| AWS bundler | **esbuild** (Lambda bundles) + **CDK v2** (infra) | Tree-shaking, fast cold starts |
|
|
29
|
+
| Runtime target | Node 20 (Lambda) + latest Workers runtime; ES2022+ | Aligns with platform-supported runtimes |
|
|
30
|
+
|
|
31
|
+
## Consequences
|
|
32
|
+
|
|
33
|
+
**Positive:**
|
|
34
|
+
- pnpm workspaces + turbo give fast local dev: only changed packages rebuild;
|
|
35
|
+
tests run incrementally.
|
|
36
|
+
- vitest's ESM-native design avoids the CJS/ESM interop pain that plagues
|
|
37
|
+
Jest-based monorepos. The same test files run under `vitest-pool-workers`
|
|
38
|
+
(real `workerd`) for CF adapter tests.
|
|
39
|
+
- Biome eliminates the ESLint/Prettier config drift problem — one tool, one
|
|
40
|
+
config, one command (`biome check`).
|
|
41
|
+
- TypeScript project references enforce package boundaries at compile time:
|
|
42
|
+
`irc-core` cannot accidentally import from `cf-adapter`.
|
|
43
|
+
|
|
44
|
+
**Negative:**
|
|
45
|
+
- pnpm's strict node-linker can surprise contributors used to npm/yarn's
|
|
46
|
+
hoisting. `node_modules` is per-package; global scripts need
|
|
47
|
+
`pnpm --filter`.
|
|
48
|
+
- turbo's caching requires consistent environment hashing; a CI cache miss
|
|
49
|
+
(e.g. different Node minor version) degrades to a full rebuild silently.
|
|
50
|
+
- Biome is newer than ESLint and lacks some ecosystem plugins. Custom rules
|
|
51
|
+
(e.g. "no ticket IDs in source files") are enforced via convention
|
|
52
|
+
(`AGENTS.md`) rather than a Biome plugin.
|
|
53
|
+
|
|
54
|
+
## References
|
|
55
|
+
|
|
56
|
+
- PLAN §9 — "Monorepo: pnpm + TypeScript project references; turbo for
|
|
57
|
+
caching"
|
|
58
|
+
- `pnpm-workspace.yaml`, `turbo.json`, `tsconfig.base.json`, `biome.json`
|
|
59
|
+
- `.github/workflows/ci.yml` — coverage gates and CI pipeline
|
|
60
|
+
- `AGENTS.md` — code style conventions
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
# ADR-009: Dual transport — wss (default) + irc+tls on :6697
|
|
2
|
+
|
|
3
|
+
**Date:** 2026-07-26 (Phase 7)
|
|
4
|
+
**Status:** Accepted
|
|
5
|
+
**Supersedes:** ADR-005 (wss-only transport in v1)
|
|
6
|
+
**Superseded by:** —
|
|
7
|
+
|
|
8
|
+
## Context
|
|
9
|
+
|
|
10
|
+
ADR-005 chose **wss-only** for v1. That decision rested on four points, all
|
|
11
|
+
still accurate as facts about the serverless substrates:
|
|
12
|
+
|
|
13
|
+
1. Both target platforms (CF Workers, AWS API Gateway WebSocket) support wss
|
|
14
|
+
natively with zero additional infrastructure; neither can accept raw TCP
|
|
15
|
+
from its request-response compute (Workers is request-response; API Gateway
|
|
16
|
+
is WebSocket-only).
|
|
17
|
+
2. wss is TLS-terminated at the edge (CF) or at API Gateway (AWS), so the
|
|
18
|
+
Lambda/Worker never sees plaintext credentials.
|
|
19
|
+
3. One IRC message per WebSocket text frame eliminates the need for a
|
|
20
|
+
stateful byte-stream line buffer in the core (the parser already tolerates
|
|
21
|
+
`\r\n`-joined frames for robustness).
|
|
22
|
+
4. The serverless cost/ops story stays clean: no long-running origin, no TCP
|
|
23
|
+
keepalive management, one codebase + two adapters.
|
|
24
|
+
|
|
25
|
+
What changed the decision is **demand, not capability**:
|
|
26
|
+
|
|
27
|
+
- **RFC 1459/2812 compliance.** The target modern clients (WeeChat, HexChat,
|
|
28
|
+
IRCCcd, TheLounge) mostly support wss, but there is a long tail of older
|
|
29
|
+
clients, bots, bridges, and monitoring tools that only speak `irc+tls`
|
|
30
|
+
(raw TCP + TLS on :6697). Supporting them was a non-goal for the initial v1
|
|
31
|
+
cut; the gap now matters for the compatibility-sweep deliverable.
|
|
32
|
+
- **SASL EXTERNAL (mTLS).** `AUTHENTICATE EXTERNAL` needs the client
|
|
33
|
+
certificate to reach the application layer (ADR-006). With wss and
|
|
34
|
+
edge-terminated TLS, the cert is consumed at the edge and the app only gets
|
|
35
|
+
a verified subject via platform config (CF API Shield mTLS, API Gateway
|
|
36
|
+
custom-domain mTLS — both TICKET-054). A real `irc+tls` path gives a more
|
|
37
|
+
conventional mTLS surface that matches client expectations.
|
|
38
|
+
- **Marginal cost is small.** The core is transport-agnostic by design: pure
|
|
39
|
+
reducers + a `ConnectionActor` that already accepts `\r\n`-joined frames.
|
|
40
|
+
Adding a second transport is a **second per-platform entry-point adapter**,
|
|
41
|
+
not a re-architecture. The generalized TCP byte-stream transport seam is
|
|
42
|
+
TICKET-053; the per-platform adapters are TICKET-055 (CF) and TICKET-056
|
|
43
|
+
(AWS).
|
|
44
|
+
|
|
45
|
+
## Decision
|
|
46
|
+
|
|
47
|
+
v1.x adopts a **dual-transport** model:
|
|
48
|
+
|
|
49
|
+
- **wss stays the serverless default.** `wss://server.tld/` with one IRC
|
|
50
|
+
message per WebSocket text frame remains the primary path. It needs zero
|
|
51
|
+
extra infrastructure on either platform and keeps the clean serverless
|
|
52
|
+
story for the common case.
|
|
53
|
+
- **`irc+tls` on :6697 is added** as a second, per-platform adapter for
|
|
54
|
+
RFC-compliant clients. TLS is mandatory; **plaintext TCP on :6667 stays
|
|
55
|
+
unsupported.** The entry point differs per platform because neither
|
|
56
|
+
serverless compute can accept raw TCP directly:
|
|
57
|
+
|
|
58
|
+
| Platform | Edge (TLS termination) | Origin / compute |
|
|
59
|
+
|----------|-------------------------------------|-----------------------------------------------|
|
|
60
|
+
| CF | Cloudflare Spectrum (Enterprise) | Cloudflare Container running TCP byte-stream |
|
|
61
|
+
| | | `ConnectionActor` over a persistent runtime |
|
|
62
|
+
| AWS | Network Load Balancer (`tls` listener) | Lambda **streaming** function (target); |
|
|
63
|
+
| | | connection ID derived from NLB flow metadata |
|
|
64
|
+
|
|
65
|
+
Spectrum terminates TLS at the edge and forwards plaintext TCP to the
|
|
66
|
+
container origin; NLB terminates TLS and invokes a Lambda streaming
|
|
67
|
+
function as target. Both reuse `AwsRuntime`/the CF runtime storage layer
|
|
68
|
+
for connection/channel/nick state.
|
|
69
|
+
|
|
70
|
+
The **pure reducer core and `ConnectionActor` are shared** across both
|
|
71
|
+
transports and both platforms. Only two things differ on the new path:
|
|
72
|
+
|
|
73
|
+
1. The **transport seam** (TICKET-053): `ConnectionActor` accepts either a
|
|
74
|
+
`WsTextFrameTransport` (one message per frame — current behavior) or a
|
|
75
|
+
`TcpByteStreamTransport` (stateful `\r\n` framing across chunks with
|
|
76
|
+
partial-line buffering). Parser → reducer → dispatch is unchanged.
|
|
77
|
+
2. The **entry-point adapter** (TICKET-055 / TICKET-056): Spectrum+Container
|
|
78
|
+
on CF, NLB+Lambda streaming on AWS.
|
|
79
|
+
|
|
80
|
+
mTLS (TICKET-054) is done at the edge on the wss path (CF API Shield mTLS /
|
|
81
|
+
API Gateway custom-domain mTLS) and via the TLS handshake on the TCP path
|
|
82
|
+
(Spectrum cert verification / NLB ACM cert + optional client-cert
|
|
83
|
+
verification).
|
|
84
|
+
|
|
85
|
+
## Consequences
|
|
86
|
+
|
|
87
|
+
**Positive:**
|
|
88
|
+
- RFC 1459/2812-compliant clients, bots, and bridges connect natively without
|
|
89
|
+
a `tcp-ws-forwarder` bridge. This unblocks the compatibility-sweep
|
|
90
|
+
deliverable for the long tail of TCP-only clients.
|
|
91
|
+
- A conventional mTLS surface opens for SASL `EXTERNAL` (TICKET-054): the
|
|
92
|
+
client cert reaches the application via the TLS handshake on the TCP path,
|
|
93
|
+
matching standard IRC client expectations, in addition to the edge-mTLS
|
|
94
|
+
path on wss.
|
|
95
|
+
- Core reuse: the pure reducers, `IrcRuntime` port, and `ConnectionActor`
|
|
96
|
+
are shared verbatim. The transport seam (TICKET-053) is the only new
|
|
97
|
+
abstraction in the core; everything else is per-platform glue.
|
|
98
|
+
- The wss default is untouched — deployments that do not need raw TCP pay no
|
|
99
|
+
infra cost and keep the clean serverless story.
|
|
100
|
+
|
|
101
|
+
**Negative:**
|
|
102
|
+
- **CF breaks the pure-serverless story on the TCP path.** Spectrum is an
|
|
103
|
+
Enterprise-tier feature, and the origin is a stateful Cloudflare Container
|
|
104
|
+
(or external compute), not a Worker. Connection state must survive origin
|
|
105
|
+
reconnects via the runtime's persistence layer — a new operational surface
|
|
106
|
+
that the wss path (Durable Objects) does not have.
|
|
107
|
+
- **AWS NLB + Lambda streaming has hard limits:** Lambda streaming invoke
|
|
108
|
+
idle timeout and maximum connection/duration caps. Long-idle IRC clients
|
|
109
|
+
can be dropped; reconnect/PING behavior must tolerate this (same class of
|
|
110
|
+
risk as the APIGW 2h WS cap, PLAN §10).
|
|
111
|
+
- **Extra per-platform adapter surface.** Two entry-point adapters
|
|
112
|
+
(TICKET-055, TICKET-056) and a new transport contract dimension
|
|
113
|
+
(TICKET-057) are added to the test matrix. Cross-adapter drift is now a
|
|
114
|
+
transport × runtime matrix, mitigated by the parametrized contract suite.
|
|
115
|
+
- **Double deploy/ops paths per platform.** Each platform now ships a wss
|
|
116
|
+
stack and a TCP+TLS stack with different infra (DO vs Container; APIGW vs
|
|
117
|
+
NLB). Deploy docs, cost monitoring, and incident runbooks must cover both
|
|
118
|
+
(TICKET-058).
|
|
119
|
+
|
|
120
|
+
## References
|
|
121
|
+
|
|
122
|
+
- ADR-005 — wss-only transport in v1 (**superseded** by this ADR)
|
|
123
|
+
- ADR-006 — SASL mechanism scope (PLAIN only; EXTERNAL deferred to Phase 7;
|
|
124
|
+
this ADR unblocks the mTLS path for EXTERNAL)
|
|
125
|
+
- PLAN §3 — Protocol scope (connection framing)
|
|
126
|
+
- PLAN §9 — Key technical decisions (framing)
|
|
127
|
+
- TICKET-052 — this ADR; revises the transport decision
|
|
128
|
+
- TICKET-053 — generalize `ConnectionActor` transport seam (TCP byte-stream
|
|
129
|
+
framing)
|
|
130
|
+
- TICKET-054 — mTLS support (edge config + `AccountStore` plumbing; enables
|
|
131
|
+
functional SASL EXTERNAL)
|
|
132
|
+
- TICKET-055 — CF TCP+TLS adapter via Cloudflare Spectrum + Container origin
|
|
133
|
+
- TICKET-056 — AWS TCP+TLS adapter via Network Load Balancer (TLS) + Lambda
|
|
134
|
+
streaming
|
|
135
|
+
- TICKET-057 — extend integration contract suite over transport
|
|
136
|
+
(wss × TCP+TLS)
|
|
137
|
+
- TICKET-058 — docs: `Cloudflare-TCP-Deployment.md` and `AWS-TCP-Deployment.md`
|
|
138
|
+
(TCP+TLS variants)
|