GitHunt

๐Ÿš€ Flutter MVVM BLoC & Cubit Architecture (Using SOLID Principles)

A scalable Flutter architecture that combines MVVM (Model-View-ViewModel), BLoC & Cubit state management, and follows the SOLID principles to maintain clean, maintainable, and testable code.

ย 

๐Ÿ’ก SOLID Principles Applied

This project follows a clean, layered architecture:

Principle Description
S - Single Responsibility Each class/component has one clear responsibility
O - Open/Closed Entities are open for extension, closed for modification
L - Liskov Substitution Interfaces implemented by substitutable components
I - Interface Segregation No client is forced to depend on unused methods
D - Dependency Inversion High-level modules depend on abstractions, not concretions

ย 

๐Ÿ“ฆ Project Structure

This project follows a clean, layered architecture:

  • MVVM design pattern for clear separation of concerns
  • BLoC & Cubit for reactive state management
  • Strict adherence to SOLID principles
  • Dependency Injection using get_it
  • Scalable and testable folder structure
  • Error handling using sealed UIState pattern
lib/
โ”œโ”€โ”€ core/                             # App initialization, base states, firebase config
โ”‚   โ””โ”€โ”€ Contains foundational setup files like app_initialization, base states, firebase config
โ”‚
โ”œโ”€โ”€ data/                             # API services, network layer, response models
โ”‚   โ”œโ”€โ”€ model/                        # Generic data models like Result, Serializable
โ”‚   โ”œโ”€โ”€ network/                      # API calls and configuration (URLs, base service)
โ”‚   โ”‚   โ””โ”€โ”€ env/                      # Environment-specific variables or config
โ”‚   โ”œโ”€โ”€ storage/                      # Local storage or shared preferences (if any)
โ”‚   โ””โ”€โ”€ ui_state/                     # UIState abstraction for handling loading/error/success states
โ”‚
โ”œโ”€โ”€ dependency_injection/            # Service locator setup (e.g., GetIt)
โ”‚   โ””โ”€โ”€ Central registration point for all services, repositories, cubits
โ”‚
โ”œโ”€โ”€ enum/                             # Application-wide enums (e.g., user roles, status types)
โ”‚
โ”œโ”€โ”€ features/                         # Feature-specific folders (modular architecture)
โ”‚   โ”œโ”€โ”€ authentication/              # Auth-related logic
โ”‚   โ”‚   โ”œโ”€โ”€ api_request/             # Request payloads (DTOs)
โ”‚   โ”‚   โ”œโ”€โ”€ cubit/                   # Cubit classes for state management
โ”‚   โ”‚   โ”œโ”€โ”€ model/                   # Feature-specific models (e.g., login response)
โ”‚   โ”‚   โ”œโ”€โ”€ repository/              # Abstraction and implementation of auth repository
โ”‚   โ”‚   โ”œโ”€โ”€ service/                 # Business logic layer (calls API or local DB)
โ”‚   โ”‚   โ””โ”€โ”€ view/                    # UI screens, widgets for authentication
โ”‚   โ”œโ”€โ”€ profile/                     # Profile-related logic
โ”‚   โ”‚   โ”œโ”€โ”€ api_request/             # Request payloads for updating/fetching profile
โ”‚   โ”‚   โ”œโ”€โ”€ cubit/                   # Profile state management
โ”‚   โ”‚   โ”œโ”€โ”€ model/                   # Profile models (e.g., UserProfile)
โ”‚   โ”‚   โ”œโ”€โ”€ repository/              # Profile repo abstractions and implementations
โ”‚   โ”‚   โ”œโ”€โ”€ service/                 # Profile business logic
โ”‚   โ”‚   โ””โ”€โ”€ view/                    # Profile UI
โ”‚   โ””โ”€โ”€ splash/                      # Splash screen feature (intro, logo, navigation)
โ”‚
โ”œโ”€โ”€ helpers/                          # Utility functions
โ”‚   โ””โ”€โ”€ analytics_helper.dart        # Firebase or analytics-related logic
โ”‚   โ””โ”€โ”€ date_helper.dart             # Date formatting and time utilities
โ”‚
โ”œโ”€โ”€ routing/                          # App routing and navigation
โ”‚   โ”œโ”€โ”€ app_route_name.dart          # Route name constants
โ”‚   โ””โ”€โ”€ app_routes.dart              # Route configuration and navigation logic
โ”‚
โ”œโ”€โ”€ service/                          # Independent services used across the app
โ”‚   โ”œโ”€โ”€ hasInternet/                 # Connectivity check service
โ”‚   โ””โ”€โ”€ push_notification/           # Push notification config, payload, display logic
โ”‚       โ”œโ”€โ”€ notification_helper.dart
โ”‚       โ”œโ”€โ”€ notification_payload.dart
โ”‚       โ”œโ”€โ”€ notification_service.dart
โ”‚       โ””โ”€โ”€ notification_view.dart
โ”‚
โ”œโ”€โ”€ utils/                            # Reusable UI components and extensions
โ”‚   โ”œโ”€โ”€ common_dialog_view/         # Custom dialogs
โ”‚   โ”œโ”€โ”€ extensions/                 # String, DateTime, Iterable extensions, etc.
โ”‚   โ”œโ”€โ”€ text_field_input_formatter/    # Input formatting logic
โ”‚   โ”œโ”€โ”€ upload_images_and_documents/ # Uploading utility
โ”‚   โ”œโ”€โ”€ app_application_bar.dart    # Custom app bar widget
โ”‚   โ”œโ”€โ”€ app_bottom_sheet_body.dart  # Bottom sheet UI
โ”‚   โ”œโ”€โ”€ app_button.dart             # Button component
โ”‚   โ”œโ”€โ”€ app_button_style.dart       # Button styles
โ”‚   โ”œโ”€โ”€ app_check_box.dart          # Checkbox UI
โ”‚   โ”œโ”€โ”€ app_colors.dart             # App color palette
โ”‚   โ”œโ”€โ”€ app_dropdown.dart           # Dropdown UI
โ”‚   โ”œโ”€โ”€ app_global_variables.dart   # Shared global values/constants
โ”‚   โ”œโ”€โ”€ app_icon_button.dart        # Icon button UI
โ”‚   โ”œโ”€โ”€ app_icons.dart              # Centralized icon set
โ”‚   โ”œโ”€โ”€ app_image.dart              # Image UI handler
โ”‚   โ”œโ”€โ”€ app_json.dart               # JSON-related utilities
โ”‚   โ”œโ”€โ”€ app_route.dart              # Route helper or redirection logic
โ”‚   โ”œโ”€โ”€ app_search_bar.dart         # Custom search bar UI
โ”‚   โ””โ”€โ”€ app_string.dart             # Centralized string constants
โ”‚
โ””โ”€โ”€ main.dart                         # Application entry point

