# rashidsadeed/kitadostu architecture

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

- Interactive diagram: https://gitdiagram.com/rashidsadeed/kitadostu
- Repository: https://github.com/rashidsadeed/kitadostu

## Overview

##### Project type and purpose
- This is a cross‑platform mobile application built with Flutter (“Kitap Dostu”).
- Purpose: allow book lovers to list books for sale/donation and search for second readers by geolocation.

##### File structure
- Top‑level “android” and “ios” folders hold the native wrappers, build files, and configuration (google‑services.json/Info.plist).
- “lib/” is the Dart code:
- main.dart – app entry point
- models/ – domain entities (Book, User)
- providers/ – state‑management classes (AuthProvider, BookProvider)
- services/ – business logic & Firebase access (AuthService, BookService)
- screens/ – UI pages (login, signup, splash, book listing, details, profile, wishlist, home)
- widgets/ – reusable UI components (BookCard, CustomButton)
- Firebase setup: firebase_options.dart, firebase.json
- Assets: app logo, screenshots

##### Architectural patterns
- Flutter + Provider = a light MVVM (View ←→ ViewModel(provider) ←→ Model(Service/Repository))
- Services wrap Firebase Auth and Firestore calls
- Providers expose service methods & hold UI state
- Screens and widgets consume providers for reactive updates

##### Main components
- Mobile Device (Android / iOS)
– Flutter Engine
· UI Layer: Screens & Widgets
· State Layer: Providers (AuthProvider, BookProvider)
· Service Layer: AuthService, BookService
– Platform Channels (native wrappers)
· Android (gradle, Manifest, google‑services.json)
· iOS (Xcode project, Info.plist, GoogleService‑Info.plist)
- External Backend
– Firebase Authentication
– Firebase Firestore
· “users” collection
· “books” collection
- Optional External APIs
– Geolocation / Maps API (for location‑based search)

##### Relationships & data flow
1. User interacts with UI (Screen → Widget)
2. Widget invokes Provider API (e.g., BookProvider.addBook())
3. Provider calls Service (BookService)
4. Service uses Firebase SDK to read/write Firestore or Auth
5. Firebase returns data/result → Service → Provider → UI

##### Architectural patterns & principles
- Separation of concerns (UI vs. state vs. data)
- Single Responsibility (each provider/service handles one domain)
- Reactive data flow via ChangeNotifier/Stream

##### Technologies & frameworks
- Flutter & Dart
- Provider (state management)
- Firebase Auth, Firestore
- Gradle (Android), Xcode (iOS)

## Diagram (Mermaid)

