# m-khallouf/toolshare architecture

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

- Interactive diagram: https://gitdiagram.com/m-khallouf/toolshare
- Repository: https://github.com/m-khallouf/toolshare

## Overview

##### Project type and purpose
- Project type: Cross-platform mobile/web/desktop app built with Flutter (Dart).
- Purpose: A peer-to-peer tool-sharing marketplace. Users list, search, filter, borrow, or lend tools. Includes real-time chat, authentication, and offers.

##### File structure
- Top-level Flutter modules:
– android/, ios/, web/, linux/, macos/, windows/: platform folders generated by Flutter.
– lib/: the Dart application code.
– test/: widget tests.
– screens/: UI pages (home, chat, login/signup, profile, settings).
– services/: business logic & data access (authentication, chat, offers, security).
– models/: data classes (e.g. Message).
– widget/: reusable UI components.
– themes/: light/dark theme management.
– utilities/: barrel export files.
- Config files: pubspec.yaml (dependencies), firebase.json + lib/firebase_options.dart (Firebase setup).

##### README for additional insights
- Backend: Firebase (Auth, Firestore/Real-Time DB).
- Key features: tool search/filter, listing management, chat messaging, authentication.
- No custom servers—entirely client + Firebase.

##### Main components and interactions
a. Components
1. Client App (Flutter)
– UI Layer (screens/, widget/)
– State & Theme Layer (theme_provider)
– Service Layer (services/)
– Data Models (models/)
2. Firebase Backend
– Authentication (Email/Password, Social Login)
– Firestore Database (tools collection, offers, chat rooms, messages)
– Cloud Storage (tool images, user profile pictures)
– Optional Cloud Functions (validation, notifications)
3. Third-party Services
– OAuth providers (Google, Facebook, etc.)
– Push Notifications (FCM)
b. Relationships
- UI → calls Service Layer APIs → read/write Firestore or Auth.
- Auth-Gate widget listens to Auth state changes → UI routing (login vs. home).
- Chat screens subscribe to Firestore “messages” collection for real-time updates.
- Offer submissions write to Firestore “offers” collection.
- Profile changes update Firestore user document + possibly Storage.
- ThemeProvider broadcasts theme changes to UI.
c. Architectural patterns
- Layered architecture: UI → Services → Data
- Dependency Injection in services/security/injections.dart
- MVVM-like separation: Screens (View) bind to Services (ViewModel) using Providers.
- Real-time event-driven flows via Firestore streams.
d. Key technologies
- Flutter & Dart
- Firebase (Auth, Firestore, Storage, Functions)
- Provider or similar state-management for DI & theming
- Platform channels auto-generated by Flutter for Android, iOS, desktop targets

