How sumanpstu/medisynthia-web-app works
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: dbConnection.js Database · index.js Server · email Email OTP · userRoute.js User Route
Components 21
API Layer
Express entrypoint, routes, and request middleware
- Server · Bootstraps the Node.js app and wires routes and services
index.js - Routes · Request boundaries for the REST API
- Middleware · Authentication, rate limiting, upload, and sanitization
- User Route · User and auth endpoints
routes/userRoute.js - Catalog Routes · Product, category, subcategory, and banner routes
- Commerce Routes · Cart and order endpoints
- Prescription Route · Prescription upload and review endpoints
routes/prescriptionRoute.js
Domain Modules
Business capability controllers and persistence models
- Users · User onboarding, auth, session, and token lifecycle
- Catalog · Products, categories, subcategories, and banners
- Commerce · Shopping cart and order placement flow
- Prescriptions · Prescription upload, review, and fulfillment gate
- Communication · Comments, contact messages, and other user communication
- Admin · Admin-facing management and oversight functions
- Suppliers · Supplier management and related records
- Generic CRUD · Reusable controller, route, and model pattern
Infrastructure
Database, storage, email, and shared utilities
- Database · Persistent datastore behind the model layer
config/dbConnection.js - File Storage · Server-local media and document storage
uploads - Email OTP · Verification email templates and sender utilities
email - Security Utils · Password utilities, input sanitization, and token blacklist support
Realtime
Socket-based chat handling
- Chat Socket · Socket handler for live chat messaging
socketHandlers/chatHandler.js - Chat Route · Socket entrypoint for chat events
routes/chatRoute.js
Connections 25
- 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