How ahmedabdoelhawary/flutter-clean-architecture-instagram works
The project is a full-stack Flutter application implementing an Instagram-like social media app using a clean architecture pattern. The goal is to provide a comprehensive Instagram clone with functionalities such as posting images and videos, supporting real-time chat, notifications, calling features (video and voice via Agora), and both mobile and web support. Firebase is used extensively for backend services including Authentication, Firestore Database, Storage, and Messaging.
Main Components
• Presentation Layer:
– Located under the “lib/presentation” directory.
– Contains UI screens, blocs/cubits for state management (e.g., StoryCubit, FirebaseAuthCubit, etc.), pages (e.g., Home, Profile, Comments, Story, Chat, Video call), custom packages (audio recorder, crop image, sliding sheet, story view).
• Domain Layer:
– Found under “lib/domain” with entities, use cases, and repository abstractions.
– Includes business logic use cases for authentication, posts (creation, deletion, updating, like/unlike), chat handling, notifications, story operations, and user management.
• Data Layer:
– Located under “lib/data” and consists of data sources (remote APIs, Firebase Firestore calls), model definitions, and repository implementations.
– Manages data interactions with Firebase services (Authentication, Storage, Firestore for posts, comments, notifications, and stories).
• Configuration & Utilities:
– “lib/config” contains routing and theme configurations.
• External Services:
– Firebase services for authentication, Firestore, storage, notifications.
– Agora for video and voice calling.
– Custom packages integrated for additional functionality like image picking, cropping, audio recording, and custom UI elements.
Relationships and Interactions
• The Presentation Layer (UI and state management using Cubit/Bloc) communicates with the Domain layer by triggering use cases.
• The Domain Layer defines interfaces for repositories, which are fulfilled by the Data Layer.
• The Data Layer interacts with the external Firebase services, Agora, and other external dependencies.
• The Config layer routes the user among different pages and sets up the themes, while dependency injection (injector in “lib/core/utility”) ties the layers together.
• Custom packages are reusable components that can be placed as auxiliary modules feeding into the presentation layer (e.g., for recording audio or cropping images).
Architectural Patterns and Design Principles
• Clean Architecture: Separation of concerns among Presentation, Domain, and Data layers.
• MVVM/MVC Style: The structure separates the UI (widgets & pages), state management (Cubit/Bloc), and business logic (use cases).
• Reactive State Management: Leveraging Cubit/Bloc to manage user interactions and data flows.
• Modularization: The “customPackages” folder shows modular design for shared features.
Relevant Technologies
• Flutter for the UI across mobile, web, and desktop.
• Firebase for backend services.
• Agora for realtime communication.
• Bloc/Cubit for state management.
• Dart language and dependency injection pattern for managing use cases and repositories.