Skip to content

A comprehensive Flutter learning resource demonstrating 4 architecture patterns (MVC, MVVM, Clean Architecture, DDD) with identical features for easy comparison. Includes extensive documentation and best practices.

Notifications You must be signed in to change notification settings

YoussefSalem582/flutter_architecture_patterns

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Flutter Architecture Patterns

A comprehensive collection of Flutter projects demonstrating four different architecture patterns for building scalable and maintainable applications. All patterns implement identical features and UI for easy comparison.

📚 Architecture Patterns

1. MVC (Model-View-Controller)

📁 mvc_architeture_pattern/

Pattern Overview:

  • Model: Data and business logic
  • View: UI components
  • Controller: Mediates between Model and View

Best For: Small to medium apps, rapid prototyping, learning Flutter basics

Features:

  • ✅ Counter with increment/decrement/reset
  • ✅ Notes with add/view/delete
  • ✅ Theme toggle (dark/light)
  • ✅ Home view with navigation
  • ✅ Persistent storage with GetStorage

Complexity: ⭐ Simple | Files: ~10 | Lines: ~800


2. MVVM (Model-View-ViewModel)

📁 mvvm_architeture_pattern/

Pattern Overview:

  • Model: Data entities
  • View: UI components
  • ViewModel: Presentation logic with observables

Best For: Medium to large apps, complex UI state, reactive programming

Features:

  • ✅ Counter with increment/decrement/reset
  • ✅ Notes with add/view/delete
  • ✅ Theme toggle (dark/light)
  • ✅ Home view with navigation
  • ✅ Persistent storage with GetStorage

Complexity: ⭐⭐ Moderate | Files: ~15 | Lines: ~1,000


3. Clean Architecture

📁 clean_architeture_pattern/

Pattern Overview:

  • Data Layer: Repositories, data sources, models
  • Domain Layer: Use cases, entities, repository interfaces
  • Presentation Layer: Controllers, views, bindings

Best For: Large scalable apps, multiple teams, high testability requirements

Features:

  • ✅ Counter with increment/decrement/reset
  • ✅ Notes with add/view/delete
  • ✅ Theme toggle (dark/light)
  • ✅ Home view with navigation
  • ✅ Persistent storage with GetStorage
  • ✅ Framework-independent domain layer

Complexity: ⭐⭐⭐ Complex | Files: ~25 | Lines: ~1,500


4. DDD (Domain-Driven Design)

📁 ddd_architeture_pattern/

Pattern Overview:

  • Domain Layer: Entities, value objects, repository interfaces (pure Dart)
  • Application Layer: Use cases orchestrating domain logic
  • Infrastructure Layer: DTOs, data sources, repository implementations
  • Presentation Layer: Controllers, views, bindings

Best For: Enterprise applications, complex business logic, evolving requirements

Features:

  • ✅ Counter with increment/decrement/reset
  • ✅ Notes with add/view/delete
  • ✅ Theme toggle (dark/light)
  • ✅ Home view with navigation
  • ✅ Persistent storage with GetStorage
  • ✅ Pure domain layer (zero Flutter dependencies)
  • ✅ Value objects with validation
  • ✅ Rich domain models with behavior

Complexity: ⭐⭐⭐⭐ Most Complex | Files: ~40 | Lines: ~2,500


🔄 State Management Options

This repository provides TWO complete implementations of each pattern:

📂 BLoC Folder (/bloc/)

  • State Management: BLoC/Cubit with flutter_bloc
  • Persistence: HydratedBloc
  • Approach: Stream-based reactive programming
  • Best For: Large teams, strict architecture, high testability

📂 GetX Folder (/getx/)

  • State Management: GetX Controllers
  • Persistence: GetStorage
  • Approach: Observer pattern with reactive variables
  • Best For: Rapid development, smaller teams, simpler syntax

See: STATE_MANAGEMENT_COMPARISON.md for comprehensive comparison

  • 📊 Quick comparison & decision guide
  • 🏗️ Architecture deep dive (how they work)
  • 💻 Side-by-side code examples
  • ⚡ Performance benchmarks
  • 👨‍💻 Developer experience comparison
  • 🔄 Migration guides

