# mahi8026/health_care_e-commerce architecture

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

- Interactive diagram: https://gitdiagram.com/mahi8026/health_care_e-commerce
- Repository: https://github.com/mahi8026/health_care_e-commerce

## Overview

#### 1. System Purpose and Entrypoints
Mediport BD is a Bangladesh-focused B2B/B2C medical-equipment commerce system. The main application is nested under `health-care/`; outer-root files are primarily repository administration. Runtime entrypoints are the Next.js App Router frontend at `health-care/src/app/layout.jsx` and `health-care/src/app/page.jsx`, plus the Express API at `health-care/backend/src/server.js`.

#### 2. Frontend Delivery Layer
Next.js 16 / React 19 renders public commerce, customer, B2B, and admin experiences. File-based routes separate major surfaces: catalog/detail pages in `health-care/src/app/products/page.jsx` and `health-care/src/app/products/[...id]/page.jsx`; checkout in `health-care/src/app/checkout/page.jsx`; privileged operations in `health-care/src/app/admin/layout.jsx`. Client state crosses UI boundaries through contexts, notably `health-care/src/context/AuthContext.jsx`, `health-care/src/context/CartContext.jsx`, and `health-care/src/context/WishlistContext.jsx`.

#### 3. API Boundary and Request Pipeline
The Express service exposes domain-specific REST route modules, which dispatch to controllers and services, then Mongoose models. Core routing domains include `health-care/backend/src/routes/authRoutes.js`, `health-care/backend/src/routes/productRoutes.js`, and `health-care/backend/src/routes/orderRoutes.js`. Cross-cutting middleware establishes authentication, validation, caching, throttling, health checks, request correlation, and error handling; central examples are `health-care/backend/src/middleware/auth.js`, `health-care/backend/src/middleware/cache.js`, and `health-care/backend/src/middleware/errorHandler.js`.

#### 4. Commerce and Fulfillment Domain
Catalog, category, manufacturer, cart, order, payment, coupon, review, return, quote, and B2B data are persisted as MongoDB/Mongoose documents. The commercial center is represented by `health-care/backend/src/models/Product.js`, `health-care/backend/src/models/Cart.js`, and `health-care/backend/src/models/Order.js`. Order processing is separated into service logic in `health-care/backend/src/services/orderService.js`; pricing supports standard, flash-deal, and B2B behavior through `health-care/backend/src/services/pricingService.js` and `health-care/backend/src/services/flashDealPricing.js`.

#### 5. Identity, Customer Programs, and Operations
Authentication supports JWT and Google OAuth through Passport configuration, with 2FA and token blacklisting services. Relevant boundaries are `health-care/backend/src/config/passport.js`, `health-care/backend/src/services/twoFactorService.js`, and `health-care/backend/src/services/tokenBlacklist.js`. Customer retention and enterprise workflows include loyalty, B2B terms/quotes, marketing, notifications, and WhatsApp: `health-care/backend/src/services/loyaltyService.js`, `health-care/backend/src/controllers/b2bController.js`, and `health-care/backend/src/services/whatsappService.js`.

#### 6. Integrations, Async Automation, and Observability
MongoDB Atlas is the system of record; Redis provides API/rate-limit caching with an in-memory fallback via `health-care/backend/src/services/redisCache.js` and `health-care/backend/src/services/cacheService.js`. Cloudinary is the media CDN/upload target (`health-care/backend/src/services/uploadService.js`). External delivery and engagement paths include email, SMS, Steadfast shipping, WhatsApp, and n8n webhooks, represented by `health-care/backend/src/services/emailService.js`, `health-care/backend/src/services/steadfastService.js`, and `health-care/backend/src/services/n8nWebhookService.js`. n8n workflow definitions live in `health-care/automation/workflows/`.

#### 7. SEO, Edge Functions, and Deployment
The frontend produces search and merchant-facing output through dynamic sitemap, robots, merchant-feed, and OG routes: `health-care/src/app/sitemap.xml/route.js`, `health-care/src/app/robots.js`, and `health-care/src/app/api/merchant-feed/route.js`. It also includes PWA assets under `health-care/public/sw.js`. Vercel hosts the frontend (`health-care/vercel.json`), while the Express backend is deployable to Render (`health-care/backend/render.yaml`) and contains Railway configuration. Sentry is configured separately for browser, edge, server, and API runtimes.

