serverless-ircd 0.3.0 → 0.5.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.
Files changed (223) hide show
  1. package/.github/workflows/ci.yml +2 -2
  2. package/.github/workflows/deploy-aws.yml +1 -3
  3. package/.github/workflows/deploy-cf-tcp.yml +87 -0
  4. package/.github/workflows/deploy-cf.yml +1 -1
  5. package/.node-version +1 -0
  6. package/.nvmrc +1 -0
  7. package/CHANGELOG.md +349 -18
  8. package/README.md +132 -30
  9. package/apps/aws-stack/README.md +6 -5
  10. package/apps/aws-stack/bin/aws.ts +7 -0
  11. package/apps/aws-stack/package.json +4 -4
  12. package/apps/aws-stack/src/aws-stack.ts +150 -10
  13. package/apps/aws-stack/tests/stack.test.ts +145 -4
  14. package/apps/cf-tcp-container/Dockerfile +69 -0
  15. package/apps/cf-tcp-container/package.json +34 -0
  16. package/apps/cf-tcp-container/src/config-loader.ts +145 -0
  17. package/apps/cf-tcp-container/src/container-do.ts +38 -0
  18. package/apps/cf-tcp-container/src/container-server.ts +363 -0
  19. package/apps/cf-tcp-container/src/main.ts +77 -0
  20. package/apps/cf-tcp-container/src/persistence.ts +144 -0
  21. package/apps/cf-tcp-container/src/worker.ts +41 -0
  22. package/apps/cf-tcp-container/terraform/provider.tf +24 -0
  23. package/apps/cf-tcp-container/terraform/spectrum.tf +81 -0
  24. package/apps/cf-tcp-container/tests/config-loader.test.ts +217 -0
  25. package/apps/cf-tcp-container/tests/container-server.test.ts +465 -0
  26. package/apps/cf-tcp-container/tests/persistence.test.ts +227 -0
  27. package/apps/cf-tcp-container/tests/tls-e2e.test.ts +275 -0
  28. package/apps/cf-tcp-container/tsconfig.build.json +17 -0
  29. package/apps/cf-tcp-container/tsconfig.test.json +15 -0
  30. package/apps/cf-tcp-container/vitest.config.ts +26 -0
  31. package/apps/cf-tcp-container/wrangler.toml +63 -0
  32. package/apps/cf-worker/package.json +1 -1
  33. package/apps/cf-worker/wrangler.test.toml +6 -0
  34. package/apps/cf-worker/wrangler.toml +28 -2
  35. package/apps/local-cli/package.json +1 -1
  36. package/apps/local-cli/src/config-loader.ts +10 -0
  37. package/apps/local-cli/src/server.ts +149 -24
  38. package/apps/local-cli/tests/e2e.test.ts +1 -1
  39. package/apps/local-cli/tests/ws-subprotocol.test.ts +257 -0
  40. package/package.json +14 -10
  41. package/packages/aws-adapter/package.json +3 -3
  42. package/packages/aws-adapter/src/account-store.ts +1 -1
  43. package/packages/aws-adapter/src/admission.ts +74 -0
  44. package/packages/aws-adapter/src/aws-runtime.ts +75 -4
  45. package/packages/aws-adapter/src/config-loader.ts +32 -0
  46. package/packages/aws-adapter/src/dynamo-account-store.ts +35 -96
  47. package/packages/aws-adapter/src/handlers/connect.ts +96 -9
  48. package/packages/aws-adapter/src/handlers/default.ts +98 -7
  49. package/packages/aws-adapter/src/handlers/index.ts +109 -4
  50. package/packages/aws-adapter/src/handlers/nlb-stream.ts +490 -0
  51. package/packages/aws-adapter/src/handlers/ping-checker.ts +1 -1
  52. package/packages/aws-adapter/src/index.ts +8 -0
  53. package/packages/aws-adapter/src/serialize.ts +11 -1
  54. package/packages/aws-adapter/src/stats.ts +80 -0
  55. package/packages/aws-adapter/tests/account-store-dynamo.test.ts +45 -34
  56. package/packages/aws-adapter/tests/account-store.test.ts +19 -20
  57. package/packages/aws-adapter/tests/admission.test.ts +70 -0
  58. package/packages/aws-adapter/tests/aws-harness.ts +13 -1
  59. package/packages/aws-adapter/tests/aws-integration.test.ts +1 -1
  60. package/packages/aws-adapter/tests/aws-runtime.test.ts +61 -0
  61. package/packages/aws-adapter/tests/config-loader.test.ts +20 -0
  62. package/packages/aws-adapter/tests/connect.test.ts +174 -0
  63. package/packages/aws-adapter/tests/disconnect-fanout.test.ts +47 -40
  64. package/packages/aws-adapter/tests/gone-exception.test.ts +31 -26
  65. package/packages/aws-adapter/tests/handlers.test.ts +302 -53
  66. package/packages/aws-adapter/tests/nlb-stream.test.ts +480 -0
  67. package/packages/aws-adapter/tests/ping-checker.test.ts +34 -29
  68. package/packages/aws-adapter/tests/stats.test.ts +317 -0
  69. package/packages/aws-adapter/tests/sweeper.test.ts +25 -18
  70. package/packages/aws-adapter/tests/transactions.test.ts +25 -20
  71. package/packages/cf-adapter/package.json +5 -1
  72. package/packages/cf-adapter/src/cf-runtime.ts +68 -5
  73. package/packages/cf-adapter/src/channel-do.ts +2 -2
  74. package/packages/cf-adapter/src/config-loader.ts +33 -0
  75. package/packages/cf-adapter/src/connection-do.ts +278 -85
  76. package/packages/cf-adapter/src/d1-account-store.ts +198 -0
  77. package/packages/cf-adapter/src/env.ts +54 -11
  78. package/packages/cf-adapter/src/index.ts +11 -8
  79. package/packages/cf-adapter/src/registry-do.ts +22 -3
  80. package/packages/cf-adapter/src/sharding.ts +1 -2
  81. package/packages/cf-adapter/src/stats.ts +65 -0
  82. package/packages/cf-adapter/tests/cf-harness.ts +12 -2
  83. package/packages/cf-adapter/tests/cf-integration.test.ts +6 -5
  84. package/packages/cf-adapter/tests/cf-runtime.test.ts +38 -2
  85. package/packages/cf-adapter/tests/channel-do.test.ts +2 -2
  86. package/packages/cf-adapter/tests/config-loader.test.ts +22 -0
  87. package/packages/cf-adapter/tests/connection-do-channel-registration.test.ts +37 -0
  88. package/packages/cf-adapter/tests/connection-do-no-batching-reservation.test.ts +52 -0
  89. package/packages/cf-adapter/tests/connection-do-sasl-d1.test.ts +166 -0
  90. package/packages/cf-adapter/tests/connection-do-ws-spec-contract.test.ts +289 -0
  91. package/packages/cf-adapter/tests/connection-do-ws-subprotocol.test.ts +184 -0
  92. package/packages/cf-adapter/tests/connection-do.test.ts +27 -2
  93. package/packages/cf-adapter/tests/d1-account-store.test.ts +226 -0
  94. package/packages/cf-adapter/tests/raw-modules.d.ts +11 -0
  95. package/packages/cf-adapter/tests/registry-do.test.ts +4 -4
  96. package/packages/cf-adapter/tests/sharding.test.ts +1 -1
  97. package/packages/cf-adapter/tests/stats.test.ts +120 -0
  98. package/packages/cf-adapter/tests/worker/main.ts +15 -8
  99. package/packages/cf-adapter/tests/worker/stubs/channel-stub.ts +2 -2
  100. package/packages/cf-adapter/tests/worker/stubs/registry-stub.ts +8 -2
  101. package/packages/cf-adapter/wrangler.test.toml +15 -0
  102. package/packages/in-memory-runtime/package.json +1 -1
  103. package/packages/in-memory-runtime/src/in-memory-runtime.ts +39 -0
  104. package/packages/in-memory-runtime/tests/in-memory-runtime.test.ts +259 -0
  105. package/packages/irc-core/package.json +6 -1
  106. package/packages/irc-core/scripts/generate-build-info.mjs +31 -0
  107. package/packages/irc-core/src/admission.ts +16 -15
  108. package/packages/irc-core/src/caps/capabilities.ts +24 -3
  109. package/packages/irc-core/src/cloak.ts +1 -1
  110. package/packages/irc-core/src/commands/cap.ts +8 -1
  111. package/packages/irc-core/src/commands/index.ts +17 -0
  112. package/packages/irc-core/src/commands/invite.ts +2 -4
  113. package/packages/irc-core/src/commands/ison.ts +61 -0
  114. package/packages/irc-core/src/commands/isupport.ts +6 -2
  115. package/packages/irc-core/src/commands/kick.ts +2 -4
  116. package/packages/irc-core/src/commands/kill.ts +127 -0
  117. package/packages/irc-core/src/commands/list.ts +1 -1
  118. package/packages/irc-core/src/commands/lusers.ts +204 -0
  119. package/packages/irc-core/src/commands/mode.ts +4 -8
  120. package/packages/irc-core/src/commands/names.ts +3 -5
  121. package/packages/irc-core/src/commands/part.ts +2 -4
  122. package/packages/irc-core/src/commands/quit.ts +12 -0
  123. package/packages/irc-core/src/commands/registration.ts +18 -12
  124. package/packages/irc-core/src/commands/rehash.ts +119 -0
  125. package/packages/irc-core/src/commands/sasl.ts +72 -9
  126. package/packages/irc-core/src/commands/server-info.ts +129 -0
  127. package/packages/irc-core/src/commands/setname.ts +109 -0
  128. package/packages/irc-core/src/commands/stats.ts +152 -0
  129. package/packages/irc-core/src/commands/topic.ts +2 -4
  130. package/packages/irc-core/src/commands/trace.ts +137 -0
  131. package/packages/irc-core/src/commands/userhost.ts +84 -0
  132. package/packages/irc-core/src/commands/wallops.ts +118 -0
  133. package/packages/irc-core/src/commands/whowas.ts +113 -0
  134. package/packages/irc-core/src/config.ts +65 -0
  135. package/packages/irc-core/src/credential-hashing.ts +124 -0
  136. package/packages/irc-core/src/effects.ts +33 -30
  137. package/packages/irc-core/src/index.ts +3 -0
  138. package/packages/irc-core/src/ports.ts +360 -12
  139. package/packages/irc-core/src/protocol/numerics.ts +48 -11
  140. package/packages/irc-core/src/protocol/outbound.ts +20 -3
  141. package/packages/irc-core/src/types.ts +46 -2
  142. package/packages/irc-core/src/ws-framing.ts +132 -0
  143. package/packages/irc-core/src/ws-subprotocol.ts +66 -0
  144. package/packages/irc-core/tests/account-store.test.ts +45 -2
  145. package/packages/irc-core/tests/admission.test.ts +18 -0
  146. package/packages/irc-core/tests/caps/capabilities.test.ts +4 -3
  147. package/packages/irc-core/tests/commands/cap.test.ts +33 -1
  148. package/packages/irc-core/tests/commands/ison.test.ts +166 -0
  149. package/packages/irc-core/tests/commands/kill.test.ts +243 -0
  150. package/packages/irc-core/tests/commands/lusers.test.ts +368 -0
  151. package/packages/irc-core/tests/commands/mode.test.ts +57 -0
  152. package/packages/irc-core/tests/commands/quit.test.ts +69 -2
  153. package/packages/irc-core/tests/commands/registration.test.ts +151 -6
  154. package/packages/irc-core/tests/commands/rehash.test.ts +171 -0
  155. package/packages/irc-core/tests/commands/sasl.test.ts +118 -10
  156. package/packages/irc-core/tests/commands/server-info.test.ts +274 -0
  157. package/packages/irc-core/tests/commands/setname.test.ts +225 -0
  158. package/packages/irc-core/tests/commands/stats.test.ts +294 -0
  159. package/packages/irc-core/tests/commands/tagmsg.test.ts +9 -35
  160. package/packages/irc-core/tests/commands/trace.test.ts +282 -0
  161. package/packages/irc-core/tests/commands/userhost.test.ts +264 -0
  162. package/packages/irc-core/tests/commands/wallops.test.ts +231 -0
  163. package/packages/irc-core/tests/commands/whowas.test.ts +312 -0
  164. package/packages/irc-core/tests/config.test.ts +95 -1
  165. package/packages/irc-core/tests/credential-hashing.test.ts +170 -0
  166. package/packages/irc-core/tests/dropped-s2s-and-obsolete-verbs.test.ts +90 -0
  167. package/packages/irc-core/tests/effects.test.ts +14 -27
  168. package/packages/irc-core/tests/nick-history-store.test.ts +162 -0
  169. package/packages/irc-core/tests/numerics.test.ts +102 -0
  170. package/packages/irc-core/tests/outbound.test.ts +51 -0
  171. package/packages/irc-core/tests/ports.test.ts +22 -0
  172. package/packages/irc-core/tests/raw-modules.d.ts +11 -0
  173. package/packages/irc-core/tests/stats-store.test.ts +222 -0
  174. package/packages/irc-core/tests/types.test.ts +35 -1
  175. package/packages/irc-core/tests/ws-framing.test.ts +213 -0
  176. package/packages/irc-core/tests/ws-subprotocol.test.ts +111 -0
  177. package/packages/irc-core/tsconfig.build.json +1 -1
  178. package/packages/irc-core/tsconfig.test.json +1 -1
  179. package/packages/irc-server/package.json +1 -1
  180. package/packages/irc-server/src/actor.ts +393 -16
  181. package/packages/irc-server/src/dispatch.ts +1 -3
  182. package/packages/irc-server/src/index.ts +10 -2
  183. package/packages/irc-server/src/routing.ts +15 -0
  184. package/packages/irc-server/src/runtime.ts +31 -0
  185. package/packages/irc-server/src/transport.ts +104 -0
  186. package/packages/irc-server/tests/actor.test.ts +1489 -4
  187. package/packages/irc-server/tests/dispatch.test.ts +37 -17
  188. package/packages/irc-server/tests/raw-modules.d.ts +11 -0
  189. package/packages/irc-server/tests/routing.test.ts +5 -0
  190. package/packages/irc-server/tests/runtime.test.ts +7 -0
  191. package/packages/irc-server/tests/transport.test.ts +230 -0
  192. package/packages/irc-test-support/package.json +1 -1
  193. package/packages/irc-test-support/src/harness.ts +44 -9
  194. package/packages/irc-test-support/src/in-memory-harness.ts +73 -9
  195. package/packages/irc-test-support/src/index.ts +3 -0
  196. package/packages/irc-test-support/src/scenarios.ts +141 -3
  197. package/packages/irc-test-support/tests/in-memory-harness.test.ts +2 -1
  198. package/packages/irc-test-support/tests/in-memory-scenarios.test.ts +23 -9
  199. package/pnpm-workspace.yaml +10 -1
  200. package/tools/ci-hardening/package.json +1 -1
  201. package/tools/package.json +9 -0
  202. package/tools/seed-aws-accounts.ts +5 -6
  203. package/tools/seed-cf-accounts.ts +107 -0
  204. package/tools/tcp-ws-forwarder/package.json +1 -1
  205. package/tools/tcp-ws-forwarder/src/forwarder.ts +57 -9
  206. package/tools/tcp-ws-forwarder/tests/forwarder.test.ts +34 -1
  207. package/tools/tcp-ws-forwarder/tests/framing.test.ts +65 -1
  208. package/docs/ADR-001-pure-reducers-and-effect-system.md +0 -74
  209. package/docs/ADR-002-location-of-authority.md +0 -82
  210. package/docs/ADR-003-durable-object-sharding.md +0 -93
  211. package/docs/ADR-004-dynamodb-schema.md +0 -96
  212. package/docs/ADR-005-wss-only-transport-v1.md +0 -83
  213. package/docs/ADR-006-sasl-mechanism-scope.md +0 -86
  214. package/docs/ADR-007-deterministic-ports.md +0 -82
  215. package/docs/ADR-008-monorepo-tooling.md +0 -60
  216. package/docs/AWS-Adapter-Architecture.md +0 -496
  217. package/docs/AWS-Deployment.md +0 -1186
  218. package/docs/Cloudflare-Deployment-Guide.md +0 -660
  219. package/docs/Home.md +0 -11
  220. package/docs/Observability.md +0 -87
  221. package/docs/PlanIRCv3Websocket.md +0 -489
  222. package/docs/PlanWebClient.md +0 -451
  223. package/docs/Release-Process.md +0 -443
