GitHunt
FA

fantasyrock2020/init-flutter-project

A Flutter boilerplate project provides a starter Flutter project organized with Clean Architecture and SOLID principles. Supported by tool, so you can generate structure quickly. Bloc + GetIt + GoRouter + Fastlane + CICD

Flutter Clean Architecture Project

A Flutter project following Clean Architecture principles and SOLID design patterns, with a modular structure for scalability and maintainability.

๐Ÿ“‹ Table of Contents

๐ŸŽฏ Overview

This project is built using Flutter and implements Clean Architecture with clear separation of concerns across three main layers:

  • Presentation Layer: UI components, BLoC/Cubit for state management
  • Domain Layer: Business logic, Use cases, Repository interfaces
  • Data Layer: Repository implementations, Data sources, Models

The project uses a modular approach with separate packages for domain, data, core, and shared components, making it easy to maintain and scale.

๐Ÿ—๏ธ Architecture

Clean Architecture Layers

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚      Presentation Layer             โ”‚
โ”‚  (Features, BLoC, Widgets)          โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
               โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚        Domain Layer                 โ”‚
โ”‚  (Entities, Use Cases, Repositories)โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
               โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚         Data Layer                  โ”‚
โ”‚  (Models, Data Sources, Repos)      โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Key Principles

  • Dependency Rule: Dependencies point inward (Presentation โ†’ Domain โ† Data)
  • Separation of Concerns: Each layer has a single responsibility
  • Testability: Business logic is independent of frameworks
  • Maintainability: Changes in one layer don't affect others

๐Ÿ“ Project Structure

project_structure/
โ”œโ”€โ”€ lib/                          # Main application code
โ”‚   โ”œโ”€โ”€ core/                     # Core functionality
โ”‚   โ”‚   โ”œโ”€โ”€ bloc/                 # Base BLoC classes and common BLoCs
โ”‚   โ”‚   โ”œโ”€โ”€ constants/            # App constants
โ”‚   โ”‚   โ”œโ”€โ”€ enums/                # Enumerations
โ”‚   โ”‚   โ”œโ”€โ”€ extensions/           # Extension methods
โ”‚   โ”‚   โ”œโ”€โ”€ routing/              # Navigation configuration
โ”‚   โ”‚   โ””โ”€โ”€ asset_generator/      # Generated assets
โ”‚   โ”œโ”€โ”€ di/                       # Dependency injection setup
โ”‚   โ”œโ”€โ”€ features/                 # Feature modules
โ”‚   โ”‚   โ””โ”€โ”€ my_app.dart           # Root app widget
โ”‚   โ””โ”€โ”€ widget/                   # Shared widgets
โ”‚
โ”œโ”€โ”€ domain/                       # Domain layer (package)
โ”‚   โ””โ”€โ”€ lib/
โ”‚       โ”œโ”€โ”€ entities/             # Business entities
โ”‚       โ”œโ”€โ”€ repositories/         # Repository interfaces
โ”‚       โ””โ”€โ”€ usecases/             # Business use cases
โ”‚
โ”œโ”€โ”€ data/                         # Data layer (package)
โ”‚   โ””โ”€โ”€ lib/
โ”‚       โ”œโ”€โ”€ datasource/           # Data sources
โ”‚       โ”‚   โ”œโ”€โ”€ api/              # Remote API
โ”‚       โ”‚   โ””โ”€โ”€ local/            # Local storage
โ”‚       โ”œโ”€โ”€ models/               # Data models
โ”‚       โ””โ”€โ”€ repositories/         # Repository implementations
โ”‚
โ”œโ”€โ”€ packages/                     # Shared packages
โ”‚   โ”œโ”€โ”€ core/                     # Core utilities
โ”‚   โ””โ”€โ”€ shared/                   # Shared UI components
โ”‚
โ”œโ”€โ”€ .tools/                       # Development scripts
โ”‚   โ”œโ”€โ”€ generate_model.sh         # Generate model files
โ”‚   โ”œโ”€โ”€ generate_repository.sh    # Generate repository files
โ”‚   โ””โ”€โ”€ generate_structure.sh     # Generate feature structure
โ”‚
โ”œโ”€โ”€ android/                      # Android platform files
โ”œโ”€โ”€ ios/                          # iOS platform files
โ”œโ”€โ”€ web/                          # Web platform files
โ”œโ”€โ”€ macos/                        # macOS platform files
โ”œโ”€โ”€ linux/                        # Linux platform files
โ””โ”€โ”€ windows/                      # Windows platform files

โœจ Features

Current Features

  • Theme Management: Light/Dark theme support
  • Internationalization: Multi-language support
  • Routing: Navigation with GoRouter

State Management

  • BLoC Pattern: Using flutter_bloc for state management
  • Base BLoC: Reusable base classes for common functionality
  • Status Management: Centralized status handling

๐Ÿš€ Getting Started

Prerequisites

  • Flutter SDK (>=3.10.0)
  • Dart SDK (>=3.10.0)

Installation

  1. Clone the repository

    git clone <repository-url>
    cd project_structure
  2. Install dependencies

    flutter pub get
  3. Install dependencies for packages

    cd domain && flutter pub get && cd ..
    cd data && flutter pub get && cd ..
    cd packages/core && flutter pub get && cd ../..
    cd packages/shared && flutter pub get && cd ../..
  4. Generate code

    dart run build_runner build --delete-conflicting-outputs
  5. Run the app

    flutter run

๐Ÿ”„ Renaming the Project

To rename this project from project_structure to your desired project name, follow these steps:

Step 1: Rename the Root Directory

# Navigate to the parent directory
cd ..

# Rename the project directory
mv project_structure your_project_name
cd your_project_name

Step 2: Update pubspec.yaml

Update the name field in the root pubspec.yaml:

name: your_project_name  # Change from 'project_structure'
description: "Your project description"

Step 3: Update Import Statements

Search and replace all import statements that reference project_structure:

# Find all occurrences
grep -r "project_structure" --include="*.dart" .

# Replace in all Dart files (use your preferred method)
# Option 1: Using sed (macOS/Linux)
find . -name "*.dart" -type f -exec sed -i '' 's/project_structure/your_project_name/g' {} +

# Option 2: Using find and replace in your IDE
# Search: project_structure
# Replace: your_project_name

Step 4: Update Android Configuration

android/settings.gradle:

rootProject.name = 'your_project_name'  // Update if needed

android/app/build.gradle:

applicationId "com.example.your_project_name"  // Update package name

Step 5: Update iOS Configuration

ios/Runner.xcodeproj/project.pbxproj:

  • Search for project_structure and replace with your_project_name

ios/Runner/Info.plist:

  • Update CFBundleName and CFBundleDisplayName if needed

Step 6: Clean and Rebuild

# Clean build files
flutter clean

# Get dependencies again
flutter pub get

# Generate code
dart run build_runner build --delete-conflicting-outputs

# Verify the project works
flutter run

Note: After renaming, make sure to test the app on all target platforms (Android, iOS, Web, etc.) to ensure everything works correctly.

๐Ÿ› ๏ธ Development Tools

Scripts

Make scripts executable:

cd .tools && chmod +x generate_model.sh generate_repository.sh generate_structure.sh

Generate Model

./generate_model.sh

Generate Repository

./generate_repository.sh

Generate Feature Structure

./generate_structure.sh

๐Ÿ”ง Code Generation

Generate all code:

dart run build_runner build --delete-conflicting-outputs

Watch mode (auto-regenerate on changes):

dart run build_runner watch --delete-conflicting-outputs

Generate for specific files:

dart run build_runner build --build-filter "lib/features/**"

Happy Coding! ๐Ÿš€