# alanxue1/navicart architecture

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

- Interactive diagram: https://gitdiagram.com/alanxue1/navicart
- Repository: https://github.com/alanxue1/navicart

## Overview

Based on an analysis of the file tree and README, NaviCart is a React Native mobile application (built with Expo) designed to manage your pantry and shopping list through features such as AI-powered ingredient categorization, recipe searching, real-time Firebase syncing, and more. The project neatly separates the UI structure into easily distinguishable parts (like the app folder with its tabs, modals, layouts, and screens), and it integrates with external APIs (Google Gemini Pro for AI and Firebase for data sync).

##### And List the Main Components
- Mobile App (Client-Side)
- UI/Navigation Layer: Represent the “app” folder and its subdirectories such as:
▪ Tabs Layout and Screens (app/(tabs)/_layout.tsx, index.tsx, list.tsx, recipes.tsx)
▪ Global Layout (app/_layout.tsx, app/+html.tsx, modal.tsx)
- UI Components: Located in the “components” folder (e.g., EditScreenInfo, ExternalLink, StyledText, Themed)
- Assets: Images and fonts found in the “assets” directory
- Backend / External Services:
- Firebase Firestore: For real-time shopping list syncing and pantry inventory updates (referenced in firebaseConfig.ts)
- Google Gemini Pro API: For AI-powered ingredient categorization (environment configuration in README and usage in project)
- Configuration and Constants:
- Build/Configuration Files: babel.config.js, metro.config.js, tsconfig.json, package.json for overall project setup

##### How Data and Control Flow
- The UI and Navigation: The React Native Navigation (Expo Router) handling transitions between different tabs/screens
- UI Components and Backend: Interaction with Firebase for reading/updating data, and making API calls to Google Gemini Pro for categorization
- That user interactions (like marking items, searching recipes, or long-press deletion) trigger these flows:
- For example, when a user searches for a recipe, a request may process through the UI component, then call the Gemini Pro API for categorization before updating the UI
- Similarly, shopping list updates are sent to Firebase for real-time sync across devices

##### Architectural Patterns and Design Principles
- Separation of Concerns: The separation between the presentation layer (screens and components) and the data interaction layer (Firebase and Gemini API integrations)
- Modular Design: The project is structured in modules (like app screens, assets, and components) to keep the codebase clean
- Reactive Design: Use of Firebase for real-time data sync and Expo’s navigation for responsive screen transitions
- Environment-specific configuration: Using .env files and configuration files to manage API keys and settings securely

