Skip to content

feat(server): analytics and limits as Effect service packages #73

Closed

Description

@allisonmahmood

Problem

apps/server/src/analytics.ts and rate-limit.ts are modules with two consumers each (auth and patches once they exist). They port before their first consumer so auth can depend on them.

Do

  • packages/analytics: an Analytics service (Context.Service, one file per the conventions) with a track interface the emitters use; a PostHog layer whose finalizer flushes and gives up under 3 s; a no-op layer for tests and when the key is unset. Config slice with the key as Redacted.
  • packages/limits: the fixed-window limiter as a Limits service whose interface mirrors RateLimiter.consume (returns remaining and a Retry-After), keeping today's semantics: fails closed at 10k tracked keys. Pure in-memory layer; the interface must allow a Redis-backed layer later with no consumer change.
  • The Fastify app consumes both through a thin Effect.runPromise seam (a ManagedRuntime built once in start.ts); the old modules and their tests are deleted, tests ported to @effect/vitest (TestClock for window expiry; fault injection by a failing PostHog layer, not a mock).
  • CONTEXT.md for each (analytics event; rate limit, window, fails closed); promote the language-service warnings to error for both packages.

Done when

No limiter or analytics code remains in apps/server/src; the limiter's Retry-After and fail-closed behaviour are tested through the service; the finalizer flush is tested with TestClock.

Decisions implemented

Spec §8; Package decomposition by capability.


Filed from the Effect v4 port spec (#68) by the map task Write the port spec and file the build tickets.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:serverready-for-agent

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions