Skip to content

feat: add Structured Logging and CQRS standards#6

Merged
don-petry merged 4 commits intomainfrom
feat/logging-and-cqrs-standards
Mar 31, 2026
Merged

feat: add Structured Logging and CQRS standards#6
don-petry merged 4 commits intomainfrom
feat/logging-and-cqrs-standards

Conversation

@don-petry
Copy link
Copy Markdown
Contributor

@don-petry don-petry commented Mar 30, 2026

Summary

  • Adds Structured Logging section to org-wide AGENTS.md with JSON format requirements, canonical field names, correlation/tracing rules, log level guidance, and security-sensitive data exclusions
  • Adds CQRS section covering when to apply, command/query/event naming conventions, separation rules, idempotency requirements, eventual consistency, GraphQL integration mapping, and testing strategies
  • Both sections include numbered Agentic Directives — deterministic rules that AI coding agents can follow without ambiguity

Sections added

Structured Logging (~95 lines)

  • Format & fields (JSON, baseline fields, snake_case, canonical names)
  • Correlation & tracing (request_id, trace_id, span_id propagation)
  • Log levels table with rules for when to use each
  • What to log / what NOT to log checklists
  • 8 agentic directives for deterministic agent behavior
  • Go patterns (slog, context propagation)
  • TypeScript patterns (pino, child loggers)

CQRS (~95 lines)

  • When to apply vs when to skip (simple CRUD)
  • Separation rules (commands don't return data, queries don't mutate)
  • Naming conventions table (imperative commands, past-tense events, Get/List queries)
  • Command patterns (idempotency, one aggregate per transaction, outbox)
  • Query patterns (projections, read-optimized stores)
  • Domain events (fat events, immutability, versioning)
  • GraphQL + CQRS integration (mutations=commands, queries=read models)
  • 8 agentic directives
  • Testing guidance (commands, queries, events, projections, integration)

Test plan

  • Verify AGENTS.md renders correctly on GitHub
  • Confirm no conflicts with repo-level AGENTS.md files in markets, broodly, TalkTerm
  • Review agentic directives for clarity and determinism

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Documentation
    • Added an End-to-End Testing standard mandating full-stack round-trip verification, deterministic waits, realistic selectors/data, and required coverage of error and authorization paths.
    • Introduced a Breaking Changes — Human Approval Required process with detection, stop/describe/identify/alternative/propose/approval protocol.
    • Expanded Structured Logging guidance: JSON logs, baseline fields, snake_case, trace/request correlation, log-level rules, and sensitive-data prohibitions.
    • Added CQRS guidance on command/query separation, naming, idempotency/outbox, eventual consistency, and testing expectations.

Add two new organization-wide sections with agentic-friendly directives:

- Structured Logging: JSON format, canonical fields, correlation/tracing,
  log levels, what to log/not log, Go (slog) and TypeScript (pino) patterns
- CQRS: when to apply, command/query/event naming conventions, separation
  rules, idempotency, eventual consistency, GraphQL integration, testing

Both sections include numbered "Agentic Directives" blocks with deterministic
rules that AI coding agents can follow without ambiguity.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings March 30, 2026 22:53
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR expands the organization-wide AGENTS.md standards by introducing deterministic, agent-followable guidance for Structured Logging and CQRS, aiming to improve observability consistency and architectural correctness across services.

Changes:

  • Adds a structured logging standard (JSON schema, canonical fields, correlation/tracing, level guidance, do/don’t lists, and language-specific patterns).
  • Adds a CQRS standard (when to apply, separation rules, naming conventions, idempotency/outbox/event guidance, GraphQL mapping, and testing strategies).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread AGENTS.md
Comment thread AGENTS.md Outdated
Comment thread AGENTS.md
Comment thread AGENTS.md Outdated
Comment thread AGENTS.md Outdated
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 30, 2026

📝 Walkthrough

Walkthrough

Added organization-wide guidelines to AGENTS.md: End-to-End Testing (prescriptive full-stack E2E requirements and forbidden patterns), Breaking Changes (detection, approval protocol, non-breaking alternatives), Structured Logging (JSON baseline fields, correlation, language examples), and CQRS guidance. Documentation-only changes.