🎯 Why This Repository?

✨ Standardized Features

All four patterns implement identical features with consistent UI/UX:

  • Same Counter and Notes functionality
  • Identical home view design
  • Consistent theme toggle
  • Uniform styling and layouts

This allows you to:

  • 🔍 Compare architectures side-by-side
  • 📚 Learn pattern differences without UI distractions
  • 🎯 Choose the right pattern for your project
  • 💡 Understand trade-offs clearly

📚 Comprehensive Documentation

  • STATE_MANAGEMENT_COMPARISON.md - BLoC vs GetX comparison (7 focused guides) ⭐ NEW STRUCTURE
    • 01: Overview & Quick Comparison (5 min)
    • 02: How They Work (10 min)
    • 03: Architecture Integration (15 min)
    • 04: Performance & Benchmarks (8 min)
    • 05: Developer Experience (12 min)
    • 06: Decision Guide (7 min)
    • 07: Migration Guide (10 min)
  • STANDARDIZATION_SUMMARY.md - Complete standardization details
  • COMPARISON_GUIDE.md - In-depth pattern comparison
  • Each project has detailed README and code comments

✅ Production Ready

  • Clean, maintainable code
  • Best practices implementation
  • Zero compilation errors
  • Dual state management (BLoC & GetX)
  • Proper error handling

🚀 Getting Started

Requirements

  • Flutter SDK (3.9.2 or higher)
  • Dart SDK (3.9.2 or higher)
  • VS Code or Android Studio (recommended)

Installation

  1. Clone this repository:

    git clone https://github.com/YoussefSalem582/flutter_architecture_patterns.git
    cd flutter_architecture_patterns
  2. Choose a pattern and navigate to it:

    # For MVC
    cd mvc_architeture_pattern
    
    # For MVVM
    cd mvvm_architeture_pattern
    
    # For Clean Architecture
    cd clean_architeture_pattern
    
    # For DDD
    cd ddd_architeture_pattern
  3. Install dependencies:

    flutter pub get
  4. Run the app:

    flutter run
    
    # Or run on specific device
    flutter run -d chrome
    flutter run -d windows

📖 Learning Path

Recommended Order (Beginner → Advanced):

Week 1: MVC Pattern

  • Understand basic separation of concerns
  • Learn Model-View-Controller fundamentals
  • Build simple apps quickly
  • Start Here if new to Flutter architecture

Week 2-3: MVVM Pattern ⭐⭐

  • Learn reactive programming with GetX
  • Understand ViewModel pattern
  • Master observable state management
  • Choose This for UI-heavy apps

Week 4-6: Clean Architecture ⭐⭐⭐

  • Understand layered architecture
  • Learn use case pattern
  • Master dependency inversion
  • Choose This for large-scale apps

Week 7-12: DDD Pattern ⭐⭐⭐⭐

  • Master tactical DDD patterns
  • Understand value objects and entities
  • Learn bounded contexts
  • Choose This for enterprise apps

📊 Quick Comparison

Architecture Patterns

Feature MVC MVVM Clean DDD
Layers 3 3 3 4
Complexity Simple Moderate Complex Most Complex
Learning Curve Easy Moderate Hard Very Hard
Files ~10 ~15 ~25 ~40
Best For Small apps Medium apps Large apps Enterprise
Testability Moderate Good Excellent Best

State Management Solutions

Feature BLoC GetX
Learning Curve Steep (3-6 months) Easy (1 month)
Code Amount More (Verbose) Less (64% reduction)
Performance Excellent ⚡⚡⚡⚡⚡ Excellent ⚡⚡⚡⚡⚡
Memory Usage Lower (~68 MB) Slightly Higher (~72 MB)
Testability Excellent (blocTest) Good
Boilerplate High Low
Type Safety Excellent Good
DI & Routing External packages Built-in
Best For Large teams, complex state Rapid development, MVPs

See STATE_MANAGEMENT_COMPARISON.md for detailed analysis.


🎨 Features Implemented

All Patterns Include:

🏠 Home View

  • Landing page with navigation
  • Architecture information card
  • Feature cards for Counter and Notes
  • Theme toggle button

