Skip to content

refactor(http): deepen route registration into per-feature modules#142

Merged
allisson merged 3 commits into
mainfrom
next-steps
Jul 17, 2026
Merged

refactor(http): deepen route registration into per-feature modules#142
allisson merged 3 commits into
mainfrom
next-steps

Conversation

@allisson

Copy link
Copy Markdown
Owner

Summary

Deepens the seam between feature modules and the HTTP server. internal/http/server.go was the single most-churned file in the repo (13 edits in the last 40 commits) because every feature change had to touch it, plus RouterDeps (a 13-field inventory duplicated across di.go and server.go) and four near-identical register*Routes funcs.

After this change, each feature owns its route registration next to its handlers, and server.go imports no feature package.

What changed

  • New seam in internal/http (imports only gin + metrics): RouteRegistrar interface + RouteMiddlewares{Auth, RateLimit} bundle. SetupRouter is now feature-agnostic — it builds the global middleware chain and loops over a []RouteRegistrar.
  • Four feature Modules (auth, secrets, transit, tokenization) — each captures its handlers + authorizer + business metrics and registers its own routes. Verbatim relocation of the existing gin stanzas; no behavior change. The auth module owns the /token irregular layout (no-auth + IP-based rate limit).
  • di.go builds all middleware (auth, rate-limit, token-rate-limit, authorizer), assembles the registrars, and calls the new SetupRouter. CLI access to the container is untouched.
  • Deleted: RouterDeps + the four register*Routes funcs (~320 lines).
  • Import direction reversed: http → features becomes features → internal/http (no cycle).
  • CONTEXT.md: recorded Route Module, RouteRegistrar, RouteMiddlewares.

A follow-up chore commit bumps Go 1.26.3 → 1.26.5 and updates dependencies.

Test plan

  • Route-manifest golden test (server_routes_test.go) — asserts the full set of 35 method + path pairs is byte-identical before and after the relocation.
  • make test (race) — 1250 pass.
  • make test-integration (serial, DB up) — green, including the auth + authz + business-metrics end-to-end flows.
  • make lint — golangci clean.
  • Verified server.go imports no feature-http package.

🤖 Generated with Claude Code

allisson and others added 3 commits July 17, 2026 10:38
server.go no longer imports any feature package. Each feature (auth, secrets,
transit, tokenization) owns a Module in its http package that registers its own
routes next to its handlers, implementing the new RouteRegistrar seam. The
composition root builds every middleware, assembles the []RouteRegistrar, and
hands it to a feature-agnostic SetupRouter; RouterDeps and the four
register*Routes funcs are gone. The import direction reverses to feature ->
internal/http.

A route-manifest golden test (server_routes_test.go) locks the 35 method+path
pairs so the relocation is provably behavior-preserving. CLI access to the
container is untouched.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@allisson
allisson merged commit 4099987 into main Jul 17, 2026
3 checks passed
@allisson
allisson deleted the next-steps branch July 17, 2026 13:54
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