.cursor/skills/service-pattern-standardization/SKILL.md
--- name: service-pattern-standardization description: Standardizes service patterns: constructor injection, error handling, logging with developer.log(), service-to-service communication. Use when creating new services or refactoring existing services. --- # Service Pattern Standardization ## Core Pattern All services use constructor injection with required and optional dependencies. ## Service Structure ```dart import 'dart:developer' as developer; import 'package:avrai/core/services/logg
npx skillsauth add avra-cadavra/avrai .cursor/skills/service-pattern-standardizationInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
All services use constructor injection with required and optional dependencies.
import 'dart:developer' as developer;
import 'package:avrai/core/services/logger.dart';
class MyService {
final RequiredService _requiredService;
final OptionalService? _optionalService;
final AppLogger _logger = const AppLogger(
defaultTag: 'MyService',
minimumLevel: LogLevel.debug,
);
MyService({
required RequiredService requiredService,
OptionalService? optionalService,
}) : _requiredService = requiredService,
_optionalService = optionalService;
Future<void> performOperation() async {
_logger.info('Starting operation');
try {
// Service logic
_logger.debug('Operation completed');
} catch (e, st) {
_logger.error('Operation failed', error: e, stackTrace: st);
rethrow;
}
}
}
class MyService {
final DependencyService _dependencyService;
MyService({
required DependencyService dependencyService,
}) : _dependencyService = dependencyService;
}
class MyService {
final RequiredService _requiredService;
final OptionalService? _optionalService;
MyService({
required RequiredService requiredService,
OptionalService? optionalService,
}) : _requiredService = requiredService,
_optionalService = optionalService;
void useOptional() {
_optionalService?.doSomething(); // Null-safe access
}
}
Always handle errors explicitly:
Future<Result<String>> performOperation() async {
try {
final result = await _dependencyService.getData();
return Result.success(result);
} on NetworkException catch (e) {
_logger.error('Network error', error: e);
return Result.failure('Connection failed');
} catch (e, st) {
_logger.error('Unexpected error', error: e, stackTrace: st);
return Result.failure('Operation failed');
}
}
Use AppLogger for consistent logging:
class MyService {
final AppLogger _logger = const AppLogger(
defaultTag: 'MyService',
minimumLevel: LogLevel.debug,
);
Future<void> operation() async {
_logger.info('Starting operation');
_logger.debug('Processing data: $data');
_logger.error('Operation failed', error: e, stackTrace: st);
}
}
Services communicate through dependency injection:
// Service A depends on Service B
class ServiceA {
final ServiceB _serviceB;
ServiceA({required ServiceB serviceB}) : _serviceB = serviceB;
Future<void> operation() async {
await _serviceB.doSomething(); // Use injected service
}
}
Register in dependency injection:
// Register dependencies first
sl.registerLazySingleton(() => ServiceB());
// Register service with dependencies
sl.registerLazySingleton(() => ServiceA(
serviceB: sl<ServiceB>(),
));
Some infrastructure services may use singleton pattern:
class StorageService {
static StorageService? _instance;
StorageService._();
static StorageService get instance {
_instance ??= StorageService._();
return _instance!;
}
}
Note: Still register in DI container:
final storageService = StorageService.instance;
await storageService.init();
sl.registerLazySingleton<StorageService>(() => storageService);
See existing service patterns in:
lib/core/services/ - Core service exampleslib/injection_container_core.dart - Registration examplesdevelopment
--- name: world-model-development description: Guides world model development patterns: state/action encoders, ONNX inference, feature extraction pipeline, latency budgets. Use when implementing world model components, state encoders, action encoders, feature extractors, or ONNX models. Core skill for Phases 3-6. --- # World Model Development Patterns ## Core Principle All world model components follow LeCun's autonomous machine intelligence framework. State observations flow through a percep
tools
Implements base workflow controller patterns for multi-step processes. Use when creating complex workflows that require orchestration of multiple steps with error handling and rollback.
testing
--- name: widget-test-patterns description: Guides widget test patterns: BLoC testing, user interactions, state changes, material app setup. Use when writing widget tests, testing UI components, or validating widget behavior. --- # Widget Test Patterns ## Core Pattern Widget tests verify UI behavior: user interactions, state changes, and visual display. ## Basic Widget Test Setup ```dart testWidgets('widget displays correctly', (WidgetTester tester) async { // Arrange: Create widget awa
testing
--- name: test-template-generation description: Generates test templates: unit, widget, integration, service tests following project patterns. Use when creating new tests or ensuring tests follow project standards. --- # Test Template Generation ## Available Templates Test templates are located in `test/templates/`: - `unit_test_template.dart` - `widget_test_template.dart` - `integration_test_template.dart` - `service_test_template.dart` ## Unit Test Template ```dart /// SPOTS Component Uni