# ahmedabdoelhawary/flutter-clean-architecture-instagram architecture

> Architecture diagram of the GitHub repository ahmedabdoelhawary/flutter-clean-architecture-instagram, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ahmedabdoelhawary/flutter-clean-architecture-instagram
- Repository: https://github.com/ahmedabdoelhawary/flutter-clean-architecture-instagram

## Overview

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.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        PPT["UI Screens & State Management"]:::presentation
        CP["Custom Packages"]:::presentation
    end

    %% Domain Layer
    subgraph "Domain Layer"
        DM["Entities & Use Cases"]:::domain
    end

    %% Data Layer
    subgraph "Data Layer"
        DL["Data Sources & Repositories"]:::data
    end

    %% External Services
    subgraph "External Services"
        Firebase["Firebase (Auth, Firestore, Storage, Notifications)"]:::external
        Agora["Agora (Video/Voice Calling)"]:::external
    end

    %% Configuration & Utilities
    subgraph "Configuration & Utilities"
        Config["Routing & Theme Config"]:::config
        Core["Dependency Injection & Resources"]:::config
    end

    %% Relationships
    PPT -->|"triggersUseCase"| DM
    DM -->|"callsRepository"| DL
    DL -->|"interactsWithFirebase"| Firebase
    DL -->|"interactsWithAgora"| Agora
    CP -->|"integratesWithUI"| PPT

    Config -->|"routesUI"| PPT
    Core -->|"injectsDepsIntoUI"| PPT
    Core -->|"injectsDepsIntoDomain"| DM
    Core -->|"injectsDepsIntoData"| DL

    %% Click Events
    click PPT "https://github.com/ahmedabdoelhawary/flutter-clean-architecture-instagram/tree/main/lib/presentation"
    click CP "https://github.com/ahmedabdoelhawary/flutter-clean-architecture-instagram/tree/main/lib/presentation/customPackages"
    click DM "https://github.com/ahmedabdoelhawary/flutter-clean-architecture-instagram/tree/main/lib/domain"
    click DL "https://github.com/ahmedabdoelhawary/flutter-clean-architecture-instagram/tree/main/lib/data"
    click Config "https://github.com/ahmedabdoelhawary/flutter-clean-architecture-instagram/tree/main/lib/config"
    click Core "https://github.com/ahmedabdoelhawary/flutter-clean-architecture-instagram/tree/main/lib/core"
    click Firebase "https://github.com/ahmedabdoelhawary/flutter-clean-architecture-instagram/tree/main/lib/data/data_sources/remote"
    click Agora "https://github.com/ahmedabdoelhawary/flutter-clean-architecture-instagram/tree/main/lib/data/data_sources/remote/calling_rooms"

    %% Styles
    classDef presentation fill:#bbdefb,stroke:#0d47a1,stroke-width:2px;
    classDef domain fill:#c8e6c9,stroke:#1b5e20,stroke-width:2px;
    classDef data fill:#ffe0b2,stroke:#e65100,stroke-width:2px;
    classDef external fill:#e0e0e0,stroke:#424242,stroke-width:2px;
    classDef config fill:#d1c4e9,stroke:#512da8,stroke-width:2px;
```
