# faresouhachi/thriftcorner architecture

> Architecture diagram of the GitHub repository faresouhachi/thriftcorner, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/faresouhachi/thriftcorner
- Repository: https://github.com/faresouhachi/thriftcorner

## Overview

##### Project Type and Purpose
- This is a full-stack mobile application built with Flutter.
- It targets Android and iOS (see android/ and ios/ folders).
- It uses a Clean Architecture approach (layers: presentation, domain, data).
- Backend and persistence are provided via Firebase (Auth, Firestore/Realtime DB, Storage).

##### Main Components
a. Mobile Client (Flutter App)
– Presentation Layer
· Screens, Controllers, Widgets (lib/presentation/…)
– Domain Layer
· Business Models, Repositories Interfaces, Use-Case Services (lib/domain/…)
– Data Layer
· Repository Implementations, Firebase Service Wrappers (lib/data/…)
b. Platform Build Targets
– Android native build (android/)
– iOS native build (ios/)
c. External Services
– Firebase Authentication
– Firebase Firestore (or Realtime Database)
– Firebase Storage (for images)
– (Optionally) Firebase Cloud Functions, Analytics

##### Relationships and Data Flows
- UI Widgets ↔ Controllers (presentation)
- Controllers ↔ Domain Services (use-cases)
- Domain Services ↔ Repository Interfaces
- Repository Implementations ↔ Firebase Service Classes
- Firebase Services ↔ Firebase Cloud (Auth/Database/Storage)
- Data flows from user input → UI → controller → domain → data → Firebase and back.

