# anthonyrovira/insta-chef architecture

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

- Interactive diagram: https://gitdiagram.com/anthonyrovira/insta-chef
- Repository: https://github.com/anthonyrovira/insta-chef

## Overview

##### Main System Components

a) Frontend Layer:
- Next.js App Router (app directory structure)
- Client Components (components directory)
- Server Components (app directory)
- Theme System (ThemeProvider)
- Authentication UI (AuthButton)

b) Backend Layer:
- Next.js API Routes (auth/confirm/route.ts)
- Middleware (middleware.ts)
- Supabase Integration (utils/supabase)

c) External Services:
- Supabase (Authentication & Database)

##### Detailed Component Breakdown

a) Frontend Architecture:
- Pages/Routes:
- Home (app/page.tsx)
- Recipe Details (app/recipe/[id]/page.tsx)
- Error Page (app/error/page.tsx)
- Components Layer:
- UI Components (RecipeCard, SearchBar, etc.)
- Authentication Components
- Theme Components

b) Data Flow Layer:
- API Services (services/api.ts)
- Custom Hooks (hooks/useUser.ts)
- Type Definitions (types directory)

##### Interaction Flows

- Client-Server Communication
- Authentication Flow
- Data Fetching Patterns
- State Management

##### Specific Implementation Details

- Configuration (next.config.ts, tailwind.config.ts)
- Static Assets (public directory)
- Styling System (Tailwind CSS)

##### Static and dynamic routing

Key Relationships to Highlight:

- How the auth middleware interacts with protected routes
- How Supabase client/server utilities are utilized
- The relationship between pages and their corresponding components
- Theme system implementation across the application

Remember to:
- Use consistent styling and naming conventions
- Notes for important architectural decisions

- The application's overall architecture
- How different parts of the system interact
- The data flow between client and server
- The authentication and authorization flow
- The role of each major component

Creating separate views for:
##### Data flow patterns

This will provide a complete picture of the application's architecture while maintaining clarity and usefulness for the development team.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Legend"
        direction TB
        L1[Frontend Component]:::frontend
        L2[Backend Component]:::backend
        L3[Authentication Component]:::auth
        L4[External Service]:::external
        L5[Configuration]:::config
    end

    subgraph "Frontend Layer"
        direction TB
        AppRouter["Next.js App Router"]:::frontend
        click AppRouter "https://github.com/anthonyrovira/insta-chef/tree/master/app"
        
        subgraph "Pages"
            direction TB
            Home["Home Page"]:::frontend
            click Home "https://github.com/anthonyrovira/insta-chef/blob/master/app/page.tsx"
            RecipeDetails["Recipe Details"]:::frontend
            click RecipeDetails "https://github.com/anthonyrovira/insta-chef/blob/master/app/recipe/[id]/page.tsx"
            ErrorPage["Error Page"]:::frontend
            click ErrorPage "https://github.com/anthonyrovira/insta-chef/blob/master/app/error/page.tsx"
            RootLayout["Root Layout"]:::frontend
            click RootLayout "https://github.com/anthonyrovira/insta-chef/blob/master/app/layout.tsx"
        end

        subgraph "Components"
            direction TB
            AuthUI["Authentication UI"]:::frontend
            click AuthUI "https://github.com/anthonyrovira/insta-chef/blob/master/components/AuthButton.tsx"
            ThemeSystem["Theme System"]:::frontend
            click ThemeSystem "https://github.com/anthonyrovira/insta-chef/blob/master/components/ThemeProvider.tsx"
            RecipeCard["Recipe Card"]:::frontend
            click RecipeCard "https://github.com/anthonyrovira/insta-chef/blob/master/components/RecipeCard.tsx"
            SearchComponents["Search Components"]:::frontend
            click SearchComponents "https://github.com/anthonyrovira/insta-chef/blob/master/components/SearchBar.tsx"
            Navigation["Navigation"]:::frontend
            click Navigation "https://github.com/anthonyrovira/insta-chef/blob/master/components/HomeButton.tsx"
        end
    end

    subgraph "Backend Layer"
        direction TB
        APIRoutes["API Routes"]:::backend
        click APIRoutes "https://github.com/anthonyrovira/insta-chef/blob/master/auth/confirm/route.ts"
        AuthMiddleware["Auth Middleware"]:::auth
        click AuthMiddleware "https://github.com/anthonyrovira/insta-chef/blob/master/middleware.ts"
        
        subgraph "Supabase Integration"
            direction TB
            SupabaseConfig["Supabase Config"]:::backend
            click SupabaseConfig "https://github.com/anthonyrovira/insta-chef/blob/master/config/supabase.ts"
            ClientUtils["Client Utils"]:::backend
            click ClientUtils "https://github.com/anthonyrovira/insta-chef/blob/master/utils/supabase/client.ts"
            ServerUtils["Server Utils"]:::backend
            click ServerUtils "https://github.com/anthonyrovira/insta-chef/blob/master/utils/supabase/server.ts"
        end
    end

    subgraph "Data Layer"
        direction TB
        APIServices["API Services"]:::backend
        click APIServices "https://github.com/anthonyrovira/insta-chef/blob/master/services/api.ts"
        UserHook["User Hook"]:::backend
        click UserHook "https://github.com/anthonyrovira/insta-chef/blob/master/hooks/useUser.ts"
        Types["Type Definitions"]:::backend
        click Types "https://github.com/anthonyrovira/insta-chef/blob/master/types/index.ts"
    end

    subgraph "Configuration"
        direction TB
        NextConfig["Next.js Config"]:::config
        click NextConfig "https://github.com/anthonyrovira/insta-chef/blob/master/next.config.ts"
        TSConfig["TypeScript Config"]:::config
        click TSConfig "https://github.com/anthonyrovira/insta-chef/blob/master/tsconfig.json"
        TailwindConfig["Tailwind Config"]:::config
        click TailwindConfig "https://github.com/anthonyrovira/insta-chef/blob/master/tailwind.config.ts"
    end

    subgraph "External Services"
        direction TB
        Supabase["Supabase"]:::external
    end

    %% Connections
    AppRouter --> Pages
    AppRouter --> Components
    AuthMiddleware --> APIRoutes
    APIRoutes --> Supabase
    Components --> APIServices
    APIServices --> ServerUtils
    ServerUtils --> Supabase
    ClientUtils --> Supabase
    UserHook --> ClientUtils

    %% Styles
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef backend fill:#2ecc71,stroke:#27ae60,color:white
    classDef auth fill:#f1c40f,stroke:#f39c12,color:black
    classDef external fill:#9b59b6,stroke:#8e44ad,color:white
    classDef config fill:#e74c3c,stroke:#c0392b,color:white
```
