In Clean Architecture, which layer contains business logic?
The Domain layer contains entities, use cases, and repository interfaces: the core business logic.
Structure your Flutter project with Clean Architecture layers
You can read this lesson publicly. Sign in to unlock exercises, quiz, and FX progress tracking.
Having trouble? AI is here to help
Ask context-aware questions about this lesson. Free plan: 5 questions/day. Upgrade to Premium for higher daily limits.
Use the AI button at the bottom of the screen
Clean Architecture is a software design approach that organizes code into layers with strict dependency rules. The inner layers contain your core business logic and know nothing about the outer layers. This makes your code framework-independent, meaning you could swap Flutter for another framework and your business logic would remain untouched. In Flutter projects, Clean Architecture typically uses three layers. The Presentation layer contains widgets, screens, and state management classes. The Domain layer holds your business entities, use case classes, and abstract repository interfaces. The Data layer implements those interfaces and handles API calls, database operations, and local caching.
1// ── Folder Structure ──2// lib/3// features/4// auth/5// data/6// datasources/7// auth_remote_datasource.dart8// models/9// user_model.dart10// repositories/11// auth_repository_impl.dart12// domain/13// entities/14// user.dart15// repositories/16// auth_repository.dart (abstract)17// usecases/18// login_usecase.dart19// presentation/20// pages/21// login_page.dart22// providers/23// auth_provider.dart2425// ── Domain Layer: Entity ──26class User {27final String id;28final String name;29final String email;30const User({required this.id, required this.name, required this.email});31}3233// ── Domain Layer: Repository (abstract) ──34abstract class AuthRepository {35Future<User> login(String email, String password);36Future<void> logout();37}3839// ── Domain Layer: Use Case ──40class LoginUseCase {41final AuthRepository repository;42LoginUseCase(this.repository);4344Future<User> call(String email, String password) {45return repository.login(email, password);46}47}4849// ── Data Layer: Repository Implementation ──50class AuthRepositoryImpl implements AuthRepository {51final AuthRemoteDataSource remoteDataSource;52AuthRepositoryImpl(this.remoteDataSource);5354@override55Future<User> login(String email, String password) async {56final model = await remoteDataSource.login(email, password);57return model.toEntity(); // Convert model to domain entity58}5960@override61Future<void> logout() => remoteDataSource.logout();62}
Dependencies point INWARD. Presentation → Domain ← Data. The domain layer NEVER imports from data or presentation layers. This makes business logic testable and framework-independent.
Clean Architecture fails when boundaries are documented but not enforced in code review. Use these guardrails:
This discipline keeps refactoring safe when data sources or UI frameworks change.
Structure your Flutter project with Clean Architecture layers. This lesson adds one more building block for creating stable and user-friendly Flutter apps.
Think in architecture, reliability, and team-level maintainability.
After reading, rewrite the concept in your own words and apply it in a tiny runnable sample.
Each lesson becomes useful when you connect concept, implementation, and real-user outcome together.
Connect this lesson to separation of concerns so your codebase stays maintainable as it grows.
As your app grows, keep UI, state, and data responsibilities separate so each part stays testable and easier to modify.
The Domain layer contains entities, use cases, and repository interfaces: the core business logic.
The Dependency Rule says inner layers cannot know about outer layers. Domain is the innermost layer.
The abstract repository interface is in Domain. The implementation is in Data layer, which handles actual API/database calls.
Something seems incorrect, unclear, or missing? Let us know.
FlutterCraft editorial lessons are reviewed by experienced Flutter developers and updated to stay aligned with modern Flutter and Dart best practices.
Reference docs: Flutter Documentation, Dart Language Tour, and official package documentation where relevant.
Sign in to continue with exercises and quiz for this lesson.
Sign In to Continue