Skip to content

๐Ÿ“ 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
Each module contains everything it needs to function independently.


๐Ÿงช 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.