```mermaid
flowchart TB
  %% Mobile Application
  subgraph "Mobile Application"
    direction TB

    %% Flutter Engine Layers
    subgraph "UI Layer"
      direction TB
      LoginScreen["LoginScreen"]:::ui
      SignupScreen["SignupScreen"]:::ui
      SplashScreen["SplashScreen"]:::ui
      HomeScreen["HomeScreen"]:::ui
      BookListingScreen["BookListingScreen"]:::ui
      BookDetailsScreen["BookDetailsScreen"]:::ui
      ProfileScreen["ProfileScreen"]:::ui
      WishlistScreen["WishlistScreen"]:::ui
      BookCard["BookCard"]:::ui
      CustomButton["CustomButton"]:::ui
    end

    subgraph "State Layer"
      direction TB
      AuthProvider["AuthProvider"]:::state
      BookProvider["BookProvider"]:::state
    end

    subgraph "Service Layer"
      direction TB
      AuthService["AuthService"]:::service
      BookService["BookService"]:::service
    end

    %% Platform Channels
    subgraph "Platform Channels"
      direction TB
      subgraph Android
        direction TB
        Gradle["build.gradle"]:::native
        GoogleServicesAndroid["google-services.json"]:::native
        MainActivity["MainActivity.kt"]:::native
      end
      subgraph iOS
        direction TB
        AppDelegate["AppDelegate.swift"]:::native
        InfoPlist["Info.plist"]:::native
        GoogleServicesiOS["GoogleService-Info.plist"]:::native
      end
    end
  end

  %% External Backend
  subgraph "External Backend"
    direction TB
    FirebaseAuth["Firebase Authentication"]:::backend
    subgraph Firestore
      direction TB
      UsersCol["users (collection)"]:::backend
      BooksCol["books (collection)"]:::backend
    end
    GeolocationAPI["Geolocation / Maps API"]:::api
  end

  %% Data Flow
  %% UI to State
  LoginScreen -->|"signIn()"| AuthProvider
  SignupScreen -->|"signUp()"| AuthProvider
  ProfileScreen -->|"getUser()"| AuthProvider
  BookListingScreen -->|"loadBooks()"| BookProvider
  BookDetailsScreen -->|"getBookDetail()"| BookProvider
  WishlistScreen -->|"loadWishlist()"| BookProvider
  HomeScreen -->|"fetchNearbyBooks()"| BookProvider

  %% State to Service
  AuthProvider -->|"signInWithEmail()"| AuthService
  AuthProvider -->|"signUpWithEmail()"| AuthService
  AuthProvider -->|"getCurrentUser()"| AuthService
  BookProvider -->|"addBook(), fetchBooks()"| BookService

  %% Service to Backend
  AuthService -->|"AuthSDK"| FirebaseAuth
  BookService -->|"Firestore SDK"| UsersCol
  BookService -->|"Firestore SDK"| BooksCol
  BookService -->|"useLocation()"| GeolocationAPI

  %% Backend to Service to State to UI (responses)
  FirebaseAuth -->|"authState"| AuthService
  UsersCol -->|"queryResult"| BookService
  BooksCol -->|"queryResult"| BookService
  GeolocationAPI -->|"coordinates"| BookService
  AuthService -->|"userData"| AuthProvider
  BookService -->|"bookData"| BookProvider
  AuthProvider -->|"notifyListeners()"| LoginScreen
  BookProvider -->|"notifyListeners()"| BookListingScreen

  %% Click events
  click LoginScreen "https://github.com/rashidsadeed/kitadostu/blob/main/lib/screens/login_screen.dart"
  click SignupScreen "https://github.com/rashidsadeed/kitadostu/blob/main/lib/screens/signup_screen.dart"
  click SplashScreen "https://github.com/rashidsadeed/kitadostu/blob/main/lib/screens/splash_screen.dart"
  click HomeScreen "https://github.com/rashidsadeed/kitadostu/blob/main/lib/screens/home_screen.dart"
  click BookListingScreen "https://github.com/rashidsadeed/kitadostu/blob/main/lib/screens/book_listing_screen.dart"
  click BookDetailsScreen "https://github.com/rashidsadeed/kitadostu/blob/main/lib/screens/book_details_screen.dart"
  click ProfileScreen "https://github.com/rashidsadeed/kitadostu/blob/main/lib/screens/profile_screen.dart"
  click WishlistScreen "https://github.com/rashidsadeed/kitadostu/blob/main/lib/screens/wishlist_screen.dart"
  click BookCard "https://github.com/rashidsadeed/kitadostu/blob/main/lib/widgets/book_card.dart"
  click CustomButton "https://github.com/rashidsadeed/kitadostu/blob/main/lib/widgets/custom_button.dart"
  click AuthProvider "https://github.com/rashidsadeed/kitadostu/blob/main/lib/providers/auth_provider.dart"
  click BookProvider "https://github.com/rashidsadeed/kitadostu/blob/main/lib/providers/book_provider.dart"
  click AuthService "https://github.com/rashidsadeed/kitadostu/blob/main/lib/services/auth_service.dart"
  click BookService "https://github.com/rashidsadeed/kitadostu/blob/main/lib/services/book_service.dart"
  click Gradle "https://github.com/rashidsadeed/kitadostu/blob/main/android/app/build.gradle"
  click GoogleServicesAndroid "https://github.com/rashidsadeed/kitadostu/blob/main/android/app/google-services.json"
  click MainActivity "https://github.com/rashidsadeed/kitadostu/blob/main/android/app/src/main/kotlin/com/phoenix/kitapdostu/MainActivity.kt"
  click AppDelegate "https://github.com/rashidsadeed/kitadostu/blob/main/ios/Runner/AppDelegate.swift"
  click InfoPlist "https://github.com/rashidsadeed/kitadostu/blob/main/ios/Runner/Info.plist"
  click GoogleServicesiOS "https://github.com/rashidsadeed/kitadostu/blob/main/ios/Runner/GoogleService-Info.plist"

  %% Styles
  classDef ui fill:#D0E6FF,stroke:#0366D6,color:#0366D6
  classDef state fill:#E6F4EA,stroke:#28A745,color:#28A745
  classDef service fill:#FFE5B4,stroke:#FF8C00,color:#FF8C00
  classDef backend fill:#E0DBF5,stroke:#6F42C1,color:#6F42C1
  classDef native fill:#F0F0F0,stroke:#6A737D,color:#6A737D
  classDef api fill:#FDE2E4,stroke:#D73A49,color:#D73A49
```
