๐ Folder Structure¶
This Flutter project is organized with Clean Architecture and Modular Design in mind. Below is an overview of the main directories and what each one is responsible for.
๐ Root Structure¶
lib/
โโโ _core/ # App-wide core logic (DI, theming, routing, localization)
โโโ _shared/ # Shared logic (widgets, utilities, services, etc.)
โโโ modules/ # Feature-based modules (auth, posts, etc.)
โโโ app.dart # App widget setup (MaterialApp.router, theming, localization, etc.)
โโโ main.dart # App entry point
๐ฆ lib/_core/¶
Core configuration and services used across the entire app.
_core/
โโโ error/ # Handles cache, network, and connection-related errors
โโโ layout/ # App layout logic for mobile, tablet, and desktop
โโโ _bootstrap.dart # Initializes libraries and modules at app startup
โโโ __init_module.dart # Registers and configures all feature modules
โโโ app_router.dart # Global route config, guards, and transitions (GoRouter)
โโโ constants.dart # App-wide constants and static config values
โโโ database.dart # Database setup and initialization (e.g., Hive, Drift)
โโโ di.dart # Dependency injection setup and registration (e.g., GetIt)
โโโ http_client.dart # HTTP client setup (e.g., Dio instance with interceptors)
โโโ network_info.dart # Utility to check internet connectivity status
โโโ theme.dart # Light and dark theme configurations
โป๏ธ lib/_shared/¶
Reusable components and logic shared between modules.
_shared/
โโโ blocs/ # Global BLoC or Cubit classes not tied to any specific module
โโโ data/ # Shared data services or models
โโโ domain/ # Shared use cases, entities, and contracts
โโโ features/ # Shared logic or partial features (non-module-specific)
โโโ utils/ # Helpers, extensions, formatters
โโโ widgets/ # Reusable UI components and custom widgets
โโโ shared_module.dart # Initialization logic for shared services or state
โโโ shared_routes.dart # Shared routes accessible across modules
๐ lib/modules/¶
Each module is feature-specific and self-contained.
Example: auth and posts modules
modules/
โโโ auth/
โ โโโ bloc/ # BLoC related to authentication (persists throughout the app lifecycle)
โ โโโ data/ # DTOs, models, repository implementations
โ โโโ domain/ # Entities, use cases, repository contracts
โ โโโ features/ # UI components, screens, and local BLoC logic
โ โโโ __tests__/ # Unit and integration tests specific to the auth module
โ โโโ auth_module.dart # DI setup and initialization for auth
โ โโโ auth_routes.dart # Route definitions specific to auth
โ
โโโ posts/
โ โโโ data/
โ โโโ domain/
โ โโโ features/
โ โโโ __tests__/ # Tests scoped to the posts module
โ โโโ posts_module.dart
โ โโโ posts_routes.dart
๐งช mock (Optional)¶
A simple local Dart server to mock backend APIs without needing Go or Node servers.
mock/
โโโ server/
โโโ routes/
โ โโโ auth.dart # Mock auth endpoints
โ โโโ posts.dart # Mock posts endpoints
โโโ main.dart # Entry file to run the mock server
๐ Summary¶
This structure helps achieve:
โ
Clear separation of concerns
โ
Modular and scalable codebase
โ
Ease of testing and collaboration
โ
Simplicity in adding/removing features
Each module can be dropped in or out without tightly coupling it to the rest of the app.