Skip to main content

Directory Layout

app/flutter/
├── android/           # Android-specific code
├── ios/               # iOS-specific code
├── lib/               # Main Dart code
├── test/              # Unit and widget tests
├── assets/            # Images, fonts, etc.
├── pubspec.yaml       # Dependencies
└── analysis_options.yaml  # Lint rules

The lib/ Directory

lib/
├── cache/                    # Cache layer
│   ├── cache.dart           # Barrel exports
│   ├── cache_manager.dart   # Main cache API
│   ├── database/            # SQLite setup
│   ├── models/              # Data models
│   ├── providers/           # Storage providers
│   ├── repositories/        # CRUD operations
│   └── services/            # Sync service
├── app/
│   ├── app.dart            # App exports
│   └── view/
│       └── app.dart        # Root app widget
├── l10n/                   # Internationalization
├── bootstrap.dart          # App initialization
└── main_*.dart             # Entry points

Cache Layer

The most important directory:
PathPurpose
cache/models/Data models (Wallet, Transaction, etc.)
cache/repositories/Database operations
cache/services/Sync logic
cache_manager.dartMain API for app code

Entry Points

  • main_development.dart - Development mode
  • main_staging.dart - Staging mode
  • main_production.dart - Production mode
All call bootstrap.dart for initialization.

Key Files

bootstrap.dart

App initialization:
Future<void> bootstrap(...) async {
  // Initialize cache
  final cache = await CacheManager.initialize();
  
  // Configure sync
  cache.configureSync(apiClient);
  
  // Auto-sync on startup
  await cache.initializeSync();
  
  runApp(...);
}

pubspec.yaml

Dependencies include:
dependencies:
  flutter:
    sdk: flutter
  sqflite: ^2.3.0          # SQLite
  path_provider: ^2.1.1    # File paths
  uuid: ^4.2.1             # UUID generation
  bloc: ^9.2.0             # State management
  flutter_bloc: ^9.1.1

Best Practices

  1. Feature-based folders - Group by feature, not type
  2. Barrel exports - Use index.dart or *.dart for clean imports
  3. Separation of concerns - UI, business logic, data layers separate
  4. Dependency injection - Inject repositories into blocs/cubits