Skip to content

docs(repo): add STYLE_GUIDE.md and TESTING.md adapted from Flutter's guides#2793

Open
xsahil03x wants to merge 14 commits into
masterfrom
docs/style-guide
Open

docs(repo): add STYLE_GUIDE.md and TESTING.md adapted from Flutter's guides#2793
xsahil03x wants to merge 14 commits into
masterfrom
docs/style-guide

Conversation

@xsahil03x

@xsahil03x xsahil03x commented Jul 1, 2026

Copy link
Copy Markdown
Member

Summary

  • Adds STYLE_GUIDE.md at the repo root — a canonical style guide adapted from Flutter's repo style guide, reshaped for this SDK.
  • Adds TESTING.md at the repo root — a companion doc on how to write good tests adapted from Flutter's Writing-Effective-Tests. Complements STYLE_GUIDE.md's Testing section, which owns conventions (mocktail, alchemist, self-containment).
  • Wires CLAUDE.md to open with a pointer telling AI agents to read STYLE_GUIDE.md before writing or reviewing code, and links the Chat SDK Design System Figma project directly (both docs).

What's in the style guide

  • Quick rules — a scannable checklist near the top with the hard rules (line width, private-member commenting, changelog policy, initState inherited-lookup ban, named boolean parameters, file_names, directives_ordering, etc.). Every bullet links to its full section.
  • Philosophy — layering, avoiding secret state, error-message quality, and the LLC-must-not-reference-UI rule that keeps stream_chat pure Dart.
  • Repository structure — monorepo layout, Melos-managed dependencies, cross-repo workflow with stream_core_flutter, generated-code policy.
  • Documentation — dartdoc conventions, plus repo-specific rules (public docs describe the contract not the implementation, no Flutter internals in comments, private members use // not ///).
  • Coding patterns — asserts (prefer_asserts_with_message), dispose lifecycle, equality boilerplates, dot shorthands, streams as the primary reactive primitive for real-time data, no InheritedWidget lookup in initState, early-return pattern, extensions on domain-typed collections OK but not on unconstrained types.
  • Testing — self-contained tests, mocktail, alchemist golden tests. Points at TESTING.md for writing-style guidance.
  • Naming, comments, formatting, widgets/state, localization, commits/PRs/changelogs — the usual sections, with rules that match verified repo practice.
  • Theming@themeGen + theme_extensions_builder code generation (never hand-roll copyWith/merge/lerp), Flutter-style defaults in the widget implementation (nullable theme fields, null-coalescing in build), root StreamChatThemeData as the sole ThemeExtension.

What's in TESTING.md

Four principles from Flutter's Writing-Effective-Tests, with Stream-chat-flavored examples:

  1. Name tests based on the behavior being tested, not the object.
  2. One behavior per test.
  3. Only include relevant details — extract setup into named helpers.
  4. Optimize for comprehension — separate "the thing under test" from "the actions on it".

Examples use real API surfaces (StreamChannelListController, Channel.watch, StreamMessageComposer, Message.copyWith, StreamMessageReactionPicker).

Divergences from Flutter's guide

Called out inline in the doc every time; the notable ones:

  • Bare // ignore: directives are the repo style (verified: 38 bare vs 11 with rationale). Flutter's guide requires an explanatory comment; we do not.
  • Private members use //, not /// (verified: 51 // vs 17 ///). Flutter uses /// for "public-quality" private docs.
  • Streams are the primary reactive primitive for real-time data (WebSocket events, channel state, message updates). Flutter's guide recommends Listenable over Stream inside the framework; that reasoning doesn't apply to a real-time SDK.
  • Bare // TODO: matches repo practice (15 of 16), not Flutter's TODO(handle): convention.
  • Line width 120, not 100.

Verified against the repo before merging

  • Changelog labels (✅ Added, 🔄 Changed, ⚠️ Deprecated, 🐛 Fixed, 🔄 Internal / Non-breaking, 🔒 Security) match what packages currently use.
  • Testing section describes mocktail (the library actually in use), not mockito.
  • Theming section describes theme_extensions_builder + @themeGen (bare) for component themes and the @ThemeExtensions(constructor: 'raw', ...) root-only pattern for StreamChatThemeData — verified against stream_chat_theme.dart and message_list_view_theme.dart.
  • Extension-methods section acknowledges legacy StringExtension / IntExtension / SafeCastExtension and prescribes "no new ones on unconstrained common types".
  • Dot-shorthand section retained (217 usages in the repo).
  • Formatting section leads with melos run format (the repo's canonical entrypoint), not raw dart format.
  • TESTING.md examples use APIs that actually exist in the SDK (verified StreamChannelListController, Message.copyWith, StreamMessageReactionPicker, Filter.equal, ConnectionStatus.connected, doInitialLoad, MockStreamChatClient).
  • CodeRabbit review comments addressed (text language tag on ASCII trees, "GitHub" capitalization).

Test plan

  • Skim the "Quick rules" section — every bullet links to its full section below.
  • Read TESTING.md end-to-end — it's short (~190 lines).
  • Verify divergences from Flutter's guide match your read of current repo practice.
  • Confirm the CHANGELOG label set, mocktail, and @themeGen wording match your day-to-day.
  • Suggest anything missing (a rule you rely on that isn't captured, an example that would help).

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Documentation
    • Added a new repo-wide style guide covering coding conventions, architecture boundaries, testing practices, naming/formatting, theming/localization guidance, and PR/release process expectations.
    • Added a testing guide (“Writing effective tests”) with recommendations for behavior-focused test design and readability.
    • Updated repository guidance to reference the new style and testing materials, and corrected the Figma design-system branding text to “Chat SDK Design System.”

Adds a canonical style guide at the repo root, adapted from
https://github.com/flutter/flutter/blob/master/docs/contributing/Style-guide-for-Flutter-repo.md.
Divergences from Flutter's guide (bare `// ignore` directives, `//` for private
members, streams as the primary reactive primitive) are called out inline.

CLAUDE.md now opens with a pointer directing AI agents to read STYLE_GUIDE.md
before writing or reviewing code.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b95747b7-438e-4927-af1d-fecf4abc82ea

📥 Commits

Reviewing files that changed from the base of the PR and between 54d5385 and 4aaf966.

📒 Files selected for processing (1)
  • STYLE_GUIDE.md
✅ Files skipped from review due to trivial changes (1)
  • STYLE_GUIDE.md

📝 Walkthrough

Walkthrough

This PR adds repository-wide guidance in STYLE_GUIDE.md and TESTING.md, and updates CLAUDE.md to point to them and correct the design-system wording.

Changes

Repository documentation guidance

Layer / File(s) Summary
CLAUDE references
CLAUDE.md
CLAUDE.md now directs readers to STYLE_GUIDE.md before code work, links to TESTING.md, and updates the Figma design-system wording.
Style guide overview
STYLE_GUIDE.md
STYLE_GUIDE.md adds the guide’s header, audience, section map, and quick rules checklist.
Policy and repository rules
STYLE_GUIDE.md
STYLE_GUIDE.md adds design principles, layering rules, and repository/licensing policies.
Package and doc conventions
STYLE_GUIDE.md
STYLE_GUIDE.md defines monorepo structure expectations, generated-code handling, and documentation/dartdoc conventions.
Coding and state conventions
STYLE_GUIDE.md
STYLE_GUIDE.md adds conventions for asserts, constructors, enums, typing, equality, lifecycle, streams, and subscription disposal.
Testing, comments, formatting, widgets, and process
STYLE_GUIDE.md
STYLE_GUIDE.md adds testing, naming, comment, formatting, widget, localization, changelog, and PR guidance.
Testing guide
TESTING.md
TESTING.md adds guidance for naming tests, keeping one behavior per test, reducing setup noise, structuring actions clearly, and linking related references.

Estimated code review effort: 3 (Moderate) | ~25 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change by adding the new style and testing guides adapted from Flutter.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch docs/style-guide

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

xsahil03x and others added 2 commits July 1, 2026 13:11
Verified 15 of 16 TODOs in the repo use bare `// TODO:` (no handle); one uses
a category tag `// TODO(perf-migration):`. Flutter's `TODO(github-handle):`
convention is not what this repo does.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…_GUIDE.md

`melos run format` wraps `dart format --set-exit-if-changed .` across every
package with consistent settings; the guide now points contributors at the
melos command they actually run, not the underlying binary.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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 current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@STYLE_GUIDE.md`:
- Around line 186-192: The two fenced ASCII-tree diagrams in STYLE_GUIDE.md are
missing an explicit language tag, causing the markdownlint MD040 warning. Update
both fenced blocks by adding a tag such as text to the opening fence so the docs
remain lint-clean. Use the fenced diagram sections around the package tree
examples as the target for this change.
🪄 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: 960807c8-2f6e-463a-91f4-84c1d3fda668

📥 Commits

Reviewing files that changed from the base of the PR and between 023687f and ac0ae91.

📒 Files selected for processing (2)
  • CLAUDE.md
  • STYLE_GUIDE.md

Comment thread STYLE_GUIDE.md Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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 current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@STYLE_GUIDE.md`:
- Around line 1072-1074: Update the wording in the TODO guidance text to
capitalize “GitHub” so it reads “GitHub handle.” Locate the sentence describing
the optional short tag in the TODO format section and replace the lowercase
platform name while keeping the rest of the guidance unchanged.
🪄 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: d1e63c25-762a-4958-86d9-3479dc539731

📥 Commits

Reviewing files that changed from the base of the PR and between ac0ae91 and 59cdcb7.

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

Comment thread STYLE_GUIDE.md Outdated
xsahil03x and others added 8 commits July 1, 2026 13:23
Themes use theme_extensions_builder to generate copyWith/merge/lerp/equality
from @ThemeExtensions annotations — the guide previously told contributors
to hand-roll these. Also aligns with the repo's Flutter-style pattern of
placing defaults in the widget implementation (nullable theme fields with
null-coalescing resolution in build), not baked into StreamChatThemeData.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…CLAUDE

Both docs referenced the project by name only; now link the file directly
so contributors and agents can click through.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…ction

Verified against packages/stream_chat_flutter/lib/src/theme: component
themes use bare @themeGen and don't extend ThemeExtension; the
@ThemeExtensions(constructor: 'raw', ...) form is exclusive to the root
StreamChatThemeData so it can plug into Material's ThemeData.extensions.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
"Never skip without a linked issue" was overly strict — a skip because a
test is flaky or slow shouldn't need a fabricated issue link. What matters
is the reason being captured; a link is a bonus when there's a tracked
issue. Softened to require a reason, encourage a link when applicable, and
suggest filing an issue if the skip becomes long-lived.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Opening line said "Themes are ThemeExtensions" but the following steps
clarify only the root is. Rephrased to name @themeGen upfront so the
paragraph doesn't contradict the detailed steps beneath it.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…ests

Adds a companion doc at the repo root covering how to write good tests
(behavior-based test names, one behavior per test, extracting irrelevant
setup, optimizing for comprehension). STYLE_GUIDE.md's Testing section now
points to TESTING.md for the deeper guidance; STYLE_GUIDE keeps the
tool/convention rules (mocktail, alchemist, self-containment).

Examples are Stream-chat-flavoured rather than Flutter-widget-flavoured,
and modernised (no `new`, no magic-number expectations that would
contradict STYLE_GUIDE's "avoid magic numbers" rule).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- StreamMessageListController → StreamChannelListController (real class).
- Reworked the state-transition example to use Message.copyWith on text
  (MessageState.sending doesn't exist; actual states are initial/outgoing/
  completed/failed, and state is non-nullable so the `state: null` assert
  was bogus).
- StreamReactionPicker → StreamMessageReactionPicker (actual class name).
- Renamed the "Tapping a message" test to "Long-pressing" to match the
  gesture the example actually performs.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- Add `text` language tag to the two ASCII-tree fenced blocks (layered
  package diagram, monorepo layout tree) so markdownlint MD040 stops
  warning on unlanguaged fences.
- Capitalize "GitHub" in the TODO section's category-tag guidance.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@xsahil03x xsahil03x changed the title docs(repo): add STYLE_GUIDE.md adapted from Flutter's guide docs(repo): add STYLE_GUIDE.md and TESTING.md adapted from Flutter's guides Jul 1, 2026
xsahil03x and others added 2 commits July 1, 2026 14:50
Adds a contextual pointer near the test commands so agents writing tests
hit the writing-effective-tests guidance directly, without needing to
transit through STYLE_GUIDE.md first.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Matches the format the equivalent section in stream-core-flutter's
STYLE_GUIDE.md uses after its recent cleanup — a compact theme-file
skeleton (annotation, mixin, InheritedTheme, of() lookup) plus a
widget-consumption sample showing the null-coalescing default chain.
The previous six-step numbered walkthrough was harder to model against
than a copy-paste-worthy skeleton.

No rule changes, just format.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Comment thread STYLE_GUIDE.md

## A word on designing APIs

Designing an API is an art. Like all forms of art, one learns by practicing. The best

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I find this section a bit weird, I am not sure if it contributes anything (except maybe the last sentence).

Comment thread STYLE_GUIDE.md
```text
stream_chat # Pure Dart, no Flutter dependency
└── stream_chat_persistence # Local disk cache using Drift (optional)
└── stream_chat_flutter_core # Flutter business logic, no UI

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this is not fully correct, stream_chat_flutter_core is not built on top of stream_chat_persistence

Comment thread STYLE_GUIDE.md
mostly do the right thing but don't give the developer any way to adjust the results.
Predictability is reassuring.

### Solve real problems by literally solving a real problem

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not sure if this section is relevant - can we expect direct communication with customers here? (relevant for developers, but not for agents I would say)

Comment thread STYLE_GUIDE.md
would be at the level that most developers interact with. Then, once that API is
cleanly designed, build the lower levels so the higher level can be layered atop.

Concretely: design the `StreamChatFlutter` widget or `Channel` method first, then the

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we have something like StreamChatFlutter? This should probably reference the package stream_chat_flutter

Comment thread STYLE_GUIDE.md

### Copyright and licensing

New source files should carry the standard header used elsewhere in the repo. Third-

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hmm do we have a standard header that we apply to each file?

Comment thread STYLE_GUIDE.md
melos run update:goldens
```

Regenerate goldens deliberately, in a separate commit from behavior changes, so

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we mention here the GitHub action? I am afraid this sentence might be misleading, and the agent will regenerate the Goldens locally

Comment thread STYLE_GUIDE.md
the three).
8. Read-only properties (other than `hashCode`).
9. Operators (other than `==`).
10. Methods (other than `toString` and `build`).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we add some guidelines on how to group the methods? (public vs private, grouped by "feature"...)

Comment thread STYLE_GUIDE.md
`translations_*.dart` file.
3. Reference it via `StreamChatLocalizations.of(context)?.newString ?? 'fallback'` in
the widget.
4. If the fallback isn't the same as the English translation, document why.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we should add a reference to the test that requires updating as well - something I missed on my first localisation update.

Comment thread STYLE_GUIDE.md

- Added `StreamChatClient.searchRoles` for searching channel roles.

🐛 Fixed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Small thing, but I think we should make sure to use the correct icon for the Fixed section: Sometimes we use :caterpillar:, sometimes :ladybug:.

Comment thread TESTING.md

When writing a test, imagine the developer who will read it six months from now.
Anything you can do to help that reader understand what and why the test is checking
is worth doing.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Mentioned it earlier: I think we should add a section about using test groups.

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