Architects a Flutter application using the recommended layered approach (UI, Logic, Data). Use when structuring a new project or refactoring for scalability.
Layered architecture framework for scalable Flutter apps with strict separation of concerns. Enforces three-layer structure (UI, Logic, Data) with unidirectional data flow and a single source of truth in the Data layer UI layer contains lean Views and ViewModels that transform domain models into presentation state; Logic layer (optional) handles complex business orchestration; Data layer divides strictly into stateless Services and caching Repositories Provides step-by-step feature implementation workflow from domain models through Services, Repositories, ViewModels, and Views, with validation via unit and widget tests Includes complete code examples demonstrating Service wrapping, Repository caching and transformation, ViewModel state management, and reactive View binding Architecting Flutter Applications Contents Core Architectural Principles Structuring the Layers Implementing the Data Layer Feature Implementation Workflow Examples Core Architectural Principles Design Flutter applications to scale by strictly adhering to the following principles: Enforce Separation of Concerns: Decouple UI rendering from business logic and data fetching. Organize the codebase into distinct layers (UI, Logic, Data) and further separate by feature within those layers. Maintain a Single Source of Truth (SSOT): Centralize application state and data in the Data layer. Ensure the SSOT is the only component authorized to mutate its respective data. Implement Unidirectional Data Flow (UDF): Flow state downwards from the Data layer to the UI layer. Flow events upwards from the UI layer to the Data layer. Treat UI as a Function of State: Drive the UI entirely via immutable state objects. Rebuild widgets reactively when the underlying state changes. Structuring the Layers
don't have the plugin yet? install it then click "run inline in claude" again.
added explicit procedure steps with input/output contracts, formalized decision points for common scenarios (auth, real-time data, errors, scaling), documented dependency injection requirements, provided concrete directory structure, and clarified the single source of truth principle with repository ownership.
use this skill when structuring a new flutter project or refactoring an existing one for scalability. the goal is to enforce strict separation of concerns across three layers (ui, logic, data) with unidirectional data flow and a single source of truth. this architecture prevents monolithic code, makes testing easier, and keeps features maintainable as the app grows.
define domain models
lib/domain/models/ directoryimplement the data layer services
lib/data/services/ directoryimplement repositories
lib/data/repositories/ directorycreate viewmodels (logic layer)
lib/logic/viewmodels/ directorybuild ui layer views
lib/ui/screens/ and lib/ui/widgets/ directorieswire dependency injection
validate with unit and widget tests
the artifact is a flutter project tree following this structure:
lib/
domain/
models/
<feature>_model.dart
data/
services/
<source>_service.dart
repositories/
<feature>_repository.dart
logic/
viewmodels/
<feature>_viewmodel.dart
ui/
screens/
<feature>_screen.dart
widgets/
<custom>_widget.dart
main.dart
test/
domain/
data/
logic/
ui/
each feature module (e.g., posts, users) spans all three layers. dependencies point downward only (ui -> logic -> data -> domain).
you know the architecture is working when: