# divk-ashwin/food-rescue architecture

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

- Interactive diagram: https://gitdiagram.com/divk-ashwin/food-rescue
- Repository: https://github.com/divk-ashwin/food-rescue

## Overview

##### Main Components
- Mobile Application (Android App) – This is the central piece of the system.
- User Interface Layer – Comprises all UI components such as MainActivity, ComposableScreens.kt, and XML layout files found in the “app/src/main/res/” directory.
- Application Logic Layer – Includes the ViewModels (FoodFeedViewModel, viewModel.kt) and the application-wide class FoodRescueApplication.kt which initializes Firebase. This layer follows the MVVM pattern.
- Data/Repository Layer – Represented by FirestoreRepository.kt. This component abstracts the interaction with the backend.
- Backend Services – Firebase services (both Firestore as the main database and Firebase Authentication). Also include Firebase Cloud Firestore rules and collections as described in the README.
- External Services – Google Maps API integration for map-based features, which allows location display of food posts.

##### Out the Component Relationships
- MVVM Flow: The UI components call the ViewModel for business logic. Then, the ViewModel communicates with the Repository (FirestoreRepository) to perform data operations.
- Backend Communication: The Repository directly interfaces with Firebase services – both reading and writing to Firestore and handling authentication. Represent directional data flows (requests and responses) between these components.
- External API Calls: The app also integrates with Google Maps; so include a connection between UI components (or possibly a dedicated “Maps” component within the UI) and the external Google Maps API.

##### Architectural Patterns and Design Principles
- MVVM Pattern: Emphasize the clear separation between UI (Composable screens and layouts), the ViewModels (handling the app’s logic), and the Repository (data abstraction with Firebase).
- Separation of Concerns: Each component is responsible for a specific set of tasks:
– UI handles rendering and user interaction.
– ViewModel manages state and mediates between UI and the data layer.
– Repository encapsulates data operations (CRUD operations with Firestore).
- Modularization: The project structure separates concerns by using directories for UI, business logic, and repository code. Indicate this modularity with clearly labeled blocks.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External User and Mobile Application Container
    User("User"):::external
    App("FoodRescue Mobile App"):::app

    %% Mobile Application Subgraph
    subgraph "Mobile Application"
        %% User Interface Layer
        UI("User Interface Layer"):::ui
        subgraph "UI Components"
            Main("MainActivity.kt"):::ui
            Screens("ComposableScreens.kt"):::ui
            Layout("Activity Layouts"):::ui
        end

        %% Application Logic Layer
        Logic("Application Logic Layer"):::logic
        subgraph "Logic Components"
            FeedVM("FoodFeedViewModel.kt"):::logic
            OtherVM("viewmodel.kt"):::logic
            AppInit("FoodRescueApplication.kt"):::logic
        end

        %% Data/Repository Layer
        Data("Data/Repository Layer"):::data
        subgraph "Repository Components"
            Repository("FirestoreRepository.kt"):::data
        end
    end

    %% External Backend and Services
    Firebase("Firebase Services"):::backend
    Maps("Google Maps API"):::external_service

    %% Connections
    User -->|"interacts"| UI
    Main -->|"calls"| FeedVM
    Screens -->|"calls"| FeedVM
    FeedVM -->|"operates"| Repository
    OtherVM -->|"operates"| Repository
    AppInit -->|"initializes"| Firebase
    Repository -->|"readsWrites"| Firebase
    UI -->|"integrates"| Maps

    %% Click Events
    click App "https://github.com/divk-ashwin/food-rescue/tree/master/app/"
    click Main "https://github.com/divk-ashwin/food-rescue/blob/master/app/src/main/java/com/example/food_rescue/MainActivity.kt"
    click Screens "https://github.com/divk-ashwin/food-rescue/blob/master/app/src/main/java/com/example/food_rescue/ComposableScreens.kt"
    click Layout "https://github.com/divk-ashwin/food-rescue/blob/master/app/src/main/res/layout/activity_main.xml"
    click FeedVM "https://github.com/divk-ashwin/food-rescue/blob/master/app/src/main/java/com/example/food_rescue/FoodFeedViewModel.kt"
    click OtherVM "https://github.com/divk-ashwin/food-rescue/blob/master/app/src/main/java/com/example/food_rescue/viewmodel.kt"
    click AppInit "https://github.com/divk-ashwin/food-rescue/blob/master/app/src/main/java/com/example/food_rescue/FoodRescueApplication.kt"
    click Repository "https://github.com/divk-ashwin/food-rescue/blob/master/app/src/main/java/com/example/food_rescue/repository/FirestoreRepository.kt"
    click Firebase "https://github.com/divk-ashwin/food-rescue/blob/master/app/google-services.json"

    %% Styles
    classDef external fill:#ffdead,stroke:#d2691e,stroke-width:2px;
    classDef app fill:#add8e6,stroke:#00008b,stroke-width:2px;
    classDef ui fill:#98fb98,stroke:#006400,stroke-width:2px;
    classDef logic fill:#ffa07a,stroke:#ff4500,stroke-width:2px;
    classDef data fill:#ffe4b5,stroke:#cd853f,stroke-width:2px;
    classDef backend fill:#f08080,stroke:#8b0000,stroke-width:2px;
    classDef external_service fill:#dda0dd,stroke:#9400d3,stroke-width:2px;
```
