How deepkushmarkup/firebase_chatapp works
Project Type and Purpose
• This is a cross-platform mobile chat application built in Flutter.
• It uses Firebase as a Backend-as-a-Service (BaaS) for authentication, real-time data (Firestore), file storage, and notifications.
• It follows an enhanced clean-architecture style with a clear separation of presentation, domain, and data layers. State management is handled via Flutter Bloc (Cubits).
File Structure Analysis
• Root:
• pubspec.yaml, pubspec.lock – dependency definitions
• android/, ios/, linux/, web/ – platform-specific projects for deployment
• assets/ – images, Lottie animations
• lib/ (core Dart code):
• main.dart – application entry point and Firebase initialization
• api/ – low-level wrappers around REST/APIs (notification_access_token.dart, apis.dart)
• helper/ – utilities (dialog helpers, date formatting)
• models/ – domain entities (UserModel, chat_user, message)
• screens/ – UI screens organized by feature (auth, chat, profile, AI screen, group chat)
• widgets/ – reusable UI components (message cards, profile images, dialogs)
• tests/ – unit tests for key screens
Key Technologies and Architectural Patterns
• Flutter Bloc (Cubit) for unidirectional data flow and separation of UI from business logic
• Clean architecture layers:
• Presentation (screens, widgets)
• State Management (Cubit classes)
• Domain/Models (data structures and business rules)
• Data (Firebase Firestore, Storage, Auth, network API wrappers)
• Firebase services: Auth, Firestore, Storage, Cloud Messaging (via apis.dart)
• Real-time data via Firestore streams
Main Components
a. Presentation Layer (Client UI)
• Screens (Login, Register, ChatScreen, GroupChat, AI Screen, Profile, Splash)
• Widgets (MessageCard, ChatUserCard, AIMessageCard, ProfileImage, Dialogs)
b. State Management Layer
• Cubits/Blocs managing request and response flows between UI and domain/data
c. Domain/Data Layer
• Models (UserModel, ChatUser, Message)
• Repositories/Services (FirebaseAuthService, FirestoreService, StorageService, NotificationService)
• API Wrappers (notification_access_token.dart, apis.dart)
d. External Services (BaaS)
• Firebase Auth
• Firestore Database (Chats, Users collections)
• Firebase Storage (media assets)
• Firebase Cloud Messaging (push notifications)
• (Optional) Third-party AI service if used by ai_screen
e. Deployment Pipeline
• Deployment Script (bash script invoking Flutter, build flavors, Firebase CLI)
Relationships and Data Flows
• UI triggers events → Cubit processes event → calls repository/service → interacts with Firebase → returns streams or futures → Cubit emits new state → UI rebuilds.
• Media upload flows: UI → Cubit → StorageService.upload() → returns URL → FirestoreService.createMessage(mediaURL).
• Real-time updates: Firestore stream listeners push new chat documents into Cubit.
• Authentication flow: UI → AuthCubit.login() → FirebaseAuth.signInWithPhoneNumber → onSuccess navigate to HomeScreen.
• Notification flow: NotificationService fetches token via apis.dart, registers with FCM, triggers push notifications.