feat: scaffold Fiber API with probes, metrics, and middleware stubs#7
Merged
Conversation
Bring the api repo up to "compiles, starts, answers probes" per #1. No business logic yet — that arrives with #2 (storage), #3 (runtime), #4-#5 (agent), and #6 (workflow). Structure mirrors the layout sibling Go services will adopt: cmd/api/ fiber app + env-driven config internal/handlers/ thin HTTP layer — probes + /metrics internal/middleware/ requestID, logger, recover; auth/RBAC/audit stubs internal/observability/ slog JSON logger internal/services/ placeholder for business logic pkg/storage/ placeholder; reserved for postgres (#2) pkg/runtime/ placeholder; reserved for redis (#3) pkg/workflow/ placeholder; reserved for approval engine (#6) The pkg/* split is intentional: those packages are the import surface that worker reuses (per REFACTOR_PLAN.md §4). internal/* is closed. Middleware order is fixed in this PR so downstream issues don't have to refactor route registration: RequestID → Logger → Recover → /api/v1 group → Auth → RBAC → Audit Auth/RBAC/Audit are explicit stubs today. The audit stub logs a "TODO: emit immutable audit event with correlation_id" line on every authenticated request so missing coverage stays visible during dev. Endpoints: GET /healthz unconditional 200 once the process answers HTTP GET /readyz gated by atomic.Bool (default true; SetReady flips) GET /metrics Prometheus exposition via expfmt.Encoder directly Tests cover: probe semantics (Healthz unconditional, Readyz gated), /metrics produces real go_* / process_* series, requestID middleware generates/echoes/rejects-overlong inbound IDs, Auth stub sets the anonymous actor on the context. All pass under -race. CI: same 4-job workflow shape as secrets-bridge/core — build (+ vet), test (-race), golangci-lint, tidy check. Dockerfile: multi-stage golang:1.25-alpine → distroless/static:nonroot. Note: Go 1.25 (not 1.24 as written in REFACTOR_PLAN) because gofiber/fiber/v3 v3.3.0 requires it. core will be bumped to match when it next changes.
v6 ships golangci-lint v1.x built with Go 1.24, which refuses to lint a module declaring 'go 1.25'. v7 uses golangci-lint v2.x built with Go 1.25+.
golangci-lint v2 (in CI via golangci-lint-action@v7) flags expfmt.FmtText under staticcheck SA1019. NewFormat(TypeTextPlain) is the replacement since prometheus/common v0.49.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Close #1 — bring
apiup to "compiles, starts, answers probes." No business logic yet; that arrives with #2 (storage), #3 (runtime), #4 / #5 (agent), and #6 (workflow).Layout
pkg/*is the import surface thatworkerreuses (perREFACTOR_PLAN.md§4).internal/*is closed.Middleware order (fixed by this PR so downstream issues don't refactor route registration)
Auth / RBAC / Audit are explicit stubs today. The audit stub logs
"TODO: emit immutable audit event with correlation_id"on every authenticated request so missing coverage stays visible during development.Endpoints
GET /healthzGET /readyzatomic.Bool. Defaults to ready; flips to 503 whenSetReady(false). Real dep checks register here as #2 / #3 land.GET /metricsexpfmt.Encoderwriting directly to the response writer — nonet/http↔Fiber adapter.Tests (all pass under
-race)Healthzunconditional 200 even whenSetReady(false)Readyzreturns 503 when not ready and 200 when ready/metricsproduces realgo_*andprocess_*seriesRequestIDgenerates when absent, echoes inbound, rejects overlong (>128 char) inbound headersAuthstub sets"anonymous"actor on the contextLocal verification
Decisions worth flagging in review
gofiber/fiber/v3 v3.3.0requires Go 1.25.corewill be bumped to match when it next changes.DisableStartupMessage; banner is just stdout noise.expfmt.Encoderfor/metricsnet/httpto Fiber. Removes an entire dependency surface.charts/api(#14) restricts external reachability.pkg/*exported,internal/*closedpkg/storage,pkg/runtime,pkg/workfloware the surfaceworkerwill import.Hard rules respected (BRD / CLAUDE.md)
Test plan
cmd/api/main.goand confirms it matches the contract (RequestID → Logger → Recover → group → Auth → RBAC → Audit)Closes #1