# sumanpstu/medisynthia-web-app architecture

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

- Interactive diagram: https://gitdiagram.com/sumanpstu/medisynthia-web-app
- Repository: https://github.com/sumanpstu/medisynthia-web-app

## Overview

1. **What this repository is**
   - This is a **Node.js backend** for a medicine-oriented commerce/portal app (`MediSynthia-web-app`).
   - The architecture is centered on **REST APIs**, with a **real-time chat channel** alongside standard request/response flows.
   - Data is persisted in a database through the `models/` layer, and files are stored on disk under `uploads/`.

2. **Primary request pipeline**
   - Incoming HTTP requests enter through `index.js`, then are routed by the modules in `routes/`.
   - Most flows follow the same boundary pattern:
     - **route** → **middleware** (auth, rate limit, upload, sanitization) → **controller** → **model** → **database**
   - This separation is consistent across users, products, orders, categories, suppliers, prescriptions, and admin functions.

3. **Core domain subsystems**
   - The app is organized around these main business areas:
     - **User/auth management**: `userController`, `userModel`, token/session support
     - **Catalog management**: products, categories, subcategories, banners/adds
     - **Commerce flow**: cart and orders
     - **Prescription handling**: upload and review of prescription images/documents
     - **Communication**: comments, contact messages, and chat
     - **Admin/supplier operations**: admin-specific APIs and supplier records
   - These subsystems are mirrored in both `controllers/` and `routes/`, which makes the system easy to diagram by business capability.

4. **Authentication and security boundary**
   - Security is handled through `middleware/isAuthentication.js`, `middleware/rateLimiter.js`, and utility helpers in `utils/`.
   - The presence of `sessionModel.js`, `tokenBlacklistModel.js`, and `utils/tokenBlacklist.js` suggests the app supports **session/token lifecycle management**, including invalidation/blacklisting.
   - `utils/inputSanitization.js` and `utils/passwordUtils.js` indicate request hygiene and credential handling are treated as separate concerns, not embedded in business controllers.

5. **Database layer**
   - All persisted business entities have a matching model under `models/`.
   - Important entities include:
     - users, admins
     - products, categories, subcategories
     - carts, orders
     - prescriptions
     - comments, contacts, chats
     - suppliers, banners/adds
   - `config/dbConnection.js` is the database integration point, so the database is a clear architectural boundary outside the app’s main logic.

6. **File upload and media storage**
   - File handling is a first-class part of the architecture.
   - `config/multerConfig.js`, `config/prescriptionUploadConfig.js`, and `middleware/upload.js` coordinate multipart uploads.
   - Image/media files are stored in the filesystem under:
     - `uploads/products`
     - `uploads/carousel`
     - `uploads/subCategory`
     - `uploads/prescriptions`
   - Dedicated config files for carousel/category/subcategory image handling imply different upload rules or destinations per content type.

7. **Product catalog and merchandising**
   - Product discovery and catalog structure are split into:
     - `productController` / `productModel`
     - `categoryControllers` / `categoryModels`
     - `subCategoryController` / `subCategoryModel`
     - `addController` / `bannerAddModel`
   - This suggests a hierarchy of catalog entities where products are organized by category/subcategory, with promotional banner/add content managed separately.

8. **Commerce flow: cart → order**
   - `cartController`/`cartModel` and `orderController`/`orderModel` represent the transaction path.
   - The architectural flow is likely:
     - user interacts with cart APIs
     - cart state is persisted
     - order creation consumes cart/user data
   - Because cart and order are separate models, the system likely keeps “shopping state” distinct from “fulfilled transaction state.”

9. **Prescription-driven workflow**
   - `prescriptionController`, `prescriptionModel`, and `routes/prescriptionRoute.js` indicate a specialized flow for uploading and managing prescriptions.
   - The dedicated upload config for prescriptions implies prescription files are treated differently from ordinary product images.
   - In a diagram, this should be shown as a separate branch from normal product browsing, because it introduces a compliance/validation step before fulfillment.

10. **Communication features**
    - There are three distinct communication channels:
      - **comments** (`commentController`, `commentModel`)
      - **contact messages** (`contactController`, `contactModel`)
      - **chat** (`socketHandlers/chatHandler.js`, `chatModel`)
    - The chat subsystem uses sockets instead of plain HTTP, which makes it the only clearly real-time part of the repository.
    - This is an important architecture boundary: most features are synchronous REST, while chat is event-driven.

11. **Admin and supplier management**
    - `adminController`, `adminModel`, `adminRoute.js`, and `supplierController`/`supplierModel` show an operator-facing side of the app.
    - Admin workflows likely manage content, users, products, and order/prescription oversight.
    - Supplier management appears as a separate entity, suggesting administrative operations over inventory or fulfillment partners.

12. **Email and verification**
    - The `email/` directory contains Handlebars templates and mail sender utilities for OTP verification.
    - There are separate templates/utilities for regular users and admins:
      - `sendOtpMail.js` / `otpTemplate.hbs`
      - `sendOtpMailAdmin.js` / `otpTemplateAdmin.hbs`
    - This indicates email is used as an external service boundary for account verification or onboarding.