Main entry points: [`health-care/src/app/layout.jsx`](https://github.com/mahi8026/health_care_e-commerce/blob/main/health-care/src/app/layout.jsx) (Next.js App Router), [`health-care/backend/src/server.js`](https://github.com/mahi8026/health_care_e-commerce/blob/main/health-care/backend/src/server.js) (Express API server), [`health-care/backend/src/routes/productRoutes.js`](https://github.com/mahi8026/health_care_e-commerce/blob/main/health-care/backend/src/routes/productRoutes.js) (Domain REST routes), [`health-care/backend/src/services/orderService.js`](https://github.com/mahi8026/health_care_e-commerce/blob/main/health-care/backend/src/services/orderService.js) (Order and pricing)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Next.js storefront"]
  node_next_app["Next.js App Router<br/>frontend runtime<br/>[layout.jsx]"]
  node_commerce_pages["Catalog and checkout<br/>route pages<br/>[page.jsx]"]
  node_product_detail["Product detail route<br/>dynamic route<br/>[page.jsx]"]
  node_admin_ui["Admin surface<br/>protected UI<br/>[layout.jsx]"]
  node_client_state["Auth, cart, wishlist state<br/>React contexts<br/>[AuthContext.jsx]"]
  node_seo_pwa["SEO, feeds, and PWA<br/>edge routes and assets<br/>[route.js]"]
end

subgraph group_api["Express commerce API"]
  node_express_api["Express API server<br/>API runtime<br/>[server.js]"]
  node_rest_routes["Domain REST routes<br/>route modules<br/>[productRoutes.js]"]
  node_api_middleware["API middleware<br/>cross-cutting pipeline<br/>[auth.js]"]
end

subgraph group_services["Domain and platform services"]
  node_commerce_services["Order and pricing<br/>commerce services<br/>[orderService.js]"]
  node_identity_services["Identity and security<br/>auth services<br/>[passport.js]"]
  node_customer_operations["Customer and B2B operations<br/>engagement services<br/>[loyaltyService.js]"]
  node_commerce_models["Commerce models<br/>Mongoose models<br/>[Order.js]"]
  node_redis_cache[("Redis cache<br/>cache service<br/>[redisCache.js]")]
end

subgraph group_external["Data, automation, and providers"]
  node_mongodb[("MongoDB Atlas<br/>system of record")]
  node_media_cdn["Cloudinary<br/>media provider<br/>[uploadService.js]"]
  node_delivery_engagement["Delivery and messaging providers<br/>external integrations"]
  node_n8n["n8n automation<br/>webhook workflows"]
  node_deployment["Vercel and Render<br/>deployment targets<br/>[vercel.json]"]
end

node_next_app -->|"renders"| node_commerce_pages
node_next_app -->|"renders"| node_product_detail
node_next_app -->|"renders"| node_admin_ui
node_next_app -->|"provides"| node_client_state
node_next_app -->|"publishes"| node_seo_pwa
node_commerce_pages -->|"commerce requests"| node_express_api
node_product_detail -->|"catalog requests"| node_express_api
node_client_state -->|"session and cart requests"| node_express_api
node_express_api -->|"runs through"| node_api_middleware
node_api_middleware -->|"dispatches"| node_rest_routes
node_rest_routes -->|"auth flows"| node_identity_services
node_rest_routes -->|"orders and pricing"| node_commerce_services
node_rest_routes -->|"B2B and retention"| node_customer_operations
node_commerce_services -->|"reads and writes"| node_commerce_models
node_customer_operations -->|"reads and writes"| node_commerce_models
node_commerce_models -->|"persists to"| node_mongodb
node_api_middleware -->|"cache and rate limits"| node_redis_cache
node_commerce_services -->|"product media"| node_media_cdn
node_commerce_services -->|"shipping and notices"| node_delivery_engagement
node_customer_operations -->|"engagement messages"| node_delivery_engagement
node_customer_operations -->|"webhooks"| node_n8n
node_deployment -->|"hosts"| node_next_app
node_deployment -->|"deploys"| node_express_api

click node_next_app "https://github.com/mahi8026/health_care_e-commerce/blob/main/health-care/src/app/layout.jsx"
click node_commerce_pages "https://github.com/mahi8026/health_care_e-commerce/blob/main/health-care/src/app/products/page.jsx"
click node_product_detail "https://github.com/mahi8026/health_care_e-commerce/blob/main/health-care/src/app/products/%5B...id%5D/page.jsx"
click node_admin_ui "https://github.com/mahi8026/health_care_e-commerce/blob/main/health-care/src/app/admin/layout.jsx"
click node_client_state "https://github.com/mahi8026/health_care_e-commerce/blob/main/health-care/src/context/AuthContext.jsx"
click node_seo_pwa "https://github.com/mahi8026/health_care_e-commerce/blob/main/health-care/src/app/sitemap.xml/route.js"
click node_express_api "https://github.com/mahi8026/health_care_e-commerce/blob/main/health-care/backend/src/server.js"
click node_rest_routes "https://github.com/mahi8026/health_care_e-commerce/blob/main/health-care/backend/src/routes/productRoutes.js"
click node_api_middleware "https://github.com/mahi8026/health_care_e-commerce/blob/main/health-care/backend/src/middleware/auth.js"
click node_commerce_services "https://github.com/mahi8026/health_care_e-commerce/blob/main/health-care/backend/src/services/orderService.js"
click node_identity_services "https://github.com/mahi8026/health_care_e-commerce/blob/main/health-care/backend/src/config/passport.js"
click node_customer_operations "https://github.com/mahi8026/health_care_e-commerce/blob/main/health-care/backend/src/services/loyaltyService.js"
click node_commerce_models "https://github.com/mahi8026/health_care_e-commerce/blob/main/health-care/backend/src/models/Order.js"
click node_redis_cache "https://github.com/mahi8026/health_care_e-commerce/blob/main/health-care/backend/src/services/redisCache.js"
click node_media_cdn "https://github.com/mahi8026/health_care_e-commerce/blob/main/health-care/backend/src/services/uploadService.js"
click node_delivery_engagement "https://github.com/mahi8026/health_care_e-commerce/blob/main/health-care/backend/src/services/steadfastService.js"
click node_deployment "https://github.com/mahi8026/health_care_e-commerce/blob/main/health-care/vercel.json"

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_next_app,node_commerce_pages,node_product_detail,node_admin_ui,node_client_state,node_seo_pwa toneBlue
class node_express_api,node_rest_routes,node_api_middleware toneAmber
class node_commerce_services,node_identity_services,node_customer_operations,node_commerce_models,node_redis_cache toneMint
class node_mongodb,node_media_cdn,node_delivery_engagement,node_n8n,node_deployment toneRose
```

## Components

### Next.js storefront

- [Next.js App Router](https://github.com/mahi8026/health_care_e-commerce/blob/main/health-care/src/app/layout.jsx): frontend runtime · Public, customer, B2B, and admin experiences. · `health-care/src/app/layout.jsx`
- [Catalog and checkout](https://github.com/mahi8026/health_care_e-commerce/blob/main/health-care/src/app/products/page.jsx): route pages · `health-care/src/app/products/page.jsx`
- [Product detail route](https://github.com/mahi8026/health_care_e-commerce/blob/main/health-care/src/app/products/%5B...id%5D/page.jsx): dynamic route · `health-care/src/app/products/[...id]/page.jsx`
- [Admin surface](https://github.com/mahi8026/health_care_e-commerce/blob/main/health-care/src/app/admin/layout.jsx): protected UI · `health-care/src/app/admin/layout.jsx`
- [Auth, cart, wishlist state](https://github.com/mahi8026/health_care_e-commerce/blob/main/health-care/src/context/AuthContext.jsx): React contexts · `health-care/src/context/AuthContext.jsx`
- [SEO, feeds, and PWA](https://github.com/mahi8026/health_care_e-commerce/blob/main/health-care/src/app/sitemap.xml/route.js): edge routes and assets · `health-care/src/app/sitemap.xml/route.js`

### Express commerce API

- [Express API server](https://github.com/mahi8026/health_care_e-commerce/blob/main/health-care/backend/src/server.js): API runtime · `health-care/backend/src/server.js`
- [Domain REST routes](https://github.com/mahi8026/health_care_e-commerce/blob/main/health-care/backend/src/routes/productRoutes.js): route modules · Auth, product, and order endpoints. · `health-care/backend/src/routes/productRoutes.js`
- [API middleware](https://github.com/mahi8026/health_care_e-commerce/blob/main/health-care/backend/src/middleware/auth.js): cross-cutting pipeline · Auth, validation, cache, throttling, correlation, and errors. · `health-care/backend/src/middleware/auth.js`

### Domain and platform services

- [Order and pricing](https://github.com/mahi8026/health_care_e-commerce/blob/main/health-care/backend/src/services/orderService.js): commerce services · Handles fulfillment and standard, flash-deal, and B2B prices. · `health-care/backend/src/services/orderService.js`
- [Identity and security](https://github.com/mahi8026/health_care_e-commerce/blob/main/health-care/backend/src/config/passport.js): auth services · JWT, Google OAuth, 2FA, and token blacklisting. · `health-care/backend/src/config/passport.js`
- [Customer and B2B operations](https://github.com/mahi8026/health_care_e-commerce/blob/main/health-care/backend/src/services/loyaltyService.js): engagement services · Loyalty, quotes, marketing, notifications, and WhatsApp. · `health-care/backend/src/services/loyaltyService.js`
- [Commerce models](https://github.com/mahi8026/health_care_e-commerce/blob/main/health-care/backend/src/models/Order.js): Mongoose models · Product, cart, order, payments, promotions, returns, and B2B records. · `health-care/backend/src/models/Order.js`
- [Redis cache](https://github.com/mahi8026/health_care_e-commerce/blob/main/health-care/backend/src/services/redisCache.js): cache service · API and rate-limit cache with in-memory fallback. · `health-care/backend/src/services/redisCache.js`

### Data, automation, and providers

- **MongoDB Atlas**: system of record
- [Cloudinary](https://github.com/mahi8026/health_care_e-commerce/blob/main/health-care/backend/src/services/uploadService.js): media provider · Upload target and media CDN. · `health-care/backend/src/services/uploadService.js`
- [Delivery and messaging providers](https://github.com/mahi8026/health_care_e-commerce/blob/main/health-care/backend/src/services/steadfastService.js): external integrations · Email, SMS, Steadfast shipping, and WhatsApp. · `health-care/backend/src/services/steadfastService.js`
- **n8n automation**: webhook workflows
- [Vercel and Render](https://github.com/mahi8026/health_care_e-commerce/blob/main/health-care/vercel.json): deployment targets · Vercel serves Next.js; Render can host the API. · `health-care/vercel.json`

## Connections

- Next.js App Router → Catalog and checkout: renders
- Next.js App Router → Product detail route: renders
- Next.js App Router → Admin surface: renders
- Next.js App Router → Auth, cart, wishlist state: provides
- Next.js App Router → SEO, feeds, and PWA: publishes
- Catalog and checkout → Express API server: commerce requests
- Product detail route → Express API server: catalog requests
- Auth, cart, wishlist state → Express API server: session and cart requests
- Express API server → API middleware: runs through
- API middleware → Domain REST routes: dispatches
- Domain REST routes → Identity and security: auth flows
- Domain REST routes → Order and pricing: orders and pricing
- Domain REST routes → Customer and B2B operations: B2B and retention
- Order and pricing → Commerce models: reads and writes
- Customer and B2B operations → Commerce models: reads and writes
- Commerce models → MongoDB Atlas: persists to
- API middleware → Redis cache: cache and rate limits
- Order and pricing → Cloudinary: product media
- Order and pricing → Delivery and messaging providers: shipping and notices
- Customer and B2B operations → Delivery and messaging providers: engagement messages
- Customer and B2B operations → n8n automation: webhooks
- Vercel and Render → Next.js App Router: hosts
- Vercel and Render → Express API server: deploys