##### Relevant Technologies/Frameworks
- React Native with Expo framework – emphasize the cross-platform support for iOS and Android
- TypeScript as the programming language for type safety throughout the project
- Firebase Firestore for data synchronization and real-time updates
- Google Gemini Pro API for AI categorization
- Expo Router / React Native Navigation for handling screen routing and navigation
- Expo Speech API for enabling text-to-speech, supporting accessibility

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Mobile App Subgraph
    subgraph "Mobile App"
        AS("App Root"):::mobile
        subgraph "Tabs Screens"
            layouttabs("Tabs Layout (_layout.tsx)"):::mobile
            index("Tabs Index (index.tsx)"):::mobile
            list("List Screen (list.tsx)"):::mobile
            recipes("Recipes Screen (recipes.tsx)"):::mobile
        end
        subgraph "Global Layout"
            globlay("Global Layout (_layout.tsx)"):::mobile
            html("HTML Template (+html.tsx)"):::mobile
            modal("Modal (modal.tsx)"):::mobile
        end
    end

    %% UI Components Subgraph
    subgraph "UI Components"
        edit("Edit Screen Info"):::mobile
        externalLink("External Link"):::mobile
        styled("Styled Text"):::mobile
        themed("Themed"):::mobile
    end

    %% Assets Subgraph
    subgraph "Assets"
        images("Images"):::mobile
        fonts("Fonts"):::mobile
    end

    %% External Services Subgraph
    subgraph "External Services"
        firebase("Firebase Firestore"):::external
        gemini("Google Gemini Pro API"):::external
    end

    %% Configuration & Constants Subgraph
    subgraph "Configuration & Constants"
        envConst("Env & Constants"):::config
        colors("Colors (constants/Colors.ts)"):::config
        configNode("Config (config.ts)"):::config
        build("Build Configs"):::config
        babel("Babel Config (babel.config.js)"):::config
        metro("Metro Config (metro.config.js)"):::config
        tsconfig("TS Config (tsconfig.json)"):::config
        pkg("PackageJSON (package.json)"):::config
    end

    %% Internal Mobile App Connections
    AS --> layouttabs
    layouttabs --> index
    layouttabs --> list
    layouttabs --> recipes
    AS --> globlay
    globlay --> html
    globlay --> modal

    %% Connections between Mobile App and UI Components / Assets
    index --> edit
    index --> styled
    modal --> externalLink
    AS --> images
    AS --> fonts

    %% UI Components interacting with External Services
    list -->|"RealtimeSync"| firebase
    recipes -->|"RealtimeSync"| firebase
    edit -->|"AI_Categorize"| gemini

    %% Configuration influencing External Services
    envConst -->|"Configures"| firebase
    envConst -->|"Configures"| gemini
    configNode -->|"Provides Settings"| gemini

    %% Build Configurations Breakdown
    build --> babel
    build --> metro
    build --> tsconfig
    build --> pkg

    %% Click Events for Mobile App
    click AS "https://github.com/alanxue1/navicart/tree/main/app"
    click layouttabs "https://github.com/alanxue1/navicart/blob/main/app/(tabs)/_layout.tsx"
    click index "https://github.com/alanxue1/navicart/blob/main/app/(tabs)/index.tsx"
    click list "https://github.com/alanxue1/navicart/blob/main/app/(tabs)/list.tsx"
    click recipes "https://github.com/alanxue1/navicart/blob/main/app/(tabs)/recipes.tsx"
    click globlay "https://github.com/alanxue1/navicart/blob/main/app/_layout.tsx"
    click html "https://github.com/alanxue1/navicart/blob/main/app/+html.tsx"
    click modal "https://github.com/alanxue1/navicart/blob/main/app/modal.tsx"

    %% Click Events for UI Components
    click edit "https://github.com/alanxue1/navicart/blob/main/components/EditScreenInfo.tsx"
    click externalLink "https://github.com/alanxue1/navicart/blob/main/components/ExternalLink.tsx"
    click styled "https://github.com/alanxue1/navicart/blob/main/components/StyledText.tsx"
    click themed "https://github.com/alanxue1/navicart/blob/main/components/Themed.tsx"

    %% Click Events for Assets
    click images "https://github.com/alanxue1/navicart/tree/main/assets/images"
    click fonts "https://github.com/alanxue1/navicart/tree/main/assets/fonts"

    %% Click Events for External Services
    click firebase "https://github.com/alanxue1/navicart/blob/main/firebaseConfig.ts"
    click gemini "https://github.com/alanxue1/navicart/blob/main/config.ts"

    %% Click Events for Configuration & Constants
    click colors "https://github.com/alanxue1/navicart/blob/main/constants/Colors.ts"
    click configNode "https://github.com/alanxue1/navicart/blob/main/config.ts"
    click babel "https://github.com/alanxue1/navicart/blob/main/babel.config.js"
    click metro "https://github.com/alanxue1/navicart/blob/main/metro.config.js"
    click tsconfig "https://github.com/alanxue1/navicart/blob/main/tsconfig.json"
    click pkg "https://github.com/alanxue1/navicart/blob/main/package.json"

    %% Styles
    classDef mobile fill:#ADD8E6,stroke:#000,stroke-width:2px
    classDef external fill:#90EE90,stroke:#000,stroke-width:2px
    classDef config fill:#FFA500,stroke:#000,stroke-width:2px
```