Changes

Cohort / File(s) Summary
Primary doc
AGENTS.md
Inserted four organization-wide guideline sections: End-to-End Testing — Validate Real Functionality (full-stack round-trip verification, multi-layer/data assertions, deterministic polling waits, selector/test-ID rules, Arrange/Act/Assert/Verify/Cleanup structure, forbidden E2E anti-patterns), Breaking Changes — Human Approval Required (definitions of breaking changes across API/DB/frontend/backend/shared contracts, detection rules, stop/describe/list/propose/wait protocol, non-breaking alternatives and agentic directives), Structured Logging (mandatory JSON format, baseline fields like timestamp, service, version, canonical snake_case, correlation fields request_id/OpenTelemetry, log-level rules, ERROR/FATAL fields, prohibitions on sensitive/unstructured logs, Go/Node examples and middleware/context guidance), and CQRS (when to apply CQRS, command/query separation and naming, command/query/event handler patterns, idempotency/outbox requirements, eventual consistency expectations, GraphQL mapping, and CQRS-specific testing guidance).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • Addressing PR comments #1 — Modifies AGENTS.md with organization-wide engineering guidelines (TDD/CI/BMAD content) and is closely related by scope and file.
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main additions to the pull request: two organization-wide standards (Structured Logging and CQRS) added to AGENTS.md. It is concise, clear, and specific enough for teammates to understand the primary change.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/logging-and-cqrs-standards

Comment @coderabbitai help to get the list of available commands and usage tips.

…oke tests

Add comprehensive E2E testing section to org-wide AGENTS.md that enforces
testing real business outcomes through the full stack. Key additions:

- Philosophy: every E2E test must answer "what would break for a real user?"
- Forbidden patterns table: smoke tests disguised as E2E, UI-only assertions,
  mocked backends, status-code-only checks, arbitrary sleeps, happy-path-only
- Required test structure: Arrange → Act → Assert → Verify → Cleanup
- Multi-layer assertions: UI + API response + database state
- GraphQL E2E: mutation→query round trips, auth on every resolver, pagination
- Go backend E2E: testcontainers for real databases, migration testing,
  concurrency/idempotency testing
