# afras-cyber/e-com architecture

> Architecture diagram of the GitHub repository afras-cyber/e-com, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/afras-cyber/e-com
- Repository: https://github.com/afras-cyber/e-com

## Overview

Legacy Sports is a Next.js storefront and admin system for browsing products, placing and tracking orders, and managing catalog and store content. Product browsing flows through product APIs to MongoDB; the cart is persisted client-side, and order submission is handled by the order API. Staff manage orders and products through admin interfaces and protected APIs. The graph uses sampled source and SOURCE INDEX references; several listed page and API implementations were not sampled, so their internal relationships are left unasserted.

Main entry points: [`src/app/api/orders/[id]/route.ts`](https://github.com/afras-cyber/e-com/blob/main/src/app/api/orders/%5Bid%5D/route.ts) (Order status API), [`src/lib/db/mongoose.ts`](https://github.com/afras-cyber/e-com/blob/main/src/lib/db/mongoose.ts) (MongoDB connection), [`src/app/api/products/[id]/route.ts`](https://github.com/afras-cyber/e-com/blob/main/src/app/api/products/%5Bid%5D/route.ts) (Product item API), [`src/app/api/orders/route.ts`](https://github.com/afras-cyber/e-com/blob/main/src/app/api/orders/route.ts) (Order API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_storefront["Storefront"]
  node_product_pages["Product browsing"]
  node_product_detail["Product details"]
  node_product_gallery["Product gallery<br/>[ProductGallery.tsx]"]
  node_product_info["Product information<br/>[ProductInfo.tsx]"]
  node_cart["Cart state<br/>[useCartStore.ts]"]
  node_wishlist["Wishlist<br/>[useWishlist.ts]"]
  node_tracking["Order tracking<br/>[page.tsx]"]
end

subgraph group_commerce["Commerce"]
  node_product_api["Product API<br/>[route.ts]"]
  node_product_item_api["Product item API<br/>[route.ts]"]
  node_product_model[("Product records<br/>[Product.ts]")]
  node_order_api["Order API<br/>[route.ts]"]
  node_order_item_api["Order status API<br/>[route.ts]"]
  node_order_model[("Order records<br/>[Order.ts]")]
end

subgraph group_operations["Store Operations"]
  node_admin_pages["Admin screens"]
  node_order_manager["Order management<br/>[OrderManager.tsx]"]
  node_admin_content["Catalog and content APIs"]
end

subgraph group_platform["Platform"]
  node_auth["Authentication<br/>[auth.ts]"]
  node_user_model[("User records<br/>[User.ts]")]
  node_database_connection["MongoDB connection<br/>[mongoose.ts]"]
  node_email["Resend email"]
  node_object_storage["S3 image storage"]
end

node_shopper(("Shopper"))
node_staff(("Admin staff"))

node_shopper -->|"browses"| node_product_pages
node_product_pages -.->|"fetches products"| node_product_api
node_product_pages -.->|"opens item"| node_product_detail
node_product_detail -->|"renders"| node_product_gallery
node_product_detail -->|"renders"| node_product_info
node_product_info -->|"adds items"| node_cart
node_product_api -->|"connects"| node_database_connection
node_product_api -->|"queries"| node_product_model
node_product_item_api -->|"connects"| node_database_connection
node_product_item_api -->|"reads and writes"| node_product_model
node_product_item_api -->|"checks access"| node_auth
node_product_item_api -->|"deletes images"| node_object_storage
node_shopper -->|"builds cart"| node_cart
node_shopper -.->|"submits order"| node_order_api
node_order_api -->|"connects"| node_database_connection
node_order_api -->|"creates order"| node_order_model
node_order_api -->|"sends confirmations"| node_email
node_staff -.->|"manages store"| node_admin_pages
node_admin_pages -.->|"uses"| node_order_manager
node_order_manager -.->|"updates order"| node_order_item_api
node_order_item_api -->|"connects"| node_database_connection
node_order_item_api -->|"reads and updates"| node_order_model
node_order_item_api -->|"adjusts stock"| node_product_model
node_order_item_api -->|"sends status update"| node_email
node_tracking -.->|"shows status"| node_shopper
node_admin_content -.->|"checks staff access"| node_auth
node_auth -->|"connects"| node_database_connection
node_auth -->|"authenticates"| node_user_model

click node_product_pages "https://github.com/afras-cyber/e-com/tree/main/src/app/(public)/shop"
click node_product_detail "https://github.com/afras-cyber/e-com/blob/main/src/components/shop/ProductDetailsClientWrapper.tsx"
click node_product_gallery "https://github.com/afras-cyber/e-com/blob/main/src/components/shop/ProductGallery.tsx"
click node_product_info "https://github.com/afras-cyber/e-com/blob/main/src/components/shop/ProductInfo.tsx"
click node_cart "https://github.com/afras-cyber/e-com/blob/main/src/store/useCartStore.ts"
click node_wishlist "https://github.com/afras-cyber/e-com/blob/main/src/store/useWishlist.ts"
click node_product_api "https://github.com/afras-cyber/e-com/blob/main/src/app/api/products/route.ts"
click node_product_item_api "https://github.com/afras-cyber/e-com/blob/main/src/app/api/products/%5Bid%5D/route.ts"
click node_product_model "https://github.com/afras-cyber/e-com/blob/main/src/lib/db/models/Product.ts"
click node_order_api "https://github.com/afras-cyber/e-com/blob/main/src/app/api/orders/route.ts"
click node_order_item_api "https://github.com/afras-cyber/e-com/blob/main/src/app/api/orders/%5Bid%5D/route.ts"
click node_order_model "https://github.com/afras-cyber/e-com/blob/main/src/lib/db/models/Order.ts"
click node_tracking "https://github.com/afras-cyber/e-com/blob/main/src/app/(public)/track/page.tsx"
click node_admin_pages "https://github.com/afras-cyber/e-com/tree/main/src/app/(admin)"
click node_order_manager "https://github.com/afras-cyber/e-com/blob/main/src/components/admin/OrderManager.tsx"
click node_admin_content "https://github.com/afras-cyber/e-com/tree/main/src/app/api/admin"
click node_auth "https://github.com/afras-cyber/e-com/blob/main/src/lib/auth.ts"
click node_user_model "https://github.com/afras-cyber/e-com/blob/main/src/lib/db/models/User.ts"
click node_database_connection "https://github.com/afras-cyber/e-com/blob/main/src/lib/db/mongoose.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_product_pages,node_product_detail,node_product_gallery,node_product_info,node_cart,node_wishlist,node_tracking toneBlue
class node_product_api,node_product_item_api,node_product_model,node_order_api,node_order_item_api,node_order_model toneAmber
class node_admin_pages,node_order_manager,node_admin_content toneMint
class node_auth,node_user_model,node_database_connection,node_email,node_object_storage toneRose
class node_shopper,node_staff toneIndigo
```

## Components

### Storefront

- [Product browsing](https://github.com/afras-cyber/e-com/tree/main/src/app/(public)/shop): `src/app/(public)/shop`
- [Product details](https://github.com/afras-cyber/e-com/blob/main/src/components/shop/ProductDetailsClientWrapper.tsx): `src/components/shop/ProductDetailsClientWrapper.tsx`
- [Product gallery](https://github.com/afras-cyber/e-com/blob/main/src/components/shop/ProductGallery.tsx): `src/components/shop/ProductGallery.tsx`
- [Product information](https://github.com/afras-cyber/e-com/blob/main/src/components/shop/ProductInfo.tsx): `src/components/shop/ProductInfo.tsx`
- [Cart state](https://github.com/afras-cyber/e-com/blob/main/src/store/useCartStore.ts): `src/store/useCartStore.ts`
- [Wishlist](https://github.com/afras-cyber/e-com/blob/main/src/store/useWishlist.ts): `src/store/useWishlist.ts`
- [Order tracking](https://github.com/afras-cyber/e-com/blob/main/src/app/(public)/track/page.tsx): `src/app/(public)/track/page.tsx`

### Commerce

- [Product API](https://github.com/afras-cyber/e-com/blob/main/src/app/api/products/route.ts): `src/app/api/products/route.ts`
- [Product item API](https://github.com/afras-cyber/e-com/blob/main/src/app/api/products/%5Bid%5D/route.ts): `src/app/api/products/[id]/route.ts`
- [Product records](https://github.com/afras-cyber/e-com/blob/main/src/lib/db/models/Product.ts): `src/lib/db/models/Product.ts`
- [Order API](https://github.com/afras-cyber/e-com/blob/main/src/app/api/orders/route.ts): `src/app/api/orders/route.ts`
- [Order status API](https://github.com/afras-cyber/e-com/blob/main/src/app/api/orders/%5Bid%5D/route.ts): `src/app/api/orders/[id]/route.ts`
- [Order records](https://github.com/afras-cyber/e-com/blob/main/src/lib/db/models/Order.ts): `src/lib/db/models/Order.ts`

### Store Operations

- [Admin screens](https://github.com/afras-cyber/e-com/tree/main/src/app/(admin)): `src/app/(admin)`
- [Order management](https://github.com/afras-cyber/e-com/blob/main/src/components/admin/OrderManager.tsx): `src/components/admin/OrderManager.tsx`
- [Catalog and content APIs](https://github.com/afras-cyber/e-com/tree/main/src/app/api/admin): `src/app/api/admin`

### Platform

- [Authentication](https://github.com/afras-cyber/e-com/blob/main/src/lib/auth.ts): `src/lib/auth.ts`
- [User records](https://github.com/afras-cyber/e-com/blob/main/src/lib/db/models/User.ts): `src/lib/db/models/User.ts`
- [MongoDB connection](https://github.com/afras-cyber/e-com/blob/main/src/lib/db/mongoose.ts): `src/lib/db/mongoose.ts`
- **Resend email**
- **S3 image storage**

### Other components

- **Shopper**
- **Admin staff**

## Connections

- Shopper → Product browsing: browses
- Product browsing → Product API: fetches products
- Product browsing → Product details: opens item
- Product details → Product gallery: renders (evidence: `src/components/shop/ProductDetailsClientWrapper.tsx`)
- Product details → Product information: renders (evidence: `src/components/shop/ProductDetailsClientWrapper.tsx`)
- Product information → Cart state: adds items (evidence: `src/components/shop/ProductInfo.tsx`)
- Product API → MongoDB connection: connects (evidence: `src/app/api/products/route.ts`)
- Product API → Product records: queries (evidence: `src/app/api/products/route.ts`)
- Product item API → MongoDB connection: connects (evidence: `src/app/api/products/[id]/route.ts`)
- Product item API → Product records: reads and writes (evidence: `src/app/api/products/[id]/route.ts`)
- Product item API → Authentication: checks access (evidence: `src/app/api/products/[id]/route.ts`)
- Product item API → S3 image storage: deletes images (evidence: `src/app/api/products/[id]/route.ts`)
- Shopper → Cart state: builds cart
- Shopper → Order API: submits order
- Order API → MongoDB connection: connects (evidence: `src/app/api/orders/route.ts`)
- Order API → Order records: creates order (evidence: `src/app/api/orders/route.ts`)
- Order API → Resend email: sends confirmations (evidence: `src/app/api/orders/route.ts`)
- Admin staff → Admin screens: manages store
- Admin screens → Order management: uses
- Order management → Order status API: updates order
- Order status API → MongoDB connection: connects (evidence: `src/app/api/orders/[id]/route.ts`)
- Order status API → Order records: reads and updates (evidence: `src/app/api/orders/[id]/route.ts`)
- Order status API → Product records: adjusts stock (evidence: `src/app/api/orders/[id]/route.ts`)
- Order status API → Resend email: sends status update (evidence: `src/app/api/orders/[id]/route.ts`)
- Order tracking → Shopper: shows status
- Catalog and content APIs → Authentication: checks staff access (evidence: `src/app/api/admin/staff/route.ts`)
- Authentication → MongoDB connection: connects (evidence: `src/lib/auth.ts`)
- Authentication → User records: authenticates (evidence: `src/lib/auth.ts`)
