Skip to content

Add .claude/rules/ and refresh CLAUDE.md#745

Merged
rdimitrov merged 3 commits into
mainfrom
docs/add-invariants
Apr 22, 2026
Merged

Add .claude/rules/ and refresh CLAUDE.md#745
rdimitrov merged 3 commits into
mainfrom
docs/add-invariants

Conversation

@rdimitrov
Copy link
Copy Markdown
Member

@rdimitrov rdimitrov commented Apr 21, 2026

Summary

  • New: .claude/rules/ — six scoped rule files (layering.md, data-model.md, auth.md, api.md, sync.md, secrets.md) capturing the design decisions that shaped this codebase and should not be broken without explicit discussion. Each file uses a paths: frontmatter glob so Claude Code loads the rule only when working on files in its scope. Matches the convention already used in stacklok/toolhive (.claude/rules/vmcp-anti-patterns.md and siblings). Credit to Alejandro for the suggestion.
  • Refresh: CLAUDE.md — the previous version referenced paths under cmd/thv-registry-api/ that no longer exist (real packages live under internal/) and described a Provider / RegistryDataProvider abstraction that is not in the codebase. This update replaces the stale architecture section with an accurate directory tree, rewrites the "Key Patterns" and "Common Tasks" sections against the real code (builder + functional options, SourceConfig.GetType, RecordFilter chains, audit wrapping, source type registration steps), fixes the dependency list to match go.mod, and points at .claude/rules/ for the per-area design rules.

No code changes; docs and rules only.

Rule file scopes

File Paths Covers
layering.md internal/**, cmd/** layer direction, two HTTP servers, builder + factory pattern
data-model.md internal/config/**, internal/service/**, internal/sources/**, database/** claims on names, source-type inference, managed-source uniqueness, flat claims, CONFIG/API exclusivity, app-level filtering
auth.md internal/auth/**, internal/authz/**, claims filter authn/authz separation, IdP-sourced roles, uniform claim matching, default-deny, subset validation, HTTPS for OIDC
api.md internal/api/** upstream spec compliance, single publish endpoint, personalized responses, audit wrapping, entry-level dedup
sync.md internal/sync/**, internal/sources/**, internal/kubernetes/** serializable txn + rollback, non-synced source skip, K8s per-CRD claims
secrets.md internal/auth/**, internal/config/**, internal/db/** file-based secrets, symlink resolution, mutually-exclusive auth modes

Test plan

  • Skim each rule file and flag any rule that is not actually load-bearing, or any constraint that is missing
  • Verify the paths: globs on each rule match the code that should trigger them
  • Verify the CLAUDE.md directory tree matches reality (especially the internal/ layout)
  • Confirm the "Common Tasks" recipes describe the right files for adding an admin endpoint, a source type, and a DB query

Introduce `docs/invariants.md`, a shortlist of design decisions that
should survive future refactors — layering boundaries, the claims model,
upstream API compatibility, sync atomicity, and related constraints.
Each entry names the decision, the rationale, what must hold, and what
breaks if it is undone. The intent is to give reviewers (human and
agentic) a single place to cite when a change conflicts with a
load-bearing choice that is otherwise only implicit in the code.

Refresh `CLAUDE.md` to match the current codebase and reference the new
doc. The previous version pointed to paths under `cmd/thv-registry-api/`
that no longer exist (the real packages are under `internal/`) and
described a `Provider` / `RegistryDataProvider` abstraction that was
never part of this repository. Replace the layer description with an
accurate directory tree, rewrite the "Key Patterns" and "Common Tasks"
sections against the actual architecture (builder + functional options,
`SourceConfig.GetType`, `RecordFilter` chains, audit wrapping, source
type registration steps), and update the dependency list to reflect
what is in `go.mod` today. Add a prominent pointer to
`docs/invariants.md` at the top of the file and note that the
`code-reviewer` subagent should cross-check against it.
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 21, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 60.40%. Comparing base (c46b908) to head (09ee66a).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #745      +/-   ##
==========================================
- Coverage   60.64%   60.40%   -0.24%     
==========================================
  Files         108      108              
  Lines       10482    13041    +2559     
==========================================
+ Hits         6357     7878    +1521     
- Misses       3572     4610    +1038     
  Partials      553      553              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Following review feedback, convert `docs/invariants.md` into scoped rule
files under `.claude/rules/` so Claude Code loads each rule only when
working on files in its declared path glob, matching the convention
already used in `stacklok/toolhive` (`.claude/rules/vmcp-anti-patterns.md`
and siblings). This keeps `CLAUDE.md` tight, avoids always-loaded context
bloat, and lets rules be maintained alongside the code they govern.

The content is the same set of constraints previously captured in
`docs/invariants.md`, split by theme: `layering.md` (layer direction,
two HTTP servers, builder/factory pattern), `data-model.md` (claims on
names, source-type inference, managed-source uniqueness, flat claim
values, CONFIG/API exclusivity, app-level filtering), `auth.md`
(authn/authz separation, IdP-sourced roles, uniform claim matching,
default-deny, subset validation, HTTPS for OIDC), `api.md` (upstream
spec compliance, single publish endpoint, personalized responses, audit
wrapping, entry-level dedup), `sync.md` (serializable txn, non-synced
types, K8s per-CRD claims), and `secrets.md` (file-based secrets,
symlink resolution, mutually-exclusive auth modes). Each file uses a
`paths:` frontmatter glob and the gateway's **Detect** / **Instead**
idiom where it fits.

Update `CLAUDE.md` to point to the rules directory instead of the
removed `docs/invariants.md` and refresh inline `§`-references in the
"Common Tasks" recipes to name the specific rule file.
@rdimitrov rdimitrov changed the title Add design invariants doc, refresh CLAUDE.md Add .claude/rules/ and refresh CLAUDE.md Apr 21, 2026
Copy link
Copy Markdown
Member

@aponcedeleonch aponcedeleonch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

@rdimitrov rdimitrov self-assigned this Apr 22, 2026
@rdimitrov rdimitrov merged commit 334bb42 into main Apr 22, 2026
14 checks passed
@rdimitrov rdimitrov deleted the docs/add-invariants branch April 22, 2026 11:21
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.

3 participants