- Mobile E2E: Detox/Maestro patterns, offline/online, testID selectors
- 12 agentic directives for deterministic agent behavior

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@AGENTS.md`:
- Around line 741-744: Update the "CQRS — Command Query Responsibility
Segregation" section to explicitly distinguish CQRS from event sourcing: add a
brief note under that header stating that CQRS only separates read/write models
and does not mandate how writes are persisted (stateful persistence or event
sourcing are both valid), and that event sourcing is a separate pattern which
records state as a sequence of events and can be used with or without CQRS;
include two concise bullet points reflecting these distinctions so readers of
the "CQRS — Command Query Responsibility Segregation" section won't conflate the
patterns.
- Around line 724-730: Add an explicit example showing how to attach a
request-scoped slog logger to a context in middleware so downstream code can use
slog.InfoContext; implement a LoggingMiddleware (referenced as
LoggingMiddleware) that generates or reads a request ID (requestID /
uuid.New().String()), creates a logger via slog.Default().With("request_id",
requestID), stores it on the request context using context.WithValue and a
loggerKey, and then calls next.ServeHTTP with r.WithContext(ctx) so handlers can
extract the logger and use slog.InfoContext(ctx, ...) or a helper to retrieve
the logger.
- Around line 796-802: The Outbox pattern mention is too brief; expand the
“Outbox pattern” section by adding a short implementation overview describing
writing events to an outbox table in the same DB transaction as the aggregate
update, an async publisher that polls/streams the outbox and publishes events,
and how to mark events as dispatched (idempotency/visibility); include one or
two authoritative references (e.g., Martin Fowler, transactional outbox patterns
or Debezium) and add a small “Language-specific examples” subsection (mirroring
the Structured Logging section) with brief notes for at least two ecosystems
(e.g., Java/Spring and Node.js) and pointers to implementation patterns (DB
transactions, polling workers, or CDC). Ensure you reference the existing terms
“Outbox pattern”, “outbox table”, “transactional outbox”, and “publish from the
outbox asynchronously” so reviewers can locate the new content.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 63f8705a-2dd1-409f-99f3-8093b28191c9

📥 Commits

Reviewing files that changed from the base of the PR and between 4ac0be1 and 2466ece.

📒 Files selected for processing (1)
  • AGENTS.md

Comment thread AGENTS.md
Comment thread AGENTS.md
Comment thread AGENTS.md
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@AGENTS.md`:
- Around line 113-130: The fenced code block in the "Multi-Layer Assertion
Example" is opened without a language tag and without surrounding blank lines,
causing MD031/MD040 lint failures; fix by adding a language tag (e.g., ```ts) to
the opening fence and ensure there is a blank line before the opening ``` and a
blank line after the closing ``` so the block is properly separated from
surrounding text (apply to the triple-backtick fenced block shown in the
example).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 932dfaff-9191-46e5-bb78-5c378bcfc8d7

📥 Commits

Reviewing files that changed from the base of the PR and between 2466ece and d6426a1.

📒 Files selected for processing (1)
  • AGENTS.md

Comment thread AGENTS.md
…contracts

Add "Breaking Changes — Human Approval Required" subsection to Coding
Standards. Technology-agnostic rules covering all layers:

- What constitutes a breaking change (API, database, frontend, backend,
  shared contracts) with concrete examples table
- Tests as the primary detection mechanism — existing tests encode contracts,
  never modify a test to accommodate a breaking change
- Mandatory human approval gate: stop, describe, list impact, propose
  non-breaking alternative, wait for explicit approval
- Non-breaking alternatives in priority order: additive changes, deprecation,
  feature flags, adapters, staged database migrations
- 9 agentic directives (deterministic always/never rules)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

♻️ Duplicate comments (1)
AGENTS.md (1)

114-130: ⚠️ Potential issue | 🟡 Minor

Fix fenced code block markdown compliance.

The code block at line 114 violates MD031 (missing blank lines around fence) and MD040 (missing language identifier).

🔧 Proposed fix
 **Multi-Layer Assertion Example:**
+
-```
+```ts
 // WRONG — only checks UI
 await page.click("#submit-order");
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@AGENTS.md` around lines 114 - 130, The fenced code block must include a
language identifier and have blank lines before and after the triple backticks
to satisfy MD040 and MD031; update the offending fence around the example (the
block containing "await page.click..." / "expect(await page.getText...") to
start with ```ts and ensure there is an empty line above the opening fence and
an empty line below the closing fence so the block is properly separated from
surrounding text.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@AGENTS.md`:
- Around line 114-130: The fenced code block must include a language identifier
and have blank lines before and after the triple backticks to satisfy MD040 and
MD031; update the offending fence around the example (the block containing
"await page.click..." / "expect(await page.getText...") to start with ```ts and
ensure there is an empty line above the opening fence and an empty line below
the closing fence so the block is properly separated from surrounding text.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: d661a923-d433-48ba-85e4-e6d063eebb32

📥 Commits

Reviewing files that changed from the base of the PR and between d6426a1 and afb7032.

📒 Files selected for processing (1)
  • AGENTS.md

…fic refs, address review comments

E2E Testing section:
- Replace "workflow" with "functional requirement" throughout
- Remove all technology-specific references (Playwright, Detox, Maestro,
  testcontainers-go, httptest, errgroup, React Native, GraphQL)
- Generalize subsections: "GraphQL E2E" → "API E2E", "Go Backend E2E" →
  "Backend E2E", "Mobile / React Native E2E" → "Frontend E2E (Web and Mobile)"
- Use generic terms: "frontend", "backend", "database", "test-ID attributes"
- Fix code block: add language identifier (pseudocode) for MD031/MD040

Logging section (addressing Copilot + CodeRabbit review comments):
- Add logger initialization guidance for baseline fields (timestamp, service,
  version) — addresses Copilot comment on line 826
- Add correlation_id, causation_id to canonical field names with explicit
  relationship definitions linking to CQRS — addresses comments on lines 832, 962
- Clarify error_message vs err object serialization — addresses line 853
- Narrow sensitive field name matching from substring "key" to explicit
  suffixes (api_key, private_key, etc.) — addresses line 882

CQRS section:
- Add "CQRS is not Event Sourcing" clarification — addresses CodeRabbit nitpick
- Cross-reference correlation_id/causation_id back to Structured Logging

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@AGENTS.md`:
- Around line 884-885: Harden the sensitive-field detection rule by making the
match case-insensitive and matching across naming styles (snake_case, camelCase,
PascalCase, kebab-case) so names like apiKey, accessToken, authHeader,
refreshToken, cardNumber, api-key, api_key, etc. are caught; update the rule
that currently lists exact or ends-with names (password, secret, token, api_key,
private_key, secret_key, access_key, authorization, cookie, ssn, credit_card,
card_number) to instead check for those tokens as whole-word or substring
matches in a case-insensitive manner and include common camelCase variants and
hyphenated forms, and ensure any detection logic (used when deciding whether to
log a field) omits or redacts the field rather than logging it.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 41d53dd6-56cc-4f35-9476-f5c88eca6e80

📥 Commits

Reviewing files that changed from the base of the PR and between afb7032 and 1b6d9f9.

📒 Files selected for processing (1)
  • AGENTS.md

Comment thread AGENTS.md
Comment on lines +884 to +885
6. NEVER log any variable whose name exactly matches or ends with: `password`, `secret`, `token`, `api_key`, `private_key`, `secret_key`, `access_key`, `authorization`, `cookie`, `ssn`, `credit_card`, `card_number`. When in doubt, omit the field rather than risk leaking sensitive data.
7. When adding retry logic, log each retry at WARN with `attempt_number` and `max_retries`.
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Harden sensitive-field detection beyond snake_case suffixes.

The current “exact or ends with” list is too narrow and can miss common names like apiKey, accessToken, authHeader, or refreshToken, which weakens the no-secrets logging rule.

🔐 Suggested doc patch
-6. NEVER log any variable whose name exactly matches or ends with: `password`, `secret`, `token`, `api_key`, `private_key`, `secret_key`, `access_key`, `authorization`, `cookie`, `ssn`, `credit_card`, `card_number`. When in doubt, omit the field rather than risk leaking sensitive data.
+6. NEVER log any variable whose normalized field name indicates sensitive data.
+   Normalize names to lowercase and treat snake_case/camelCase/PascalCase/kebab-case equivalently.
+   Block fields that exactly match or end with: `password`, `secret`, `token`, `api_key`, `apikey`, `private_key`, `secret_key`, `access_key`, `authorization`, `auth_header`, `cookie`, `ssn`, `credit_card`, `card_number`.
+   When in doubt, omit the field rather than risk leaking sensitive data.

As per coding guidelines "Never commit secrets; use environment variables, GitHub Actions secrets, or external secret managers instead".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@AGENTS.md` around lines 884 - 885, Harden the sensitive-field detection rule
by making the match case-insensitive and matching across naming styles
(snake_case, camelCase, PascalCase, kebab-case) so names like apiKey,
accessToken, authHeader, refreshToken, cardNumber, api-key, api_key, etc. are
caught; update the rule that currently lists exact or ends-with names (password,
secret, token, api_key, private_key, secret_key, access_key, authorization,
cookie, ssn, credit_card, card_number) to instead check for those tokens as
whole-word or substring matches in a case-insensitive manner and include common
camelCase variants and hyphenated forms, and ensure any detection logic (used
when deciding whether to log a field) omits or redacts the field rather than
logging it.

@don-petry don-petry merged commit 28e485d into main Mar 31, 2026
3 checks passed
@don-petry don-petry deleted the feat/logging-and-cqrs-standards branch March 31, 2026 01:42
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.

2 participants