Skip to content

Commit 0309cfe

Browse files
authored
Pr epic issue 58 (#71)
This pull request introduces a comprehensive Claude Code configuration for the PetSphere Flutter project, adding project-specific automation, code review, and code generation skills. It establishes a robust developer workflow with automated formatting, protected file permissions, and specialized tools for scaffolding features, components, and tests. The most important changes are summarized below: **Project Automation & Configuration** - Added `.claude/settings.json` to configure automatic Dart formatting and linting hooks after file edits, define protected files to prevent accidental changes, and register MCP servers for Supabase database access and real-time Flutter/Dart documentation lookup. - Updated `.claude/settings.local.json` to expand allowed permissions for local development, including running tests, managing git, and interacting with Supabase MCP plugins. **Developer Skills & Scaffolding Tools** - Introduced `/flutter-new-component` skill to scaffold new Flutter components following PetSphere conventions, with options for stateless, stateful, and Riverpod consumer widgets. - Added `/migration-helper` skill to generate a complete feature layer (model, repository, controller) for new database-backed features, supporting options for images, timestamps, and user relationships. - Added `/test-writer` skill to generate unit tests for controllers, repositories, and utilities, following arrange-act-assert and Riverpod testing patterns. **Code Review Automation** - Added a dedicated code review agent (`@code-reviewer`) with a detailed checklist for Riverpod patterns, architecture compliance, null safety, repository pattern, error handling, and test readiness. Includes CI/CD integration instructions. **Documentation & Workflow** - Created a comprehensive `.claude/README.md` documenting all automation, skills, agents, hooks, workflow recommendations, troubleshooting, and file organization for the PetSphere project. These changes collectively establish a modern, automated, and best-practice-driven workflow for PetSphere Flutter development. - Project Automation & Configuration: [[1]](diffhunk://#diff-f27ac6f39d89fe021c56900069198aa7d9968f2cd6645c00b11ffd1b78fcf546R1-R39) [[2]](diffhunk://#diff-fca16cae5b0e32edfa6b55eaa32a98ffbf4a0c7d885fb585785fc83b6ea2d9c3L5-R13) - Developer Skills & Scaffolding Tools: [[1]](diffhunk://#diff-3db7031ba726f9cc965844d9a34aac9a7424da573eb5922354fd45854b4bcc82R1-R106) [[2]](diffhunk://#diff-b2249c820f00fa250296bb8416bb4001269a735d64749aeb7b8d20877c1a0cceR1-R139) [[3]](diffhunk://#diff-48e9bd17374ab37882496bebaeffd1bde6c8367789eaaf0f82b1f981181ccbacR1-R99) - Code Review Automation: [.claude/agents/code-reviewer.mdR1-R126](diffhunk://#diff-c0a2150c92b282c9817c6c5f7ebaec0c020d45e9aeedff28f8c49e21c09cafebR1-R126) - Documentation & Workflow: [.claude/README.mdR1-R258](diffhunk://#diff-2299e67d57e898bc0991b42cf6a33a56497600bfbc83191d4a1438c6d5aa13b4R1-R258)
2 parents de21588 + 49c4c56 commit 0309cfe

114 files changed

Lines changed: 13852 additions & 1873 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.claude/README.md

Lines changed: 258 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,258 @@
1+
# Claude Code Configuration for PetSphere
2+
3+
This directory contains tailored automation, skills, and settings for PetSphere Flutter development.
4+
5+
## 📋 Contents
6+
7+
### Configuration
8+
- **`settings.json`** — Project-wide settings including hooks, permissions, and MCP server configuration
9+
10+
### Skills (User-Invocable)
11+
12+
#### 1. `/flutter-new-component`
13+
Scaffold new reusable Flutter components following PetSphere patterns.
14+
15+
```bash
16+
/flutter-new-component PetCard "Displays a pet profile card"
17+
/flutter-new-component HealthMetricGraph "Shows health trend chart" --stateful
18+
/flutter-new-component CareBadgeList "Lists earned care badges" --consumer
19+
```
20+
21+
**Output**: Creates `lib/views/components/{component_name}.dart` with proper typing, theming, and patterns.
22+
23+
---
24+
25+
#### 2. `/test-writer`
26+
Generate unit tests for Notifiers, repositories, and utilities following arrange-act-assert pattern.
27+
28+
```bash
29+
/test-writer lib/controllers/pet_controller.dart
30+
/test-writer lib/repositories/health_repository.dart --coverage
31+
```
32+
33+
**Output**: Creates test files in `test/` mirroring `lib/` structure with mocks and test cases.
34+
35+
---
36+
37+
#### 3. `/migration-helper`
38+
Scaffold complete feature layers (model + repository + controller) in one command.
39+
40+
```bash
41+
/migration-helper PetNutrition "Track pet nutrition and dietary info" --table-name=pet_nutrition
42+
/migration-helper ActivityLog "Log pet daily activities" --table-name=activity_logs
43+
```
44+
45+
**Output**:
46+
- `lib/models/{feature_name}_model.dart`
47+
- `lib/repositories/{feature_name}_repository.dart`
48+
- `lib/controllers/{feature_name}_controller.dart`
49+
50+
All three files follow PetSphere architecture patterns and are production-ready.
51+
52+
---
53+
54+
### Agents (Specialized Reviewers)
55+
56+
#### Code Reviewer (`@code-reviewer`)
57+
Comprehensive code review agent focused on Riverpod patterns, architecture compliance, and Dart best practices.
58+
59+
```bash
60+
# Review current branch
61+
claude @code-reviewer "Review this branch for Riverpod patterns and null safety"
62+
63+
# Review specific files
64+
claude @code-reviewer "Review lib/controllers/ for state management"
65+
66+
# Pre-PR review
67+
claude @code-reviewer "Code review before merge"
68+
```
69+
70+
**Checks**:
71+
- Architecture layer compliance
72+
- Riverpod patterns (Notifier, State, providers)
73+
- Null safety and type safety
74+
- Model immutability
75+
- Repository pattern compliance
76+
- Code quality and style
77+
- Error handling
78+
- Testing readiness
79+
80+
---
81+
82+
## ⚡ Hooks (Automatic)
83+
84+
The following hooks run automatically on file edits:
85+
86+
### Auto-Format & Lint
87+
Runs `dart format` and `flutter analyze` after each edit.
88+
- Keeps code style consistent
89+
- Catches linting issues early
90+
- Runs automatically, no user action needed
91+
92+
### Protected Files
93+
Prevents accidental edits to sensitive files:
94+
- `pubspec.lock` (version lock file)
95+
- `.env*` (secrets and config)
96+
- `lib/utils/supabase_config.dart` (credentials)
97+
- `android/local.properties`, `ios/local.properties`
98+
99+
---
100+
101+
## 🔌 MCP Servers (Recommended)
102+
103+
Two MCP servers are configured in `settings.json` for enhanced capabilities:
104+
105+
### 1. **Supabase MCP**
106+
Direct access to your PostgreSQL database.
107+
108+
**Usage**:
109+
- Inspect table schemas
110+
- Debug RLS policies
111+
- Test SQL queries
112+
- Monitor migration status
113+
114+
---
115+
116+
### 2. **context7 MCP**
117+
Real-time documentation lookup for Flutter/Dart/Riverpod.
118+
119+
**Usage**:
120+
- Look up Flutter API docs while coding
121+
- Check Riverpod pattern documentation
122+
- Search Dart language features
123+
- Find Material Design guidelines
124+
125+
---
126+
127+
## 🚀 Quick Start
128+
129+
### 1. Enable Hooks
130+
Hooks are configured in `settings.json` and should activate automatically. Test with:
131+
```bash
132+
# Edit any Dart file and verify `dart format` runs
133+
echo "void main(){}" > lib/test.dart
134+
# Should be auto-formatted to proper style
135+
```
136+
137+
### 2. Try a Skill
138+
Generate your first component:
139+
```bash
140+
/flutter-new-component TestCard "A test component"
141+
```
142+
143+
Look for the created file in `lib/views/components/test_card.dart`.
144+
145+
### 3. Run a Full Feature Migration
146+
Create a complete feature layer:
147+
```bash
148+
/migration-helper TestFeature "A test feature" --table-name=test_features
149+
```
150+
151+
Check created files:
152+
- `lib/models/test_feature_model.dart`
153+
- `lib/repositories/test_feature_repository.dart`
154+
- `lib/controllers/test_feature_controller.dart`
155+
156+
### 4. Code Review Before Merge
157+
Before pushing to GitHub:
158+
```bash
159+
claude @code-reviewer "Review my feature branch for architecture compliance"
160+
```
161+
162+
---
163+
164+
## 📚 Recommended Workflow
165+
166+
### When Adding a New Feature
167+
168+
1. **Scaffold with `/migration-helper`**
169+
```bash
170+
/migration-helper PetNutrition "Track nutrition" --table-name=pet_nutrition
171+
```
172+
173+
2. **Generate Tests with `/test-writer`**
174+
```bash
175+
/test-writer lib/controllers/pet_nutrition_controller.dart
176+
```
177+
178+
3. **Create UI Components with `/flutter-new-component`**
179+
```bash
180+
/flutter-new-component NutritionCard "Shows nutrition info"
181+
/flutter-new-component NutritionForm "Edit nutrition record" --stateful
182+
```
183+
184+
4. **Review Before Merge**
185+
```bash
186+
claude @code-reviewer "Code review for nutrition feature"
187+
```
188+
189+
5. **Hooks run automatically** — no manual linting needed
190+
191+
---
192+
193+
## 🔧 Customizing
194+
195+
### Add More Hooks
196+
Edit `settings.json` hooks section to add auto-format for other languages or add validation checks.
197+
198+
Example: Auto-run tests on Dart file edits:
199+
```json
200+
{
201+
"trigger": "PostToolUse",
202+
"tool": "Edit",
203+
"command": "flutter test --help"
204+
}
205+
```
206+
207+
### Modify Protected Files
208+
Edit the `preToolUse` section to add/remove protected paths.
209+
210+
---
211+
212+
## 📖 File Organization
213+
214+
```
215+
.claude/
216+
├── settings.json # Project-wide config
217+
├── README.md # This file
218+
├── skills/
219+
│ ├── flutter-new-component/SKILL.md
220+
│ ├── test-writer/SKILL.md
221+
│ └── migration-helper/SKILL.md
222+
└── agents/
223+
└── code-reviewer.md
224+
```
225+
226+
---
227+
228+
## 🆘 Troubleshooting
229+
230+
### Hooks Not Running
231+
- Verify `settings.json` is valid JSON (no trailing commas)
232+
- Check file paths are correct relative to project root
233+
- Reload Claude Code: File → Reload
234+
235+
### Skills Not Appearing
236+
- Ensure `SKILL.md` files are in `.claude/skills/{name}/SKILL.md`
237+
- Reload Claude Code
238+
- Check skill name in frontmatter matches directory name
239+
240+
### Code Review Agent Issues
241+
- Ensure sufficient tokens available (large reviews may timeout)
242+
- Split very large PRs into multiple reviews
243+
- Check git repo is initialized (agent needs git context)
244+
245+
---
246+
247+
## 📝 Notes
248+
249+
- Skills can be customized further by editing their `.md` files
250+
- All generated code is production-ready; update with your custom logic
251+
- Tests generated have TODO comments for custom assertions
252+
- Settings are project-specific; team members should use same `.claude/` directory
253+
254+
---
255+
256+
**Last Updated**: 2026-05-05
257+
**Version**: 1.0
258+
**Maintained by**: Claude Code Automation System

.claude/agents/code-reviewer.md

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
# Code Reviewer Agent for PetSphere
2+
3+
Specialized code review agent for PetSphere Flutter codebase, focusing on Riverpod patterns, architecture compliance, and Dart best practices.
4+
5+
## Trigger
6+
7+
Invoke this agent when you need a comprehensive code review before merging:
8+
9+
```bash
10+
# Review current branch for architecture compliance
11+
claude @code-reviewer "Review this branch for Riverpod patterns and null safety"
12+
13+
# Review specific files
14+
claude @code-reviewer "Review lib/controllers/pet_controller.dart for state management"
15+
16+
# Review PR diff
17+
claude @code-reviewer "Code review: ensure immutability and error handling in lib/repositories/"
18+
```
19+
20+
## Review Checklist
21+
22+
The agent verifies:
23+
24+
### Architecture & Patterns ✅
25+
- [ ] Feature uses the correct layer (model → repo → controller → view)
26+
- [ ] Notifier extends `Notifier<State>`, not `StateNotifier`
27+
- [ ] State is immutable with `copyWith()` implementation
28+
- [ ] All data access flows through repositories
29+
- [ ] Controllers don't bypass repositories
30+
- [ ] Views use `ConsumerWidget` or `ConsumerStatefulWidget` where needed
31+
32+
### Riverpod & State Management ✅
33+
- [ ] Providers are declared at file end
34+
- [ ] `NotifierProvider` used for mutable state
35+
- [ ] `StateProvider` used for simple scalars
36+
- [ ] `FutureProvider` used only for single-value async (not long-running)
37+
- [ ] `ref.watch()` for UI state subscription
38+
- [ ] `ref.read()` for triggering actions
39+
- [ ] Proper error handling in notifier methods
40+
- [ ] Loading states set before/after async operations
41+
42+
### Null Safety & Type Safety ✅
43+
- [ ] No `!` operator without justified non-null guarantees
44+
- [ ] Use `?.` for safe optional access
45+
- [ ] Optional parameters use `?` type annotations
46+
- [ ] `late` used sparingly with clear initialization
47+
- [ ] All types are explicit (no untyped `var` or `dynamic`)
48+
49+
### Model & Data Integrity ✅
50+
- [ ] Models are immutable (all fields `final`)
51+
- [ ] `fromJson()` parses snake_case from Supabase correctly
52+
- [ ] `toJson()` converts back to snake_case for Supabase
53+
- [ ] `copyWith()` creates new instances (not mutating)
54+
- [ ] Enum handling is type-safe
55+
56+
### Repository Pattern ✅
57+
- [ ] Async operations return typed futures (not `dynamic`)
58+
- [ ] Error handling: exceptions propagate (not swallowed)
59+
- [ ] Supabase queries use `.select()` with explicit columns
60+
- [ ] RLS policies are considered in query design
61+
- [ ] Image uploads specify bucket path correctly
62+
63+
### Code Quality ✅
64+
- [ ] Methods under 20 lines (extract complex logic)
65+
- [ ] No magic numbers (use named constants)
66+
- [ ] Imports organized: dart, package, relative
67+
- [ ] Snake_case for files, PascalCase for classes, camelCase for variables
68+
- [ ] No `print()` (use `developer.log()` instead)
69+
- [ ] Comments explain "why" not "what"
70+
- [ ] No TODO comments in production code (document issues in Linear/GitHub)
71+
72+
### Error Handling ✅
73+
- [ ] Try-catch at repository/controller layers
74+
- [ ] Errors propagate to UI (state.error field)
75+
- [ ] User-friendly error messages (no stack traces in UI)
76+
- [ ] Network errors distinguished from validation errors
77+
78+
### Testing Readiness ✅
79+
- [ ] Methods are testable (dependencies injectable or via Riverpod)
80+
- [ ] State classes have test-friendly constructors
81+
- [ ] No hardcoded dependencies or singletons (except repositories)
82+
- [ ] No untestable async code in build methods
83+
84+
## Output
85+
86+
The agent provides:
87+
88+
1. **Pass/Fail Summary** — Architecture compliance status
89+
2. **Issues Found** — Specific violations with line numbers
90+
3. **Suggestions** — Refactoring recommendations
91+
4. **Examples** — Corrected code snippets for violations
92+
5. **Approval** — Merged/approved status with caveats
93+
94+
## Integration with CI/CD
95+
96+
For automated pre-merge reviews, use in GitHub Actions:
97+
98+
```yaml
99+
# .github/workflows/code-review.yml
100+
name: PetSphere Code Review
101+
102+
on: [pull_request]
103+
104+
jobs:
105+
review:
106+
runs-on: ubuntu-latest
107+
steps:
108+
- uses: actions/checkout@v3
109+
- name: Claude Code Review
110+
run: |
111+
claude @code-reviewer "Review PR changes for architecture and patterns"
112+
```
113+
114+
## Known Issues & Edge Cases
115+
116+
- **Large PRs**: Reviews top 20 files; request split reviews for >50 files
117+
- **Generated Code**: Skips code generation artifacts (normally)
118+
- **External Packages**: Doesn't review vendored code
119+
- **Monorepos**: Specify path for review scope
120+
121+
## Tips
122+
123+
- Run before opening a PR for faster feedback
124+
- Use for onboarding new team members (learn patterns)
125+
- Run monthly on main to catch drift
126+
- Pair with `/test-writer` skill for comprehensive coverage

0 commit comments

Comments
 (0)