---
id: w1/m2.5/t007
title: Finalize — delete flat internal/api, rewire cmd/api, update docs, prove green
worker: worker1
status: done
estimate: 30m
depends_on: [w1/m2.5/t003, w1/m2.5/t004, w1/m2.5/t005, w1/m2.5/t006]
---

## Objective

Close the refactor: remove whatever remains of the flat `internal/api` grab-bag, rewire `cmd/api/main.go` to construct the composition root over the feature packages, update the three CLAUDE.md files to describe the new layout, and prove the whole toolchain is unaffected.

## Context

- After t002–t006 the old `internal/api` holds only the composition root (or is fully replaced by `internal/server`). Any leftover shared symbols belong in `internal/core`.
- `cmd/api/main.go` wires the sources (PodLogs, metrics sources, APIKeys, Authz, Store) — it now injects each into the owning feature service instead of one kitchen-sink `Core`.
- Docs that assert the old shape: `lego/backend/CLAUDE.md` ("`internal/api/` — one `Core` … plus auth.go/authz.go/…"), `lego/backend/internal/api/CLAUDE.md`, and the root `CLAUDE.md` repo-map line for `lego/backend/`.

## Steps

1. Delete the emptied flat files; ensure only the composition root + feature packages + `core`/`authz`/`store` remain.
2. Rewire `cmd/api/main.go` (both `api` and `api mcp-stdio` paths).
3. Rewrite `internal/api/CLAUDE.md` (or relocate it) to document: one package per feature, files-not-subpackages, fragments register into single roots, leaf `core` + root composition, no cycles. Update `lego/backend/CLAUDE.md` Layout and the root repo-map line.
4. Run `go build ./...`, `go test ./...`, `make docker-build`, `kustomize build config/api`.
5. Doc edits only need CI's markdown check where applicable (note: `.pm/` is prettier-ignored; `lego/**/CLAUDE.md` is not).

## Files

- `lego/backend/cmd/api/main.go`
- `lego/backend/internal/api/` (delete leftovers) / `internal/server/`
- `lego/backend/CLAUDE.md`, `lego/backend/internal/api/CLAUDE.md` (or new home), root `CLAUDE.md`

## Acceptance criteria

- [ ] `go build ./... && go test ./...` green; `make docker-build` and `kustomize build config/api` succeed unchanged.
- [ ] `internal/api` no longer contains business logic; one package per feature exists.
- [ ] The three CLAUDE.md files describe the feature-package layout and the single-roots rule.

## Out of scope

- New behavior; new verbs.
