Architecture Layers
The application follows a clean architecture pattern with clear separation of concerns:Flutter + Firebase Stack
The app leverages Firebase services for backend functionality:- Firebase Authentication: User authentication and session management
- Cloud Firestore: NoSQL database for products, events, orders, and reviews
- Firebase Storage: Image and media file storage
- Firebase Core: Platform initialization and configuration
Data Flow
Data flows through the application in a unidirectional pattern:- User Interaction: User interacts with UI widgets
- State Update: Provider or local state is updated
- Service Call: Service layer methods are invoked
- Firebase Request: Service communicates with Firebase backend
- Data Normalization: Firebase data is transformed to models
- UI Update: Widgets rebuild with new data
Authentication Flow
Authentication is managed through theAuthSession service:
Authentication Steps
- User logs in via Firebase Auth
AuthSession.syncFromFirebase()is called- User profile is fetched/created in Firestore
- Session data (token, userId, role) is stored in memory
- App navigates to appropriate screen based on role
Firebase Collections Structure
The Firestore database is organized into the following collections:Collection Schemas
Users Collection
id(int): Numeric user IDname(string): User display nameemail(string): User email addressrol(int): User role (0=customer, 1=admin)firebase_uid(string): Firebase Auth UIDcreated_at(timestamp): Account creation dateupdated_at(timestamp): Last update date
Products Collection
id(int): Numeric product IDnombre(string): Product namedescripcion(string): Product descriptionprecio(string): Product pricecantidad(int): Stock quantityimagen(string): Image URLcategoria(string): Product categoryvaloracion_total(string): Average rating
Events Collection
id(int): Numeric event ID- Event details (name, description, date, etc.)
- Participant information
Reviews Collection
id(int): Numeric review ID- User feedback and ratings
- Product/event references
Firebase Backend Service
TheFirebaseBackend service provides centralized access to Firebase:
Key Features
- Numeric ID Generation: Auto-incrementing IDs for user-friendly references
- Data Normalization: Converts Firestore timestamps to ISO strings
- Error Handling: Centralized error messages for common Firebase errors
- User Profile Management: Ensures user profiles exist in Firestore
Entry Point
The application initializes Firebase inmain.dart:
- Initialize Flutter framework
- Configure and initialize Firebase
- Sync authentication session
- Launch application
Next Steps
Project Structure
Explore the codebase organization
State Management
Learn about Provider and state patterns