How mahi8026/health_care_e-commerce works
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: layout.jsx Next.js App Router · server.js Express API server · productRoutes.js Domain REST routes · orderService.js Order and pricing
Components 19
Next.js storefront
- Next.js App Router · Public, customer, B2B, and admin experiences.
health-care/src/app/layout.jsx - Catalog and checkout
health-care/src/app/products/page.jsx - Product detail route
health-care/src/app/products/[...id]/page.jsx - Admin surface
health-care/src/app/admin/layout.jsx - Auth, cart, wishlist state
health-care/src/context/AuthContext.jsx - SEO, feeds, and PWA
health-care/src/app/sitemap.xml/route.js
Express commerce API
- Express API server
health-care/backend/src/server.js - Domain REST routes · Auth, product, and order endpoints.
health-care/backend/src/routes/productRoutes.js - API middleware · Auth, validation, cache, throttling, correlation, and errors.
health-care/backend/src/middleware/auth.js
Domain and platform services
- Order and pricing · Handles fulfillment and standard, flash-deal, and B2B prices.
health-care/backend/src/services/orderService.js - Identity and security · JWT, Google OAuth, 2FA, and token blacklisting.
health-care/backend/src/config/passport.js - Customer and B2B operations · Loyalty, quotes, marketing, notifications, and WhatsApp.
health-care/backend/src/services/loyaltyService.js - Commerce models · Product, cart, order, payments, promotions, returns, and B2B records.
health-care/backend/src/models/Order.js - Redis cache · API and rate-limit cache with in-memory fallback.
health-care/backend/src/services/redisCache.js
Data, automation, and providers
- MongoDB Atlas
- Cloudinary · Upload target and media CDN.
health-care/backend/src/services/uploadService.js - Delivery and messaging providers · Email, SMS, Steadfast shipping, and WhatsApp.
health-care/backend/src/services/steadfastService.js - n8n automation
- Vercel and Render · Vercel serves Next.js; Render can host the API.
health-care/vercel.json
Connections 23
- 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