🔢 Counter Feature

  • Increment counter (+1)
  • Decrement counter (-1)
  • Reset counter (to 0)
  • Persistent storage
  • Reactive UI updates

📝 Notes Feature

  • Add new notes
  • View all notes
  • Delete individual notes
  • Delete all notes
  • Timestamps on each note
  • Empty state handling
  • Persistent storage

🎨 Theme Support

  • Light theme (default)
  • Dark theme
  • System theme (MVVM, Clean, DDD)
  • Theme toggle button in app bar

🏗️ Project Structure

MVC Structure

mvc_architeture_pattern/
├── lib/
│   ├── models/          # Data models
│   ├── views/           # UI screens
│   ├── controllers/     # Business logic
│   └── main.dart

MVVM Structure

mvvm_architeture_pattern/
├── lib/
│   ├── models/          # Data entities
│   ├── views/           # UI screens
│   ├── viewmodels/      # Presentation logic
│   ├── bindings/        # Dependency injection
│   ├── routes/          # Navigation
│   └── main.dart

Clean Architecture Structure

clean_architeture_pattern/
├── lib/
│   ├── core/            # Shared resources
│   ├── features/
│   │   ├── counter/
│   │   │   ├── data/           # Data layer
│   │   │   ├── domain/         # Domain layer
│   │   │   └── presentation/   # Presentation layer
│   │   └── notes/
│   └── main.dart

DDD Structure

ddd_architeture_pattern/
├── lib/
│   ├── domain/          # Pure business logic
│   ├── application/     # Use cases
│   ├── infrastructure/  # Implementation
│   ├── presentation/    # UI layer
│   └── main.dart

📚 Documentation

📖 Essential Guides (Root Level):

Getting Started & Learning:

  1. 📘 GETTING_STARTED.md - Complete setup guide for beginners

    • Prerequisites and installation (Windows/macOS/Linux)
    • Running apps on different platforms
    • Feature testing checklist
    • Common issues and solutions
    • Next steps and learning progression
  2. 📗 BEST_PRACTICES.md - Professional coding standards

    • General Flutter best practices
    • Pattern-specific best practices (MVC, MVVM, Clean, DDD)
    • GetX state management guidelines
    • Code organization and naming conventions
    • Testing strategies
    • Performance optimization
    • Security best practices
  3. 📕 TROUBLESHOOTING.md - Problem-solving guide

    • Installation issues
    • Build errors (Android, iOS, Windows, Web)
    • Runtime errors
    • Platform-specific issues
    • State management problems
    • Navigation and storage issues
    • Performance troubleshooting
  4. 📙 LEARNING_RESOURCES.md - Curated learning materials

    • Official documentation links
    • Architecture pattern resources
    • Video tutorials and YouTube channels
    • Recommended books
    • Online courses (Udemy, Coursera, free options)
    • Community resources (Discord, Reddit, Stack Overflow)
    • Practice project ideas
    • Month-by-month learning path

Architecture Comparison:

  1. STANDARDIZATION_SUMMARY.md - How patterns were standardized

    • Feature comparison across patterns
    • UI/UX consistency details
    • Screen-by-screen breakdown
    • Benefits of standardization
  2. COMPARISON_GUIDE.md - In-depth pattern comparison

    • Side-by-side code examples
    • Architecture layer explanations
    • Testability comparison
    • Performance metrics
    • Decision matrix for pattern selection

📂 Pattern-Specific Documentation:

MVC Pattern:

  • mvc_architeture_pattern/README.md - MVC pattern explanation and setup
  • Simple structure with clear examples

MVVM Pattern:

  • mvvm_architeture_pattern/README.md - MVVM pattern guide
  • Reactive programming examples
  • GetX integration details

Clean Architecture:

  • clean_architeture_pattern/README.md - Clean Architecture overview
  • Layer separation details
  • Use case examples

DDD Pattern:

  • ddd_architeture_pattern/README.md - DDD pattern introduction
  • ddd_architeture_pattern/tech_readme_files/ - Advanced DDD documentation:
    • ARCHITECTURE.md - Complete architecture breakdown
    • DDD_CONCEPTS.md - Domain-Driven Design concepts
    • PROJECT_OVERVIEW.dart - Code-level overview
    • QUICK_START.md - Quick start guide for DDD
    • FIXES_APPLIED.md - Implementation fixes and improvements

