স্কিপ করে মূল কন্টেন্ট এ যান

Folder Structure বিস্তারিত

FLX CLI Clean Architecture pattern অনুসরণ করে একটি সুসংগত folder structure তৈরি করে। এই structure feature-based এবং layer-based organization follow করে।

🏗 Complete Project Structure

lib/
├── core/ # Core utilities এবং shared components
│ ├── constants/
│ ├── errors/
│ ├── network/
│ ├── utils/
│ └── widgets/
├── features/ # Feature-based modules
│ ├── auth/ # Authentication feature
│ │ ├── data/
│ │ │ ├── datasources/
│ │ │ │ └── auth_remote_data_source.dart
│ │ │ ├── models/
│ │ │ │ └── auth_model.dart
│ │ │ └── repositories/
│ │ │ └── auth_repository_impl.dart
│ │ ├── domain/
│ │ │ ├── entities/
│ │ │ │ └── auth_entity.dart
│ │ │ ├── repositories/
│ │ │ │ └── auth_repository.dart
│ │ │ └── usecases/
│ │ │ └── login_usecase.dart
│ │ └── presentation/
│ │ ├── bindings/
│ │ │ └── auth_binding.dart
│ │ ├── controllers/ # GetX ব্যবহার করলে
│ │ │ └── auth_controller.dart
│ │ ├── bloc/ # BLoC ব্যবহার করলে
│ │ │ ├── auth_bloc.dart
│ │ │ ├── auth_event.dart
│ │ │ └── auth_state.dart
│ │ └── pages/
│ │ └── auth_page.dart
│ ├── dashboard/ # Dashboard feature
│ │ └── ... (same structure)
│ └── profile/ # Profile feature
│ └── ... (same structure)
├── shared/ # Shared utilities এবং components
│ ├── models/
│ ├── repositories/
│ ├── services/
│ └── widgets/
└── main.dart

🎯 Feature-Based Organization

কেন Feature-Based?

✅ Scalability

  • নতুন features যোগ করা সহজ
  • বড় team-এ multiple developers কাজ করতে পারে
  • Modular development approach

✅ Maintainability

  • Related files একসাথে থাকে
  • Feature remove করা সহজ
  • Debugging এবং testing সহজ

✅ Separation of Concerns

  • প্রতিটি feature independent
  • Cross-feature dependencies কম

📁 Feature Folder Breakdown

📊 Data Layer Structure

feature_name/
└── data/
├── datasources/ # External data sources
│ ├── feature_remote_data_source.dart
│ └── feature_local_data_source.dart
├── models/ # Data models
│ └── feature_model.dart
└── repositories/ # Repository implementations
└── feature_repository_impl.dart

🌐 Data Sources

// auth_remote_data_source.dart
abstract class AuthRemoteDataSource {
Future<AuthModel> login(String email, String password);
Future<AuthModel> register(AuthModel user);
Future<void> logout();
}

class AuthRemoteDataSourceImpl implements AuthRemoteDataSource {
final Dio _dio;

AuthRemoteDataSourceImpl(this._dio);


Future<AuthModel> login(String email, String password) async {
final response = await _dio.post('/auth/login', data: {
'email': email,
'password': password,
});
return AuthModel.fromJson(response.data);
}
}

🏗 Models

// auth_model.dart

class AuthModel with _$AuthModel {
const factory AuthModel({
required String id,
required String email,
required String name,
required String token,
}) = _AuthModel;

factory AuthModel.fromJson(Map<String, dynamic> json) =>
_$AuthModelFromJson(json);
}

extension AuthModelX on AuthModel {
AuthEntity toEntity() {
return AuthEntity(
id: id,
email: email,
name: name,
token: token,
);
}
}

🎯 Domain Layer Structure

feature_name/
└── domain/
├── entities/ # Business entities
│ └── feature_entity.dart
├── repositories/ # Repository interfaces
│ └── feature_repository.dart
└── usecases/ # Business use cases
├── feature_usecase.dart
└── specific_usecase.dart

🏷 Entities

// auth_entity.dart

class AuthEntity with _$AuthEntity {
const factory AuthEntity({
required String id,
required String email,
required String name,
required String token,
}) = _AuthEntity;
}

📋 Repository Interfaces

