Why
The relay package has separate Mastodon and LitePub implementations in packages/relay/src/mastodon.ts and packages/relay/src/litepub.ts. That separation is useful, but the shared behavior is still scattered: follow validation, accept/reject replies, undo handling, follower storage, and activity forwarding all live partly in protocol classes and partly in helpers.
As the package grows, protocol differences should be explicit rather than hidden in copied listener chains.
Current code
packages/relay/src/follow.ts contains common follow helpers. packages/relay/src/base.ts owns shared federation setup and follower listing. The Mastodon relay forwards accepted activities to followers. The LitePub relay stores pending follows, sends a reciprocal Follow, updates state on Accept, and announces activities to followers.
Scope
Refactor the relay internals so common behavior and protocol-specific behavior are easier to see and test. A good shape would include:
- a shared follow subscription flow with clear extension points for Mastodon and LitePub state changes;
- a shared representation of follower state transitions;
- tests that show exactly when a follower becomes
pending or accepted for each protocol;
- tests for
Undo(Follow) behavior in both protocols;
- a small amount of documentation in packages/relay/README.md or the CLI docs if the current public behavior becomes clearer through the refactor.
Non-goals
Do not change the public createRelay() API unless a tiny typed helper is needed. Do not merge Mastodon and LitePub into one protocol. Do not change delivery semantics for accepted followers.
Suggested checks
Add protocol-level tests under packages/relay/src/. Existing behavior should be preserved first, then the refactor can land with confidence.
Why
The relay package has separate Mastodon and LitePub implementations in packages/relay/src/mastodon.ts and packages/relay/src/litepub.ts. That separation is useful, but the shared behavior is still scattered: follow validation, accept/reject replies, undo handling, follower storage, and activity forwarding all live partly in protocol classes and partly in helpers.
As the package grows, protocol differences should be explicit rather than hidden in copied listener chains.
Current code
packages/relay/src/follow.ts contains common follow helpers. packages/relay/src/base.ts owns shared federation setup and follower listing. The Mastodon relay forwards accepted activities to followers. The LitePub relay stores pending follows, sends a reciprocal
Follow, updates state onAccept, and announces activities to followers.Scope
Refactor the relay internals so common behavior and protocol-specific behavior are easier to see and test. A good shape would include:
pendingoracceptedfor each protocol;Undo(Follow)behavior in both protocols;Non-goals
Do not change the public
createRelay()API unless a tiny typed helper is needed. Do not merge Mastodon and LitePub into one protocol. Do not change delivery semantics for accepted followers.Suggested checks
Add protocol-level tests under packages/relay/src/. Existing behavior should be preserved first, then the refactor can land with confidence.