# heng148/stock_x architecture

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

- Interactive diagram: https://gitdiagram.com/heng148/stock_x
- Repository: https://github.com/heng148/stock_x

## Overview

This is a StockX-style resale marketplace: shoppers browse products and product details, then can watch items or buy; sellers create listings, while buyers can bid and manage purchases. Registration includes email verification, and authentication supports credentials and Google. Admin pages manage catalog, users, categories, and orders. The graph also includes notifications and recommendations as supporting capabilities. Most relationships come from sampled excerpts or SOURCE INDEX references; unsampled pages are represented at their exact enclosing paths, so their internal calls are not asserted.

Main entry points: [`src/db/index.ts`](https://github.com/heng148/stock_x/blob/main/src/db/index.ts) (Marketplace database), [`src/server/market.ts`](https://github.com/heng148/stock_x/blob/main/src/server/market.ts) (Listings, bids, orders), [`src/app/api/register/send-code/route.ts`](https://github.com/heng148/stock_x/blob/main/src/app/api/register/send-code/route.ts) (Email verification), [`src/app/(home)/browse/page.tsx`](https://github.com/heng148/stock_x/blob/main/src/app/(home)/browse/page.tsx) (Product browse)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_identity["Identity"]
  node_registration["Registration<br/>[page.tsx]"]
  node_verification["Email verification<br/>[route.ts]"]
  node_account_api["Account API<br/>[route.ts]"]
  node_login["Login API<br/>[route.ts]"]
  node_auth["Authentication<br/>[auth.ts]"]
end

subgraph group_discovery["Product discovery"]
  node_browse["Product browse<br/>[page.tsx]"]
  node_product_detail["Product detail<br/>[page.tsx]"]
  node_product_card["Product cards<br/>[ProductCard.tsx]"]
  node_recommend["Recommendations<br/>[recommend.ts]"]
end

subgraph group_commerce["Marketplace operations"]
  node_market_actions["Market actions<br/>[Marketactions.tsx]"]
  node_market["Listings, bids, orders<br/>[market.ts]"]
  node_profile["Buyer and seller profile"]
end

subgraph group_operations["Administration"]
  node_admin_pages["Admin management"]
  node_featured_expiry["Featured expiry<br/>[route.ts]"]
end

subgraph group_platform["Shared services"]
  node_notifications["Notifications<br/>[notifications.ts]"]
  node_database[("Marketplace database<br/>[index.ts]")]
  node_schema["Data model<br/>[schema.ts]"]
end

node_shopper(("Shopper"))
node_seller(("Seller"))
node_admin(("Admin"))
node_google(("Google sign-in"))
node_resend["Resend email"]

node_shopper -.->|"browses"| node_browse
node_seller -.->|"lists items"| node_market_actions
node_shopper -.->|"places bids"| node_market_actions
node_admin -.->|"manages"| node_admin_pages
node_registration -.->|"requests code"| node_verification
node_verification -->|"stores token"| node_database
node_verification -->|"sends code"| node_resend
node_registration -.->|"creates account"| node_account_api
node_account_api -->|"creates user"| node_database
node_login -->|"checks user"| node_database
node_shopper -.->|"signs in"| node_auth
node_google -.->|"authenticates"| node_auth
node_auth -->|"reads users"| node_database
node_browse -->|"reads products"| node_database
node_browse -->|"renders"| node_product_card
node_product_card -->|"requests suggestions"| node_recommend
node_market_actions -->|"invokes actions"| node_market
node_market -->|"reads and writes"| node_database
node_market -->|"notifies admins"| node_notifications
node_notifications -->|"stores notices"| node_database
node_admin_pages -->|"reads and manages"| node_database
node_featured_expiry -->|"expires listings"| node_database
node_profile -->|"reads profile data"| node_database
node_market -->|"revalidates profile"| node_profile
node_database -.->|"uses tables"| node_schema

click node_registration "https://github.com/heng148/stock_x/blob/main/src/app/(auth)/register/page.tsx"
click node_verification "https://github.com/heng148/stock_x/blob/main/src/app/api/register/send-code/route.ts"
click node_account_api "https://github.com/heng148/stock_x/blob/main/src/app/api/register/route.ts"
click node_login "https://github.com/heng148/stock_x/blob/main/src/app/api/login/route.ts"
click node_auth "https://github.com/heng148/stock_x/blob/main/src/auth.ts"
click node_browse "https://github.com/heng148/stock_x/blob/main/src/app/(home)/browse/page.tsx"
click node_product_detail "https://github.com/heng148/stock_x/blob/main/src/app/(home)/%5Bcategory%5D/%5Bslug%5D/page.tsx"
click node_product_card "https://github.com/heng148/stock_x/blob/main/src/components/ProductCard.tsx"
click node_recommend "https://github.com/heng148/stock_x/blob/main/src/server/recommend.ts"
click node_market_actions "https://github.com/heng148/stock_x/blob/main/src/components/action/Marketactions.tsx"
click node_market "https://github.com/heng148/stock_x/blob/main/src/server/market.ts"
click node_profile "https://github.com/heng148/stock_x/tree/main/src/app/(home)/profile"
click node_admin_pages "https://github.com/heng148/stock_x/tree/main/src/app/admin"
click node_featured_expiry "https://github.com/heng148/stock_x/blob/main/src/app/api/expire-featured/route.ts"
click node_notifications "https://github.com/heng148/stock_x/blob/main/src/server/notifications.ts"
click node_database "https://github.com/heng148/stock_x/blob/main/src/db/index.ts"
click node_schema "https://github.com/heng148/stock_x/blob/main/src/db/schema.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_registration,node_verification,node_account_api,node_login,node_auth toneBlue
class node_browse,node_product_detail,node_product_card,node_recommend toneAmber
class node_market_actions,node_market,node_profile toneMint
class node_admin_pages,node_featured_expiry toneRose
class node_notifications,node_database,node_schema,node_shopper,node_seller,node_admin,node_google,node_resend toneIndigo
```

## Components

### Identity

- [Registration](https://github.com/heng148/stock_x/blob/main/src/app/(auth)/register/page.tsx): `src/app/(auth)/register/page.tsx`
- [Email verification](https://github.com/heng148/stock_x/blob/main/src/app/api/register/send-code/route.ts): `src/app/api/register/send-code/route.ts`
- [Account API](https://github.com/heng148/stock_x/blob/main/src/app/api/register/route.ts): `src/app/api/register/route.ts`
- [Login API](https://github.com/heng148/stock_x/blob/main/src/app/api/login/route.ts): `src/app/api/login/route.ts`
- [Authentication](https://github.com/heng148/stock_x/blob/main/src/auth.ts): `src/auth.ts`

### Product discovery

- [Product browse](https://github.com/heng148/stock_x/blob/main/src/app/(home)/browse/page.tsx): `src/app/(home)/browse/page.tsx`
- [Product detail](https://github.com/heng148/stock_x/blob/main/src/app/(home)/%5Bcategory%5D/%5Bslug%5D/page.tsx): `src/app/(home)/[category]/[slug]/page.tsx`
- [Product cards](https://github.com/heng148/stock_x/blob/main/src/components/ProductCard.tsx): `src/components/ProductCard.tsx`
- [Recommendations](https://github.com/heng148/stock_x/blob/main/src/server/recommend.ts): `src/server/recommend.ts`

### Marketplace operations

- [Market actions](https://github.com/heng148/stock_x/blob/main/src/components/action/Marketactions.tsx): `src/components/action/Marketactions.tsx`
- [Listings, bids, orders](https://github.com/heng148/stock_x/blob/main/src/server/market.ts): `src/server/market.ts`
- [Buyer and seller profile](https://github.com/heng148/stock_x/tree/main/src/app/(home)/profile): `src/app/(home)/profile`

### Administration

- [Admin management](https://github.com/heng148/stock_x/tree/main/src/app/admin): `src/app/admin`
- [Featured expiry](https://github.com/heng148/stock_x/blob/main/src/app/api/expire-featured/route.ts): `src/app/api/expire-featured/route.ts`

### Shared services

- [Notifications](https://github.com/heng148/stock_x/blob/main/src/server/notifications.ts): `src/server/notifications.ts`
- [Marketplace database](https://github.com/heng148/stock_x/blob/main/src/db/index.ts): `src/db/index.ts`
- [Data model](https://github.com/heng148/stock_x/blob/main/src/db/schema.ts): `src/db/schema.ts`

### Other components

- **Shopper**
- **Seller**
- **Admin**
- **Google sign-in**
- **Resend email**

## Connections

- Shopper → Product browse: browses
- Seller → Market actions: lists items
- Shopper → Market actions: places bids
- Admin → Admin management: manages
- Registration → Email verification: requests code
- Email verification → Marketplace database: stores token (evidence: `src/app/api/register/send-code/route.ts`)
- Email verification → Resend email: sends code (evidence: `src/app/api/register/send-code/route.ts`)
- Registration → Account API: creates account
- Account API → Marketplace database: creates user (evidence: `src/app/api/register/route.ts`)
- Login API → Marketplace database: checks user (evidence: `src/app/api/login/route.ts`)
- Shopper → Authentication: signs in
- Google sign-in → Authentication: authenticates
- Authentication → Marketplace database: reads users (evidence: `src/auth.ts`)
- Product browse → Marketplace database: reads products (evidence: `src/app/(home)/browse/page.tsx`)
- Product browse → Product cards: renders (evidence: `src/app/(home)/browse/page.tsx`)
- Product cards → Recommendations: requests suggestions (evidence: `src/components/ProductCard.tsx`)
- Market actions → Listings, bids, orders: invokes actions (evidence: `src/components/action/Marketactions.tsx`)
- Listings, bids, orders → Marketplace database: reads and writes (evidence: `src/server/market.ts`)
- Listings, bids, orders → Notifications: notifies admins (evidence: `src/server/market.ts`)
- Notifications → Marketplace database: stores notices (evidence: `src/server/notifications.ts`)
- Admin management → Marketplace database: reads and manages (evidence: `src/app/admin/categories/page.tsx`)
- Featured expiry → Marketplace database: expires listings (evidence: `src/app/api/expire-featured/route.ts`)
- Buyer and seller profile → Marketplace database: reads profile data (evidence: `src/app/(home)/profile/page.tsx`)
- Listings, bids, orders → Buyer and seller profile: revalidates profile (evidence: `src/server/market.ts`)
- Marketplace database → Data model: uses tables
