# soumyagarg30/eco-plate-predict-17 architecture

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

- Interactive diagram: https://gitdiagram.com/soumyagarg30/eco-plate-predict-17
- Repository: https://github.com/soumyagarg30/eco-plate-predict-17

## Overview

##### Project type and purpose
- This is a single-page, role-based full-stack web application built in React/TypeScript using Vite, Tailwind CSS, and shadcn-ui.
- It connects restaurants, NGOs, packers, and end-users to manage food waste, donation requests, packaging & pick-up workflows.
- The “backend” is a Supabase BaaS (Auth, PostgreSQL, Storage, Functions) accessed directly from the frontend.

##### File structure
- Top level: `public/` (static assets), `src/` (React code), `supabase/` (configuration & migrations).
- In `src/`:
- `pages/` holds route components (Index, Dashboards, Register, Prediction pages).
- `components/` holds reusable UI (shadcn-ui primitives) + domain components (login, ngo, packing, packaging, restaurant, user).
- `integrations/supabase/` contains the client wrapper and types.
- `hooks/` & `lib/` contain utility functions.
- Configs: `vite.config.ts`, `tailwind.config.ts`, `tsconfig*.json`.

##### README
- Confirms stack: Vite, TypeScript, React, shadcn-ui, Tailwind CSS.
- Mentions hosting/deploy via Lovable and custom domain options; no separate server code—uses Supabase.

##### Main components
a. Frontend SPA (browser)
- Vite-built React app
- Pages & UI Components
- Custom Hooks & Utils
b. API Layer / Integration
- Supabase client in `src/integrations/supabase`
c. BaaS Backend (Supabase)
- Auth service
- PostgreSQL database (+ migrations)
- Storage (file uploads)
- Edge functions (if any)
d. External services
- CDN / Static hosting (Lovable)
- Custom domain (optional)

##### Relationships & data flows
- User (browser) → HTTP(S) GET to CDN / static assets → SPA boots
- SPA → Supabase Auth (sign-in, sign-up)
- SPA → Supabase REST / Realtime for CRUD on users, restaurants, NGOs, orders, predictions
- SPA → Supabase Storage for upload/download of “lovable-uploads”
- (Optional) Domain DNS → CDN → SPA

##### Architectural patterns & design principles
- Component-based UI (shadcn-ui + domain components)
- Separation of concerns:
- Presentation (`components/`)
- Routing & pages (`pages/`)
- Data layer (`integrations/supabase`, `utils/dbUtils.ts`)
- BaaS pattern: no custom server—direct client↔Supabase
- Type safety with TypeScript

##### Essential elements to capture
- Static hosting (Lovable/CDN) serving `index.html` & assets
- SPA entry point (`src/main.tsx` → `App.tsx`)
- Route pages under different user roles
- Supabase services (Auth, DB, Storage) and migration file path
- Integration layer (`src/integrations/supabase/client.ts`)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Tier
    subgraph "Client Tier"
        direction TB
        CustomDomain["Custom Domain (DNS)"]:::external
        CDN["CDN / Lovable Hosting"]:::external
        Browser["Browser"]:::external

        CustomDomain --> CDN
        CDN -->|"Serves SPA"| Browser
    end

    %% SPA Layer
    subgraph "SPA (React / Vite / Tailwind / shadcn-ui)"
        direction TB
        Main["src/main.tsx"]:::frontend
        App["src/App.tsx"]:::frontend
        Pages["Pages\nsrc/pages/"]:::frontend
        Components["UI & Domain Components\nsrc/components/"]:::frontend
        HooksUtils["Hooks & Utils\nsrc/hooks/, src/lib/, src/utils/"]:::frontend

        Browser -->|Loads SPA| Main
        Main --> App
        App --> Pages
        App --> Components
        App --> HooksUtils
    end

    %% Integration / API Layer
    subgraph "Supabase Integration\n(src/integrations/supabase)" 
        direction TB
        Client["client.ts"]:::api
        Types["types.ts"]:::api
    end

    App -->|"Uses Supabase SDK"| Client
    App --> Types

    %% Backend Tier
    subgraph "Supabase BaaS Backend Services"
        direction TB
        Auth["Auth Service"]:::backend
        DB["PostgreSQL Database"]:::backend
        Migrations["Migration Files\nsupabase/migrations/"]:::backend
        Storage["Storage\npublic/lovable-uploads/"]:::backend
        Functions["Edge Functions"]:::backend

        Client --> Auth
        Client --> DB
        Client --> Storage
        Client --> Functions
        DB --> Migrations
    end

    %% Click Events
    click Main "https://github.com/soumyagarg30/eco-plate-predict-17/blob/main/src/main.tsx"
    click App "https://github.com/soumyagarg30/eco-plate-predict-17/blob/main/src/App.tsx"
    click Pages "https://github.com/soumyagarg30/eco-plate-predict-17/tree/main/src/pages/"
    click Components "https://github.com/soumyagarg30/eco-plate-predict-17/tree/main/src/components/"
    click Client "https://github.com/soumyagarg30/eco-plate-predict-17/blob/main/src/integrations/supabase/client.ts"
    click Types "https://github.com/soumyagarg30/eco-plate-predict-17/blob/main/src/integrations/supabase/types.ts"
    click Migrations "https://github.com/soumyagarg30/eco-plate-predict-17/blob/main/supabase/migrations/20250523_create_user_auth_function.sql"
    click Storage "https://github.com/soumyagarg30/eco-plate-predict-17/tree/main/public/lovable-uploads/"

    %% Styles
    classDef frontend fill:#cfe2ff,stroke:#0366d6,color:#0366d6;
    classDef api fill:#d1e7dd,stroke:#198754,color:#198754;
    classDef backend fill:#ffe5b4,stroke:#fd7e14,color:#fd7e14;
    classDef external fill:#e2e3e5,stroke:#6c757d,color:#6c757d;
```
