A comprehensive Flutter application demonstrating Clean Architecture principles with BLoC state management. This project serves as a complete reference implementation for building scalable, maintainable, and testable Flutter applications.
- β Clean Architecture implementation (Domain, Data, Presentation layers)
- β BLoC Pattern for state management
- β Dependency Injection with GetIt
- β Repository Pattern for data access
- β Model-View-BLoC architecture
- β Error Handling with custom exceptions and failures
- β Local Storage with SharedPreferences
- β HTTP API Integration (mock implementation)
- β Form Validation and input handling
- β Navigation Management with custom router
- β Theme System (Light/Dark mode support)
- β Responsive Design with consistent spacing
- β Code Documentation for all files and functions
- β Extension Methods for enhanced functionality
- β Custom Widgets and reusable components
For testing the application, use these dummy login credentials:
Email: test@example.com
Password: password
Note: These are the actual mock credentials hardcoded in the authentication system. Any other credentials will result in an "Invalid credentials" error.
Login Screen Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Home Screen
This project follows Uncle Bob's Clean Architecture principles with three distinct layers:
- Entities: Core business objects
- Repositories: Abstract interfaces for data operations
- Use Cases: Business logic implementation
- Models: Data representations with JSON serialization
- Repositories: Concrete implementations of domain interfaces
- Data Sources: Remote (API) and Local (Cache) data sources
- Services: External service integrations
- Screens: UI pages and user interfaces
- Widgets: Reusable UI components
- BLoC: State management and business logic coordination
- Constants: App-wide constants and configuration
- Utils: Helper functions and utilities
- Routes: Navigation and routing logic
- Errors: Exception handling and error management
- DI: Dependency injection setup
lib/
βββ π core/ # Core infrastructure layer
β βββ π constants/ # App-wide constants
β β βββ app_colors.dart # Color palette and theming
β β βββ app_constants.dart # App configuration constants
β β βββ app_dimensions.dart # UI spacing and sizing
β β βββ app_strings.dart # Text constants and i18n prep
β β βββ app_themes.dart # Material theme configuration
β β βββ api_endpoints.dart # API endpoint definitions
β βββ π di/ # Dependency injection
β β βββ injection_container.dart # GetIt service locator setup
β βββ π errors/ # Error handling
β β βββ exceptions.dart # Custom exception classes
β β βββ failures.dart # Domain failure classes
β βββ π helpers/ # Utility helpers
β β βββ network_helper.dart # Network connectivity utilities
β βββ π routes/ # Navigation and routing
β β βββ app_router.dart # Route generation and handling
β β βββ app_routes.dart # Route path constants
β β βββ navigation_service.dart # Global navigation service
β βββ π utils/ # Utility functions
β βββ date_helper.dart # Date formatting and utilities
β βββ string_extensions.dart # String extension methods
β βββ validators.dart # Form validation utilities
βββ π data/ # Data access layer
β βββ π datasources/ # Data source abstractions
β β βββ local_data_source.dart # Local storage interface/impl
β β βββ remote_data_source.dart # API data source interface/impl
β βββ π models/ # Data models with JSON serialization
β β βββ api_response_model.dart # Generic API response wrapper
β β βββ post_model.dart # Post data model
β β βββ user_model.dart # User data model
β βββ π repositories/ # Repository implementations
β β βββ user_repository_impl.dart # User repository concrete impl
β βββ π services/ # External service integrations
β βββ api_service.dart # HTTP API service
β βββ local_storage_service.dart # Local storage service
β βββ notification_service.dart # Push notification service
βββ π domain/ # Business logic layer
β βββ π entities/ # Core business entities
β β βββ post_entity.dart # Post business entity
β β βββ user_entity.dart # User business entity
β βββ π repositories/ # Repository interfaces
β βββ post_repository.dart # Post repository interface
β βββ user_repository.dart # User repository interface
βββ π presentation/ # UI and state management layer
β βββ π bloc/ # BLoC state management
β β βββ π auth/ # Authentication BLoC
β β β βββ auth_bloc.dart # Auth business logic
β β β βββ auth_event.dart # Auth events
β β β βββ auth_state.dart # Auth states
β β βββ π posts/ # Posts BLoC
β β βββ posts_bloc.dart # Posts business logic
β β βββ posts_event.dart # Posts events
β β βββ posts_state.dart # Posts states
β βββ π screens/ # Application screens
β β βββ π auth/ # Authentication screens
β β β βββ login_screen.dart # Login interface
β β β βββ π widgets/ # Auth-specific widgets
β β β βββ login_form.dart # Login form component
β β βββ π home/ # Home screen
β β β βββ home_screen.dart # Main dashboard
β β β βββ π widgets/ # Home-specific widgets
β β β βββ user_info_card.dart # User info component
β β βββ π posts/ # Posts screens
β β β βββ posts_screen.dart # Posts list screen
β β β βββ π widgets/ # Posts-specific widgets
β β β βββ post_card.dart # Post display card
β β β βββ post_item.dart # Post list item
β β βββ π profile/ # Profile screens
β β β βββ profile_screen.dart # User profile interface
β β βββ π splash/ # Splash screen
β β βββ splash_screen.dart # App initialization screen
β βββ π widgets/ # Reusable UI components
β βββ π common/ # Common widgets
β βββ custom_app_bar.dart # Reusable app bar
β βββ custom_button.dart # Styled button component
β βββ custom_text_field.dart # Styled input field
β βββ error_widget.dart # Error display component
β βββ loading_widget.dart # Loading indicators
β βββ skeleton_loader.dart # Skeleton loading animation
βββ main.dart # Application entry point
βββ π test/ # Test files
βββ widget_test.dart # Widget testing suite
- Flutter SDK (3.0.0 or higher)
- Dart SDK (2.17.0 or higher)
- Android Studio / VS Code with Flutter extensions
- Git
-
Clone the repository
git clone https://github.com/CodeBlood004/clean_architecture.git cd clean_architecture -
Install dependencies
flutter pub get
-
Run the application
flutter run
-
Install recommended VS Code extensions:
- Flutter
- Dart
- Bloc
- GitLens
-
Configure your IDE:
- Enable Dart formatting on save
- Set up Flutter snippets
- Configure debugging breakpoints
The app is currently configured with mock data and services. To integrate with real APIs:
- Update API endpoints in
/lib/core/constants/api_endpoints.dart - Configure real HTTP client in
/lib/data/services/api_service.dart - Update data sources in
/lib/data/datasources/remote_data_source.dart - Add environment variables for different build configurations
Customize the app's appearance by modifying:
- Colors:
/lib/core/constants/app_colors.dart - Spacing:
/lib/core/constants/app_dimensions.dart - Themes:
/lib/core/constants/app_themes.dart - Text:
/lib/core/constants/app_strings.dart
# Run all tests
flutter test
# Run tests with coverage
flutter test --coverage
# Run integration tests
flutter test integration_test/- Unit Tests: Business logic testing
- Widget Tests: UI component testing
- Integration Tests: End-to-end flow testing
This project demonstrates:
- Separation of Concerns: Each layer has distinct responsibilities
- Dependency Inversion: High-level modules don't depend on low-level modules
- Testability: Easy to unit test business logic in isolation
- Maintainability: Changes in one layer don't affect others
- Scalability: Easy to add new features and modify existing ones
- Event-Driven Architecture: UI triggers events, BLoC processes them
- State Management: Predictable state changes and updates
- Business Logic Separation: UI is purely reactive to state changes
- Testing: Easy to test business logic with mock events and states
- Data Abstraction: Domain layer doesn't know about data sources
- Multiple Data Sources: Seamless switching between remote/local data
- Caching Strategy: Offline-first approach with proper fallbacks
- Error Handling: Consistent error management across data operations
Contributions are welcome! Please feel free to submit a Pull Request. For major changes:
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
- Follow the existing code style and architecture patterns
- Add appropriate documentation for new features
- Include tests for new functionality
- Update README if necessary
This project is licensed under the MIT License - see the LICENSE file for details.
CodeBlood004
- GitHub: @CodeBlood004
- Flutter Team for the amazing framework
- BLoC Library for state management
- Clean Architecture by Uncle Bob
- GetIt for dependency injection
- Language: Dart
- Framework: Flutter
- Architecture: Clean Architecture + BLoC
- State Management: BLoC Pattern
- Dependency Injection: GetIt
- Testing: Widget & Unit Tests
- Documentation: Comprehensive inline docs
β If you found this project helpful, please consider giving it a star! β
This project serves as a complete reference for implementing Clean Architecture in Flutter applications. Feel free to use it as a starting point for your own projects or as a learning resource.

