Skip to content

Commit 291c75c

Browse files
committed
Create agents file for the feeds repo
1 parent d08e4e9 commit 291c75c

File tree

1 file changed

+317
-0
lines changed

1 file changed

+317
-0
lines changed

AGENTS.md

Lines changed: 317 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,317 @@
1+
# AGENTS.md
2+
3+
This file provides essential context for AI agents and developers working on the Stream Feeds Flutter/Dart SDK.
4+
5+
## Project Overview
6+
7+
This is the **official Flutter/Dart SDK** for Stream Feeds API v3, a scalable activity feed service. The repository contains:
8+
9+
- **Low-level SDK** (`packages/stream_feeds/`): Pure Dart SDK for Stream Feeds API v3
10+
- **Sample App** (`sample_app/`): Flutter demo application showcasing SDK usage
11+
- **Documentation** (`docs/`): Code snippets and examples
12+
13+
**Important**: Activity Feeds V3 is currently in closed alpha - not recommended for production use yet.
14+
15+
## Repository Structure
16+
17+
```
18+
stream-feeds-flutter/
19+
├── packages/
20+
│ └── stream_feeds/ # Main SDK package
21+
│ ├── lib/
22+
│ │ ├── stream_feeds.dart # Public API entry point
23+
│ │ └── src/
24+
│ │ ├── client/ # Client implementation
25+
│ │ ├── cdn/ # CDN API client
26+
│ │ ├── generated/ # OpenAPI-generated API code
27+
│ │ ├── models/ # Domain models (@freezed)
28+
│ │ ├── repository/ # Data access layer
29+
│ │ ├── resolvers/ # Feature resolvers
30+
│ │ ├── state/ # State objects and handlers
31+
│ │ ├── utils/ # Utility classes (filter, sort, batcher, uploader)
32+
│ │ └── ws/ # WebSocket event handling
33+
│ └── test/ # Test suite
34+
├── sample_app/ # Flutter demo app
35+
├── docs/ # Documentation and examples
36+
└── scripts/ # Build and generation scripts
37+
```
38+
39+
## Architecture Principles
40+
41+
### Core Design Patterns
42+
43+
1. **Pure Dart**: The low-level SDK (stream_feeds) is pure Dart and has no platform-specific dependencies. It can be used outside of Flutter.
44+
2. **Layered Architecture**: Clear separation between client, core, data, presentation, and state layers
45+
3. **Immutable Data**: All models use `@freezed` with const constructors
46+
4. **Reactive State**: StateNotifier-based state management with automatic change notifications
47+
5. **Result Pattern**: Explicit error handling using Result types (not exceptions)
48+
6. **Public API Focus**: Clean separation between public API (`lib/`) and internal implementation (`lib/src/`)
49+
50+
### Layer Responsibilities
51+
52+
- **Client Layer** (`src/client/`): Client factory and implementation
53+
- **Models** (`src/models/`): Domain models, queries, and business logic (all `@freezed` data classes)
54+
- **Repository Layer** (`src/repository/`): Data access layer with Result pattern
55+
- **State Management** (`src/state/`): StateNotifier implementations and high-level state objects (Feed, ActivityList, etc.)
56+
- **Utilities** (`src/utils/`): Helper classes for filtering, sorting, batching, and file uploads
57+
- **WebSocket** (`src/ws/`): Real-time event handling and WebSocket connections
58+
- **CDN** (`src/cdn/`): CDN API client for file uploads
59+
- **Generated** (`src/generated/`): OpenAPI-generated API client code
60+
61+
## Code Generation
62+
63+
The project uses extensive code generation:
64+
65+
### Generated Code
66+
67+
1. **OpenAPI Client** (`src/generated/api/`): Auto-generated from OpenAPI spec
68+
- Generated via `scripts/generate.sh`
69+
- Includes API models, endpoints, and serialization
70+
71+
2. **Freezed Models** (`*.freezed.dart`): Immutable data classes
72+
- Run: `melos run generate:all`
73+
- Uses `freezed` and `json_serializable`
74+
75+
3. **Retrofit** (`*.g.dart`): HTTP client generation
76+
- Uses `retrofit_generator` for API client methods
77+
78+
### Running Code Generation
79+
80+
```bash
81+
# Generate all (Dart + Flutter packages)
82+
melos run generate:all
83+
84+
# Generate only Dart packages
85+
melos run generate:dart
86+
87+
# Generate only Flutter packages
88+
melos run generate:flutter
89+
90+
# Generate OpenAPI client (requires OpenAPI spec)
91+
melos run gen:feeds
92+
```
93+
94+
**Important**: Never manually edit generated files. All changes must be made in source files or OpenAPI specs.
95+
96+
## Coding Standards
97+
98+
### Data Models
99+
100+
- Use `@freezed` for all data classes
101+
- Follow Freezed 3.0 mixed mode syntax with `@override` annotations
102+
- All models should have an `id` field when representing entities
103+
- Place custom data fields last in constructors and class definitions
104+
105+
Example:
106+
```dart
107+
@freezed
108+
class ActivityData with _$ActivityData {
109+
const ActivityData({
110+
required this.id,
111+
required this.user,
112+
this.custom,
113+
});
114+
115+
@override
116+
final String id;
117+
@override
118+
final UserData user;
119+
@override
120+
final Map<String, Object>? custom;
121+
}
122+
```
123+
124+
### State Management
125+
126+
- Use StateNotifier for reactive state management
127+
- State classes must use `@freezed` with const constructors
128+
- High-level state objects (Feed, ActivityList) are the public API
129+
- StateNotifier implementations are internal details
130+
131+
### Repository Pattern
132+
133+
- All repository methods return `Result<T>` types
134+
- Use early return patterns for validation and errors
135+
- Use extension functions for API-to-domain model mapping
136+
- Never throw exceptions - always return Result types
137+
138+
Example:
139+
```dart
140+
Future<Result<ActivityData>> getActivity(String id) async {
141+
try {
142+
final result = await apiClient.getActivity(id: id);
143+
if (result == null) {
144+
return Result.failure(NetworkException('No data returned'));
145+
}
146+
return Result.success(result.toModel());
147+
} on ClientException catch (e) {
148+
return Result.failure(_mapClientException(e));
149+
}
150+
}
151+
```
152+
153+
### Documentation
154+
155+
- Use `///` for public API documentation
156+
- Use `//` for internal/private code
157+
- Follow Effective Dart documentation guidelines
158+
- Include examples for complex APIs
159+
160+
## Testing Strategy
161+
162+
### Test Structure
163+
164+
- Tests mirror the `lib/` structure in `test/`
165+
- Focus on testing through public APIs only
166+
- Use HTTP interceptors instead of mocking repositories
167+
- Test StateNotifier behavior through high-level state objects
168+
169+
### Running Tests
170+
171+
```bash
172+
# Run all tests
173+
melos run test:all
174+
175+
# Run Dart tests only
176+
melos run test:dart
177+
178+
# Run Flutter tests only
179+
melos run test:flutter
180+
```
181+
182+
## Dependencies & Monorepo
183+
184+
### Melos Workspace
185+
186+
This is a **Melos monorepo** for managing multiple packages:
187+
188+
- All dependencies are defined in `melos.yaml`
189+
- **Never** edit `pubspec.yaml` environment or dependency versions directly
190+
- Use `melos bootstrap` to sync dependencies after changes
191+
192+
### Adding Dependencies
193+
194+
1. Add dependency to `packages/stream_feeds/pubspec.yaml`
195+
2. Add it to `melos.yaml` dependencies list
196+
3. Run `melos bootstrap` to sync
197+
198+
### Key Dependencies
199+
200+
- **state_notifier**: Reactive state management
201+
- **freezed**: Immutable data classes
202+
- **dio**: HTTP client
203+
- **retrofit**: Type-safe HTTP client
204+
- **stream_core**: Core HTTP/WSS infrastructure
205+
206+
See `melos.yaml` for complete dependency list.
207+
208+
## Development Workflow
209+
210+
### Code Quality
211+
212+
```bash
213+
# Format code
214+
melos run format
215+
216+
# Verify formatting
217+
melos run format:verify
218+
219+
# Run static analysis
220+
melos run analyze
221+
222+
# Run linting + formatting
223+
melos run lint:all
224+
```
225+
226+
### Common Tasks
227+
228+
1. **Making Changes to Models**:
229+
- Edit the `.dart` model file
230+
- Run `melos run generate:all`
231+
- Commit both source and generated files
232+
233+
2. **Updating OpenAPI Client**:
234+
- Update OpenAPI spec (if you have access)
235+
- Run `melos run gen:feeds`
236+
- Review generated changes in `src/generated/`
237+
238+
3. **Adding New Features**:
239+
- Create models in `src/models/`
240+
- Add repositories in `src/repository/`
241+
- Create state objects in `src/state/`
242+
- Export in `lib/stream_feeds.dart` if public API
243+
244+
## File Organization Rules
245+
246+
### Public vs Internal
247+
248+
- **Public API**: Files in `lib/` root
249+
- **Internal**: Everything in `lib/src/`
250+
251+
### Naming Conventions
252+
253+
- Models: `*Data` (e.g., `ActivityData`, `FeedData`)
254+
- Queries: `*Query` (e.g., `ActivitiesQuery`, `FeedsQuery`)
255+
- Requests: `*Request` (e.g., `FeedAddActivityRequest`)
256+
- State: `*State` (e.g., `FeedState`, `ActivityListState`)
257+
- StateNotifier: `*StateNotifier` (e.g., `FeedStateNotifier`)
258+
259+
## Important Files
260+
261+
- `.cursorrules`: Primary development rules for AI assistants
262+
- `.cursor/rules/`: Supplementary documentation for specific patterns
263+
- `analysis_options.yaml`: Dart analyzer configuration
264+
- `melos.yaml`: Monorepo configuration and dependencies
265+
- `scripts/generate.sh`: OpenAPI client generation script
266+
267+
## WebSocket & Real-time
268+
269+
- Real-time updates via WebSocket connections
270+
- Event handlers in `src/ws/events/`
271+
- Events use `@freezed` for type-safe event handling
272+
- State objects automatically update from WebSocket events
273+
274+
## Versioning
275+
276+
- SDK uses semantic versioning
277+
- Version managed in `packages/stream_feeds/pubspec.yaml`
278+
- Versioning mode: independent (per-package)
279+
280+
## Getting Help
281+
282+
- **Documentation**: Check `docs/` for code examples
283+
- **API Docs**: https://getstream.io/activity-feeds/docs/flutter/
284+
- **Cursor Rules**: See `.cursorrules` and `.cursor/rules/` for detailed patterns
285+
286+
## Quick Reference
287+
288+
```bash
289+
# Setup
290+
melos bootstrap
291+
292+
# Generate code
293+
melos run generate:all
294+
295+
# Test
296+
melos run test:all
297+
298+
# Format & lint
299+
melos run lint:all
300+
301+
# Clean
302+
melos run clean:flutter
303+
```
304+
305+
## Important Notes for AI Agents
306+
307+
1. **Always run code generation** after modifying `@freezed` models or OpenAPI specs
308+
2. **Never edit generated files** (`*.freezed.dart`, `*.g.dart`, `src/generated/`)
309+
3. **Use Result pattern** for error handling, not exceptions
310+
4. **Test through public APIs** only, not internal StateNotifier implementations
311+
5. **Follow Freezed 3.0 syntax** with `@override` annotations for fields
312+
6. **Keep public API minimal** - most code should be in `lib/src/`
313+
7. **Use early returns** for validation and error cases
314+
8. **Document public APIs** with `///` following Effective Dart guidelines
315+
9. **Sync dependencies** via `melos bootstrap` after changes
316+
10. **Check `.cursorrules`** for detailed implementation patterns
317+

0 commit comments

Comments
 (0)