How leleocastro/flutter_clean_arch works
Project type and purpose
• This is a multi‐platform Flutter application (mobile, web, desktop) built using Domain-Driven Design (DDD) principles and the BLoC pattern.
• Its purpose is to serve as a template or base “micro-application” that layers UI, domain logic, and data access cleanly.
File structure
• Top-level folders (android, ios, linux, macos, windows, web) hold the platform-specific Flutter shells and generated native code.
• The heart of the code lives under lib/src and splits into three layers:
– ui: pages, widgets, and BLoC components
– domain: entities, repository interfaces, and use cases
– data: data sources, data models, and repository implementations
• A shared folder holds cross-cutting utilities (error wrappers, extensions).
• Tests mirror the lib/src hierarchy, demonstrating a test-driven structure.
README for insights
• The README outlines the three DDD layers (UI, Domain, Data) and shows an example image of the layered hierarchy.
• It confirms the use of BLoC for state management and a clear contracts-and-implementations approach for the data layer.
Key components
a. Presentation Layer (UI)
– Flutter Widgets / Pages (e.g., MeuPage)
– BLoC components (MeuBloc, MeuAppBarBloc, MeuTextFieldBloc)
b. Domain Layer
– Entities (AddressEntity)
– Repository interfaces (MeuRepository)
– Use cases (GetAddressUseCase)
c. Data Layer
– Data sources (MeuDataSource)
– Data models (AddressModel)
– Repository implementations (MeuRepositoryImpl)
d. Shared / Core
– Error handling (BaseError, ResultWrapper)
– Extensions, base states
e. Platform Adapters
– Flutter engine / method channels (android/ios/… folders)
– Asset bundles (assets/images)
f. External Services
– Remote API endpoints (implied by data source)
Relationships and data flow
• UI Widgets → dispatch events to BLoC
• BLoC → invokes Use Case(s) in Domain
• Use Case → calls Repository interface
• Repository Impl → uses Data Source to fetch or persist models
• Data Source → external API or local cache
• Results flow back up through Repository → Use Case → BLoC → UI
Architectural patterns and principles
• Layered (Onion/Hexagonal) architecture with clear boundaries
• Dependency inversion: domain layer depends only on interfaces
• BLoC pattern for unidirectional data flow and state management
• Port-and-adapter approach for platform and external service integrations