Folder Structure
Folder Structure Reference
Section titled βFolder Structure ReferenceβThis reference provides the complete folder structure for MOFA architecture projects, including file placement rules and organization principles.
Single App Structure
Section titled βSingle App StructureβFor single applications, use this simplified structure:
lib/βββ main.dart # Application entry pointβββ core/ # Core features shared across the appβ βββ auth/ # Authentication featureβ β βββ services/β β β βββ auth_service.dartβ β βββ models/β β β βββ auth_state.dartβ β βββ providers/β β βββ auth_providers.dartβ βββ router/ # Navigation and routingβ β βββ app_router.dartβ β βββ routes.dartβ β βββ pages/β β βββ login_page.dartβ β βββ home_page.dartβ βββ service_locators/ # Dependency injectionβ β βββ client_providers.dart # GraphQL/HTTP clientsβ β βββ datasource_providers.dart # Datasource instancesβ β βββ repository_providers.dart # Repository implementationsβ β βββ service_providers.dart # Business logic servicesβ βββ config/ # Configurationβ βββ flavor_config.dartβ βββ app_config.dartβββ features/ # Business featuresβ βββ [feature_name]/ # Individual featureβ βββ ui/ # UI Layerβ β βββ screens/β β β βββ [feature]_screen.dartβ β βββ widgets/β β β βββ [feature]_widget.dartβ β βββ notifiers/β β βββ [feature]_notifier.dartβ βββ services/ # Service Layerβ β βββ [feature]_service.dartβ β βββ [feature]_orchestrator_service.dartβ βββ domain/ # Domain Layerβ β βββ models/β β β βββ [feature]_model.dartβ β βββ inputs/β β β βββ [feature]_inputs.dartβ β βββ repositories/β β βββ i_[feature]_repository.dartβ βββ datasource/ # Datasource Layerβ βββ [feature]_datasource.dartβ βββ [feature]_repository.dartβ βββ [feature]_datasource_module.dartβ βββ gql/β β βββ [feature]_operations.graphqlβ βββ strategies/β βββ [feature]_request_strategies.dartβ βββ [feature]_cache_strategies.dartβββ services/ # Cross-cutting servicesβ βββ caching/β β βββ secure_cache_service.dartβ β βββ simple_cache_service.dartβ β βββ complex_cache_service.dartβ βββ error_handling/β β βββ error_handling_service.dartβ βββ logging/β β βββ logging_service.dartβ βββ analytics/β βββ analytics_service.dartβββ packages/ # Generic packages βββ i18n/ β βββ lib/ β β βββ src/ β β β βββ services/ β β β βββ extensions/ β β βββ i18n.dart β βββ pubspec.yaml βββ assets/ βββ lib/ β βββ src/ β β βββ services/ β β βββ constants/ β βββ assets.dart βββ pubspec.yamlMonorepo Structure
Section titled βMonorepo StructureβMonorepo Approach
For larger projects or multiple apps, use the monorepo structure with Pub Workspaces. This provides better separation of concerns and independent package development.
βββ pubspec.yaml # Root workspace configurationβββ apps/β βββ [app_name]/ # Individual applicationsβ βββ lib/β β βββ main.dartβ β βββ src/β β βββ core/ # App-specific coreβ β β βββ providers/β β β βββ datasource_providers.dartβ β β βββ service_providers.dartβ β βββ features/β β βββ [feature]/β β βββ presentation/β β βββ screens/β β βββ widgets/β β βββ notifiers/β βββ pubspec.yamlβββ packages/β βββ domain/ # Domain layer packageβ β βββ lib/β β β βββ src/β β β β βββ [feature]/β β β β β βββ models/β β β β β βββ inputs/β β β β β βββ filters/β β β β β βββ exceptions/β β β β β βββ repositories/β β β β βββ shared/β β β βββ domain.dartβ β βββ pubspec.yamlβ βββ services/ # Service layer packageβ β βββ lib/β β β βββ src/β β β β βββ [feature]/β β β β β βββ [feature]_service.dartβ β β β β βββ [feature]_orchestrator.dartβ β β β βββ shared/β β β β βββ caching/β β β β βββ error_handling/β β β β βββ logging/β β β βββ services.dartβ β βββ pubspec.yamlβ βββ datasource/ # Datasource layer packageβ β βββ lib/β β β βββ src/β β β β βββ core/β β β β β βββ remote/β β β β β β βββ gql/β β β β β β βββ client/β β β β β β βββ schema/β β β β β βββ local/β β β β βββ [feature]/β β β β βββ remote/β β β β β βββ gql/β β β β β βββ rest/β β β β βββ repositories/β β β β βββ strategies/β β β βββ datasource.dartβ β βββ pubspec.yamlβ βββ i18n/ # Internationalization packageβ β βββ lib/β β β βββ src/β β β β βββ services/β β β β βββ models/β β β β βββ extensions/β β β βββ i18n.dartβ β βββ pubspec.yamlβ βββ assets/ # Assets management packageβ βββ lib/β β βββ src/β β β βββ services/β β β βββ constants/β β βββ assets.dartβ βββ pubspec.yamlβββ tools/ # Development tools βββ build_runner/ βββ code_generation/File Naming Conventions
Section titled βFile Naming ConventionsβDart Files
Section titled βDart Filesβ- Models:
[entity]_model.dart(e.g.,user_model.dart) - Services:
[feature]_service.dart(e.g.,user_service.dart) - Orchestrators:
[purpose]_orchestrator_service.dart(e.g.,data_merge_orchestrator_service.dart) - Repositories:
[entity]_repository.dart(e.g.,user_repository.dart) - Repository Interfaces:
i_[entity]_repository.dart(e.g.,i_user_repository.dart) - Datasources:
[entity]_datasource.dart(e.g.,user_datasource.dart) - Notifiers:
[feature]_notifier.dart(e.g.,user_list_notifier.dart) - Screens:
[feature]_screen.dart(e.g.,user_list_screen.dart) - Widgets:
[feature]_widget.dart(e.g.,user_card_widget.dart)
GraphQL Files
Section titled βGraphQL Filesβ- Operations:
[entity]_operations.graphql(e.g.,user_operations.graphql) - Fragments:
[entity]_fragments.graphql(e.g.,user_fragments.graphql)
Test Files
Section titled βTest Filesβ- Unit Tests:
[class_name]_test.dart(e.g.,user_service_test.dart) - Widget Tests:
[widget_name]_test.dart(e.g.,user_list_widget_test.dart) - Integration Tests:
[feature]_integration_test.dart
Directory Rules
Section titled βDirectory RulesβCore Folder Rules
Section titled βCore Folder Rulesβ- Purpose: Contains features that need to be imported by other features
- Rule: If a feature needs to be imported by another feature, it belongs in core
- Components: Auth, Router, Service Locators, Configuration
Feature Folder Rules
Section titled βFeature Folder Rulesβ- Independence: Features must not import other features directly
- Self-contained: Each feature contains all its layers (UI, Services, Domain, Datasource)
- Shared Logic: Extract shared logic to services or core modules
Package Rules
Section titled βPackage Rulesβ- Generic Packages: Must be business-logic independent
- Domain Package: Contains only pure models and interfaces
- Service Package: Contains all business logic
- Datasource Package: Contains only data access logic
Import Rules
Section titled βImport RulesβAllowed Imports
Section titled βAllowed Importsβ// UI Layerimport 'package:domain/domain.dart'; // β
Domain modelsimport 'package:services/services.dart'; // β
Business logicimport '../core/auth/auth_service.dart'; // β
Core featuresimport 'package:i18n/i18n.dart'; // β
Generic packages
// Service Layerimport 'package:domain/domain.dart'; // β
Domain modelsimport 'package:datasource/repositories.dart'; // β
Repository implementationsimport '../core/service_locators.dart'; // β
Service locators
// Domain Layer// No imports from other layers // β
Pure domain
// Datasource Layerimport 'package:domain/domain.dart'; // β
Domain interfaces onlyProhibited Imports
Section titled βProhibited Importsβ// UI Layerimport 'package:datasource/datasource.dart'; // β Skip service layer
// Domain Layerimport 'package:services/services.dart'; // β Domain depends on servicesimport 'package:datasource/datasource.dart'; // β Domain depends on datasource
// Datasource Layerimport 'package:services/services.dart'; // β Circular dependency
// Featuresimport '../other_feature/feature.dart'; // β Feature-to-feature dependencyTest Organization
Section titled βTest Organizationβtest/βββ unit/ # Unit testsβ βββ services/β βββ repositories/β βββ domain/βββ widget/ # Widget testsβ βββ screens/β βββ components/β βββ forms/βββ integration/ # Integration testsβ βββ features/βββ helpers/ # Test utilities βββ mocks/ βββ fixtures/ βββ test_utils.dartThis folder structure ensures clear separation of concerns, maintainable code organization, and proper architectural boundaries in MOFA architecture projects.