Skip to content

Commit 97e52e5

Browse files
committed
docs(api): add route namespace guide to API v2 CLAUDE.md
Document the namespace separation (audio/:id for clips, system/audio/* for management, streams/* for live data) and the /api/v2/audio/:id wildcard collision risk. Also add anonymization requirement for public source metadata endpoints.
1 parent d514e4e commit 97e52e5

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

internal/api/v2/CLAUDE.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
**ALWAYS read `internal/api/v2/README.md` first** - it contains:
66

7-
- Complete list of all 75 API endpoints
7+
- Complete list of all API endpoints
88
- Route registration patterns
99
- Authentication requirements
1010
- Best practices and security guidelines
@@ -39,6 +39,21 @@
3939
- Protected endpoints: `c.getEffectiveAuthMiddleware()`
4040
- Rate-limited streams: `middleware.RateLimiterWithConfig(config)`
4141

42+
### Route Namespace Guide
43+
44+
The API uses distinct namespaces. Adding endpoints to the wrong namespace causes route collisions.
45+
46+
| Namespace | Purpose | Registration | Example |
47+
|---|---|---|---|
48+
| `/audio/:id` | Detection audio clips by numeric note ID | `c.Echo.GET(...)` | `ServeAudioByID` |
49+
| `/system/audio/*` | Audio device/source management (protected) | `protectedGroup.Group("/audio")` | `GetAudioDevices`, `ListAudioSources` |
50+
| `/streams/*` | Live streaming, SSE, source listing (public) | `c.Group.GET("/streams/...")` | `StreamAudioLevel`, `ListStreamSources` |
51+
| `/media/*` | Static media files (images, spectrograms) | `c.Group.GET("/media/...")` | `ServeSpectrogram` |
52+
53+
**WARNING:** `GET /api/v2/audio/:id` is registered directly on `c.Echo` (not `c.Group`) and catches ALL paths under `/api/v2/audio/*`. Any non-numeric path like `/api/v2/audio/sources` returns 400. Never add new endpoints under `/api/v2/audio/` unless they use a numeric `:id` parameter.
54+
55+
**Public endpoints that expose source metadata** must anonymize display names for unauthenticated clients using `c.getAnonymizedSourceName()`, matching the behavior of `StreamAudioLevel`.
56+
4257
### Critical Rules
4358

4459
- **Never duplicate existing endpoints** - check README.md first

0 commit comments

Comments
 (0)