Menu

Application Architecture

Relevant source files

This document describes the architectural design of the Flutter Mobile Project Template. It provides an overview of the core architectural components, dependency structure, and application initialization flow. This page focuses on the high-level architecture of the application, how components are organized, and how they interact with each other. For specific details about initialization sequence, see App Initialization, and for navigation implementation details, see Routing and Navigation.

Architectural Principles

The Flutter Mobile Project Template follows a modular architecture with clear separation of concerns. The architecture adheres to the following principles:

  1. Modular Design: Functionality is organized into independent packages for reusability and testability
  2. Dependency Injection: Uses Riverpod for dependency management and state handling
  3. Feature-first Organization: Features are encapsulated in their own packages
  4. Clean Architecture: Separation of UI, business logic, and data layers

Sources:

Package Structure

The project is organized into a multi-package structure using Melos for workspace management. The packages are divided into several categories:

Applications

  • app: The main application
  • catalog: UI component showcase application

Core Packages

  • core: Core utilities and base functionality
  • data: Data access layer components
  • designsystem: UI theme definitions and styling
  • model: Shared data models
  • ui: Reusable UI components

Feature Packages

  • debug_mode: Development debugging tools
  • force_update: Forced app update functionality
  • maintain: Maintenance mode features
  • setting: Application settings

Utility Packages

  • pagination: Utilities for paginated data

Sources:

Application Initialization Flow

The application initialization process is handled by the AppInitializer class, which prepares the application environment before the UI is rendered.

Sources:

Dependency Injection and State Management

The application uses Riverpod for dependency injection and state management. The core dependencies are initialized in the AppInitializer and provided to the application through overrides in the ProviderScope.

Key providers include:

  1. buildConfigProvider: Provides build configuration including app flavor
  2. sharedPreferencesProvider: Provides access to persistent storage
  3. routerProvider: Provides the application's routing configuration
  4. themeModeNotifierProvider: Manages the application's theme state
  5. appExceptionNotifierProvider: Manages application exceptions

Sources:

The application uses GoRouter for navigation management. The router configuration is provided through the routerProvider and defines the application's navigation structure.

Sources:

Application Lifecycle Management

The application implements lifecycle management for various features including exception handling, force updates, and theme changes.

Sources:

Feature Architecture Pattern

Each feature package in the application follows a consistent architecture pattern. Feature packages are organized with a clean separation of concerns:

Typical Feature Package Structure

  • l10n/: Localization resources
  • domain/: Feature-specific models and domain logic
  • data/: Repositories and data sources
  • ui/: Feature UI components and screens
  • provider/: State management for the feature

Sources:

Core Packages Architecture

The core packages provide the foundation for the application and are used by multiple feature packages:

cores_core

Provides core utilities, extensions, and base functionality used throughout the application.

cores_data

Implements the data layer, including network clients, repositories, and local storage.

cores_model

Contains shared data models used across the application.

cores_designsystem

Defines the application's visual language through themes, colors, and styling.

cores_ui

Implements reusable UI components based on the design system.

Sources:

Build Flavor System

The application supports different build environments (development, staging, production) through a flavor system. The build flavor is accessed through the BuildConfig interface and implemented in AppBuildConfig.

Sources:

Utility Packages

The template includes utility packages that provide reusable functionality across features:

pagination

The pagination utility provides standardized pagination functionality for lists and collections.

Sources:

Catalog Application

The template includes a separate catalog application that showcases UI components from the design system. This helps with component discovery and visual testing.

Sources:

Summary

The Flutter Mobile Project Template provides a comprehensive, modular architecture that follows modern best practices for Flutter application development. Key characteristics include:

  1. Modular packages for features and core functionality
  2. Clean separation of concerns across UI, business logic, and data layers
  3. Dependency injection with Riverpod for flexible state management
  4. Structured navigation using GoRouter
  5. Consistent feature architecture pattern across feature packages
  6. Build configuration system supporting multiple environments
  7. Shared design system for UI consistency

This architecture promotes maintainability, testability, and scalability while providing a solid foundation for feature development.