Skip to content

refactor: architecture deepening — 9 review candidates across web and backend - #78

Merged
evenluo merged 10 commits into
mainfrom
refactor/architecture-review-deepening
Jul 31, 2026
Merged

refactor: architecture deepening — 9 review candidates across web and backend#78
evenluo merged 10 commits into
mainfrom
refactor/architecture-review-deepening

Conversation

@evenluo

@evenluo evenluo commented Jul 31, 2026

Copy link
Copy Markdown
Owner

Summary

Architecture deepening pass from the 2026-07-30 architecture review: 9 candidates landed, one commit each, plus a code-review fix commit. All changes are pure refactors behind existing seams — no HTTP contract or product-observable behavior change (one disclosed exception below).

Frontend (web/):

  • Delete the legacy analytics summary seam: useAnalytics summary variant, mergeAnalyticsCore, and the wide AnalyticsResponse type — all had zero production callers (2469c0d).
  • Sink per-surface status rules (loading only with no stale data, error only with nothing cached) from routes/index.lazy.tsx into tested features/usage-intelligence view-models (surfaces.ts, refresh.ts); the route is now pure composition (+17 Vitest cases) (d3755c4).
  • Make the load plan the single source of truth for Fixed Operational Window parameters. Investigation showed pageSize=1 is the real contract (backend explicitly accepts it for "latest evidence") and the plan's 10 was the fiction — the plan was corrected instead of the route; hook signatures narrowed to non-null TimeGranularity (7c31786).
  • Extract trend/heatmap/health-grid pure derivation into features/usage-intelligence with interfaces keyed on Time Granularity instead of range; components are now thin render adapters (+29 Vitest cases) (2ce20a6).

Backend (internal/):

  • Live Capacity: split the refresh task queue/TTL cache out of quota.Service into a task store, register worker lifecycle with the app background-task set (shutdown no longer orphans in-flight tasks), inject a narrow AuthFileIdentityLookup instead of *gorm.DB — quota dispatch tests no longer need sqlite; dead RefreshSource vocabulary removed (259d253).
  • SyncService: delete six zero-caller entry points (SyncNow/SyncOnce/SyncStatus/SyncRedisBatch/NewSyncServiceWithClient/CleanupRedisUsageInbox), turn the provider-metadata fan-out into an ordered registry (mirroring the quota registry), and eliminate the hidden mutation inside validate() (1e44674).
  • Consolidate canonical event-key alignment (Request Evidence dedup) into the single-method CanonicalEventKeyAssigner with a narrow CanonicalEventLookup seam; the full branch matrix is now table-driven without sqlite (0e72c11).
  • Thread context.Context from UsageReader/AnalyticsReader through Build*WithFilter to GORM WithContext — expensive analytics queries can now be cancelled on client disconnect, and cancellation is asserted through the seam (6bdb933).
  • Honest router wiring: OptionalProviders is a plain struct (no variadic-as-optional), AuthConfig is built once, and the shallow usageIdentityService/rollupBackfillService wrappers are folded into repository readers consumed through the internal/api seams, per the ADR-0005 amendment (2e1446b).
  • Code-review follow-ups: HasActiveIdentity moved into internal/repository, canonical lookup functions honor ctx, canonical key building unified behind one BuildEventKey path (41ed28d).

Verification

  • make verify exit 0, run twice (after the 9 candidate commits and again after the review-fix commit): backend go test + go vet, frontend lint + Vitest (105 tests) + typecheck, Playwright e2e 12/12.
  • Two-axis code review against 6fa5c6e: Spec axis confirmed all 9 candidates present with line-identical semantics and ADR-0002~0005 boundaries held; Standards axis findings fixed in 41ed28d.

Compatibility

  • No HTTP request/response shape changes; no deployment or config changes.
  • One observable rendering change, disclosed: trend-chart tick labels differ only for non-default granularity combinations whose old output was broken (7d+day rendered a completely blank axis; 30d+hour printed ~720 identical labels; 24h+day showed raw date strings). All default views are pixel-identical.
  • Deleted symbols are internal Go API surface with zero production callers (verified by grep); RefreshSource was never sent or consumed over HTTP.

Auto-close: none

evenluo added 10 commits July 30, 2026 22:23
…meters

The dashboard route hardcoded request-evidence pageSize=1 while the load
plan emitted 10 — the tested value was never wired. git a226bee shows
page_size=1 is deliberate ('latest evidence pagination': the panel only
renders events[0] as the latest request), so the plan now emits 1 and
the route consumes fixedWindow.requestEvidence.pageSize instead of a
literal. No runtime behavior change.

Also narrow useAnalyticsCore/useAnalyticsHeatmap to non-null
TimeGranularity and drop the unreachable in-hook getDefaultGranularity
fallback; the only caller (the dashboard route) always passes a
resolved granularity.
…l reads

- NewRouter takes a plain OptionalProviders struct instead of variadic-as-optional
- AuthConfig built once in app.NewWithConfig and shared by handler and router
- usageIdentityService/rollupBackfillService shallow wrappers deleted; handlers
  consume repository.UsageIdentityReader/RollupBackfillReader through api seams
  (aligns with ADR-0005 read-path amendment)
- RollupBackfill status read now honors ctx end to end (reader seam +
  GetUsageRollupBackfillStatus WithContext); backfill batch intentionally keeps
  an internal background context since cancellation only applies between batches
- move HasActiveIdentity existence check into repository (layout ownership)
- thread ctx through canonical event lookup repository functions (seam honesty,
  consistent with the analytics/usage reader ctx threading)
- unify canonical event key building behind one BuildEventKey call path
- drop unused ListUsageIdentities stub method from api tests
@cursor

cursor Bot commented Jul 31, 2026

Copy link
Copy Markdown

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@evenluo
evenluo merged commit a6e6478 into main Jul 31, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant