# vishal-gawade-031/snap-cart architecture

> Architecture diagram of the GitHub repository vishal-gawade-031/snap-cart, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/vishal-gawade-031/snap-cart
- Repository: https://github.com/vishal-gawade-031/snap-cart

## Overview

SnapCart is a role-based grocery web app. Users register or sign in, complete required profile details, and reach a role-specific dashboard; customers browse groceries and maintain a client-side cart, while admins manage grocery listings and view dashboard analytics. MongoDB-backed APIs support accounts and grocery creation, with Cloudinary used for product images. The graph combines sampled API and auth implementations with README-documented capabilities; some UI and route wiring is documented but not shown in source excerpts, so those links cite the README.

Main entry points: [`src/auth.ts`](https://github.com/vishal-gawade-031/snap-cart/blob/main/src/auth.ts) (NextAuth), [`src/app/page.tsx`](https://github.com/vishal-gawade-031/snap-cart/blob/main/src/app/page.tsx) (Role Dashboard Entry), [`src/components/UserDashboard.tsx`](https://github.com/vishal-gawade-031/snap-cart/blob/main/src/components/UserDashboard.tsx) (Customer Dashboard), [`src/components/useForAdmin/AdminDashboard.tsx`](https://github.com/vishal-gawade-031/snap-cart/blob/main/src/components/useForAdmin/AdminDashboard.tsx) (Admin Dashboard)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_identity["Identity &amp; Access"]
  node_signup["Registration UI<br/>[RegisterForm.tsx]"]
  node_register_api["Registration API<br/>[route.ts]"]
  node_auth["NextAuth<br/>[auth.ts]"]
  node_role_profile["Profile Onboarding<br/>[EditRoleMobile.tsx]"]
  node_profile_api["Profile Update API<br/>[route.ts]"]
  node_route_guard["Role Protection<br/>[proxy.ts]"]
  node_me_api["Current User API<br/>[route.ts]"]
end

subgraph group_customer["Customer Shopping"]
  node_home["Role Dashboard Entry<br/>[page.tsx]"]
  node_customer_dash["Customer Dashboard<br/>[UserDashboard.tsx]"]
  node_hero["Hero Section<br/>[HeroSection.tsx]"]
  node_categories["Category Slider<br/>[CategorySlider.tsx]"]
  node_product_cards["Grocery Cards"]
  node_navigation["Navigation &amp; Cart Badge<br/>[Nav.tsx]"]
end

subgraph group_admin["Admin Operations"]
  node_admin_dash["Admin Dashboard<br/>[AdminDashboard.tsx]"]
  node_analytics["Product Analytics"]
  node_add_product["Add Grocery Page<br/>[page.tsx]"]
  node_grocery_api["Grocery Creation API<br/>[route.ts]"]
  node_product_list["Product Inventory"]
  node_store_management["Store Management<br/>[storManagment.tsx]"]
end

subgraph group_platform["Data &amp; Client State"]
  node_cart["Cart State<br/>[cartSlice.ts]"]
  node_cloudinary["Cloudinary<br/>[cloudinary.ts]"]
  node_db[("MongoDB Connection<br/>[db.ts]")]
  node_user_model[("User Model<br/>[user.model.ts]")]
  node_grocery_model[("Grocery Model<br/>[grocery.model.tsx]")]
  node_get_me["Profile Hydration Hook<br/>[useGetMe.tsx]"]
  node_user_state["User State<br/>[userSlice.ts]"]
end

node_visitor(("Visitor"))

node_visitor -->|"registers"| node_signup
node_signup -->|"submits to"| node_register_api
node_register_api -->|"connects to"| node_db
node_register_api -->|"creates user"| node_user_model
node_visitor -->|"signs in"| node_auth
node_auth -->|"connects to"| node_db
node_auth -->|"looks up user"| node_user_model
node_home -->|"checks session"| node_auth
node_home -->|"loads user"| node_user_model
node_home -->|"shows incomplete profile"| node_role_profile
node_role_profile -->|"updates profile"| node_profile_api
node_profile_api -->|"checks session"| node_auth
node_profile_api -->|"updates user"| node_user_model
node_route_guard -->|"protects routes"| node_home
node_home -->|"shows customer view"| node_customer_dash
node_customer_dash -->|"renders"| node_hero
node_customer_dash -->|"renders"| node_categories
node_customer_dash -->|"renders"| node_product_cards
node_customer_dash -->|"loads groceries"| node_grocery_model
node_product_cards -->|"adds item"| node_cart
node_navigation -->|"reads cart count"| node_cart
node_home -->|"shows admin view"| node_admin_dash
node_admin_dash -->|"provides analytics"| node_analytics
node_admin_dash -->|"offers add flow"| node_add_product
node_admin_dash -->|"offers inventory"| node_product_list
node_admin_dash -->|"renders management"| node_store_management
node_add_product -->|"submits product"| node_grocery_api
node_grocery_api -->|"checks admin role"| node_auth
node_grocery_api -->|"uploads image"| node_cloudinary
node_grocery_api -->|"connects to"| node_db
node_grocery_api -->|"creates grocery"| node_grocery_model
node_get_me -->|"fetches profile"| node_me_api
node_me_api -->|"checks session"| node_auth
node_me_api -->|"connects to"| node_db
node_me_api -->|"loads profile"| node_user_model
node_get_me -->|"dispatches profile"| node_user_state

click node_signup "https://github.com/vishal-gawade-031/snap-cart/blob/main/src/components/RegisterForm.tsx"
click node_register_api "https://github.com/vishal-gawade-031/snap-cart/blob/main/src/app/api/auth/register/route.ts"
click node_auth "https://github.com/vishal-gawade-031/snap-cart/blob/main/src/auth.ts"
click node_role_profile "https://github.com/vishal-gawade-031/snap-cart/blob/main/src/components/EditRoleMobile.tsx"
click node_profile_api "https://github.com/vishal-gawade-031/snap-cart/blob/main/src/app/api/user/edit-role-mobile/route.ts"
click node_route_guard "https://github.com/vishal-gawade-031/snap-cart/blob/main/src/proxy.ts"
click node_home "https://github.com/vishal-gawade-031/snap-cart/blob/main/src/app/page.tsx"
click node_customer_dash "https://github.com/vishal-gawade-031/snap-cart/blob/main/src/components/UserDashboard.tsx"
click node_hero "https://github.com/vishal-gawade-031/snap-cart/blob/main/src/components/HeroSection.tsx"
click node_categories "https://github.com/vishal-gawade-031/snap-cart/blob/main/src/components/CategorySlider.tsx"
click node_product_cards "https://github.com/vishal-gawade-031/snap-cart/blob/main/src/components/GroceryItemCard.tsx"
click node_cart "https://github.com/vishal-gawade-031/snap-cart/blob/main/src/redux/cartSlice.ts"
click node_navigation "https://github.com/vishal-gawade-031/snap-cart/blob/main/src/components/Nav.tsx"
click node_admin_dash "https://github.com/vishal-gawade-031/snap-cart/blob/main/src/components/useForAdmin/AdminDashboard.tsx"
click node_analytics "https://github.com/vishal-gawade-031/snap-cart/blob/main/src/components/ProductAnalises.tsx"
click node_add_product "https://github.com/vishal-gawade-031/snap-cart/blob/main/src/app/admin/add-grocery/page.tsx"
click node_grocery_api "https://github.com/vishal-gawade-031/snap-cart/blob/main/src/app/api/admin/add-grocery/route.ts"
click node_product_list "https://github.com/vishal-gawade-031/snap-cart/blob/main/src/components/useForAdmin/AdminProductsView.tsx"
click node_store_management "https://github.com/vishal-gawade-031/snap-cart/blob/main/src/components/useForAdmin/storManagment.tsx"
click node_cloudinary "https://github.com/vishal-gawade-031/snap-cart/blob/main/src/lib/cloudinary.ts"
click node_db "https://github.com/vishal-gawade-031/snap-cart/blob/main/src/lib/db.ts"
click node_user_model "https://github.com/vishal-gawade-031/snap-cart/blob/main/src/models/user.model.ts"
click node_grocery_model "https://github.com/vishal-gawade-031/snap-cart/blob/main/src/models/grocery.model.tsx"
click node_me_api "https://github.com/vishal-gawade-031/snap-cart/blob/main/src/app/api/me/route.ts"
click node_get_me "https://github.com/vishal-gawade-031/snap-cart/blob/main/src/Hooks/useGetMe.tsx"
click node_user_state "https://github.com/vishal-gawade-031/snap-cart/blob/main/src/redux/userSlice.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_signup,node_register_api,node_auth,node_role_profile,node_profile_api,node_route_guard,node_me_api toneBlue
class node_home,node_customer_dash,node_hero,node_categories,node_product_cards,node_navigation toneAmber
class node_admin_dash,node_analytics,node_add_product,node_grocery_api,node_product_list,node_store_management toneMint
class node_cart,node_cloudinary,node_db,node_user_model,node_grocery_model,node_get_me,node_user_state toneRose
class node_visitor toneIndigo
```

## Components

### Identity & Access

- [Registration UI](https://github.com/vishal-gawade-031/snap-cart/blob/main/src/components/RegisterForm.tsx): `src/components/RegisterForm.tsx`
- [Registration API](https://github.com/vishal-gawade-031/snap-cart/blob/main/src/app/api/auth/register/route.ts): `src/app/api/auth/register/route.ts`
- [NextAuth](https://github.com/vishal-gawade-031/snap-cart/blob/main/src/auth.ts): `src/auth.ts`
- [Profile Onboarding](https://github.com/vishal-gawade-031/snap-cart/blob/main/src/components/EditRoleMobile.tsx): `src/components/EditRoleMobile.tsx`
- [Profile Update API](https://github.com/vishal-gawade-031/snap-cart/blob/main/src/app/api/user/edit-role-mobile/route.ts): `src/app/api/user/edit-role-mobile/route.ts`
- [Role Protection](https://github.com/vishal-gawade-031/snap-cart/blob/main/src/proxy.ts): `src/proxy.ts`
- [Current User API](https://github.com/vishal-gawade-031/snap-cart/blob/main/src/app/api/me/route.ts): `src/app/api/me/route.ts`

### Customer Shopping

- [Role Dashboard Entry](https://github.com/vishal-gawade-031/snap-cart/blob/main/src/app/page.tsx): `src/app/page.tsx`
- [Customer Dashboard](https://github.com/vishal-gawade-031/snap-cart/blob/main/src/components/UserDashboard.tsx): `src/components/UserDashboard.tsx`
- [Hero Section](https://github.com/vishal-gawade-031/snap-cart/blob/main/src/components/HeroSection.tsx): `src/components/HeroSection.tsx`
- [Category Slider](https://github.com/vishal-gawade-031/snap-cart/blob/main/src/components/CategorySlider.tsx): `src/components/CategorySlider.tsx`
- [Grocery Cards](https://github.com/vishal-gawade-031/snap-cart/blob/main/src/components/GroceryItemCard.tsx): `src/components/GroceryItemCard.tsx`
- [Navigation & Cart Badge](https://github.com/vishal-gawade-031/snap-cart/blob/main/src/components/Nav.tsx): `src/components/Nav.tsx`

### Admin Operations

- [Admin Dashboard](https://github.com/vishal-gawade-031/snap-cart/blob/main/src/components/useForAdmin/AdminDashboard.tsx): `src/components/useForAdmin/AdminDashboard.tsx`
- [Product Analytics](https://github.com/vishal-gawade-031/snap-cart/blob/main/src/components/ProductAnalises.tsx): `src/components/ProductAnalises.tsx`
- [Add Grocery Page](https://github.com/vishal-gawade-031/snap-cart/blob/main/src/app/admin/add-grocery/page.tsx): `src/app/admin/add-grocery/page.tsx`
- [Grocery Creation API](https://github.com/vishal-gawade-031/snap-cart/blob/main/src/app/api/admin/add-grocery/route.ts): `src/app/api/admin/add-grocery/route.ts`
- [Product Inventory](https://github.com/vishal-gawade-031/snap-cart/blob/main/src/components/useForAdmin/AdminProductsView.tsx): `src/components/useForAdmin/AdminProductsView.tsx`
- [Store Management](https://github.com/vishal-gawade-031/snap-cart/blob/main/src/components/useForAdmin/storManagment.tsx): `src/components/useForAdmin/storManagment.tsx`

### Data & Client State

- [Cart State](https://github.com/vishal-gawade-031/snap-cart/blob/main/src/redux/cartSlice.ts): `src/redux/cartSlice.ts`
- [Cloudinary](https://github.com/vishal-gawade-031/snap-cart/blob/main/src/lib/cloudinary.ts): `src/lib/cloudinary.ts`
- [MongoDB Connection](https://github.com/vishal-gawade-031/snap-cart/blob/main/src/lib/db.ts): `src/lib/db.ts`
- [User Model](https://github.com/vishal-gawade-031/snap-cart/blob/main/src/models/user.model.ts): `src/models/user.model.ts`
- [Grocery Model](https://github.com/vishal-gawade-031/snap-cart/blob/main/src/models/grocery.model.tsx): `src/models/grocery.model.tsx`
- [Profile Hydration Hook](https://github.com/vishal-gawade-031/snap-cart/blob/main/src/Hooks/useGetMe.tsx): `src/Hooks/useGetMe.tsx`
- [User State](https://github.com/vishal-gawade-031/snap-cart/blob/main/src/redux/userSlice.ts): `src/redux/userSlice.ts`

### Other components

- **Visitor**

## Connections

- Visitor → Registration UI: registers (evidence: `README.md`)
- Registration UI → Registration API: submits to (evidence: `README.md`)
- Registration API → MongoDB Connection: connects to (evidence: `src/app/api/auth/register/route.ts`)
- Registration API → User Model: creates user (evidence: `src/app/api/auth/register/route.ts`)
- Visitor → NextAuth: signs in (evidence: `README.md`)
- NextAuth → MongoDB Connection: connects to (evidence: `src/auth.ts`)
- NextAuth → User Model: looks up user (evidence: `src/auth.ts`)
- Role Dashboard Entry → NextAuth: checks session (evidence: `src/app/page.tsx`)
- Role Dashboard Entry → User Model: loads user (evidence: `src/app/page.tsx`)
- Role Dashboard Entry → Profile Onboarding: shows incomplete profile (evidence: `src/app/page.tsx`)
- Profile Onboarding → Profile Update API: updates profile (evidence: `README.md`)
- Profile Update API → NextAuth: checks session (evidence: `src/app/api/user/edit-role-mobile/route.ts`)
- Profile Update API → User Model: updates user (evidence: `src/app/api/user/edit-role-mobile/route.ts`)
- Role Protection → Role Dashboard Entry: protects routes (evidence: `README.md`)
- Role Dashboard Entry → Customer Dashboard: shows customer view (evidence: `src/app/page.tsx`)
- Customer Dashboard → Hero Section: renders (evidence: `src/components/UserDashboard.tsx`)
- Customer Dashboard → Category Slider: renders (evidence: `src/components/UserDashboard.tsx`)
- Customer Dashboard → Grocery Cards: renders (evidence: `src/components/UserDashboard.tsx`)
- Customer Dashboard → Grocery Model: loads groceries (evidence: `src/components/UserDashboard.tsx`)
- Grocery Cards → Cart State: adds item (evidence: `README.md`)
- Navigation & Cart Badge → Cart State: reads cart count (evidence: `README.md`)
- Role Dashboard Entry → Admin Dashboard: shows admin view (evidence: `README.md`)
- Admin Dashboard → Product Analytics: provides analytics (evidence: `README.md`)
- Admin Dashboard → Add Grocery Page: offers add flow (evidence: `README.md`)
- Admin Dashboard → Product Inventory: offers inventory (evidence: `README.md`)
- Admin Dashboard → Store Management: renders management (evidence: `src/components/useForAdmin/storManagment.tsx`)
- Add Grocery Page → Grocery Creation API: submits product (evidence: `README.md`)
- Grocery Creation API → NextAuth: checks admin role (evidence: `src/app/api/admin/add-grocery/route.ts`)
- Grocery Creation API → Cloudinary: uploads image (evidence: `src/app/api/admin/add-grocery/route.ts`)
- Grocery Creation API → MongoDB Connection: connects to (evidence: `src/app/api/admin/add-grocery/route.ts`)
- Grocery Creation API → Grocery Model: creates grocery (evidence: `src/app/api/admin/add-grocery/route.ts`)
- Profile Hydration Hook → Current User API: fetches profile (evidence: `README.md`)
- Current User API → NextAuth: checks session (evidence: `src/app/api/me/route.ts`)
- Current User API → MongoDB Connection: connects to (evidence: `src/app/api/me/route.ts`)
- Current User API → User Model: loads profile (evidence: `src/app/api/me/route.ts`)
- Profile Hydration Hook → User State: dispatches profile (evidence: `src/Hooks/useGetMe.tsx`)
