flutter_simple_architecture 1.0.2
flutter_simple_architecture: ^1.0.2 copied to clipboard
A robust Flutter bootstrapping tool and project template emphasizing a clean, layer-first architecture with strict state management.
FSA (Flutter Simple Architecture) #
A robust Flutter bootstrapping tool and project template emphasizing a clean, layer-first architecture with strict state management and a centralized design system.
FSA CLI #
The project includes a CLI tool (fsa) to automate project creation and component scaffolding.
Installation #
Install from GitLab (Recommended)
To install fsa globally directly from the repository:
fvm dart pub global activate --source git https://gitlab.com/godoytristanh/fsa.git
Install from Local Source
If you have cloned the repository locally:
fvm dart pub global activate --source path .
Note: Make sure your Dart SDK's bin directory is in your system's PATH (usually ~/.pub-cache/bin).
Local Usage
If you prefer not to install it globally, you can run it directly from the root:
fvm dart bin/fsa.dart <command>
Commands #
-
Create a new project:
fsa create <project_name> <org_name>Bootstraps a new Flutter project with the FSA architecture.
- Clean Template: Removes default counter app boilerplate.
- Automated Config: Pre-configures
hooks_riverpod,freezed, andl10n. - Environment Ready: Includes
.fvmrcandanalysis_options.yaml. - Analysis Passing: Generates code that passes
flutter analyzeimmediately.
-
Generate a Page:
fsa generate page <name>Creates a routeable page with a
Scaffoldinlib/presentation/<name>/. Includesview.dart,ui_state.dart, andui_state_notifier.dart. -
Generate a Smart Component:
fsa generate smart <path/to/name>Creates a complex component with its own independent state management. Useful for logic-heavy widgets nested within pages.
-
Generate a Dumb Component:
fsa generate dumb <path/to/name>Creates a single-file
StatelessWidgetin thewidgets/subfolder of the specified path.
Architectural Principles #
1. Smart vs. Dumb Components #
- Pages/Smart Components: Extend
ViewBuilder. They automate state and notifier access and handle side-effects (dialogs, notifications). - Dumb Components: Simple
StatelessWidgetsthat receive data via constructors. They are purely visual and reside in localwidgets/folders.
2. State Management #
- Manual Riverpod Providers: We strictly use
NotifierProviderandProviderwithout code generation for better stability and transparency. - UI Union States: Every smart component uses a
freezedunion class (Initial,Loading,Success,Error) to represent its UI state.
3. Error Handling #
- Functional Programming: Powered by
fpdart. Repositories returnEither<Failure, T>. - The Guard Wrapper: Asynchronous operations are wrapped in a
guard()function that automatically handles exceptions and logs them viaLoggerService.
4. Design System #
- Sealed Widgets: Base components (
AppButton,AppText,AppDialog) use sealed classes and factory constructors to enforce semantic consistency. - Centralized Theme: All styling is managed in
lib/core/theme/usingThemeExtension.
Project Structure #
bin/: CLI entry point.lib/core/: Global logic, services (Logger, ErrorHandler), and Design System (Sealed Widgets).lib/domain/: Pure business logic, entities, and repository definitions.lib/presentation/: UI layers, divided into Pages and nested Smart Components.
Getting Started #
- Ensure FVM is installed.
- Run
fvm flutter pub get. - Generate boilerplate:
fvm flutter pub run build_runner build --delete-conflicting-outputs. - Run the app:
fvm flutter run.