# yashvicoded/foodloop architecture

> Architecture diagram of the GitHub repository yashvicoded/foodloop, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-02-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/yashvicoded/foodloop
- Repository: https://github.com/yashvicoded/foodloop

## Overview

##### Project type + purpose (from file tree / README)
**Project type:** Single-page web application (SPA) built with **Vite + React + TypeScript** and styled with **TailwindCSS**.
**Backend:** **Supabase** (hosted backend-as-a-service) is the primary server-side system: Postgres DB (+ likely Auth / RLS). There is **no custom Node/Express backend** in the repo.

**Purpose (inferred from component names):** “FoodLoop” appears to be a donation/product tracking dashboard:
- `Donations`, `DonationModal` → create/manage donations
- `ProductForm`, `ProductCard` → create/view products/food items
- `Dashboard`, `Analytics` → overview + reporting

##### Frontend (client app)
Key files and what they imply:
- `index.html` → SPA entry HTML served by Vite/static hosting
- `src/main.tsx` → React root bootstrap (mounts app)
- `src/App.tsx` → top-level routing/layout/composition (even if no router is visible here, it’s the top component boundary)
- `src/components/*` → UI + feature components (these are “internal components,” not separate services)
- `src/lib/supabase.ts` → **the key integration boundary** (Supabase client initialization and all calls likely funnel through it or import it)

##### Backend (Supabase)
- `supabase/migrations/20260225151353_create_foodloop_schema.sql`
This indicates:
- You have an explicit DB schema managed via migrations.
- Supabase is not just “a cloud DB,” it’s a backend surface: Postgres + REST/GraphQL-like API + Auth (+ RLS policies commonly).

##### Client Container: “FoodLoop SPA (React/Vite/TS)”
- Runs in: Browser
- Responsibilities: UI rendering, form handling, client-side state, calling Supabase
##### Supabase Backend (managed)
Break this into sub-containers/services *inside the Supabase boundary*:
- **Supabase API layer** (PostgREST / Supabase API gateway)
- **Postgres Database** (schema from migrations)
- **Auth** (if used; most Supabase apps do)

**Key integration point:**
- “Supabase Client (supabase-js) configuration”

- SPA → Supabase API (HTTPS; supabase-js)
- Supabase API → Postgres (SQL)
- SPA → Supabase Auth (if applicable)

**Add security notes (critical for accuracy with Supabase):**
- **Row Level Security (RLS)** and policies (even if not visible yet) should be represented as “Authorization enforced at DB via RLS”.

Don’t turn every React component into an “architecture component” unless you’re trying to document feature boundaries. But for this repo, the instruction is to be detailed and “separate into as many components as possible,” so do a **feature-level decomposition**:

**Frontend components (from `src/components`):**
- `Dashboard` → aggregates KPIs / summary views
- `Analytics` → charts/metrics
- `Donations` → list/manage donations
- `DonationModal` → create/edit donation flow
- `ProductForm` → create/edit products
- `ProductCard` → display product info

**Core app wiring:**
- `main.tsx` → mounts `App`
- `App.tsx` → composes `Dashboard/Donations/Analytics/...`

**Data layer boundary (explicitly show):**
- `lib/supabase.ts` as “Data Access / API Client”

- UI components → Data Access (supabase client)
- Data Access → Supabase API

This captures how “screens” talk to the backend.

##### View dashboard/analytics
- User → Dashboard/Analytics components
- Components → Supabase client → query aggregated donation/product data → render charts/cards

##### Create donation
- User → Donations → DonationModal (submit)
- DonationModal → Supabase client → insert donation row(s) → refresh list

##### Create/update product
- User → ProductForm (submit)
- ProductForm → Supabase client → insert/update product table → ProductCard renders updated state

##### Important architectural patterns/design principles present
- **BaaS-backed SPA**: no custom backend; Supabase provides API + DB + auth.
- **Client-side feature components**: UI-driven, likely “smart components” calling Supabase directly (unless there’s an unseen service layer—based on tree, `lib/supabase.ts` is the main abstraction).
- **Schema-as-code via migrations**: `supabase/migrations/*.sql` indicates DB versioning and reproducibility.