🎯 Recommended Reading Order:

For Beginners:

  1. Start with GETTING_STARTED.md - Set up your environment
  2. Read README.md (this file) - Understand the patterns
  3. Follow the Learning Path section - Week-by-week progression
  4. Explore MVC pattern first - Simplest to understand
  5. Refer to TROUBLESHOOTING.md when needed

For Experienced Developers:

  1. Review COMPARISON_GUIDE.md - Compare all patterns quickly
  2. Check BEST_PRACTICES.md - Ensure code quality
  3. Dive into specific patterns based on your needs
  4. Read LEARNING_RESOURCES.md for advanced topics

For Team Leads/Architects:

  1. Study COMPARISON_GUIDE.md - Make informed decisions
  2. Review STANDARDIZATION_SUMMARY.md - Understand consistency approach
  3. Read pattern-specific READMEs for implementation details
  4. Check DDD tech_readme_files/ for enterprise architecture

🎯 When to Use Each Pattern

Use MVC When:

  • ✅ Building small apps (< 5 screens)
  • ✅ Rapid prototyping
  • ✅ Learning Flutter
  • ✅ Personal projects

Use MVVM When:

  • ✅ Medium-sized apps (5-15 screens)
  • ✅ Complex UI state
  • ✅ Reactive programming preferred
  • ✅ Two-way data binding needed

Use Clean Architecture When:

  • ✅ Large apps (15+ screens)
  • ✅ Multiple developers
  • ✅ High testability required
  • ✅ Long-term maintenance

Use DDD When:

  • ✅ Enterprise applications
  • ✅ Complex business logic
  • ✅ Multiple bounded contexts
  • ✅ Domain experts involved
  • ✅ Evolving requirements

🧪 Testing

All patterns are designed to be testable:

  • MVC: Controller testing
  • MVVM: ViewModel testing
  • Clean: Layer-by-layer testing
  • DDD: Pure domain testing + all layers

Run tests:

flutter test

🛠️ Technology Stack

Core Technologies (All Implementations):

  • Flutter: 3.9.2+
  • Dart: 3.9.2+

State Management Options:

BLoC Folder (/bloc/):

  • flutter_bloc: 8.1.3 (State management)
  • hydrated_bloc: 9.1.2 (State persistence)
  • bloc: 8.1.2 (Core BLoC library)
  • shared_preferences: 2.2.2 (Local storage)
  • equatable: 2.0.5 (Value equality)
  • dartz: 0.10.1 (Functional programming - Clean & DDD only)

GetX Folder (/getx/):

  • get: 4.6.6 (State management, routing, DI)
  • get_storage: 2.1.1 (Local persistence)
  • equatable: 2.0.5 (Value equality)
  • dartz: 0.10.1 (Functional programming - Clean & DDD only)
  • uuid: 4.2.1 (Unique identifiers - DDD only)

Additional Packages:

  • cupertino_icons: 1.0.8 (iOS-style icons)
  • path_provider: 2.1.1 (File paths - BLoC only)

⭐ Show Your Support

If this repository helped you learn Flutter architecture patterns, please give it a ⭐ star!

Share it with others who might find it useful!

📄 License

This project is for educational purposes. Feel free to use it for learning and reference.


🎉 What You'll Learn

By working through this repository, you will:

Master 4 Architecture Patterns - MVC, MVVM, Clean Architecture, DDD ✅ Understand Trade-offs - Know when to use each pattern ✅ Learn Best Practices - Professional coding standards ✅ Build Scalable Apps - Structure code for growth ✅ Write Testable Code - Unit, widget, and integration tests ✅ Use Modern Tools - GetX state management and more ✅ Make Informed Decisions - Choose the right pattern for your project


🚀 Quick Links

📖 Essential Documentation

🔍 Comparison Guides


Happy Learning! 🚀 Master Flutter Architecture Patterns!

About

A comprehensive Flutter learning resource demonstrating 4 architecture patterns (MVC, MVVM, Clean Architecture, DDD) with identical features for easy comparison. Includes extensive documentation and best practices.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published