Coding Standards
- File names: lowercase_with_underscores.xxx
- Everything else is in camelCase.
- Prefix underscores (_) for private members.
- Idiomatic Dart formatter (native)
- Indentation: 2 spaces
- dcm for linting (website)
Architecture
The project follows a 3-tier layered architecture with dependency injection and Firebase emulators:
Core Principles:
- Repository Pattern with Interfaces: All data access through abstract interfaces
- Dependency Injection: GetIt service locator - never instantiate dependencies directly
- Separation of Concerns: UI → Services → Repositories → Models
- Emulator-Driven Development: Uses Firebase emulators (Auth, Firestore) in development
- Zero hard-coded values: Use constants or configuration files
- One widget per file: All widgets must be in their own file in the
widgets/folder - No private widget methods in views: Extract to separate widget files in
widgets/folder - Use configuration classes directly: No thin wrapper helpers - use config classes like
ProductCategory,CollectionConfigdirectly - Keep view files concise: Centralize duplicate logic and markup by extracting reusable widgets
- Business logic in models/services: Not in widget build methods
Structure:
- Presentation Layer:
views/andwidgets/- UI components - Get dependencies via
getIt<Service>()ininitState() - No direct instantiation of services or repositories
- Views: Full-screen components that compose widgets
- Widgets: Reusable UI components, one per file, organized by feature
- No private widget builder methods (e.g.,
_buildSomething()) - extract to separate widget files - Application Layer:
services/- Business logic, validation, orchestration - Depend on repository interfaces, not concrete implementations
- Data Layer:
repositories/- Data access with Firestore implementations - Abstract interfaces (
i_*_repository.dart) - Firestore implementations (connects to emulators in dev, production in prod)
- Domain Layer:
models/- Plain data classes withtoJson()/fromJson() - Include computed properties for business logic (e.g.,
product.status)
Library Folders:
constants/: Application-wide constants and configuration classes- Configuration classes like
ProductCategory,CollectionConfig,Material3Config - Use these directly instead of creating thin wrapper helpers
models/: Data models with serialization and computed propertiesrepositories/: Data access interfaces and implementationsservices/: Business logic and orchestrationutils/: Pure utility functions (date formatting, etc.)- Avoid thin wrappers that just delegate to config classes
widgets/: Reusable UI components by feature, one widget per filewidgets/common/: Shared widgets (EmptyStateWidget, ErrorStateWidget, etc.)widgets/product/: Product-specific widgetswidgets/collection/: Collection-specific widgetswidgets/auth/: Authentication widgetsviews/: Full-screen UI components that compose widgets- Should be concise, primarily composing widgets
- Extract complex UI into separate widget files
service_locator.dart: Dependency injection configuration
Widget Development Guidelines:
- One widget per file: Never define multiple widget classes in a single file
- Extract private builders: If you find yourself writing
Widget _buildSomething(), create a new widget file instead - Reusability: Design widgets to be reusable with parameters
- Keep widgets focused: Each widget should have a single responsibility
- Use config classes: Directly use
ProductCategory.getIcon(),CollectionConfig.getColor(), etc. - Business logic belongs elsewhere: Status checks, data transformations go in models/services
Example - Good vs Bad:
Bad (private builder in view):
class MyView extends StatelessWidget {
Widget _buildCard() { ... } // ❌ Private builder method
}
Good (extracted widget):
// my_view.dart
class MyView extends StatelessWidget {
build() => MyCard(...); // ✅ Uses extracted widget
}
// widgets/my_card.dart
class MyCard extends StatelessWidget { ... } // ✅ Separate file
Bad (thin wrapper helper):
class SomeHelper {
static getIcon(type) => ConfigClass.getIcon(type); // ❌ Unnecessary wrapper
}
Good (direct config usage):
ProductCategory.getIcon(category) // ✅ Direct usage
CollectionConfig.getColor(type, colorScheme) // ✅ Direct usage