ย 

๐Ÿงฉ Asset Management & Icon Configuration

Assets are well-organized in the assets/icons/ directory and are referenced through a centralized Dart file, ensuring clean code, easy access, and consistency across the app.
This Flutter project adheres strictly to naming and structural conventions to ensure scalability and maintainability.

ย 

๐ŸŽจ Folder Structure: assets/icons/

All asset files follow the snake_case naming convention:

assets/
โ””โ”€โ”€ icons/
    โ”œโ”€โ”€ png/
    โ”‚   โ””โ”€โ”€ image_break.png
    โ”œโ”€โ”€ gif/
    โ””โ”€โ”€ svg/
        โ”œโ”€โ”€ camera.svg
        โ”œโ”€โ”€ clear_outline.svg
        โ”œโ”€โ”€ close_circle_outline.svg
  • Dart class filenames should be in snake_case.dart (e.g., app_icons.dart)
  • Folder names should be in snake_case/ (e.g., utils/, features/, etc.)
  • Asset files should use snake_case
  • Dart variable names should follow camelCase

ย 

๐Ÿ“ Feature Folder Structure Explained

๐Ÿ”ท Root: features/
Organizes the app by independent modules, making it scalable and maintainable.

Example:

features/
โ”œโ”€โ”€ authentication/
โ””โ”€โ”€ splash/

Each feature contains its own logic, views, state, and service layer, keeping responsibilities isolated.

ย 

๐Ÿ“ authentication/
A self-contained module responsible for login, signup, OTP, password reset, etc.

โœ… Subfolders:

Folder Purpose
api_request/ Contains DTO (Data Transfer Object) models or request body classes for API calls.
๐Ÿ”น e.g., LoginRequest, RegisterPayload
cubit/ Houses Cubit or Bloc classes for state management.
๐Ÿ”น e.g., AuthCubit, LoginState
model/ Contains response models or shared business models.
๐Ÿ”น e.g., UserModel, LoginResponse
repository/ Defines abstract interfaces and concrete implementations that call services.
๐Ÿ”น e.g., IAuthRepository, AuthRepositoryImpl
service/ Contains classes responsible for actual API calls or business logic.
๐Ÿ”น e.g., AuthService, FirebaseAuthService
view/ UI layer: Screens, pages, widgets used to build the authentication flow.
๐Ÿ”น e.g., login_screen.dart, otp_widget.dart

ย 

๐Ÿ’ก Example Workflow (Login Feature)

1. View (login_screen.dart)
   โฌ‡ calls
2. Cubit (auth_cubit.dart)
   โฌ‡ calls
3. Repository (auth_repository.dart)
   โฌ‡ calls
4. Service (auth_service.dart)
   โฌ‡ calls
5. Sends API Request (login_request.dart)
   โฌ… Receives Response (login_response.dart)
6. Model parsed and handled

This follows the MVVM + BLoC pattern, where View โ†’ ViewModel (Cubit) โ†’ Repository โ†’ Service โ†’ API/Local

ย 

๐Ÿงฑ Benefits of This Structure

  • Scalable: Easy to add new features without affecting others.
  • Testable: You can test cubit, service, and repository independently.
  • Maintainable: Clean separation of responsibilities aligns with SRP from SOLID.
  • Extensible: New features (like profile/, settings/) can follow the same structure.
priteshchitrode/flutter_mvvm_bloc_cubit | GitHunt