# heng148/stock_x_v2 architecture

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

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

## Overview

This is a TypeScript/Express marketplace API with account sessions, catalog and listing management, bidding, orders, watchlists, and notifications. Its principal workflow is a client request entering the versioned API, reaching a domain route and controller, invoking domain services, and—where shown—using repositories backed by PostgreSQL; successful responses are serialized by shared response helpers. The server also periodically purges expired sessions and listings/bids. Relationships are limited to those visible in the excerpts or SOURCE INDEX; unsampled route-to-controller wiring is not asserted.

Main entry points: [`server/src/app.ts`](https://github.com/heng148/stock_x_v2/blob/main/server/src/app.ts) (HTTP application), [`server/src/config/database.ts`](https://github.com/heng148/stock_x_v2/blob/main/server/src/config/database.ts) (Drizzle database), [`server/src/server.ts`](https://github.com/heng148/stock_x_v2/blob/main/server/src/server.ts) (Server scheduler), [`server/src/modules/auth/auth.service.ts`](https://github.com/heng148/stock_x_v2/blob/main/server/src/modules/auth/auth.service.ts) (Session service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API runtime"]
  node_app["HTTP application<br/>[app.ts]"]
  node_auth_route["Auth routes<br/>[auth.route.ts]"]
  node_users_route["User routes<br/>[user.route.ts]"]
  node_category_route["Category routes<br/>[category.route.ts]"]
  node_product_route["Product routes<br/>[product.route.ts]"]
  node_listing_route["Listing routes<br/>[listing.route.ts]"]
  node_bids_route["Bid routes<br/>[bids.route.ts]"]
  node_watchlist_route["Watchlist routes<br/>[watchlist.route.ts]"]
  node_notification_route["Notification routes"]
  node_server["Server scheduler<br/>[server.ts]"]
end

subgraph group_accounts["Accounts"]
  node_auth_controller["Auth controller<br/>[auth.controller.ts]"]
  node_auth_service["Session service<br/>[auth.service.ts]"]
  node_user_service["User service<br/>[user.service.ts]"]
end

subgraph group_marketplace["Marketplace"]
  node_category_service["Category service"]
  node_product_service["Product service<br/>[product.service.ts]"]
  node_listing_controller["Listing controller"]
  node_listing_service["Listing service<br/>[listing.service.ts]"]
  node_bid_controller["Bid controller<br/>[bids.controller.ts]"]
  node_bid_service["Bid service<br/>[bids.service.ts]"]
end

subgraph group_commerce["Orders and engagement"]
  node_orders_controller["Order controller"]
  node_orders_service["Order service<br/>[orders.service.ts]"]
  node_notification_service["Notification service"]
  node_watchlist_controller["Watchlist controller"]
end

subgraph group_platform["Persistence and shared"]
  node_database[("Drizzle database<br/>[database.ts]")]
  node_schema["Database schemas<br/>[index.ts]"]
  node_response["Response helpers<br/>[response.ts]"]
end

node_client(("API client"))
node_postgres[("PostgreSQL")]

node_client -->|"sends requests"| node_app
node_app -->|"mounts"| node_auth_route
node_app -->|"mounts"| node_users_route
node_app -->|"mounts"| node_category_route
node_app -->|"mounts"| node_product_route
node_app -->|"mounts"| node_listing_route
node_app -->|"mounts"| node_bids_route
node_app -->|"mounts"| node_watchlist_route
node_app -->|"mounts"| node_notification_route
node_auth_controller -->|"calls"| node_auth_service
node_auth_service -->|"calls"| node_user_service
node_listing_controller -->|"calls"| node_listing_service
node_bid_controller -->|"calls"| node_bid_service
node_orders_controller -->|"calls"| node_orders_service
node_watchlist_controller -->|"formats response"| node_response
node_listing_controller -->|"formats response"| node_response
node_bid_controller -->|"formats response"| node_response
node_orders_controller -->|"formats response"| node_response
node_auth_service -->|"uses repository"| node_database
node_category_service -->|"uses repository"| node_database
node_product_service -->|"uses repository"| node_database
node_listing_service -->|"uses repository"| node_database
node_bid_service -->|"uses repository"| node_database
node_orders_service -->|"uses repository"| node_database
node_orders_service -->|"notifies"| node_notification_service
node_database -->|"loads schema"| node_schema
node_database -->|"connects"| node_postgres
node_server -->|"starts"| node_app
node_server -->|"purges sessions"| node_auth_service
node_server -->|"expires listings"| node_listing_service
node_server -->|"expires bids"| node_bid_service

click node_app "https://github.com/heng148/stock_x_v2/blob/main/server/src/app.ts"
click node_auth_route "https://github.com/heng148/stock_x_v2/blob/main/server/src/modules/auth/auth.route.ts"
click node_users_route "https://github.com/heng148/stock_x_v2/blob/main/server/src/modules/users/user.route.ts"
click node_category_route "https://github.com/heng148/stock_x_v2/blob/main/server/src/modules/category/category.route.ts"
click node_product_route "https://github.com/heng148/stock_x_v2/blob/main/server/src/modules/products/product.route.ts"
click node_listing_route "https://github.com/heng148/stock_x_v2/blob/main/server/src/modules/listing/listing.route.ts"
click node_bids_route "https://github.com/heng148/stock_x_v2/blob/main/server/src/modules/bids/bids.route.ts"
click node_watchlist_route "https://github.com/heng148/stock_x_v2/blob/main/server/src/modules/watchlists/watchlist.route.ts"
click node_notification_route "https://github.com/heng148/stock_x_v2/blob/main/server/src/modules/notification/notification.route.ts"
click node_auth_controller "https://github.com/heng148/stock_x_v2/blob/main/server/src/modules/auth/auth.controller.ts"
click node_auth_service "https://github.com/heng148/stock_x_v2/blob/main/server/src/modules/auth/auth.service.ts"
click node_user_service "https://github.com/heng148/stock_x_v2/blob/main/server/src/modules/users/user.service.ts"
click node_category_service "https://github.com/heng148/stock_x_v2/blob/main/server/src/modules/category/category.service.ts"
click node_product_service "https://github.com/heng148/stock_x_v2/blob/main/server/src/modules/products/product.service.ts"
click node_listing_controller "https://github.com/heng148/stock_x_v2/blob/main/server/src/modules/listing/listing.controller.ts"
click node_listing_service "https://github.com/heng148/stock_x_v2/blob/main/server/src/modules/listing/listing.service.ts"
click node_bid_controller "https://github.com/heng148/stock_x_v2/blob/main/server/src/modules/bids/bids.controller.ts"
click node_bid_service "https://github.com/heng148/stock_x_v2/blob/main/server/src/modules/bids/bids.service.ts"
click node_orders_controller "https://github.com/heng148/stock_x_v2/blob/main/server/src/modules/orders/orders.controller.ts"
click node_orders_service "https://github.com/heng148/stock_x_v2/blob/main/server/src/modules/orders/orders.service.ts"
click node_notification_service "https://github.com/heng148/stock_x_v2/blob/main/server/src/modules/notification/notification.service.ts"
click node_watchlist_controller "https://github.com/heng148/stock_x_v2/blob/main/server/src/modules/watchlists/watchlist.controller.ts"
click node_database "https://github.com/heng148/stock_x_v2/blob/main/server/src/config/database.ts"
click node_schema "https://github.com/heng148/stock_x_v2/blob/main/server/src/db/schema/index.ts"
click node_response "https://github.com/heng148/stock_x_v2/blob/main/server/src/utils/response.ts"
click node_server "https://github.com/heng148/stock_x_v2/blob/main/server/src/server.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_app,node_auth_route,node_users_route,node_category_route,node_product_route,node_listing_route,node_bids_route,node_watchlist_route,node_notification_route,node_server,node_client toneBlue
class node_auth_controller,node_auth_service,node_user_service,node_postgres toneAmber
class node_category_service,node_product_service,node_listing_controller,node_listing_service,node_bid_controller,node_bid_service toneMint
class node_orders_controller,node_orders_service,node_notification_service,node_watchlist_controller toneRose
class node_database,node_schema,node_response toneIndigo
```

## Components

### API runtime

- [HTTP application](https://github.com/heng148/stock_x_v2/blob/main/server/src/app.ts): `server/src/app.ts`
- [Auth routes](https://github.com/heng148/stock_x_v2/blob/main/server/src/modules/auth/auth.route.ts): `server/src/modules/auth/auth.route.ts`
- [User routes](https://github.com/heng148/stock_x_v2/blob/main/server/src/modules/users/user.route.ts): `server/src/modules/users/user.route.ts`
- [Category routes](https://github.com/heng148/stock_x_v2/blob/main/server/src/modules/category/category.route.ts): `server/src/modules/category/category.route.ts`
- [Product routes](https://github.com/heng148/stock_x_v2/blob/main/server/src/modules/products/product.route.ts): `server/src/modules/products/product.route.ts`
- [Listing routes](https://github.com/heng148/stock_x_v2/blob/main/server/src/modules/listing/listing.route.ts): `server/src/modules/listing/listing.route.ts`
- [Bid routes](https://github.com/heng148/stock_x_v2/blob/main/server/src/modules/bids/bids.route.ts): `server/src/modules/bids/bids.route.ts`
- [Watchlist routes](https://github.com/heng148/stock_x_v2/blob/main/server/src/modules/watchlists/watchlist.route.ts): `server/src/modules/watchlists/watchlist.route.ts`
- [Notification routes](https://github.com/heng148/stock_x_v2/blob/main/server/src/modules/notification/notification.route.ts): `server/src/modules/notification/notification.route.ts`
- [Server scheduler](https://github.com/heng148/stock_x_v2/blob/main/server/src/server.ts): `server/src/server.ts`

### Accounts

- [Auth controller](https://github.com/heng148/stock_x_v2/blob/main/server/src/modules/auth/auth.controller.ts): `server/src/modules/auth/auth.controller.ts`
- [Session service](https://github.com/heng148/stock_x_v2/blob/main/server/src/modules/auth/auth.service.ts): `server/src/modules/auth/auth.service.ts`
- [User service](https://github.com/heng148/stock_x_v2/blob/main/server/src/modules/users/user.service.ts): `server/src/modules/users/user.service.ts`

### Marketplace

- [Category service](https://github.com/heng148/stock_x_v2/blob/main/server/src/modules/category/category.service.ts): `server/src/modules/category/category.service.ts`
- [Product service](https://github.com/heng148/stock_x_v2/blob/main/server/src/modules/products/product.service.ts): `server/src/modules/products/product.service.ts`
- [Listing controller](https://github.com/heng148/stock_x_v2/blob/main/server/src/modules/listing/listing.controller.ts): `server/src/modules/listing/listing.controller.ts`
- [Listing service](https://github.com/heng148/stock_x_v2/blob/main/server/src/modules/listing/listing.service.ts): `server/src/modules/listing/listing.service.ts`
- [Bid controller](https://github.com/heng148/stock_x_v2/blob/main/server/src/modules/bids/bids.controller.ts): `server/src/modules/bids/bids.controller.ts`
- [Bid service](https://github.com/heng148/stock_x_v2/blob/main/server/src/modules/bids/bids.service.ts): `server/src/modules/bids/bids.service.ts`

### Orders and engagement

- [Order controller](https://github.com/heng148/stock_x_v2/blob/main/server/src/modules/orders/orders.controller.ts): `server/src/modules/orders/orders.controller.ts`
- [Order service](https://github.com/heng148/stock_x_v2/blob/main/server/src/modules/orders/orders.service.ts): `server/src/modules/orders/orders.service.ts`
- [Notification service](https://github.com/heng148/stock_x_v2/blob/main/server/src/modules/notification/notification.service.ts): `server/src/modules/notification/notification.service.ts`
- [Watchlist controller](https://github.com/heng148/stock_x_v2/blob/main/server/src/modules/watchlists/watchlist.controller.ts): `server/src/modules/watchlists/watchlist.controller.ts`

### Persistence and shared

- [Drizzle database](https://github.com/heng148/stock_x_v2/blob/main/server/src/config/database.ts): `server/src/config/database.ts`
- [Database schemas](https://github.com/heng148/stock_x_v2/blob/main/server/src/db/schema/index.ts): `server/src/db/schema/index.ts`
- [Response helpers](https://github.com/heng148/stock_x_v2/blob/main/server/src/utils/response.ts): `server/src/utils/response.ts`

### Other components

- **API client**
- **PostgreSQL**

## Connections

- API client → HTTP application: sends requests
- HTTP application → Auth routes: mounts (evidence: `server/src/app.ts`)
- HTTP application → User routes: mounts (evidence: `server/src/app.ts`)
- HTTP application → Category routes: mounts (evidence: `server/src/app.ts`)
- HTTP application → Product routes: mounts (evidence: `server/src/app.ts`)
- HTTP application → Listing routes: mounts (evidence: `server/src/app.ts`)
- HTTP application → Bid routes: mounts (evidence: `server/src/app.ts`)
- HTTP application → Watchlist routes: mounts (evidence: `server/src/app.ts`)
- HTTP application → Notification routes: mounts (evidence: `server/src/app.ts`)
- Auth controller → Session service: calls (evidence: `server/src/modules/auth/auth.controller.ts`)
- Session service → User service: calls (evidence: `server/src/modules/auth/auth.service.ts`)
- Listing controller → Listing service: calls (evidence: `server/src/modules/listing/listing.controller.ts`)
- Bid controller → Bid service: calls (evidence: `server/src/modules/bids/bids.controller.ts`)
- Order controller → Order service: calls (evidence: `server/src/modules/orders/orders.controller.ts`)
- Watchlist controller → Response helpers: formats response (evidence: `server/src/modules/watchlists/watchlist.controller.ts`)
- Listing controller → Response helpers: formats response (evidence: `server/src/modules/listing/listing.controller.ts`)
- Bid controller → Response helpers: formats response (evidence: `server/src/modules/bids/bids.controller.ts`)
- Order controller → Response helpers: formats response (evidence: `server/src/modules/orders/orders.controller.ts`)
- Session service → Drizzle database: uses repository
- Category service → Drizzle database: uses repository
- Product service → Drizzle database: uses repository
- Listing service → Drizzle database: uses repository
- Bid service → Drizzle database: uses repository
- Order service → Drizzle database: uses repository (evidence: `server/src/modules/orders/orders.service.ts`)
- Order service → Notification service: notifies (evidence: `server/src/modules/orders/orders.service.ts`)
- Drizzle database → Database schemas: loads schema (evidence: `server/src/config/database.ts`)
- Drizzle database → PostgreSQL: connects (evidence: `server/src/config/database.ts`)
- Server scheduler → HTTP application: starts (evidence: `server/src/server.ts`)
- Server scheduler → Session service: purges sessions (evidence: `server/src/server.ts`)
- Server scheduler → Listing service: expires listings (evidence: `server/src/server.ts`)
- Server scheduler → Bid service: expires bids (evidence: `server/src/server.ts`)