##### Final advice
- Platform folders (android/, ios/, web/) in a small “Generated by Flutter” section—these aren’t hand-written but show target outputs.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client App Entry
    subgraph "Client App (Flutter)" 
        direction TB
        Main["main.dart"]:::client
        click Main "https://github.com/m-khallouf/toolshare/blob/master/lib/main.dart"

        subgraph "UI Layer" 
            direction TB
            Screens["screens/"]:::client
            click Screens "https://github.com/m-khallouf/toolshare/tree/master/lib/screens/"
            Widgets["widget/"]:::client
            click Widgets "https://github.com/m-khallouf/toolshare/tree/master/lib/widget/"

            subgraph "Home"
                HomeScreen["HomeScreen"]:::client
                click HomeScreen "https://github.com/m-khallouf/toolshare/blob/master/lib/screens/home/home_screen.dart"
            end

            subgraph "Chat Screens"
                MsgList["MessagesScreen"]:::client
                click MsgList "https://github.com/m-khallouf/toolshare/blob/master/lib/screens/chat/messages_screen.dart"
                OpenChat["OpenChatRoom"]:::client
                click OpenChat "https://github.com/m-khallouf/toolshare/blob/master/lib/screens/chat/open_chat_room.dart"
                SendMsg["SendMessageScreen"]:::client
                click SendMsg "https://github.com/m-khallouf/toolshare/blob/master/lib/screens/chat/send_message_screen.dart"
            end

            subgraph "Auth Screens"
                Login["LoginScreen"]:::client
                click Login "https://github.com/m-khallouf/toolshare/blob/master/lib/screens/login_signup/login_screen.dart"
                SignUp["SignUpScreen"]:::client
                click SignUp "https://github.com/m-khallouf/toolshare/blob/master/lib/screens/login_signup/sign_up_screen.dart"
                CreateAcc["CreateAccount"]:::client
                click CreateAcc "https://github.com/m-khallouf/toolshare/blob/master/lib/screens/login_signup/create_an_account.dart"
            end

            subgraph "Profile Screens"
                AccSettings["AccountSettings"]:::client
                click AccSettings "https://github.com/m-khallouf/toolshare/blob/master/lib/screens/profile/profile/account_settings_screen.dart"
                EmptyAcc["EmptyAccountView"]:::client
                click EmptyAcc "https://github.com/m-khallouf/toolshare/blob/master/lib/screens/profile/profile/empty_account_screen.dart"
                NonEmptyAcc["NonEmptyAccountView"]:::client
                click NonEmptyAcc "https://github.com/m-khallouf/toolshare/blob/master/lib/screens/profile/profile/not_empty_account.dart"
                PublishAdd["PublishAdd"]:::client
                click PublishAdd "https://github.com/m-khallouf/toolshare/blob/master/lib/screens/profile/profile/publish_add.dart"
                ViewAd["PublishedAdView"]:::client
                click ViewAd "https://github.com/m-khallouf/toolshare/blob/master/lib/screens/profile/profile/published_ad_or_not.dart"
            end

            Settings["SettingsScreen"]:::client
            click Settings "https://github.com/m-khallouf/toolshare/blob/master/lib/screens/profile/settings/settings_screen.dart"

            NavBar["NavBarScreen"]:::client
            click NavBar "https://github.com/m-khallouf/toolshare/blob/master/lib/screens/navbar_screen.dart"
        end

        subgraph "Service Layer"
            direction TB
            AuthService["AuthService"]:::client
            click AuthService "https://github.com/m-khallouf/toolshare/blob/master/lib/services/authentication/auth_service.dart"
            AuthGate["AuthGate"]:::client
            click AuthGate "https://github.com/m-khallouf/toolshare/blob/master/lib/services/authentication/auth_gate.dart"
            LoginHelper["LoginOrRegister"]:::client
            click LoginHelper "https://github.com/m-khallouf/toolshare/blob/master/lib/services/authentication/login_or_register.dart"

            ChatService["ChatService"]:::client
            click ChatService "https://github.com/m-khallouf/toolshare/blob/master/lib/services/chat/chat_service.dart"
            CreateChat["CreateChatRoom"]:::client
            click CreateChat "https://github.com/m-khallouf/toolshare/blob/master/lib/services/chat/create_chat_room.dart"

            OfferService["OfferService"]:::client
            click OfferService "https://github.com/m-khallouf/toolshare/blob/master/lib/services/offers/offer_service.dart"
            SubmitOffer["SubmitOffer"]:::client
            click SubmitOffer "https://github.com/m-khallouf/toolshare/blob/master/lib/services/offers/submit_offer.dart"

            subgraph "Security & DI"
                Injections["injections"]:::client
                click Injections "https://github.com/m-khallouf/toolshare/blob/master/lib/services/security/injections.dart"
                SQLInject["sql_injection"]:::client
                click SQLInject "https://github.com/m-khallouf/toolshare/blob/master/lib/services/security/sql_injection.dart"
            end
        end

        subgraph "Data Models"
            MessageModel["Message Model"]:::client
            click MessageModel "https://github.com/m-khallouf/toolshare/blob/master/lib/models/message.dart"
        end

        subgraph "Theme & State"
            ThemeProvider["ThemeProvider"]:::client
            click ThemeProvider "https://github.com/m-khallouf/toolshare/blob/master/lib/themes/theme_provider.dart"
            LightMode["LightMode"]:::client
            click LightMode "https://github.com/m-khallouf/toolshare/blob/master/lib/themes/light_mode.dart"
            DarkMode["DarkMode"]:::client
            click DarkMode "https://github.com/m-khallouf/toolshare/blob/master/lib/themes/dark_mode.dart"
        end

        subgraph "Firebase Config"
            FirebaseOpts["firebase_options.dart"]:::client
            click FirebaseOpts "https://github.com/m-khallouf/toolshare/blob/master/lib/firebase_options.dart"
            FirebaseCLI["firebase.json"]:::client
            click FirebaseCLI "https://github.com/m-khallouf/toolshare/blob/master/firebase.json"
        end
    end

    %% Generated Platforms
    subgraph "Generated by Flutter"
        direction TB
        Android[/"android/"/]:::client
        IOS[/"ios/"/]:::client
        Web[/"web/"/]:::client
        Linux[/"linux/"/]:::client
        MacOS[/"macos/"/]:::client
        Windows[/"windows/"/]:::client
    end

    %% Firebase Backend
    subgraph "Firebase Backend"
        direction TB
        Auth["Auth"]:::firebase
        Firestore["Firestore DB"]:::firebase
        Storage["Cloud Storage"]:::firebase
        Functions["Cloud Functions"]:::firebase
    end

    %% External Services
    OAuth["OAuth Providers"]:::external
    FCM["FCM (Push Notifications)"]:::external

    %% Client to Services
    Main -->|uses| Screens
    Main -->|uses| ServiceLayer["Service Layer"]
    Screens -->|binds| AuthService
    Screens -->|binds| ChatService
    Screens -->|binds| OfferService
    ThemeProvider -->|broadcasts| Screens

    %% Service to Backend
    AuthService -->|request| Auth
    AuthGate -->|listen| Auth
    ChatService -->|stream| Firestore
    CreateChat -->|write| Firestore
    OfferService -->|write| Firestore
    SubmitOffer -->|write| Firestore
    AuthService -->|upload| Storage
    Screens -->|download images| Storage

    %% Real-time arrows
    ChatService -.->|stream| Firestore
    Firestore -.->|snapshot| MsgList

    %% Firebase to External
    Auth -->|oauth| OAuth
    Functions -->|push| FCM

    %% Styles
    classDef client fill:#D0E8FF,stroke:#0366D6,color:#0366D6
    classDef firebase fill:#E0F8E9,stroke:#34A853,color:#34A853
    classDef external fill:#FFF3CD,stroke:#FF9800,color:#FF9800
```