##### Required elements
- **Clear labels** with tech + responsibility:
- “FoodLoop SPA (React + TS + Vite)”
- “Supabase API (PostgREST / Supabase client endpoint)”
- “Postgres DB (FoodLoop schema; managed via migrations)”
- “Auth (JWT/session) + RLS enforcement”
- “SELECT donations”
- “INSERT donation”
- “UPSERT product”
- “Authenticate / Refresh session”
- Blue rectangles: runtime compute (Browser app)
- Purple boundary: Supabase-managed platform

##### Boundaries explicitly
- **Browser boundary** (client-only)
- **Supabase boundary** (managed backend)

## Diagram (Mermaid)

```mermaid
flowchart TD
  %% =========================
  %% System Context (L1)
  %% =========================
  User["User (Donor/Admin/Staff)"]:::actor

  subgraph "Browser (Runtime)"
    Browser["Web Browser"]:::runtime
    FoodLoop["FoodLoop Web App (SPA)"]:::spa
  end

  subgraph "Supabase (Managed Backend Platform)"
    SB_API["Supabase API Layer (PostgREST / API Gateway)"]:::api
    SB_AUTH["Supabase Auth (JWT / Sessions)"]:::auth
    SB_DB[("Postgres DB<br/>FoodLoop schema + RLS policies")]:::db
    SB_RLS["Row Level Security (RLS)<br/>Authorization enforced in DB"]:::security
  end

  User -->|"uses"| Browser
  Browser -->|"loads"| FoodLoop
  FoodLoop -->|"HTTPS (supabase-js)"| SB_API
  FoodLoop -->|"authenticate/refresh_session"| SB_AUTH
  SB_API -->|"SQL queries"| SB_DB
  SB_AUTH -->|"issues JWT / validates sessions"| SB_API
  SB_RLS -.->|"enforces policies on"| SB_DB

  %% =========================
  %% Container + Component Decomposition (L2/L3)
  %% =========================
  subgraph "FoodLoop SPA (React + TypeScript + Vite)"
    EntryHTML["SPA Entry HTML (index.html)"]:::artifact
    Main["React Bootstrap (main.tsx)"]:::frontend
    App["App Shell (App.tsx)"]:::frontend

    subgraph "Feature Components (src/components)"
      Dashboard["Dashboard"]:::feature
      Analytics["Analytics"]:::feature
      Donations["Donations"]:::feature
      DonationModal["DonationModal (Create/Edit Donation)"]:::feature
      ProductForm["ProductForm (Create/Edit Product)"]:::feature
      ProductCard["ProductCard (Display Product)"]:::feature
    end

    DataClient["Supabase Client Adapter (lib/supabase.ts)"]:::data
    Styles["Global Styling (Tailwind + index.css)"]:::styling
  end

  EntryHTML -->|"boots"| Main
  Main -->|"mounts"| App
  App -->|"composes"| Dashboard
  App -->|"composes"| Analytics
  App -->|"composes"| Donations
  App -->|"composes"| ProductForm
  App -->|"renders"| ProductCard
  Donations -->|"opens"| DonationModal

  %% Data access flows (feature-level)
  Dashboard -->|"SELECT donations/products"| DataClient
  Analytics -->|"aggregate_metrics SELECT"| DataClient
  Donations -->|"SELECT donations"| DataClient
  DonationModal -->|"INSERT donation"| DataClient
  ProductForm -->|"UPSERT product"| DataClient
  ProductCard -->|"SELECT product details"| DataClient

  DataClient -->|"HTTPS (supabase-js)"| SB_API
  DataClient -->|"authenticate"| SB_AUTH

  %% =========================
  %% Build & Deploy (Design-time)
  %% =========================
  subgraph "Build & Deploy (Design-time)"
    Repo["Source Repo"]:::repo
    Tooling["Toolchain (Vite + TS + Tailwind + ESLint)"]:::tooling
    StaticHost["Static Hosting/CDN (TBD)"]:::external
    SB_CLI["Supabase CLI / Migration Runner"]:::tooling
    MigrationsDir["supabase/migrations/"]:::migration
    MigrationSQL["FoodLoop Schema Migration (.sql)"]:::migration
  end

  Repo -.->|"vite_build + bundle"| Tooling
  Tooling -.->|"deploy static assets"| StaticHost
  Repo -.->|"apply migrations"| SB_CLI
  MigrationsDir -.->|"contains"| MigrationSQL
  SB_CLI -.->|"executes SQL"| SB_DB

  %% Styling/tooling relations (informational)
  Styles -.->|"Tailwind classes + global CSS"| App
  Tooling -.->|"build config for"| FoodLoop

  %% =========================
  %% Click Events (from component_mapping)
  %% =========================
  click EntryHTML "https://github.com/yashvicoded/foodloop/blob/main/index.html"
  click Main "https://github.com/yashvicoded/foodloop/blob/main/src/main.tsx"
  click App "https://github.com/yashvicoded/foodloop/blob/main/src/App.tsx"
  click Dashboard "https://github.com/yashvicoded/foodloop/blob/main/src/components/Dashboard.tsx"
  click Analytics "https://github.com/yashvicoded/foodloop/blob/main/src/components/Analytics.tsx"
  click Donations "https://github.com/yashvicoded/foodloop/blob/main/src/components/Donations.tsx"
  click DonationModal "https://github.com/yashvicoded/foodloop/blob/main/src/components/DonationModal.tsx"
  click ProductForm "https://github.com/yashvicoded/foodloop/blob/main/src/components/ProductForm.tsx"
  click ProductCard "https://github.com/yashvicoded/foodloop/blob/main/src/components/ProductCard.tsx"
  click DataClient "https://github.com/yashvicoded/foodloop/blob/main/src/lib/supabase.ts"
  click Styles "https://github.com/yashvicoded/foodloop/blob/main/src/index.css"
  click MigrationSQL "https://github.com/yashvicoded/foodloop/blob/main/supabase/migrations/20260225151353_create_foodloop_schema.sql"
  click MigrationsDir "https://github.com/yashvicoded/foodloop/tree/main/supabase/migrations"
  click Tooling "https://github.com/yashvicoded/foodloop/blob/main/vite.config.ts"
  click Tooling "https://github.com/yashvicoded/foodloop/blob/main/tailwind.config.js"
  click Tooling "https://github.com/yashvicoded/foodloop/blob/main/postcss.config.js"
  click Tooling "https://github.com/yashvicoded/foodloop/blob/main/tsconfig.json"
  click Tooling "https://github.com/yashvicoded/foodloop/blob/main/tsconfig.app.json"
  click Tooling "https://github.com/yashvicoded/foodloop/blob/main/tsconfig.node.json"
  click Tooling "https://github.com/yashvicoded/foodloop/blob/main/eslint.config.js"

  %% =========================
  %% Styles
  %% =========================
  classDef actor fill:#0ea5e9,stroke:#075985,color:#ffffff,stroke-width:1px
  classDef runtime fill:#1d4ed8,stroke:#1e3a8a,color:#ffffff,stroke-width:1px
  classDef spa fill:#2563eb,stroke:#1e3a8a,color:#ffffff,stroke-width:1px
  classDef frontend fill:#60a5fa,stroke:#1e40af,color:#0b1220,stroke-width:1px
  classDef feature fill:#93c5fd,stroke:#1e40af,color:#0b1220,stroke-width:1px
  classDef data fill:#38bdf8,stroke:#075985,color:#0b1220,stroke-width:1px
  classDef styling fill:#34d399,stroke:#065f46,color:#052e1a,stroke-width:1px

  classDef api fill:#a855f7,stroke:#581c87,color:#ffffff,stroke-width:1px
  classDef auth fill:#c084fc,stroke:#6b21a8,color:#ffffff,stroke-width:1px
  classDef db fill:#7c3aed,stroke:#4c1d95,color:#ffffff,stroke-width:1px
  classDef security fill:#f97316,stroke:#7c2d12,color:#ffffff,stroke-width:1px

  classDef repo fill:#64748b,stroke:#334155,color:#ffffff,stroke-width:1px
  classDef tooling fill:#94a3b8,stroke:#475569,color:#0b1220,stroke-width:1px
  classDef migration fill:#fbbf24,stroke:#92400e,color:#0b1220,stroke-width:1px
  classDef external fill:#0f766e,stroke:#134e4a,color:#ffffff,stroke-width:1px
  classDef artifact fill:#22c55e,stroke:#14532d,color:#052e1a,stroke-width:1px
```
