From 07b61d05e9d81fa6fc81a57b145506db7d4fb89d Mon Sep 17 00:00:00 2001 From: Jan Unterbrink Date: Mon, 23 Nov 2026 12:13:18 +0100 Subject: [PATCH 1/2] docs: add CLAUDE.md with Go conventions Rules for coding agents working in this repo: layering, own types per layer, exported interfaces over unexported implementations, validating constructors for values with rules or secrets, and the checks to run before handing over. Co-Authored-By: Claude Opus 5.5 --- CLAUDE.md | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 CLAUDE.md diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 0000000..fa0a570 --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1,38 @@ +# CLAUDE.md + +Instructions for coding agents in **spotify-mcp**: the MCP server that controls Spotify playback, with an invite-link connect page (Go, Helm chart in `charts/`). + +- Target layout (from PR #2, `refactor/layering`): domain packages `internal/account` and `internal/playback`; adapters `internal/spotify`, `internal/filestore`, `internal/store`; transports `internal/mcpserver`, `internal/tools`, `internal/web`. Code on `main` from before PR #2 doesn't follow it yet; new code does. Keep the README in step. +- Lint config is `.golangci.yml`: run `golangci-lint run` before handing over. + +## Go conventions + +Jan reads this code as production Go, even for a home project. Follow these from the first commit; don't argue against them with Go proverbs ("accept interfaces, return structs", "changing interfaces breaks implementers"). Explain a trade-off only when it is concrete. + +### Layers + +- **Domain first.** One domain package holds the types, the rules and the use cases (a `Service` with methods). It declares the interfaces (ports) it needs and knows nothing about HTTP, files, SQL or external APIs. +- **Adapters** (storage, file formats, external APIs) implement the domain's ports. +- **Transports** (HTTP, MCP, CLI) depend only on domain interfaces. +- **Thin `main`:** an `app` struct holds the parts; commands are its methods. + +### Types and interfaces + +- **Each layer owns its types and maps them explicitly** at every boundary: wire types, DB rows/columns, file formats. Never pass storage or generated types across a layer, and never `json.Marshal` domain types into a column. +- **Interfaces between layers**, defined by the consumer and kept small. A new capability gets a new or composed interface instead of a bigger one. +- **Exported interface, unexported implementation:** `type DB interface{…}`, `type db struct{…}`, `func Open(…) (DB, error)`. +- **Values that carry a rule or a secret** (IDs, names, keys, codes, tokens) are an exported interface over an unexported struct, created only by a validating constructor (`Parse…`/`New…`), plus `Restore…` for trusted stored data. No bare `string` types callers can forge. Compare through methods, not `==` on interface values. +- **Methods on types**, not free functions that all take the same dependency. +- **Typed values** (dates, enums, durations) instead of strings and ints; inject a clock instead of calling `time.Now()` in the domain. +- **Generated code** lives in its own package and is never edited by hand. HTTP APIs are spec-first (OpenAPI + oapi-codegen) where the repo has a spec. + +### Tests and verification + +- Tests per layer: table tests for rules, handlers against fakes, storage against the real thing (SQLite file, temp dir), one end-to-end test. +- Before handing over: `go build ./...`, `go vet ./...`, `go test -race ./...`, and `golangci-lint run` if the repo has a config. Run the service locally once. +- Report what was verified and what was not. Keep the README's code layout section current when packages change. + +### Working rules + +- Technical text (code, comments, commits, PRs, docs) in English, even for a German UI. +- Don't commit, push or merge without Jan's OK. From aad70ada4d3bc8487a13c44479afba3f8a56cb1a Mon Sep 17 00:00:00 2001 From: Jan Unterbrink Date: Mon, 23 Nov 2026 12:14:02 +0100 Subject: [PATCH 2/2] docs: merge type and constructor rules into CLAUDE.md Adds the detailed rules for values and entities: no exported named basic types for values with rules or secrets, sealed interfaces, redacted secrets, no exported mutable globals. Co-Authored-By: Claude Opus 5.5 --- CLAUDE.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/CLAUDE.md b/CLAUDE.md index fa0a570..fc226e9 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -21,11 +21,20 @@ Jan reads this code as production Go, even for a home project. Follow these from - **Each layer owns its types and maps them explicitly** at every boundary: wire types, DB rows/columns, file formats. Never pass storage or generated types across a layer, and never `json.Marshal` domain types into a column. - **Interfaces between layers**, defined by the consumer and kept small. A new capability gets a new or composed interface instead of a bigger one. - **Exported interface, unexported implementation:** `type DB interface{…}`, `type db struct{…}`, `func Open(…) (DB, error)`. -- **Values that carry a rule or a secret** (IDs, names, keys, codes, tokens) are an exported interface over an unexported struct, created only by a validating constructor (`Parse…`/`New…`), plus `Restore…` for trusted stored data. No bare `string` types callers can forge. Compare through methods, not `==` on interface values. - **Methods on types**, not free functions that all take the same dependency. - **Typed values** (dates, enums, durations) instead of strings and ints; inject a clock instead of calling `time.Now()` in the domain. - **Generated code** lives in its own package and is never edited by hand. HTTP APIs are spec-first (OpenAPI + oapi-codegen) where the repo has a spec. +### Values, entities and constructors + +- No exported named basic types (`type ProfileID string`) for values that carry a rule or a secret: they can be created by plain conversion and skip validation. +- Values and entities with a rule or a secret are an exported interface with an unexported implementation, created only through functions that validate (`ParseX`, `NewX`, `RestoreX` for adapters reading storage). Seal value interfaces with an unexported marker method; keep a defensive check where a value ends up in a file name or key. +- Entities passed between layers are interfaces too, not exported structs with open fields. Services and adapters: `NewX` returns an exported interface (or the port it implements). +- No exported mutable globals for rules (scope lists, kind lists): use functions that return a copy. +- Secrets print as redacted (`String()`), and logs pass explicit strings (slog's JSON handler doesn't call `String()`). +- Fine to keep: sentinel errors and error types (`errors.Is/As`), functional options, plain config/input structs with no rule. Say so explicitly when keeping one. +- Don't copy an existing `type X string` pattern from a codebase; flag it. + ### Tests and verification - Tests per layer: table tests for rules, handlers against fakes, storage against the real thing (SQLite file, temp dir), one end-to-end test.