# alaa-m-saleh/market-backend architecture

> Architecture diagram of the GitHub repository alaa-m-saleh/market-backend, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/alaa-m-saleh/market-backend
- Repository: https://github.com/alaa-m-saleh/market-backend

## Overview

Market Backend is a layered Express/PostgreSQL e-commerce API. Clients enter through the mounted REST routes; domain controllers delegate to services that implement catalog, cart, checkout, order, and supporting commerce capabilities. The graph also includes administration, analytics, and live notifications. Edges follow excerpted wiring, SOURCE INDEX references, or README statements; unsampled details and uncertain runtime links are omitted.

Main entry points: [`src/app.js`](https://github.com/alaa-m-saleh/market-backend/blob/main/src/app.js) (Express application), [`src/services/order.service.js`](https://github.com/alaa-m-saleh/market-backend/blob/main/src/services/order.service.js) (Order management), [`src/config/db.js`](https://github.com/alaa-m-saleh/market-backend/blob/main/src/config/db.js) (PostgreSQL pool), [`src/services/notification.service.js`](https://github.com/alaa-m-saleh/market-backend/blob/main/src/services/notification.service.js) (Notifications)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["API and security"]
  node_app["Express application<br/>[app.js]"]
  node_auth["Authentication<br/>[auth.service.js]"]
  node_sanitize["Input sanitization<br/>[sanitize.js]"]
end

subgraph group_commerce["Commerce workflow"]
  node_catalog["Product catalog<br/>[product.service.js]"]
  node_variants["Product variants<br/>[variant.service.js]"]
  node_categories["Categories"]
  node_cart["Shopping cart<br/>[cart.service.js]"]
  node_pricing["Pricing<br/>[pricing.service.js]"]
  node_promotions["Promotions engine"]
  node_orders["Order management<br/>[order.service.js]"]
  node_inventory["Inventory ledger"]
  node_payments["Payment service<br/>[payment.service.js]"]
end

subgraph group_support["Customer features"]
  node_reviews["Reviews<br/>[review.service.js]"]
  node_wishlist["Wishlist"]
  node_addresses["Address book<br/>[address.service.js]"]
  node_notifications["Notifications"]
  node_socket["Live delivery<br/>[socket.js]"]
end

subgraph group_operations["Operations"]
  node_admin["Administration<br/>[admin.service.js]"]
  node_promotionadmin["Promotion admin"]
  node_analytics["Analytics"]
  node_database[("PostgreSQL pool<br/>[db.js]")]
end

node_client(("API client"))

node_client -->|"sends requests"| node_app
node_app -->|"mounts auth routes"| node_auth
node_app -->|"mounts catalog routes"| node_catalog
node_app -->|"mounts category routes"| node_categories
node_app -->|"mounts cart routes"| node_cart
node_app -->|"mounts order routes"| node_orders
node_app -->|"mounts review routes"| node_reviews
node_app -->|"mounts wishlist routes"| node_wishlist
node_app -->|"mounts address routes"| node_addresses
node_app -->|"mounts pricing routes"| node_pricing
node_app -->|"mounts notification routes"| node_notifications
node_app -->|"mounts admin routes"| node_admin
node_app -->|"mounts analytics routes"| node_analytics
node_catalog -->|"offers variants"| node_variants
node_orders -->|"reads cart"| node_cart
node_orders -->|"uses pricing"| node_pricing
node_orders -->|"evaluates promotions"| node_promotions
node_orders -->|"records stock"| node_inventory
node_orders -->|"triggers updates"| node_notifications
node_variants -->|"updates stock"| node_inventory
node_notifications -->|"pushes events"| node_socket
node_admin -->|"sends notices"| node_notifications
node_admin -->|"delegates promotion work"| node_promotionadmin
node_auth -->|"sanitizes input"| node_sanitize
node_reviews -->|"sanitizes comments"| node_sanitize
node_auth -->|"queries"| node_database
node_catalog -->|"queries"| node_database
node_orders -->|"queries"| node_database
node_reviews -->|"reads and writes"| node_database
node_promotions -->|"queries"| node_database
node_promotionadmin -->|"manages promotions"| node_database
node_analytics -.->|"queries"| node_database
node_payments -.->|"checkout association"| node_orders

click node_app "https://github.com/alaa-m-saleh/market-backend/blob/main/src/app.js"
click node_auth "https://github.com/alaa-m-saleh/market-backend/blob/main/src/services/auth.service.js"
click node_catalog "https://github.com/alaa-m-saleh/market-backend/blob/main/src/services/product.service.js"
click node_variants "https://github.com/alaa-m-saleh/market-backend/blob/main/src/services/variant.service.js"
click node_categories "https://github.com/alaa-m-saleh/market-backend/blob/main/src/services/category.service.js"
click node_cart "https://github.com/alaa-m-saleh/market-backend/blob/main/src/services/cart.service.js"
click node_pricing "https://github.com/alaa-m-saleh/market-backend/blob/main/src/services/pricing.service.js"
click node_promotions "https://github.com/alaa-m-saleh/market-backend/blob/main/src/services/promotion.service.js"
click node_orders "https://github.com/alaa-m-saleh/market-backend/blob/main/src/services/order.service.js"
click node_inventory "https://github.com/alaa-m-saleh/market-backend/blob/main/src/services/inventory.service.js"
click node_payments "https://github.com/alaa-m-saleh/market-backend/blob/main/src/services/payment.service.js"
click node_reviews "https://github.com/alaa-m-saleh/market-backend/blob/main/src/services/review.service.js"
click node_wishlist "https://github.com/alaa-m-saleh/market-backend/blob/main/src/services/wishlist.service.js"
click node_addresses "https://github.com/alaa-m-saleh/market-backend/blob/main/src/services/address.service.js"
click node_notifications "https://github.com/alaa-m-saleh/market-backend/blob/main/src/services/notification.service.js"
click node_socket "https://github.com/alaa-m-saleh/market-backend/blob/main/src/socket/socket.js"
click node_admin "https://github.com/alaa-m-saleh/market-backend/blob/main/src/services/admin.service.js"
click node_promotionadmin "https://github.com/alaa-m-saleh/market-backend/blob/main/src/services/promotion.admin.service.js"
click node_analytics "https://github.com/alaa-m-saleh/market-backend/blob/main/src/services/analytics.service.js"
click node_database "https://github.com/alaa-m-saleh/market-backend/blob/main/src/config/db.js"
click node_sanitize "https://github.com/alaa-m-saleh/market-backend/blob/main/src/utils/sanitize.js"

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,node_sanitize,node_client toneBlue
class node_catalog,node_variants,node_categories,node_cart,node_pricing,node_promotions,node_orders,node_inventory,node_payments toneAmber
class node_reviews,node_wishlist,node_addresses,node_notifications,node_socket toneMint
class node_admin,node_promotionadmin,node_analytics,node_database toneRose
```

## Components

### API and security

- [Express application](https://github.com/alaa-m-saleh/market-backend/blob/main/src/app.js): `src/app.js`
- [Authentication](https://github.com/alaa-m-saleh/market-backend/blob/main/src/services/auth.service.js): `src/services/auth.service.js`
- [Input sanitization](https://github.com/alaa-m-saleh/market-backend/blob/main/src/utils/sanitize.js): `src/utils/sanitize.js`

### Commerce workflow

- [Product catalog](https://github.com/alaa-m-saleh/market-backend/blob/main/src/services/product.service.js): `src/services/product.service.js`
- [Product variants](https://github.com/alaa-m-saleh/market-backend/blob/main/src/services/variant.service.js): `src/services/variant.service.js`
- [Categories](https://github.com/alaa-m-saleh/market-backend/blob/main/src/services/category.service.js): `src/services/category.service.js`
- [Shopping cart](https://github.com/alaa-m-saleh/market-backend/blob/main/src/services/cart.service.js): `src/services/cart.service.js`
- [Pricing](https://github.com/alaa-m-saleh/market-backend/blob/main/src/services/pricing.service.js): `src/services/pricing.service.js`
- [Promotions engine](https://github.com/alaa-m-saleh/market-backend/blob/main/src/services/promotion.service.js): `src/services/promotion.service.js`
- [Order management](https://github.com/alaa-m-saleh/market-backend/blob/main/src/services/order.service.js): `src/services/order.service.js`
- [Inventory ledger](https://github.com/alaa-m-saleh/market-backend/blob/main/src/services/inventory.service.js): `src/services/inventory.service.js`
- [Payment service](https://github.com/alaa-m-saleh/market-backend/blob/main/src/services/payment.service.js): `src/services/payment.service.js`

### Customer features

- [Reviews](https://github.com/alaa-m-saleh/market-backend/blob/main/src/services/review.service.js): `src/services/review.service.js`
- [Wishlist](https://github.com/alaa-m-saleh/market-backend/blob/main/src/services/wishlist.service.js): `src/services/wishlist.service.js`
- [Address book](https://github.com/alaa-m-saleh/market-backend/blob/main/src/services/address.service.js): `src/services/address.service.js`
- [Notifications](https://github.com/alaa-m-saleh/market-backend/blob/main/src/services/notification.service.js): `src/services/notification.service.js`
- [Live delivery](https://github.com/alaa-m-saleh/market-backend/blob/main/src/socket/socket.js): `src/socket/socket.js`

### Operations

- [Administration](https://github.com/alaa-m-saleh/market-backend/blob/main/src/services/admin.service.js): `src/services/admin.service.js`
- [Promotion admin](https://github.com/alaa-m-saleh/market-backend/blob/main/src/services/promotion.admin.service.js): `src/services/promotion.admin.service.js`
- [Analytics](https://github.com/alaa-m-saleh/market-backend/blob/main/src/services/analytics.service.js): `src/services/analytics.service.js`
- [PostgreSQL pool](https://github.com/alaa-m-saleh/market-backend/blob/main/src/config/db.js): `src/config/db.js`

### Other components

- **API client**

## Connections

- API client → Express application: sends requests (evidence: `src/app.js`)
- Express application → Authentication: mounts auth routes (evidence: `src/app.js`)
- Express application → Product catalog: mounts catalog routes (evidence: `src/app.js`)
- Express application → Categories: mounts category routes (evidence: `src/app.js`)
- Express application → Shopping cart: mounts cart routes (evidence: `src/app.js`)
- Express application → Order management: mounts order routes (evidence: `src/app.js`)
- Express application → Reviews: mounts review routes (evidence: `src/app.js`)
- Express application → Wishlist: mounts wishlist routes (evidence: `src/app.js`)
- Express application → Address book: mounts address routes (evidence: `src/app.js`)
- Express application → Pricing: mounts pricing routes (evidence: `src/app.js`)
- Express application → Notifications: mounts notification routes (evidence: `src/app.js`)
- Express application → Administration: mounts admin routes (evidence: `src/app.js`)
- Express application → Analytics: mounts analytics routes (evidence: `src/app.js`)
- Product catalog → Product variants: offers variants
- Order management → Shopping cart: reads cart (evidence: `src/services/order.service.js`)
- Order management → Pricing: uses pricing (evidence: `src/services/order.service.js`)
- Order management → Promotions engine: evaluates promotions (evidence: `src/services/order.service.js`)
- Order management → Inventory ledger: records stock (evidence: `src/services/order.service.js`)
- Order management → Notifications: triggers updates (evidence: `src/services/order.service.js`)
- Product variants → Inventory ledger: updates stock (evidence: `src/services/variant.service.js`)
- Notifications → Live delivery: pushes events (evidence: `src/services/notification.service.js`)
- Administration → Notifications: sends notices (evidence: `src/services/admin.service.js`)
- Administration → Promotion admin: delegates promotion work (evidence: `src/controllers/admin.controller.js`)
- Authentication → Input sanitization: sanitizes input (evidence: `src/services/auth.service.js`)
- Reviews → Input sanitization: sanitizes comments (evidence: `src/services/review.service.js`)
- Authentication → PostgreSQL pool: queries (evidence: `src/services/auth.service.js`)
- Product catalog → PostgreSQL pool: queries (evidence: `src/services/product.service.js`)
- Order management → PostgreSQL pool: queries (evidence: `src/services/order.service.js`)
- Reviews → PostgreSQL pool: reads and writes (evidence: `src/services/review.service.js`)
- Promotions engine → PostgreSQL pool: queries (evidence: `src/services/promotion.service.js`)
- Promotion admin → PostgreSQL pool: manages promotions (evidence: `src/services/promotion.admin.service.js`)
- Analytics → PostgreSQL pool: queries
- Payment service → Order management: checkout association
