# abrahamvg/snacfacts architecture

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

- Interactive diagram: https://gitdiagram.com/abrahamvg/snacfacts
- Repository: https://github.com/abrahamvg/snacfacts

## Overview

##### Main Components Identification

The system architecture should be divided into the following key components:

A. Frontend Layer
- Client-Side Components
- Page Routes
- UI Components
- Custom Hooks
- State Management

B. API Integration Layer
- Google Gemini API Integration
- Next.js API Routes

C. Core Features
- Image Analysis
- Nutrition Visualization
- Report Generation

**[Client Browser]**
- ↕
**[Next.js Frontend]**
- Pages Layer
- Home (/)
- Analyse (/analyse)
- Report (/analyse/report)

- Component Layer
- Core Components
- Navbar
- Footer
- Feature Components
- UI Components
- Shadcn UI Elements

- Custom Hooks Layer
- useDropDownData
- useNutritionHook

**[External Services]**
- Google Gemini API

##### Important Architectural Elements to Highlight

a. App Router Structure (Next.js 13+)
- App directory structure
- Page.tsx components in each route
- Server and client components

b. Component Architecture
- Hierarchy of components
- Shared UI components
- Relationship between components and hooks

c. External Integration
- Connection to Google Gemini API
- Data flow for image analysis

##### Data Flow Indicators

- User interaction flow
- API request/response paths
- State management flow
- Image processing pipeline

##### Technical Stack Indicators

Use of:
- Next.js 13+ with App Router
- Tailwind CSS
- Shadcn UI
- TypeScript
- Google Gemini API

Remember to indicate the client-side and server-side boundaries, as this is crucial in a Next.js application. Also, show how the custom hooks (useDropDownData and useNutritionHook) integrate with the components and external services.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        Browser["Web Browser"]
    end

    subgraph NextApp["Next.js Application"]
        subgraph Pages["Pages Layer"]
            Home["Home Page"]:::page
            Analyse["Analysis Page"]:::page
            Visualise["Visualization Page"]:::page
            Report["Report Page"]:::page
        end

        subgraph Components["Component Layer"]
            CoreComp["Core Components"]
            NavBar["Navigation Bar"]:::component
            Footer["Footer"]:::component
            NutritionTable["Nutrition Info Table"]:::component
            FactsCard["Facts Card"]:::component
            IngredientInfo["Ingredient Info"]:::component
            VisualiseCard["Visualise Card"]:::component
            
            subgraph UIComponents["UI Components"]
                Button["Button"]:::ui
                Table["Table"]:::ui
                Dialog["Dialog"]:::ui
                Skeleton["Skeleton"]:::ui
            end
        end

        subgraph Hooks["Custom Hooks Layer"]
            NutritionHook["Nutrition Hook"]:::hook
            DropdownHook["Dropdown Data Hook"]:::hook
        end

        subgraph Integration["API Integration Layer"]
            GeminiIntegration["Gemini API Integration"]:::api
            Constants["API Constants"]:::util
            Utils["Utility Functions"]:::util
        end

        subgraph Assets["Asset Management"]
            Fonts["Fonts Configuration"]:::asset
            Images["Images Directory"]:::asset
            NutrientSVGs["Nutrient SVGs"]:::asset
        end

        subgraph Types["Type Definitions"]
            TypeDefs["Types"]:::types
        end
    end

    subgraph External["External Services"]
        GeminiAPI["Google Gemini API"]:::external
    end

    %% Relationships
    Browser --> Home
    Browser --> Analyse
    Browser --> Visualise
    Browser --> Report
    
    CoreComp --> NavBar
    CoreComp --> Footer
    CoreComp --> NutritionTable
    CoreComp --> FactsCard
    CoreComp --> IngredientInfo
    CoreComp --> VisualiseCard
    
    Components --> Hooks
    Integration --> GeminiAPI
    Hooks --> Integration
    Pages --> Components
    
    %% Click Events
    click Home "https://github.com/abrahamvg/snacfacts/blob/master/app/page.tsx"
    click Analyse "https://github.com/abrahamvg/snacfacts/blob/master/app/analyse/page.tsx"
    click Visualise "https://github.com/abrahamvg/snacfacts/blob/master/app/visualise/page.tsx"
    click Report "https://github.com/abrahamvg/snacfacts/blob/master/app/analyse/report/page.tsx"
    click NavBar "https://github.com/abrahamvg/snacfacts/blob/master/components/Navbar.tsx"
    click Footer "https://github.com/abrahamvg/snacfacts/blob/master/components/Footer.tsx"
    click NutritionTable "https://github.com/abrahamvg/snacfacts/blob/master/components/NutritionInfoTable.tsx"
    click FactsCard "https://github.com/abrahamvg/snacfacts/blob/master/components/FactsCard.tsx"
    click IngredientInfo "https://github.com/abrahamvg/snacfacts/blob/master/components/IngredientInfo/IngredientInfo.tsx"
    click VisualiseCard "https://github.com/abrahamvg/snacfacts/blob/master/components/VisualiseCard.tsx"
    click Button "https://github.com/abrahamvg/snacfacts/blob/master/components/ui/button.tsx"
    click Table "https://github.com/abrahamvg/snacfacts/blob/master/components/ui/table.tsx"
    click Dialog "https://github.com/abrahamvg/snacfacts/blob/master/components/ui/dialog.tsx"
    click Skeleton "https://github.com/abrahamvg/snacfacts/blob/master/components/ui/skeleton.tsx"
    click NutritionHook "https://github.com/abrahamvg/snacfacts/blob/master/hooks/useNutritionHook.tsx"
    click DropdownHook "https://github.com/abrahamvg/snacfacts/blob/master/hooks/useDropDownData.tsx"
    click GeminiIntegration "https://github.com/abrahamvg/snacfacts/blob/master/lib/geminiAPI.ts"
    click Constants "https://github.com/abrahamvg/snacfacts/blob/master/lib/constants.ts"
    click Utils "https://github.com/abrahamvg/snacfacts/blob/master/lib/utils.ts"
    click TypeDefs "https://github.com/abrahamvg/snacfacts/blob/master/types/types.ts"
    click Fonts "https://github.com/abrahamvg/snacfacts/blob/master/fonts/fonts.tsx"
    click Images "https://github.com/abrahamvg/snacfacts/tree/master/public/images/"
    click NutrientSVGs "https://github.com/abrahamvg/snacfacts/tree/master/public/images/nutrientSVGs/"

    %% Styles
    classDef page fill:#2563eb,color:white
    classDef component fill:#4f46e5,color:white
    classDef ui fill:#9333ea,color:white
    classDef hook fill:#f97316,color:white
    classDef api fill:#16a34a,color:white
    classDef util fill:#6b7280,color:white
    classDef asset fill:#94a3b8,color:white
    classDef types fill:#475569,color:white
    classDef external fill:#22c55e,color:white
```
