This is a comprehensive Flutter application template implementing MVVM (Model-View-ViewModel) architecture with Domain-Driven Design (DDD) principles. The template is designed to be flexible, modular, and maintainable, with clear separation of concerns for efficient team collaboration.
- Clean Architecture: Clear separation between domain, data, and presentation layers
- MVVM Pattern: Model-View-ViewModel for reactive UI management
- Domain-Driven Design: Business logic encapsulation and value objects
- Modular Structure: Each feature has its own complete module
- Dependency Injection: Service locator pattern with GetIt
- Complex Routing: Advanced deeplink support with go_router
lib/
βββ core/ # Shared infrastructure
β βββ dependency_injection.dart # DI configuration
β βββ error_handling.dart # Result type & error handling
β βββ route_manager.dart # Global routing configuration
β βββ utils.dart # Shared utilities
βββ features/ # Feature modules
β βββ auth/ # Authentication feature
β βββ profile/ # User profile feature
β βββ blog/ # Blog system feature
β βββ common/ # Shared UI components
βββ app.dart # Application widget & theme configuration
βββ config.dart # Application configuration & constants
βββ constants.dart # UI constants & design tokens
βββ main.dart # Application entry point
- Authentication System: Login, register, logout, token management
- User Profile Management: Profile viewing, editing, stats, tabbed interface
- Blog System: Post listing, detail view, complex date-based routing
- Shared Components: Loading widgets, error views, common UI elements
- Complex Deeplinks:
/blog/2024/01/15/my-blog-post - Query Parameters: Preview mode, pagination, filtering
- Event Booking:
/event/123/booking?step=payment&coupon=SAVE20 - Nested Navigation: Tab-based profile navigation
- Material Design 3: Modern UI with dynamic theming
- Dark Mode Support: System-based theme switching
- Responsive Design: Adaptive layouts for different screen sizes
- Loading States: Comprehensive loading and error handling
- Infinite Scrolling: Performance-optimized list views
Each feature follows the same modular structure:
features/[feature_name]/
βββ domain/ # Business logic layer
β βββ entities/ # Core business objects
β βββ value_objects/ # Domain value objects
β βββ repositories/ # Repository interfaces
βββ data/ # Data access layer
β βββ models/ # Data transfer objects
β βββ datasources/ # Remote & local data sources
β βββ repositories/ # Repository implementations
βββ application/ # Use case layer
β βββ usecases/ # Business use cases
βββ presentation/ # UI layer
βββ viewmodels/ # State management
βββ views/ # UI screens
βββ routes/ # Feature routing
main.dart: Application entry point with dependency injection setupapp.dart: Main application widget with theme and routing configurationconfig.dart: Centralized application configuration and environment settingsconstants.dart: UI constants, design tokens, and asset management
- Material Design 3 with comprehensive theming
- Design tokens for consistent spacing, colors, and typography
- Dark mode support with automatic system detection
- Responsive design with breakpoint constants
- Animation curves and duration constants
dependencies:
flutter: sdk: flutter
provider: ^6.1.2 # State management
go_router: ^14.2.7 # Advanced routing
get_it: ^7.7.0 # Dependency injection
dio: ^5.4.3+1 # HTTP client
shared_preferences: ^2.2.3 # Local storage
json_annotation: ^4.9.0 # JSON serialization
dev_dependencies:
build_runner: ^2.4.12 # Code generation
json_serializable: ^6.8.0 # JSON code generationgit clone <repository>
cd blueprint_application
flutter pub getflutter packages pub run build_runner buildflutter run- Create Feature Structure
mkdir -p lib/features/[feature_name]/{domain,data,application,presentation}/{entities,repositories,models,datasources,usecases,viewmodels,views,routes}- Define Domain Layer
// Domain Entity
class Product {
final String id;
final String name;
final Price price;
const Product({
required this.id,
required this.name,
required this.price,
});
}
// Value Object
class Price {
final double value;
final String currency;
const Price({required this.value, required this.currency});
bool get isValid => value > 0;
}- Implement Repository Interface
abstract class ProductRepository {
Future<Result<List<Product>>> getProducts();
Future<Result<Product>> getProduct(String id);
Future<Result<void>> createProduct(Product product);
}- Create Use Cases
class GetProductsUseCase {
final ProductRepository repository;
GetProductsUseCase(this.repository);
Future<Result<List<Product>>> call() async {
return await repository.getProducts();
}
}- Build ViewModel
class ProductViewModel extends ChangeNotifier {
final GetProductsUseCase getProductsUseCase;
ProductViewModel({required this.getProductsUseCase});
List<Product> _products = [];
bool _isLoading = false;
String? _error;
List<Product> get products => _products;
bool get isLoading => _isLoading;
String? get error => _error;
Future<void> loadProducts() async {
_isLoading = true;
_error = null;
notifyListeners();
final result = await getProductsUseCase();
result.when(
success: (products) {
_products = products;
_isLoading = false;
notifyListeners();
},
failure: (error) {
_error = error.toString();
_isLoading = false;
notifyListeners();
},
);
}
}// Navigate to blog post with date-based URL
AppRouter.goToBlogPost(
year: '2024',
month: '01',
day: '15',
slug: 'flutter-architecture-guide',
preview: true,
);
// Navigate to event booking with query parameters
AppRouter.goToEventBooking(
'event-123',
step: 'payment',
coupon: 'SAVE20',
);
// Navigate to user profile with specific tab
AppRouter.goToProfile('user-456', tab: 'posts');Comprehensive unit testing examples with Thai documentation covering all architectural layers:
- Domain Layer (30/30 β ): Entities, value objects, business rules validation
- Application Layer (16/16 β ): Use cases, business logic, repository integration
- Data Layer (24/24 β ): Repository implementations, data source integration
- Presentation Layer (72/72 β ): ViewModels, state management, async operations
- Widget Tests (1/1 β ): UI components, dependency injection setup
- Async Operation Testing: Comprehensive patterns for testing complex async workflows
- State Management Testing: Complete ViewModel lifecycle and state transition testing
- Error Handling Testing: Recovery scenarios and edge case handling
- Unicode Support Testing: International character validation (Thai, Chinese, Japanese)
- Dependency Injection Testing: GetIt service locator setup for widget tests
- Fake Implementations: Preferred over mocking for reliability and maintainability
- Self-Contained Tests: No external dependencies required
- Concurrent Operations: Testing multiple simultaneous operations
- Edge Case Coverage: Comprehensive validation testing with business rules
- Performance Testing: Async timing and resource management patterns
- Provider pattern for reactive state updates
- Factory registration for ViewModels to prevent memory leaks
- Lazy loading for expensive dependencies
- Infinite scrolling with pagination
- Image caching for profile and blog images
- Debounced search to reduce API calls
- Optimized list views with builders
- Request/Response interceptors for logging and debugging
- Automatic retry for failed requests
- Timeout configuration for better UX
- Error handling with user-friendly messages
- JWT token management with automatic refresh
- Secure local storage for sensitive data
- Logout cleanup to clear all auth data
- Token expiration handling
- Input validation with value objects
- XSS prevention in user-generated content
- API key protection (not hardcoded)
# Development
flutter run --debug
# Staging
flutter run --profile
# Production
flutter build apk --release
flutter build ios --release// Configure different API endpoints
const String apiBaseUrl = String.fromEnvironment(
'API_BASE_URL',
defaultValue: 'https://api.example.com',
);- Follow Effective Dart guidelines
- Use meaningful variable and function names
- Document complex business logic
- Write tests for new features
- Create feature branch from main
- Implement following the established architecture
- Write comprehensive tests
- Update documentation
- Submit pull request with clear description
- Clear module boundaries for parallel development
- Consistent patterns across all features
- Easy onboarding with documented structure
- Scalable architecture for growing applications
- 100% test coverage with comprehensive examples
- Production-ready patterns with proven testing strategies
- Faster feature delivery with reusable components
- Lower maintenance costs with clean architecture
- Better quality with comprehensive error handling
- Future-proof with modern Flutter patterns
- Reduced bugs with extensive unit test coverage
- Reliable CI/CD with stable test suite
This template is provided as-is for educational and commercial use. Feel free to modify and distribute according to your needs.
Happy Coding! π
This template demonstrates enterprise-level Flutter development practices with a focus on maintainability, scalability, and team collaboration. Now featuring 100% test coverage with comprehensive unit testing examples for all architectural layers.