priteshchitrode/flutter_mvvm_bloc_cubit
Flutter base project MVVM architecture using BloC & Cubit
๐ 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.