@@ -1,74 +0,0 @@
1
- # ADR-001: Pure reducers and the effect system
2
-
3
- **Date:** 2025-01-15 (Phase 1)
4
- **Status:** Accepted
5
- **Supersedes:** —
6
- **Superseded by:** —
7
-
8
- ## Context
9
-
10
- Every IRC daemon must decide where side effects happen. A traditional ircd
11
- threads mutable state and IO through command handlers — the handler reads a
12
- channel roster, sends messages, mutates a user record, and returns. That makes
13
- handlers hard to unit-test (they require a live socket, a real timer, a
14
- populated data store) and hard to reason about (the handler's observable
15
- behaviour is inseparable from its IO).
16
-
17
- ServerlessIRCd targets two cloud adapters (Cloudflare Workers, AWS Lambda)
18
- that share one protocol core. If the core performed IO directly, each adapter
19
- would need its own mock surface for every core test — or worse, the core
20
- would grow adapter-specific code paths.
21
-
22
- ## Decision
23
-
24
- Every command handler is a **pure function** with the signature:
25
-
26
- ```ts
27
- type Reducer<S> = (state: S, msg: IrcMessage, ctx: Ctx) => { state: S; effects: Effect[] };
28
- ```
29
-
30
- - **No IO in the reducer.** No `await`, no `fetch`, no `setTimeout`, no
31
- `Date.now()`, no `Math.random()`. The reducer reads `ctx.clock.now()` and
32
- `ctx.ids.nonce()` instead (see ADR-007).
33
- - **Side effects are values.** The reducer returns an `Effect[]` — a
34
- discriminated union (`Send`, `Broadcast`, `Disconnect`, `ReserveNick`,
35
- `ChangeNick`, `ReleaseNick`, `ApplyChannelDelta`, `SendToNick`, …). Each
36
- effect tag maps one-to-one to an `IrcRuntime` method.
37
- - **A single `dispatch(effects, runtime)` function** in `irc-server`
38
- interprets the effects against the bound runtime. Only `dispatch` awaits.
39
- - **Reducer purity is enforced by convention and testability, not by a
40
- sandbox.** The type system carries the contract; the 100% coverage gate on
41
- `irc-core` verifies it empirically.
42
-
43
- ## Consequences
44
-
45
- **Positive:**
46
- - Every reducer is a trivial unit test: arrange state, apply message, assert
47
- `state` and `effects`. No mocks, no fakes beyond an injected `Clock` and
48
- `IdFactory`.
49
- - The same reducer code runs unchanged on in-memory, CF, and AWS runtimes.
50
- Adapter work is "wire the runtime", not "rewrite the handler".
51
- - Reducer behaviour is deterministic and reproducible — critical for the
52
- parametrized contract suite (TICKET-032) that runs identical scenarios
53
- across all three runtimes.
54
- - Mutation testing (Stryker, TICKET-048) is meaningful because reducers have
55
- no hidden IO to mask a mutation's effect.
56
-
57
- **Negative:**
58
- - The `Effect` union grows with every new side-effect type. Adding a novel
59
- effect (e.g. `QueryHistory` for chathistory) requires touching `effects.ts`,
60
- `dispatch.ts`, and every runtime implementation. This is by design (the
61
- type system makes missing-runtime-support a compile error) but adds
62
- ceremony.
63
- - Reducers cannot directly observe the result of a side effect they emit
64
- (e.g. "did the broadcast actually reach anyone?"). Cross-effect
65
- coordination is deferred to the actor layer, which can pre-fetch runtime
66
- state before invoking the reducer.
67
-
68
- ## References
69
-
70
- - PLAN §2.1 — "The key idea: pure reducers + location-of-authority"
71
- - PLAN §2.2 — `IrcRuntime` port
72
- - `packages/irc-core/src/effects.ts` — `Effect` union
73
- - `packages/irc-core/src/types.ts` — `Reducer<S>` signature
74
- - `packages/irc-server/src/dispatch.ts` — `dispatch(effects, runtime)`
@@ -1,82 +0,0 @@
1
- # ADR-002: Location-of-authority state split
2
-
3
- **Date:** 2025-01-15 (Phase 1)
4
- **Status:** Accepted
5
- **Supersedes:** —
6
- **Superseded by:** —
7
-
8
- ## Context
9
-
10
- An IRC server manages several kinds of state: connection records (nick, caps,
11
- away status), channel rosters (who is in `#foo`, with what prefix), channel
12
- metadata (topic, modes, ban lists), and the nick registry (nick → connection
13
- map). In a single-process ircd all of this lives in one address space, so
14
- read-modify-write races are handled with locks or a single event loop.
15
-
16
- ServerlessIRCd runs on stateless-per-request compute (Lambda) or
17
- per-entity-isolated compute (Durable Objects). There is no global lock. If
18
- two connections race to JOIN the same channel, or two clients race to claim
19
- the same nick, the outcome must still be correct. Traditional locking is
20
- impossible across instances.
21
-
22
- ## Decision
23
-
24
- Each piece of state has **exactly one authority** — the single entity that
25
- owns the canonical copy and serializes all mutations to it. Reducers are
26
- routed to the authority that owns the state they mutate:
27
-
28
- | Command family | Authority | Primary state |
29
- |---|---|---|
30
- | Registration (NICK/USER/PASS) | Connection entity | `ConnectionState` |
31
- | PING/PONG, QUIT, AWAY, user MODE | Connection entity | `ConnectionState` |
32
- | JOIN/PART/channel MODE/TOPIC/KICK/INVITE | Channel entity | `ChannelState` + roster |
33
- | PRIVMSG/NOTICE to channel | Channel entity | Fanout (reads roster) |
34
- | PRIVMSG/NOTICE to user | Sender Connection | Nick → Connection route |
35
- | Nick reservation | Registry entity | Nick → Connection map |
36
-
37
- Cross-authority coordination is done via **effects**, not direct mutation.
38
- When a connection accepts a JOIN, the connection-authority reducer emits an
39
- `ApplyChannelDelta` effect that the channel authority consumes. The channel
40
- authority is the sole writer of its roster; the connection never touches it
41
- directly.
42
-
43
- Platform mapping:
44
- - **Cloudflare:** each authority is a Durable Object (`ConnectionDO`,
45
- `ChannelDO`, `RegistryDO`). DO single-threaded serial execution gives the
46
- uniqueness invariant for free — two concurrent requests to the same DO are
47
- queued, not racing.
48
- - **AWS:** each authority is a DynamoDB table with conditional writes
49
- (`ConditionExpression`) or `TransactWriteItems` for multi-row atomicity
50
- (e.g. JOIN spans `Connections` and `ChannelMembers`).
51
-
52
- ## Consequences
53
-
54
- **Positive:**
55
- - Races are structurally impossible, not defended against. Two clients
56
- claiming the same nick both route to the same `RegistryDO` shard (or the
57
- same `Nicks` row with a conditional PutItem) — exactly one wins.
58
- - The reducer signature stays uniform (`Reducer<S>`) regardless of which
59
- authority it runs in. The actor layer routes; the reducer does not know or
60
- care whether it is running in a DO or a Lambda.
61
- - Each authority can be tested in isolation. The channel reducer tests
62
- arrange a `ChannelState` and assert effects; they never need a live
63
- connection registry.
64
-
65
- **Negative:**
66
- - Cross-authority coordination requires a round-trip (DO `stub()` call on CF;
67
- extra DynamoDB write on AWS). A JOIN that updates both the connection's
68
- joined-list and the channel roster is two writes, not one.
69
- - The actor layer must pre-fetch authoritative state before invoking a
70
- reducer (e.g. WHOIS needs the target connection's state from a different
71
- authority). This adds a `prefetchChannelState` step in the actor pipeline.
72
- - Listing all channels (LIST) or resolving every member of a channel (WHO)
73
- requires aggregating across authorities — there is no global view. The CF
74
- adapter needs a channel registry (TICKET-073); the AWS adapter does a
75
- DynamoDB scan.
76
-
77
- ## References
78
-
79
- - PLAN §2.1 — location-of-authority table
80
- - PLAN §4 — state model & authoritative ownership
81
- - ADR-001 — pure reducers (how effects flow between authorities)
82
- - `packages/irc-server/src/actor.ts` — `route()` switch (authority routing)
@@ -1,93 +0,0 @@
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
- ## References
86
-
87
- - PLAN §9 — open question: "Channel DO sharding granularity"
88
- - PLAN §6.1 — `RegistryDO` sharded by `hash(nick) % N`
89
- - `packages/cf-adapter/src/sharding.ts` — `shardNick`, `registryKeyForNick`,
90
- `DEFAULT_REGISTRY_SHARDS = 32`
91
- - `packages/cf-adapter/src/registry-do.ts` — per-shard registry authority
92
- - TICKET-034 — RegistryDO implementation
93
- - TICKET-073 — CF runtime stubbed lookups (channel registry gap)
@@ -1,96 +0,0 @@
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`
@@ -1,83 +0,0 @@
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)
@@ -1,86 +0,0 @@
1
- # ADR-006: SASL mechanism scope (PLAIN only, EXTERNAL deferred)
2
-
3
- **Date:** 2025-01-20 (Phase 1)
4
- **Status:** Accepted (EXTERNAL re-evaluation tracked in 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
- v1 ships **SASL PLAIN only** as a functional mechanism. EXTERNAL is
31
- **recognized but stubbed**: the reducer accepts `AUTHENTICATE EXTERNAL`,
32
- acknowledges the mechanism, and immediately returns `904 ERR_SASLFAIL` with a
33
- documented code comment cross-referencing TICKET-054 (mTLS) and TICKET-079
34
- (decision: implement or stop advertising).
35
-
36
- The `sasl` cap advertises `PLAIN,EXTERNAL` (both names listed) so clients
37
- that probe mechanism availability see EXTERNAL as nominally supported. The
38
- actual `904` on EXTERNAL attempt is the functional gate. TICKET-079 is the
39
- follow-up that decides whether to implement EXTERNAL against a pluggable
40
- `MtlsIdentityProvider` or stop advertising it until mTLS lands.
41
-
42
- `AccountStore` is a port in `irc-core` consumed by the SASL reducer. The
43
- `verify(mechanism, payload)` method is **synchronous** — adapters pre-load
44
- credentials at boot so the reducer stays pure (ADR-001). PLAIN verification
45
- decodes the base64 payload, extracts username + password, and matches against
46
- the store.
47
-
48
- ## Consequences
49
-
50
- **Positive:**
51
- - PLAIN works end-to-end in v1 with no special infrastructure. The
52
- `AccountStore` port abstracts the credential store; adapters seed it from
53
- config (in-memory), DynamoDB (AWS), or a persistent backend (D1/DO for CF,
54
- TICKET-093).
55
- - EXTERNAL is forward-compatible: advertising it now means clients that
56
- prefer EXTERNAL will attempt it; once mTLS lands (Phase 7), the same
57
- `AUTHENTICATE EXTERNAL` flow succeeds without a client-side change.
58
- - The synchronous `AccountStore.verify()` keeps the reducer pure and
59
- deterministic. Async credential lookups (DynamoDB) are resolved at cold
60
- start or via pre-loading, not inside the reducer.
61
-
62
- **Negative:**
63
- - EXTERNAL is advertised but non-functional in v1 — a client that negotiates
64
- `sasl` and sends `AUTHENTICATE EXTERNAL` gets `904` with no actionable
65
- error message. This is a poor UX until TICKET-079 resolves (stop-advertising
66
- is the recommended interim per the ticket).
67
- - PLAIN sends the password base64-encoded (not encrypted) inside the wss
68
- frame. wss provides the TLS layer, so the password is encrypted in transit
69
- — but PLAIN is still weaker than EXTERNAL (no mutual auth).
70
- - The synchronous `AccountStore` contract means the adapter must pre-load all
71
- credentials. For deployments with many accounts, cold-start latency grows
72
- linearly with account count. A lazy/async lookup variant is a documented
73
- follow-up but would require an async-reducer or effect-based credential
74
- query — a significant architecture change.
75
-
76
- ## References
77
-
78
- - PLAN §3 — "sasl (mechanisms: PLAIN, EXTERNAL reserved for later with mTLS)"
79
- - PLAN §9 — SASL mechanism scope
80
- - TICKET-026 — SASL reducer implementation
81
- - TICKET-071 — AccountStore wiring into ConnectionActor
82
- - TICKET-072 — AWS DynamoDB AccountStore (scrypt hashing)
83
- - TICKET-079 — SASL EXTERNAL: implement or stop advertising (interim decision)
84
- - TICKET-054 — mTLS support (Phase 7, enables functional EXTERNAL)
85
- - `packages/irc-core/src/commands/sasl.ts` — `authenticateReducer`
86
- - `packages/irc-core/src/ports.ts` — `AccountStore` port
@@ -1,82 +0,0 @@
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`
@@ -1,60 +0,0 @@
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