##### Key Architectural Patterns & Design Principles
- Clean Architecture separation of concerns.
- Dependency Inversion: domain layer depends on abstractions; data layer provides implementations.
- Single source of truth via repository pattern.
- Platform-agnostic business logic with Flutter framework for UI.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        direction TB
        MainApp["Main Application Entry\n(lib/main.dart)"]:::frontend
        subgraph "UI Screens"
            direction TB
            AuthScreens["Authentication Screens"]:::frontend
            SectionsScreens["Sections Screens"]:::frontend
        end
        Controllers["HomeController"]:::frontend
        SharedWidgets["CustomTextField Widget"]:::frontend
    end

    %% Domain Layer
    subgraph "Domain Layer"
        direction TB
        DomainRoot["lib/domain"]:::domain
        subgraph "Models"
            direction TB
            ProductModel["ProductModel"]:::domain
            TransactionModel["TransactionModel"]:::domain
            UserModel["UserModel"]:::domain
            ReviewModel["ReviewModel"]:::domain
            WishlistModel["WishlistModel"]:::domain
        end
        subgraph "Repository Interfaces"
            direction TB
            IProductRepo["IProductRepository"]:::domain
            ITransactionRepo["ITransactionRepository"]:::domain
            IUserRepo["IUserRepository"]:::domain
            IWishlistRepo["IWishlistRepository"]:::domain
        end
        subgraph "Service Interfaces"
            direction TB
            IAuthService["IAuthService"]:::domain
            IProductService["IProductService"]:::domain
        end
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        DataRoot["lib/data"]:::data
        subgraph "Repository Implementations"
            direction TB
            ProductRepoImpl["ProductRepositoryImpl"]:::data
            TransactionRepoImpl["TransactionRepositoryImpl"]:::data
            UserRepoImpl["UserRepositoryImpl"]:::data
            WishlistRepoImpl["WishlistRepositoryImpl"]:::data
        end
        subgraph "Firebase Service Wrappers"
            direction TB
            FirebaseAuthService["FirebaseAuthService"]:::data
            ProductServiceData["ProductService"]:::data
        end
    end

    %% External Services
    subgraph "External Firebase Services"
        direction TB
        FirebaseAuth["Firebase Authentication"]:::external
        FirestoreDB["Firebase Firestore/Realtime DB"]:::external
        FirebaseStorage["Firebase Storage"]:::external
        CloudFunctions["Firebase Cloud Functions"]:::external
    end

    %% Platform Targets
    subgraph "Platform Builds"
        direction TB
        Android["Android Build\n(android/)"]:::platform
        iOS["iOS Build\n(ios/)"]:::platform
    end

    %% Connections
    MainApp -->|launches| AuthScreens
    MainApp -->|launches| SectionsScreens
    AuthScreens -->|use| Controllers
    SectionsScreens -->|use| Controllers
    Controllers -->|invoke use-cases| IAuthService
    Controllers -->|invoke use-cases| IProductService
    Controllers -->|invoke repos| IProductRepo
    Controllers -->|invoke repos| IUserRepo

    IAuthService -->|implemented by| FirebaseAuthService
    IProductService -->|implemented by| ProductServiceData
    IProductRepo -->|implemented by| ProductRepoImpl
    ITransactionRepo -->|implemented by| TransactionRepoImpl
    IUserRepo -->|implemented by| UserRepoImpl
    IWishlistRepo -->|implemented by| WishlistRepoImpl

    ProductRepoImpl -->|calls| ProductServiceData
    UserRepoImpl -->|calls| FirebaseAuthService
    TransactionRepoImpl -->|calls| FirestoreDB
    WishlistRepoImpl -->|calls| FirestoreDB
    ProductServiceData -->|SDK calls| FirestoreDB
    FirebaseAuthService -->|SDK calls| FirebaseAuth
    FirebaseStorage -->|stores images| ProductServiceData

    FirebaseAuth -->|auth data| FirebaseAuthService
    FirestoreDB -->|data| ProductRepoImpl
    FirebaseStorage -->|assets| SectionsScreens

    Android -->|builds from| MainApp
    iOS -->|builds from| MainApp

    %% Click Events
    click MainApp "https://github.com/faresouhachi/thriftcorner/blob/master/lib/main.dart"
    click AuthScreens "https://github.com/faresouhachi/thriftcorner/tree/master/lib/presentation/screens/Authentication"
    click SectionsScreens "https://github.com/faresouhachi/thriftcorner/tree/master/lib/presentation/screens/Sections"
    click Controllers "https://github.com/faresouhachi/thriftcorner/blob/master/lib/presentation/controllers/home_controller.dart"
    click SharedWidgets "https://github.com/faresouhachi/thriftcorner/blob/master/lib/presentation/widgets/custom_text_field.dart"
    click DomainRoot "https://github.com/faresouhachi/thriftcorner/tree/master/lib/domain"
    click ProductModel "https://github.com/faresouhachi/thriftcorner/blob/master/lib/domain/models/product_model.dart"
    click TransactionModel "https://github.com/faresouhachi/thriftcorner/blob/master/lib/domain/models/transaction_model.dart"
    click UserModel "https://github.com/faresouhachi/thriftcorner/blob/master/lib/domain/models/user_model.dart"
    click ReviewModel "https://github.com/faresouhachi/thriftcorner/blob/master/lib/domain/models/review_model.dart"
    click WishlistModel "https://github.com/faresouhachi/thriftcorner/blob/master/lib/domain/models/wishlist_model.dart"
    click IProductRepo "https://github.com/faresouhachi/thriftcorner/blob/master/lib/domain/repositories/product_repository.dart"
    click ITransactionRepo "https://github.com/faresouhachi/thriftcorner/blob/master/lib/domain/repositories/transaction_repository.dart"
    click IUserRepo "https://github.com/faresouhachi/thriftcorner/blob/master/lib/domain/repositories/user_repository.dart"
    click IWishlistRepo "https://github.com/faresouhachi/thriftcorner/blob/master/lib/domain/repositories/wishlist_repository.dart"
    click IAuthService "https://github.com/faresouhachi/thriftcorner/blob/master/lib/domain/services/auth_service.dart"
    click IProductService "https://github.com/faresouhachi/thriftcorner/blob/master/lib/domain/services/product_service.dart"
    click DataRoot "https://github.com/faresouhachi/thriftcorner/tree/master/lib/data"
    click ProductRepoImpl "https://github.com/faresouhachi/thriftcorner/blob/master/lib/data/repositories/product_repository.dart"
    click TransactionRepoImpl "https://github.com/faresouhachi/thriftcorner/blob/master/lib/data/repositories/transaction_repository.dart"
    click UserRepoImpl "https://github.com/faresouhachi/thriftcorner/blob/master/lib/data/repositories/user_repository.dart"
    click WishlistRepoImpl "https://github.com/faresouhachi/thriftcorner/blob/master/lib/data/repositories/wishlist_repository.dart"
    click FirebaseAuthService "https://github.com/faresouhachi/thriftcorner/blob/master/lib/data/services/firebase_auth_service.dart"
    click ProductServiceData "https://github.com/faresouhachi/thriftcorner/blob/master/lib/data/services/product_service.dart"
    click Android "https://github.com/faresouhachi/thriftcorner/tree/master/android/"
    click iOS "https://github.com/faresouhachi/thriftcorner/tree/master/ios/"

    %% Styles
    classDef frontend fill:#D0E7FF,stroke:#0284C7,color:#000
    classDef domain fill:#DFFFE0,stroke:#22C55E,color:#000
    classDef data fill:#FFE8CC,stroke:#F97316,color:#000
    classDef external fill:#F3E8FF,stroke:#A855F7,color:#000
    classDef platform fill:#E5E7EB,stroke:#6B7280,color:#000
```