13. **Shared/generic abstractions**
    - `genericController.js`, `genericModel.js`, and `genericRoute.js` suggest there is a reusable CRUD or common-response abstraction for some entities.
    - This is likely used to reduce repetition for structurally similar resources.
    - In an architecture diagram, this can be shown as a shared service layer feeding simpler domain objects.

14. **Infrastructure and deployment-relevant components**
    - The repo depends on filesystem storage for uploads, database connectivity via `config/dbConnection.js`, and email delivery via the `email/` utilities.
    - Environment-specific configuration is implied by `.env`.
    - The main external dependencies that materially affect the architecture are:
      - database
      - file storage on the server filesystem
      - email/OTP delivery
      - socket-based realtime transport for chat

15. **How to draw the system**
    - A good diagram would show:
      - **clients** hitting **Express routes**
      - routes passing through **auth/rate-limit/upload/sanitization middleware**
      - controllers talking to **models**
      - models persisting to **database**
      - file uploads going to **local uploads directories**
      - email verification going to **mail templates/senders**
      - chat requests going through **socket handlers**
    - The main structural idea is a **modular monolith backend**: one server, many domain modules, with a small set of cross-cutting utilities.

Main entry points: [`config/dbConnection.js`](https://github.com/sumanpstu/medisynthia-web-app/blob/main/config/dbConnection.js) (Database), [`index.js`](https://github.com/sumanpstu/medisynthia-web-app/blob/main/index.js) (Server), [`email`](https://github.com/sumanpstu/medisynthia-web-app/tree/main/email) (Email OTP), [`routes/userRoute.js`](https://github.com/sumanpstu/medisynthia-web-app/blob/main/routes/userRoute.js) (User Route)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["API Layer"]
  node_index["Server<br/>Express entrypoint<br/>[index.js]"]
  node_routes["Routes<br/>HTTP routing"]
  node_middleware["Middleware<br/>cross-cutting"]
  node_user_route["User Route<br/>HTTP route<br/>[userRoute.js]"]
  node_catalog_route["Catalog Routes<br/>HTTP route"]
  node_commerce_route["Commerce Routes<br/>HTTP route"]
  node_prescription_route["Prescription Route<br/>HTTP route"]
end

subgraph group_domain["Domain Modules"]
  node_user["Users<br/>auth and accounts"]
  node_catalog["Catalog<br/>merchandising"]
  node_commerce["Commerce<br/>cart and orders"]
  node_prescriptions["Prescriptions<br/>upload workflow"]
  node_communication["Communication<br/>messages and comments"]
  node_admin["Admin<br/>operator APIs"]
  node_suppliers["Suppliers<br/>partner records"]
  node_generic["Generic CRUD<br/>shared abstraction"]
end

subgraph group_infra["Infrastructure"]
  node_db[("Database<br/>persistence<br/>[dbConnection.js]")]
  node_uploads[("File Storage<br/>filesystem")]
  node_email["Email OTP<br/>mail delivery"]
  node_security["Security Utils<br/>auth helpers"]
end

subgraph group_realtime["Realtime"]
  node_chat(("Chat Socket<br/>realtime channel<br/>[chatHandler.js]"))
  node_chat_route(("Chat Route<br/>socket route<br/>[chatRoute.js]"))
end

node_index -->|"mounts"| node_routes
node_index -->|"uses"| node_middleware
node_routes -->|"includes"| node_user_route
node_routes -->|"includes"| node_catalog_route
node_routes -->|"includes"| node_commerce_route
node_routes -->|"includes"| node_prescription_route
node_routes -->|"includes"| node_chat_route
node_middleware -->|"delegates"| node_security
node_user_route -->|"dispatches"| node_user
node_catalog_route -->|"dispatches"| node_catalog
node_commerce_route -->|"dispatches"| node_commerce
node_prescription_route -->|"dispatches"| node_prescriptions
node_chat_route -->|"handles"| node_chat
node_user -->|"persists"| node_db
node_catalog -->|"persists"| node_db
node_commerce -->|"persists"| node_db
node_prescriptions -->|"persists"| node_db
node_communication -->|"persists"| node_db
node_admin -->|"persists"| node_db
node_suppliers -->|"persists"| node_db
node_generic -->|"persists"| node_db
node_catalog -->|"stores media"| node_uploads
node_prescriptions -->|"stores files"| node_uploads
node_email -->|"verifies"| node_user
node_email -->|"verifies"| node_admin

click node_index "https://github.com/sumanpstu/medisynthia-web-app/blob/main/index.js"
click node_db "https://github.com/sumanpstu/medisynthia-web-app/blob/main/config/dbConnection.js"
click node_uploads "https://github.com/sumanpstu/medisynthia-web-app/tree/main/uploads"
click node_email "https://github.com/sumanpstu/medisynthia-web-app/tree/main/email"
click node_chat "https://github.com/sumanpstu/medisynthia-web-app/blob/main/socketHandlers/chatHandler.js"
click node_user_route "https://github.com/sumanpstu/medisynthia-web-app/blob/main/routes/userRoute.js"
click node_prescription_route "https://github.com/sumanpstu/medisynthia-web-app/blob/main/routes/prescriptionRoute.js"
click node_chat_route "https://github.com/sumanpstu/medisynthia-web-app/blob/main/routes/chatRoute.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_index,node_routes,node_middleware,node_user_route,node_catalog_route,node_commerce_route,node_prescription_route toneBlue
class node_user,node_catalog,node_commerce,node_prescriptions,node_communication,node_admin,node_suppliers,node_generic toneAmber
class node_db,node_uploads,node_email,node_security toneMint
class node_chat,node_chat_route toneRose
```

## Components

### API Layer

Express entrypoint, routes, and request middleware

- [Server](https://github.com/sumanpstu/medisynthia-web-app/blob/main/index.js): Express entrypoint · Bootstraps the Node.js app and wires routes and services · `index.js`
- **Routes**: HTTP routing · Request boundaries for the REST API
- **Middleware**: cross-cutting · Authentication, rate limiting, upload, and sanitization
- [User Route](https://github.com/sumanpstu/medisynthia-web-app/blob/main/routes/userRoute.js): HTTP route · User and auth endpoints · `routes/userRoute.js`
- **Catalog Routes**: HTTP route · Product, category, subcategory, and banner routes
- **Commerce Routes**: HTTP route · Cart and order endpoints
- [Prescription Route](https://github.com/sumanpstu/medisynthia-web-app/blob/main/routes/prescriptionRoute.js): HTTP route · Prescription upload and review endpoints · `routes/prescriptionRoute.js`

### Domain Modules

Business capability controllers and persistence models

- **Users**: auth and accounts · User onboarding, auth, session, and token lifecycle
- **Catalog**: merchandising · Products, categories, subcategories, and banners
- **Commerce**: cart and orders · Shopping cart and order placement flow
- **Prescriptions**: upload workflow · Prescription upload, review, and fulfillment gate
- **Communication**: messages and comments · Comments, contact messages, and other user communication
- **Admin**: operator APIs · Admin-facing management and oversight functions
- **Suppliers**: partner records · Supplier management and related records
- **Generic CRUD**: shared abstraction · Reusable controller, route, and model pattern

### Infrastructure

Database, storage, email, and shared utilities

- [Database](https://github.com/sumanpstu/medisynthia-web-app/blob/main/config/dbConnection.js): persistence · Persistent datastore behind the model layer · `config/dbConnection.js`
- [File Storage](https://github.com/sumanpstu/medisynthia-web-app/tree/main/uploads): filesystem · Server-local media and document storage · `uploads`
- [Email OTP](https://github.com/sumanpstu/medisynthia-web-app/tree/main/email): mail delivery · Verification email templates and sender utilities · `email`
- **Security Utils**: auth helpers · Password utilities, input sanitization, and token blacklist support

### Realtime

Socket-based chat handling

- [Chat Socket](https://github.com/sumanpstu/medisynthia-web-app/blob/main/socketHandlers/chatHandler.js): realtime channel · Socket handler for live chat messaging · `socketHandlers/chatHandler.js`
- [Chat Route](https://github.com/sumanpstu/medisynthia-web-app/blob/main/routes/chatRoute.js): socket route · Socket entrypoint for chat events · `routes/chatRoute.js`

## Connections

- Server → Routes: mounts · Server initializes the API route surface
- Server → Middleware: uses · Server registers shared request middleware
- Routes → User Route: includes · User/auth endpoints are exposed through routing
- Routes → Catalog Routes: includes · Catalog endpoints are exposed through routing
- Routes → Commerce Routes: includes · Cart and order endpoints are exposed through routing
- Routes → Prescription Route: includes · Prescription endpoints are exposed through routing
- Routes → Chat Route: includes · Realtime chat is wired as a separate channel
- Middleware → Security Utils: delegates · Auth, sanitization, and token handling are centralized here
- User Route → Users: dispatches · User endpoints reach account controllers and models
- Catalog Routes → Catalog: dispatches · Catalog endpoints reach merchandising controllers and models
- Commerce Routes → Commerce: dispatches · Commerce endpoints reach cart and order controllers
- Prescription Route → Prescriptions: dispatches · Prescription endpoints reach upload and review logic
- Chat Route → Chat Socket: handles · Live chat events are processed over sockets
- Users → Database: persists · User state, sessions, and token records are stored
- Catalog → Database: persists · Catalog entities are stored in the database
- Commerce → Database: persists · Cart and order state are stored in the database
- Prescriptions → Database: persists · Prescription metadata and workflow state are stored
- Communication → Database: persists · Comments and contact messages are stored
- Admin → Database: persists · Administrative records are stored in the database
- Suppliers → Database: persists · Supplier records are stored in the database
- Generic CRUD → Database: persists · Shared CRUD abstractions still rely on the database
- Catalog → File Storage: stores media · Product and content images are written to local storage
- Prescriptions → File Storage: stores files · Prescription documents are uploaded to disk
- Email OTP → Users: verifies · OTP mail supports user onboarding and verification
- Email OTP → Admin: verifies · OTP mail also supports admin verification flows