// auth_repository.dart
abstract class AuthRepository {
Future<AuthEntity> login(String email, String password);
Future<AuthEntity> register(String name, String email, String password);
Future<void> logout();
Future<bool> isLoggedIn();
}

🎯 Use Cases

// login_usecase.dart
class LoginUseCase {
final AuthRepository _repository;

LoginUseCase(this._repository);

Future<AuthEntity> call(String email, String password) async {
// Business logic validations
if (email.isEmpty || password.isEmpty) {
throw Exception('Email and password are required');
}

return await _repository.login(email, password);
}
}

🖥 Presentation Layer Structure

feature_name/
└── presentation/
├── bindings/ # Dependency injection
│ └── feature_binding.dart
├── controllers/ # GetX controllers
│ └── feature_controller.dart
├── bloc/ # BLoC files
│ ├── feature_bloc.dart
│ ├── feature_event.dart
│ └── feature_state.dart
└── pages/ # UI pages
├── feature_page.dart
└── widgets/ # Feature-specific widgets
└── feature_widget.dart

🔧 Core এবং Shared Folders

🎯 Core Folder

Application-এর core utilities এবং base classes।

core/
├── constants/
│ ├── app_constants.dart
│ ├── api_constants.dart
│ └── colors.dart
├── errors/
│ ├── exceptions.dart
│ └── failures.dart
├── network/
│ ├── dio_client.dart
│ └── network_info.dart
├── utils/
│ ├── helpers.dart
│ └── validators.dart
└── widgets/
├── custom_button.dart
└── custom_text_field.dart

🤝 Shared Folder

Multiple features-এ ব্যবহৃত components।

shared/
├── models/
│ └── response_model.dart
├── repositories/
│ └── base_repository.dart
├── services/
│ ├── storage_service.dart
│ └── notification_service.dart
└── widgets/
├── loading_widget.dart
└── error_widget.dart

🎨 FLX CLI Generated Structure

GetX Project Structure

flx gen feature auth

Output:

lib/features/auth/
├── data/
│ ├── datasources/
│ │ └── auth_remote_data_source.dart
│ ├── models/
│ │ └── auth_model.dart
│ └── repositories/
│ └── auth_repository_impl.dart
├── domain/
│ ├── entities/
│ │ └── auth_entity.dart
│ ├── repositories/
│ │ └── auth_repository.dart
│ └── usecases/
│ └── auth_usecase.dart
└── presentation/
├── bindings/
│ └── auth_binding.dart
├── controllers/
│ └── auth_controller.dart
└── pages/
└── auth_page.dart

BLoC Project Structure

flx config --state bloc
flx gen feature auth

Output:

lib/features/auth/
├── data/
│ └── ... (same as above)
├── domain/
│ └── ... (same as above)
└── presentation/
├── bindings/
│ └── auth_binding.dart
├── bloc/
│ ├── auth_bloc.dart
│ ├── auth_event.dart
│ └── auth_state.dart
└── pages/
└── auth_page.dart

📝 Naming Conventions

🎯 File Naming

  • snake_case ব্যবহার করুন
  • Feature name prefix ব্যবহার করুন
  • Descriptive names দিন
✅ Correct:
- auth_remote_data_source.dart
- user_profile_controller.dart
- dashboard_repository_impl.dart

❌ Incorrect:
- AuthRemoteDataSource.dart
- userprofilecontroller.dart
- DashRepo.dart

🏷 Class Naming

  • PascalCase ব্যবহার করুন
  • Feature name prefix ব্যবহার করুন
  • Purpose-specific suffix যোগ করুন
✅ Correct:
- AuthRemoteDataSource
- UserProfileController
- DashboardRepositoryImpl

❌ Incorrect:
- authRemoteDataSource
- Userprofilecontroller
- DashRepo

📚 Best Practices

✅ DO

  1. Feature-based organization follow করুন
  2. Layer separation maintain করুন
  3. Consistent naming ব্যবহার করুন
  4. Single responsibility principle follow করুন

❌ DON'T

  1. Cross-layer dependencies তৈরি করবেন না
  2. Features mixing করবেন না
  3. God classes তৈরি করবেন না
  4. Deep nesting avoid করুন

💡 Pro Tip: FLX CLI automatically এই structure follow করে files generate করে, তাই manually structure maintain করার চিন্তা করতে হবে না!