/firebase_real_time_chat

A modern real-time chat application built with Flutter and Firebase, featuring a clean architecture, robust authentication, and real-time messaging capabilities.

Primary LanguageDart

Novatech Chat

A modern real-time chat application built with Flutter and Firebase, featuring a clean architecture, robust authentication, and real-time messaging capabilities.

Overview

Novatech Chat is a full-featured chat application that demonstrates modern Flutter development practices and architectural patterns. The app includes:

  • Real-time messaging with Firebase Firestore
  • Authentication with both Google Sign-in and Email/Password
  • User presence system (online/offline status)
  • Clean and modern UI using shadcn_ui
  • Form validation using Formz
  • Comprehensive test coverage

Architecture πŸ—οΈ

The project follows Clean Architecture principles, separated into distinct layers:

lib/
β”œβ”€β”€ app/                  # App initialization and configuration
β”œβ”€β”€ authentication/       # Authentication feature
β”‚   β”œβ”€β”€ bloc/            # Authentication business logic
β”‚   β”œβ”€β”€ view/            # Authentication UI components
β”‚   └── models/          # Authentication-related models
β”œβ”€β”€ core/                # Core functionality and shared code
β”‚   β”œβ”€β”€ data/           
β”‚   β”‚   β”œβ”€β”€ datasource/  # Remote data sources
β”‚   β”‚   └── repository/  # Repository implementations
β”‚   └── domain/
β”‚       β”œβ”€β”€ models/      # Domain entities
β”‚       └── usecase/     # Business logic use cases
β”œβ”€β”€ chats/               # Chat feature
β”‚   β”œβ”€β”€ bloc/           
β”‚   β”œβ”€β”€ view/           
β”‚   └── models/         
└── register/            # User registration feature
    β”œβ”€β”€ bloc/           
    β”œβ”€β”€ view/           
    └── models/         

Architecture Diagram

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚     UI Layer    β”‚     β”‚  BLoC Layer  β”‚     β”‚ Repository     β”‚
β”‚  (Flutter Views)│────▢│(Business     │────▢│   Layer        β”‚
β”‚                 β”‚     β”‚   Logic)     β”‚     β”‚                β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                                     β”‚
                                                     β–Ό
                                            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                                            β”‚  Data Sources  β”‚
                                            β”‚   (Firebase)   β”‚
                                            β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Technical Decisions and Trade-offs πŸ€”

State Management

  • BLoC Pattern: Chosen for its clear separation of concerns and excellent testability
  • Formz: Used for form validation to maintain consistent validation logic across the app

Authentication

  • Dual authentication methods (Google & Email/Password) for flexibility
  • Firebase Auth for secure user management
  • User profiles stored in Firestore to maintain additional user data

Real-time Features

  • Firebase Firestore for real-time messages and user presence
  • Optimistic UI updates for better user experience
  • Batch operations for efficient database access

Testing Strategy

  • Comprehensive unit tests for business logic
  • Integration tests for critical user flows
  • Mock repositories for isolated testing

Firebase Emulator Setup πŸ”₯

To run the app with Firebase Emulator Suite:

  1. Install Firebase CLI:

    npm install -g firebase-tools
  2. Login to Firebase:

    firebase login
  3. Initialize Firebase project:

    firebase init emulators
  4. Start the emulators with data persistence:

    firebase emulators:start --import=./firebase-data --export-on-exit=./firebase-data

This will:

  • Start Authentication and Firestore emulators
  • Import existing data from ./firebase-data (if it exists)
  • Export data to ./firebase-data when stopping

Emulator Configuration

The emulators will run on these default ports:

  • Authentication: 9099
  • Firestore: 8080
  • UI: 4000

You can configure these in firebase.json:

{
  "emulators": {
    "auth": {
      "port": 9099
    },
    "firestore": {
      "port": 8080
    },
    "ui": {
      "port": 4000
    }
  }
}

Getting Started πŸš€

This project contains 3 flavors:

  • development (uses emulators)
  • staging
  • production

To run the desired flavor:

# Development (with emulators)
flutter run --flavor development --target lib/main_development.dart

# Staging
flutter run --flavor staging --target lib/main_staging.dart

# Production
flutter run --flavor production --target lib/main_production.dart

Running Tests πŸ§ͺ

Run all tests with coverage:

flutter test --coverage --test-randomize-ordering-seed random

View coverage report:

genhtml coverage/lcov.info -o coverage/

License πŸ“

This project is licensed under the MIT License - see the LICENSE file for details.