- Introduced the Krow Platform System Bible detailing the executive summary, system vision, ecosystem overview, architecture, application responsibilities, use cases, and security model. - Created a detailed use case overview for the Krow Web Application, outlining workflows for Admin, Client, and Vendor roles. - Established non-negotiable agent development rules for mobile applications, emphasizing file structure, naming conventions, logic placement, localization, and error handling. - Defined architecture principles for the Krow mobile platform, focusing on clean architecture, dependency direction, and session management. - Documented design system usage guidelines to ensure UI consistency and adherence to design tokens across applications.
8.2 KiB
8.2 KiB
Agent Development Rules
These rules are NON-NEGOTIABLE. They are designed to prevent architectural degradation by automated agents.
1. File Creation & Structure
- Feature-First Packaging:
- DO: Create new features as independent packages in
apps/mobile/packages/features/<app_name>/<feature_name>. - DO NOT: Add features to
apps/mobile/packages/coreor existing apps directly. - DO NOT: Create cross-feature or cross-app dependencies.
- DO: Create new features as independent packages in
- Path Conventions:
- Entities:
apps/mobile/packages/domain/lib/src/entities/<entity>.dart - Repositories (Interface):
apps/mobile/packages/features/<app_name>/<feature>/lib/src/domain/repositories/<name>_repository_interface.dart - Repositories (Impl):
apps/mobile/packages/features/<app_name>/<feature>/lib/src/data/repositories_impl/<name>_repository_impl.dart - Use Cases:
apps/mobile/packages/features/<app_name>/<feature>/lib/src/application/<name>_usecase.dart - BLoCs:
apps/mobile/packages/features/<app_name>/<feature>/lib/src/presentation/blocs/<name>_bloc.dart - Pages:
apps/mobile/packages/features/<app_name>/<feature>/lib/src/presentation/pages/<name>_page.dart - Widgets:
apps/mobile/packages/features/<app_name>/<feature>/lib/src/presentation/widgets/<name>_widget.dart
- Entities:
- Barrel Files:
- DO: Use
exportinlib/<package_name>.dartonly for public APIs. - DO NOT: Export internal implementation details in the main package file.
- DO: Use
2. Naming Conventions
Follow Dart standards strictly.
| Type | Convention | Example |
|---|---|---|
| Files | snake_case |
user_profile_page.dart |
| Classes | PascalCase |
UserProfilePage |
| Variables | camelCase |
userProfile |
| Interfaces | terminate with Interface |
AuthRepositoryInterface |
| Implementations | terminate with Impl |
AuthRepositoryImpl |
3. Logic Placement (Strict Boundaries)
- Business Rules: MUST reside in Use Cases (Domain/Feature Application layer).
- Forbidden: Placing business rules in BLoCs or Widgets.
- State Logic: MUST reside in BLoCs or StatefulWidgets (only for ephemeral UI state).
- Forbidden:
setStatein Pages for complex state management. - Recommendation: Pages should be
StatelessWidgetwith state delegated to BLoCs.
- Forbidden:
- Data Transformation: MUST reside in Repositories (Data Connect layer).
- Forbidden: Parsing JSON in the UI or Domain.
- Pattern: Repositories map Data Connect models to Domain entities.
- Navigation Logic: MUST reside in Flutter Modular Routes.
- Forbidden:
Navigator.pushwith hardcoded widgets. - Pattern: Use named routes via
Modular.to.navigate().
- Forbidden:
- Session Management: MUST reside in DataConnectService via SessionHandlerMixin.
- Pattern: Automatic token refresh, auth state listening, and role-based validation.
- UI Reaction: SessionListener widget wraps the entire app and responds to session state changes.
4. Localization (core_localization) Integration
All user-facing text MUST be localized using the centralized core_localization package:
- String Management:
- Define all user-facing strings in
apps/mobile/packages/core_localization/lib/src/l10n/ - Use
slangor similar i18n tooling for multi-language support - Access strings in presentation layer via
context.strings.<key>
- Define all user-facing strings in
- BLoC Integration:
LocaleBlocmanages the current locale state- Apps import
core_localization.LocalizationModule()in their module imports - Wrap app with
BlocProvider<LocaleBloc>()to expose locale state globally
- Feature Usage:
- Pages and widgets access localized strings:
Text(context.strings.buttonLabel) - Build methods receive
BuildContextwith access to current locale - No hardcoded English strings in feature packages
- Pages and widgets access localized strings:
- Error Messages:
- Use
ErrorTranslatorfromcore_localizationto map domain failures to user-friendly messages - Pattern: Failures emitted from BLoCs are translated to localized strings in the UI
- Use
5. Data Connect Integration Strategy
All backend access is centralized through DataConnectService in apps/mobile/packages/data_connect:
- Repository Interface First: Define
abstract interface class <Name>RepositoryInterfacein the feature'sdomain/repositories/folder. - Repository Implementation: Implement the interface in
data/repositories_impl/using_service.run()wrapper.- Pattern:
await _service.run(() => connector.<query>().execute()) - Benefit: Automatic auth validation, token refresh, and error handling.
- Pattern:
- Session Handling: Use
DataConnectService.instance.initializeAuthListener(allowedRoles: [...])in app main.dart.- Automatic: Token refresh with 5-minute expiry threshold.
- Retry Logic: 3 attempts with exponential backoff (1s → 2s → 4s) before emitting error.
- Role Validation: Configurable per app (e.g., Staff:
['STAFF', 'BOTH'], Client:['CLIENT', 'BUSINESS', 'BOTH']).
- Session State Management: Wrap app with
SessionListenerwidget to react to session changes.- Dialogs: Shows session expired or error dialogs for user-facing feedback.
- Navigation: Routes to login on session loss, to home on authentication.
5. Prototype Migration Rules
You have access to prototypes/ folders. When migrating code:
- Extract Assets:
- You MAY copy icons, images, and colors. But they should be tailored to the current design system. Do not change the colours and typgorahys in the design system. They are final. And you have to use these in the UI.
- When you matching colous and typography, from the POC match it with the design system and use the colors and typography from the design system. As mentioned in the
apps/mobile/docs/03-design-system-usage.md.
- When you matching colous and typography, from the POC match it with the design system and use the colors and typography from the design system. As mentioned in the
- You MAY copy icons, images, and colors. But they should be tailored to the current design system. Do not change the colours and typgorahys in the design system. They are final. And you have to use these in the UI.
- Extract Layouts: You MAY copy
buildmethods for UI structure. - REJECT Architecture: You MUST NOT copy the
GetX,Provider, orMVCpatterns often found in prototypes. Refactor immediately to Bloc + Clean Architecture with Flutter Modular and Melos.
6. Handling Ambiguity
If a user request is vague:
- STOP: Do not guess domain fields or workflows.
- ANALYZE:
- For architecture related questions, refer to
apps/mobile/docs/01-architecture-principles.mdor existing code. - For design system related questions, refer to
apps/mobile/docs/03-design-system-usage.mdor existing code.
- DOCUMENT: If you must make an assumption to proceed, add a comment
// ASSUMPTION: <explanation>and mention it in your final summary. - ASK: Prefer asking the user for clarification on business rules (e.g., "Should a 'Job' have a 'status'?").
7. Dependencies
- DO NOT add 3rd party packages without checking
apps/mobile/packages/corefirst. - DO NOT add
firebase_authorfirebase_data_connectto any Feature package. They belong indata_connectonly. - Service Locator: Use
DataConnectService.instancefor singleton access to backend operations. - Dependency Injection: Use Flutter Modular for BLoC and UseCase injection in
Module.routes().
8. Error Handling
- Domain Failures: Define custom
Failureclasses indomain/failures/. - Data Connect Errors: Map Data Connect exceptions to Domain failures in repositories.
- User Feedback: BLoCs emit error states; UI displays snackbars or dialogs.
- Session Errors: SessionListener automatically shows dialogs for session expiration/errors.
9. Testing
- Unit Tests: Test use cases and repositories with real implementations.
- Widget Tests: Use
WidgetTesterto test UI widgets and BLoCs. - Integration Tests: Test full feature flows end-to-end with Data Connect.
- Pattern: Use dependency injection via Modular to swap implementations if needed for testing.
10. Follow Clean Code Principles
- Add doc comments to all classes and methods you create.
- Keep methods and classes focused and single-responsibility.
- Use meaningful variable names that reflect intent.
- Keep widget build methods concise; extract complex widgets to separate files.