Directory Structure
Layer Responsibilities
View Layer (lib/view/)
Contains all Flutter widget screens and UI components. Organized by feature:
- admin/: Administrative interfaces for managing products, events, orders, and users
- cart/: Shopping cart and checkout flows
- home/: Main user-facing screens (catalog, events, profile)
- login/: Authentication screens
- product_detail/: Product details and reviews
- register/: User registration
Component Layer (lib/component/)
Reusable UI widgets shared across multiple screens:
event_card.dart: Display event information in a card formatreview_card.dart: Show user reviews and ratingssmart_network_image.dart: Optimized image loading with caching
Model Layer (lib/model/)
Data transfer objects (DTOs) representing business entities:
- Immutable fields (marked as
final) - Type-safe constructors
fromJsonfactory methods for deserialization- Validation and error handling
Service Layer (lib/service/)
Business logic and Firebase interactions:
firebase_backend.dart: Core Firebase service wrapperauth_session.dart: Session and authentication stateproduct.dart,order.dart,user.dart: Domain-specific servicesapp_error.dart: Custom error types
- Firebase queries and mutations
- Data transformation and validation
- Error handling and reporting
Provider Layer (lib/provider/)
State management using the Provider pattern:
cart_provider.dart: Shopping cart state management
ChangeNotifier and use notifyListeners() to update UI.
Util Layer (lib/util/)
Utility functions and helpers:
error_message.dart: User-friendly error message formatting
Key Files
main.dart
Application entry point that:
- Initializes Flutter framework
- Configures Firebase
- Syncs authentication state
- Sets up Provider for state management
- Defines Material theme
- Launches root widget
firebase_options.dart
Generated configuration file containing Firebase project credentials:
- API keys
- Project IDs
- Storage bucket names
- Platform-specific settings (Android, iOS, Web)
This file is typically generated by
flutterfire configure and should not be manually edited.lib/service/firebase_backend.dart
Centralized Firebase service providing:
- Collection references (users, products, events, reviews)
- Numeric ID generation
- User profile management
- Data normalization
- Error handling
Naming Conventions
The codebase follows Dart/Flutter naming conventions:Files and Directories
- snake_case: All file and directory names use lowercase with underscores
- ✅
auth_session.dart,product_detail.dart - ❌
AuthSession.dart,productDetail.dart
- ✅
Classes
- PascalCase: Class names use upper camel case
- ✅
CartProvider,FirebaseBackend,Product - ❌
cartProvider,firebase_backend
- ✅
Variables and Functions
- camelCase: Variables and functions use lower camel case
- ✅
userId,syncFromFirebase(),totalAmount - ❌
user_id,SyncFromFirebase()
- ✅
Constants
- lowerCamelCase: Constants use lower camel case
- ✅
const background = Color(0xFFEDE3C8); - Note: Dart doesn’t use SCREAMING_SNAKE_CASE for constants
- ✅
Private Members
- Leading underscore: Private members start with
_- ✅
_items,_buildTheme(),_FirebaseSetupScreen - Used for implementation details not exposed outside the file
- ✅
Feature Organization
Features are organized by domain:| Feature | View | Service | Model | Provider |
|---|---|---|---|---|
| Authentication | view/login/, view/register/ | service/auth_session.dart, service/login.dart, service/register.dart | model/login.dart, model/user.dart | - |
| Products | view/home/catalog.dart, view/product_detail/ | service/product.dart | model/product.dart | provider/cart_provider.dart |
| Shopping Cart | view/cart/ | service/order.dart | model/order.dart | provider/cart_provider.dart |
| Events | view/home/event_list.dart, view/admin/event_list.dart | service/roleplay_event.dart | model/roleplay_event.dart | - |
| Admin | view/admin/ | Various services | Various models | - |
Dependency Flow
Dependencies flow inward:- Views depend on providers, services, models, and components
- Providers depend on models and services
- Services depend on models and Firebase
- Models have no dependencies (pure data classes)
- Components can depend on models but not services
Next Steps
Architecture
Learn about the overall architecture
State Management
Understand Provider and state patterns