The Chatify application follows the Model-View-ViewModel (MVVM) architectural pattern using Flutter's Provider state management solution. This ensures separation of concerns, testability, and maintainability.
Responsibility: Manages all Firestore database operations
Key Functions:
├── User Management
│ ├── createUser() - Create new user profile
│ ├── getUser() - Retrieve user data
│ ├── getUsers() - Get all users list
│ └── updateUserLastSeenTime() - Update activity status
│
├── Chat Management
│ ├── createChat() - Initialize new conversation
│ ├── getChats() - Retrieve user's chats
│ └── getChatMessages() - Load chat history
│
└── Message Operations
├── sendChatMessage() - Store new message
├── deleteMessage() - Remove message
└── streamMessagesForChat() - Real-time listenerFirebase Collections Structure:
Firestore Database
├── Users/
│ ├── {userId}/
│ │ ├── name: String
│ │ ├── email: String
│ │ ├── image: String
│ │ └── last_active: Timestamp
│
└── Chats/
├── {chatId}/
│ ├── is_group: Boolean
│ ├── is_activity: Boolean
│ ├── members: Array
│ └── messages/
│ ├── {messageId}/
│ │ ├── content: String
│ │ ├── sender_id: String
│ │ ├── sent_time: Timestamp
│ │ └── type: String
Responsibility: Handles Firebase Storage operations for media files
Key Functions:
├── Image Upload
│ ├── saveUserImageToStorage() - Profile pictures
│ └── saveChatImageToStorage() - Chat media
│
├── File Management
│ ├── generateDownloadURL() - Get accessible URLs
│ ├── deleteFile() - Remove uploaded files
│ └── getFileMetadata() - File information
│
└── Storage Organization
├── users/{userId}/images/ - User profile images
└── chats/{chatId}/images/ - Chat media filesResponsibility: Device media access and file handling
Key Functions:
├── File Selection
│ ├── pickImageFromLibrary() - Gallery access
│ ├── pickImageFromCamera() - Camera capture
│ └── pickMultipleImages() - Batch selection
│
├── Image Processing
│ ├── compressImage() - Optimize file size
│ ├── resizeImage() - Adjust dimensions
│ └── validateImageFormat() - Format checking
│
└── Permission Handling
├── requestCameraPermission()
├── requestStoragePermission()
└── checkPermissionStatus()Responsibility: Centralized route management and navigation
Key Functions:
├── Navigation Control
│ ├── navigateToRoute() - Push new screen
│ ├── navigateToReplacement() - Replace current
│ ├── goBack() - Pop navigation stack
│ └── removeAndNavigateToRoute() - Clear stack
│
├── Route Management
│ ├── generateRoute() - Dynamic routing
│ ├── getRouteName() - Current route info
│ └── canPop() - Navigation state check
│
└── Navigation Context
├── navigatorKey - Global navigation key
└── currentContext - Current build contextResponsibility: User authentication state management
State Management:
├── Authentication State
│ ├── user: ChatUser - Current user data
│ ├── isLoading: bool - Auth operation status
│ └── authState: AuthState - Login status
│
├── Authentication Methods
│ ├── loginUserWithEmailAndPassword() - User login
│ ├── registerUserWithEmailAndPassword() - User signup
│ ├── logout() - Sign out user
│ └── autoLogin() - Session restoration
│
└── User Profile Management
├── updateUserProfile() - Modify user data
├── uploadProfileImage() - Change avatar
└── deleteUserAccount() - Account removalResponsibility: Chat list management and operations
State Management:
├── Chat Data
│ ├── chats: List<Chat> - User's conversations
│ ├── isLoading: bool - Loading state
│ └── selectedChatIndex: int - UI selection
│
├── Chat Operations
│ ├── getChats() - Load chat list
│ ├── createNewChat() - Start conversation
│ ├── deleteChat() - Remove conversation
│ └── markChatAsRead() - Update read status
│
└── Real-time Updates
├── chatStreamSubscription - Live data stream
├── updateChatList() - Refresh data
└── sortChatsByLastMessage() - Order chatsResponsibility: Individual chat interaction management
State Management:
├── Message Data
│ ├── messages: List<ChatMessage> - Chat history
│ ├── chat: Chat - Current conversation
│ └── isLoading: bool - Load status
│
├── Message Operations
│ ├── sendTextMessage() - Send text
│ ├── sendImageMessage() - Send media
│ ├── deleteMessage() - Remove message
│ └── editMessage() - Modify content
│
├── Real-time Communication
│ ├── messageStreamSubscription - Live messages
│ ├── listenToMessages() - Setup listener
│ └── updateMessageList() - Refresh UI
│
└── Chat Functionality
├── markMessagesAsRead() - Read receipts
├── typing indicators - Show typing status
└── scrollToBottom() - UI navigationResponsibility: User discovery and management
State Management:
├── User Data
│ ├── users: List<ChatUser> - Available users
│ ├── selectedUsers: List<String> - Group chat selection
│ └── isLoading: bool - Load status
│
├── User Operations
│ ├── getUsers() - Load user list
│ ├── getUsersWithFilter() - Search users
│ ├── selectUser() - Choose for chat
│ └── createChatWithSelectedUsers() - Start conversation
│
└── User Status Management
├── updateUserStatus() - Online/offline
├── getLastActiveTime() - Activity tracking
└── refreshUserList() - Data refresh- Purpose: App initialization and loading screen
- Components: Loading animation, Firebase setup, auto-navigation
- Lifecycle: 2-3 seconds display → Authentication check → Route to appropriate page
- Purpose: User authentication interface
- Components: Email/password fields, validation, login button, register link
- Interactions: Form validation, Firebase auth, error handling, navigation
- Purpose: New user account creation
- Components: Name/email/password fields, image picker, submit button
- Interactions: Input validation, image upload, account creation, profile setup
- Purpose: Main navigation hub
- Components: Bottom navigation bar, tab views, app bar, floating action button
- Tabs: Chats tab, Users tab, settings menu
- Purpose: Display conversation list
- Components: Chat tiles, last message preview, unread badges, search bar
- Interactions: Chat selection, swipe actions, pull-to-refresh
- Purpose: Individual chat interface
- Components: Message list, input field, send button, media picker
- Features: Real-time messages, media sharing, scroll management
- Purpose: User discovery and selection
- Components: User tiles, online indicators, search functionality
- Interactions: User selection, chat initiation, profile viewing
Components:
├── CustomTextField - Standard text input
├── CustomPasswordField - Password with visibility toggle
├── CustomEmailField - Email with validation
└── CustomSearchField - Search with iconsComponents:
├── UserTile - User list item with avatar and status
├── ChatTile - Chat list item with preview
├── MessageTile - Individual message display
└── MediaTile - Image/video message displayComponents:
├── TextMessageBubble - Text message container
├── ImageMessageBubble - Image message with preview
├── TimestampBubble - Message time display
└── StatusBubble - Read/delivered indicatorsVariants:
├── PrimaryButton - Main action buttons
├── SecondaryButton - Secondary actions
├── IconButton - Icon-based buttons
└── FloatingButton - Floating action buttonsTypes:
├── ProfileImage - User avatar display
├── NetworkImage - Remote image loading
├── LocalImage - Local file display
└── PlaceholderImage - Loading stateFeatures:
├── CustomAppBar - Standard app bar
├── ChatAppBar - Chat-specific header
├── SearchAppBar - Search functionality
└── BackAppBar - Navigation back buttonProperties:
├── uid: String - Unique user identifier
├── name: String - User display name
├── email: String - User email address
├── imageURL: String - Profile picture URL
└── lastActive: DateTime - Last activity timestamp
Methods:
├── fromJSON() - Parse from Firestore data
├── toMap() - Convert to Map for storage
└── copyWith() - Create modified copyProperties:
├── senderID: String - Message sender identifier
├── type: MessageType - TEXT, IMAGE, or UNKNOWN
├── content: String - Message content or URL
└── sentTime: DateTime - Message timestamp
Enums:
└── MessageType { TEXT, IMAGE, UNKNOWN }
Methods:
├── fromJSON() - Parse from Firestore
└── toMap() - Convert for storageProperties:
├── uid: String - Chat unique identifier
├── currentUserUID: String - Current user ID
├── activity: bool - Chat activity status
├── group: bool - Group chat indicator
├── members: List<ChatUser> - Chat participants
└── messages: List<ChatMessage> - Chat message history
Methods:
├── fromJSON() - Parse chat data
├── toMap() - Convert for storage
├── lastMessage() - Get most recent message
└── isRead() - Check read statusFunctions:
├── checkFirebaseConnection() - Test connectivity
├── validateFirebaseConfig() - Configuration check
├── testAuthentication() - Auth service test
└── testDatabaseAccess() - Firestore connectivityService Registration:
├── NavigationService - Global navigation
├── DatabaseService - Firestore operations
├── CloudStorageService - Firebase storage
└── MediaService - Device media access
Provider Setup:
├── AuthenticationProvider - User state
├── ChatsPageProvider - Chat list state
├── ChatPageProvider - Individual chat state
└── UsersPageProvider - Users list stateUI Event → Provider Method → Service Call → Firebase Operation → State Update → UI Rebuild
Firestore Change → Stream Listener → Provider Update → UI Notification → User Interface Refresh
- Firebase Authentication with JWT tokens
- Automatic session management
- Secure logout and session cleanup
- Firestore security rules
- User-specific data access
- Role-based permissions
- Firebase Storage rules
- File access validation
- Secure URL generation
This architecture ensures scalability, maintainability, and optimal performance for real-time chat functionality.