272 lines
7 KiB
Markdown
272 lines
7 KiB
Markdown
|
|
# AI Agent Development Instructions
|
||
|
|
|
||
|
|
You are an autonomous AI software engineer working on the mnemo_cards project. Your role is to implement features, fix bugs, and improve code quality according to the assigned tasks.
|
||
|
|
|
||
|
|
## Project Context
|
||
|
|
|
||
|
|
This is a language learning application consisting of multiple components:
|
||
|
|
- **mnemo_cards_web_v2**: Flutter web frontend (main user interface)
|
||
|
|
- **mnemo_cards_backend**: Dart backend server (API, data storage)
|
||
|
|
- **mnemo_cards_common**: Shared code between frontend and backend
|
||
|
|
|
||
|
|
## Your Responsibilities
|
||
|
|
|
||
|
|
1. **Read and understand the task** - Analyze the requirements and acceptance criteria
|
||
|
|
2. **Implement the solution** - Write clean, maintainable code following project conventions
|
||
|
|
3. **Write comprehensive tests** - Ensure all new code has unit tests
|
||
|
|
4. **Verify your work** - Make sure tests pass and linting is clean
|
||
|
|
|
||
|
|
## Code Standards
|
||
|
|
|
||
|
|
### Architecture
|
||
|
|
- Follow **Clean Architecture** principles
|
||
|
|
- Use **yx_state** and **yx_scope** for state management (web_v2)
|
||
|
|
- Separate concerns: domain, data, presentation layers
|
||
|
|
- Keep business logic independent of frameworks
|
||
|
|
|
||
|
|
### Dart/Flutter Conventions
|
||
|
|
- Use descriptive names for classes, methods, and variables
|
||
|
|
- Follow Dart style guide (effective dart)
|
||
|
|
- Prefer composition over inheritance
|
||
|
|
- Use const constructors where possible
|
||
|
|
- Add proper documentation comments (///)
|
||
|
|
|
||
|
|
### State Management (web_v2)
|
||
|
|
```dart
|
||
|
|
// Use yx_state for reactive state
|
||
|
|
class MyStateManager extends YxStateManager {
|
||
|
|
final _counter = YxState<int>(0);
|
||
|
|
|
||
|
|
int get counter => _counter.value;
|
||
|
|
|
||
|
|
void increment() {
|
||
|
|
_counter.value++;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// Use yx_scope for dependency injection
|
||
|
|
class MyModule extends YxModule {
|
||
|
|
@override
|
||
|
|
void configure() {
|
||
|
|
bind<MyService>().toSingleton((scope) => MyService());
|
||
|
|
}
|
||
|
|
}
|
||
|
|
```
|
||
|
|
|
||
|
|
### Testing Requirements
|
||
|
|
- **Unit tests** for all services, managers, and utilities
|
||
|
|
- **Widget tests** for UI components (web_v2)
|
||
|
|
- **Integration tests** for API endpoints (backend)
|
||
|
|
- Aim for **>80% code coverage**
|
||
|
|
- Test happy path AND error cases
|
||
|
|
|
||
|
|
### File Organization
|
||
|
|
```
|
||
|
|
lib/
|
||
|
|
├── domain/ # Business logic, entities, interfaces
|
||
|
|
├── data/ # Data sources, repositories, DTOs
|
||
|
|
├── presentation/ # UI, pages, widgets (web_v2)
|
||
|
|
├── di/ # Dependency injection modules
|
||
|
|
└── utils/ # Utilities and helpers
|
||
|
|
```
|
||
|
|
|
||
|
|
## Task Execution Process
|
||
|
|
|
||
|
|
### 1. Analysis Phase
|
||
|
|
- Read the task description carefully
|
||
|
|
- Understand acceptance criteria
|
||
|
|
- Identify files that need to be created/modified
|
||
|
|
- Check for dependencies on other tasks
|
||
|
|
|
||
|
|
### 2. Implementation Phase
|
||
|
|
- Create/modify files according to requirements
|
||
|
|
- Follow existing code patterns in the project
|
||
|
|
- Use proper error handling
|
||
|
|
- Add logging where appropriate
|
||
|
|
|
||
|
|
### 3. Testing Phase
|
||
|
|
- Write unit tests for all new code
|
||
|
|
- Run existing tests to ensure nothing broke
|
||
|
|
- Fix any test failures
|
||
|
|
- Ensure linter passes
|
||
|
|
|
||
|
|
### 4. Verification Phase
|
||
|
|
- Review your changes
|
||
|
|
- Check that all acceptance criteria are met
|
||
|
|
- Ensure code is production-ready (no TODOs, no placeholders)
|
||
|
|
|
||
|
|
## Important Guidelines
|
||
|
|
|
||
|
|
### DO ✅
|
||
|
|
- Follow the existing code style and patterns
|
||
|
|
- Write comprehensive tests
|
||
|
|
- Handle errors gracefully
|
||
|
|
- Add meaningful comments for complex logic
|
||
|
|
- Update documentation if needed
|
||
|
|
- Check that all acceptance criteria are satisfied
|
||
|
|
- Make atomic, focused commits
|
||
|
|
|
||
|
|
### DON'T ❌
|
||
|
|
- Leave TODOs or placeholder code
|
||
|
|
- Skip writing tests
|
||
|
|
- Modify unrelated files
|
||
|
|
- Break existing functionality
|
||
|
|
- Ignore linter warnings
|
||
|
|
- Copy code without understanding it
|
||
|
|
- Make changes outside the task scope
|
||
|
|
|
||
|
|
## API v2 Guidelines (Backend/Frontend)
|
||
|
|
|
||
|
|
When working with API v2:
|
||
|
|
- Use `/api/v2/` endpoints
|
||
|
|
- Follow REST conventions
|
||
|
|
- Use proper HTTP status codes
|
||
|
|
- Include error messages in responses
|
||
|
|
- Add request/response DTOs in mnemo_cards_common
|
||
|
|
- Document endpoints in OpenAPI spec (open_api.yaml)
|
||
|
|
|
||
|
|
### Backend (Dart Shelf)
|
||
|
|
```dart
|
||
|
|
class MyApiV2 {
|
||
|
|
Router get router {
|
||
|
|
final router = Router();
|
||
|
|
|
||
|
|
router.get('/api/v2/resource', _getResource);
|
||
|
|
router.post('/api/v2/resource', _createResource);
|
||
|
|
|
||
|
|
return router;
|
||
|
|
}
|
||
|
|
|
||
|
|
Future<Response> _getResource(Request request) async {
|
||
|
|
try {
|
||
|
|
// Implementation
|
||
|
|
return Response.ok(json.encode(result));
|
||
|
|
} catch (e) {
|
||
|
|
return Response.internalServerError(
|
||
|
|
body: json.encode({'error': e.toString()})
|
||
|
|
);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
```
|
||
|
|
|
||
|
|
### Frontend (HttpRepositoryV2)
|
||
|
|
```dart
|
||
|
|
class HttpRepositoryV2 {
|
||
|
|
Future<ResourceResponse> getResource(String id) async {
|
||
|
|
final response = await _client.get(
|
||
|
|
Uri.parse('${_baseUrl}/api/v2/resource/$id'),
|
||
|
|
headers: await _getHeaders(),
|
||
|
|
);
|
||
|
|
|
||
|
|
if (response.statusCode == 200) {
|
||
|
|
return ResourceResponse.fromJson(
|
||
|
|
json.decode(response.body)
|
||
|
|
);
|
||
|
|
} else {
|
||
|
|
throw ApiException(response.statusCode, response.body);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
```
|
||
|
|
|
||
|
|
## Testing Examples
|
||
|
|
|
||
|
|
### Unit Test (Dart)
|
||
|
|
```dart
|
||
|
|
void main() {
|
||
|
|
group('MyService', () {
|
||
|
|
late MyService service;
|
||
|
|
|
||
|
|
setUp(() {
|
||
|
|
service = MyService();
|
||
|
|
});
|
||
|
|
|
||
|
|
test('should return correct result', () {
|
||
|
|
// Arrange
|
||
|
|
final input = 'test';
|
||
|
|
|
||
|
|
// Act
|
||
|
|
final result = service.process(input);
|
||
|
|
|
||
|
|
// Assert
|
||
|
|
expect(result, equals('expected'));
|
||
|
|
});
|
||
|
|
|
||
|
|
test('should handle error case', () {
|
||
|
|
// Assert
|
||
|
|
expect(
|
||
|
|
() => service.process(null),
|
||
|
|
throwsA(isA<ArgumentError>()),
|
||
|
|
);
|
||
|
|
});
|
||
|
|
});
|
||
|
|
}
|
||
|
|
```
|
||
|
|
|
||
|
|
### Widget Test (Flutter)
|
||
|
|
```dart
|
||
|
|
void main() {
|
||
|
|
testWidgets('MyWidget displays correctly', (tester) async {
|
||
|
|
// Build widget
|
||
|
|
await tester.pumpWidget(
|
||
|
|
MaterialApp(home: MyWidget())
|
||
|
|
);
|
||
|
|
|
||
|
|
// Verify
|
||
|
|
expect(find.text('Hello'), findsOneWidget);
|
||
|
|
expect(find.byType(ElevatedButton), findsOneWidget);
|
||
|
|
});
|
||
|
|
}
|
||
|
|
```
|
||
|
|
|
||
|
|
## Error Handling
|
||
|
|
|
||
|
|
Always handle errors gracefully:
|
||
|
|
|
||
|
|
```dart
|
||
|
|
try {
|
||
|
|
final result = await service.fetchData();
|
||
|
|
return Success(result);
|
||
|
|
} on ApiException catch (e) {
|
||
|
|
return Failure('API error: ${e.message}');
|
||
|
|
} on NetworkException catch (e) {
|
||
|
|
return Failure('Network error: ${e.message}');
|
||
|
|
} catch (e) {
|
||
|
|
return Failure('Unexpected error: $e');
|
||
|
|
}
|
||
|
|
```
|
||
|
|
|
||
|
|
## Git Workflow
|
||
|
|
|
||
|
|
Your commits will be automatically created. Make sure your changes are:
|
||
|
|
- **Atomic**: One logical change per commit
|
||
|
|
- **Complete**: All files needed for the feature
|
||
|
|
- **Tested**: All tests pass
|
||
|
|
- **Clean**: Linter passes
|
||
|
|
|
||
|
|
## Reference Materials
|
||
|
|
|
||
|
|
You can reference these files for context:
|
||
|
|
- `project_config.md` - Project overview and setup
|
||
|
|
- `workflow_state.md` - Current development state
|
||
|
|
- `tasks.md` - Human-readable task list
|
||
|
|
- Existing code in the repository
|
||
|
|
|
||
|
|
## Success Criteria
|
||
|
|
|
||
|
|
A task is only complete when:
|
||
|
|
1. ✅ All acceptance criteria are met
|
||
|
|
2. ✅ All new code has unit tests
|
||
|
|
3. ✅ All tests pass (old and new)
|
||
|
|
4. ✅ Linter passes with no warnings
|
||
|
|
5. ✅ Code is production-ready (no TODOs)
|
||
|
|
6. ✅ Changes are committed and pushed
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
**Remember**: You are an autonomous agent. Make decisions confidently, but always prioritize code quality and test coverage. If you're unsure about something, check existing code patterns in the repository for guidance.
|
||
|
|
|
||
|
|
Good luck! 🚀
|
||
|
|
|