# theunstopabble/swadkart-pro architecture

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

- Interactive diagram: https://gitdiagram.com/theunstopabble/swadkart-pro
- Repository: https://github.com/theunstopabble/swadkart-pro

## Overview

1. **System shape**
   - SwadKart is a full-stack, multi-role food delivery platform split into a React frontend and an Express/MongoDB backend.
   - The main user roles are **customer**, **restaurant owner**, **delivery partner**, and **admin**; the UI and API are both organized around these boundaries.

2. **Frontend application boundary**
   - The frontend is a **Vite + React** app with **React Router** for page navigation and **Redux Toolkit** for shared state, mainly cart and user/session state.
   - Most UI is composed from domain-specific component groups: ordering, restaurant management, delivery workflows, and admin dashboards.

3. **Frontend feature surfaces**
   - Customer-facing pages cover discovery, cart, checkout, payments, order history/details, profile, auth, and support-style pages.
   - There are dedicated interfaces for **admin dashboards**, **restaurant owner dashboards**, and **delivery partner dashboards**, which means the frontend is not just a consumer app but a multi-portal system.
   - The app also includes interactive extras like voice search, chatbot, PWA install prompts, and local notification helpers.

4. **Backend application boundary**
   - The backend is structured in classic **Express MVC style**: `routes` map HTTP endpoints, `controllers` hold business logic, `models` define MongoDB schemas, and `middleware` handles auth/error behavior.
   - `server.js` is the composition point where the app, database, auth, and realtime services are wired together.

5. **Core data model**
   - MongoDB/Mongoose models center on **users, restaurants, products, orders, coupons, coupon usage, and emergency records**.
   - This indicates the main domain entities are commerce and fulfillment, with support for promotions and delivery safety workflows.

6. **Authentication and identity**
   - Authentication is hybrid: **JWT-based email/password auth** plus **Firebase Google auth** on the frontend side.
   - There is also a **WebAuthn biometric flow** with backend config and routes, supporting device-native fingerprint/Face ID login.
   - `authMiddleware` acts as the access-control boundary for role-based features and protected APIs.

7. **Order lifecycle flow**
   - The primary data flow is: browse restaurants/products → add to cart → apply coupon → enter address → pay → create order → track status → confirm delivery.
   - Order-related components and routes indicate that status changes are a first-class part of the architecture, not just a final checkout step.

8. **Realtime and fulfillment**
   - **Socket.io** is used for realtime order tracking and live operational updates.
   - This likely connects customer tracking views, restaurant “live orders” screens, and delivery partner dashboards through a shared event stream.
   - Delivery verification includes OTP-based confirmation, which ties the backend order state to final handoff.

9. **Admin and merchant operations**
   - The backend and frontend both support rich operational dashboards: restaurant menu management, live order handling, user administration, coupon management, and analytics.
   - Admin-specific tooling includes revenue/order/user overview and demand heatmap visualization, showing that the system is built for operational decision-making, not only order placement.

10. **External service integrations**
   - **Cloudinary** handles image uploads/media storage.
   - **Stripe** and **Razorpay** appear as payment gateways.
   - **SMTP email** is used for OTPs, notifications, and transactional messaging.
   - A push-notification utility and Firebase config suggest additional messaging/device notification integration.

11. **Caching and background processing**
   - There is an optional **Redis** configuration with a fallback to in-memory caching, so the app can run locally without Redis but benefit from it in production.
   - Email sending is offloaded to a **worker** (`emailWorker.js`), which separates slow notification work from request/response handling.

12. **Security and hardening**
   - The repo includes sanitization utilities and error middleware, indicating input hardening and centralized failure handling.
   - The README also calls out role-based access, secure OTPs, cookie-based auth behavior, and production-vs-local differences in cookie settings.

13. **Deployment boundary**
   - The frontend is intended for **Vercel**, and the backend for a Node host such as **Render**.
   - `vercel.json` rewrites `/api/*` to the backend, which matters architecturally because it keeps frontend-origin requests compatible with cookie-based authentication in production.

14. **What an architecture diagram should emphasize**
   - Draw three main zones: **client UI**, **Express API backend**, and **external services/data stores**.
   - Show the frontend split into role-based portals, the backend split into route/controller/model layers, and the cross-cutting realtime channel via Socket.io.
   - Include MongoDB as the system of record, Redis as optional cache, and Cloudinary/payment/email/biometric providers as external dependencies.

Main entry points: [`backend/controllers/orderController.js`](https://github.com/theunstopabble/swadkart-pro/blob/main/backend/controllers/orderController.js) (Controllers), [`frontend/src/App.jsx`](https://github.com/theunstopabble/swadkart-pro/blob/main/frontend/src/App.jsx) (App shell), [`frontend/src/pages/Home.jsx`](https://github.com/theunstopabble/swadkart-pro/blob/main/frontend/src/pages/Home.jsx) (Customer flows), [`backend/server.js`](https://github.com/theunstopabble/swadkart-pro/blob/main/backend/server.js) (API entry)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_frontend_shell["App shell<br/>Vite React app<br/>[App.jsx]"]
  node_frontend_shared_state["Shared state<br/>Redux Toolkit<br/>[store.js]"]
  node_customer_portals["Customer flows<br/>pages<br/>[Home.jsx]"]
  node_merchant_portal["Merchant portal<br/>owner dashboard"]
  node_delivery_portal["Delivery portal<br/>partner dashboard"]
  node_admin_portal["Admin portal<br/>admin dashboard<br/>[AdminDashboard.jsx]"]
  node_ux_extras["UX extras<br/>assistive UI<br/>[ChatBot.jsx]"]
  node_order_ui["Order UI<br/>checkout components<br/>[CheckoutSteps.jsx]"]
  node_restaurant_ui["Restaurant UI<br/>merchant components<br/>[MenuManagement.jsx]"]
  node_delivery_ui["Delivery UI<br/>partner components<br/>[DeliveryCard.jsx]"]
  node_frontend_integrations["Client integrations<br/>auth and realtime helpers<br/>[firebaseConfig.js]"]
end

subgraph group_backend["Backend"]
  node_api_entry["API entry<br/>Express server<br/>[server.js]"]
  node_api_routes["API routes<br/>HTTP routes<br/>[orderRoutes.js]"]
  node_api_controllers["Controllers<br/>business logic<br/>[orderController.js]"]
  node_api_models["Data models<br/>Mongoose schemas<br/>[orderModel.js]"]
  node_api_middleware["Middleware<br/>security and errors<br/>[authMiddleware.js]"]
  node_api_config["Backend config<br/>service config<br/>[db.js]"]
  node_email_worker["Email worker<br/>background job<br/>[emailWorker.js]"]
end

subgraph group_external["External services"]
  node_db[("MongoDB<br/>primary datastore")]
  node_redis[("Redis<br/>optional cache")]
  node_cloudinary["Cloudinary<br/>media storage"]
  node_payments["Payments<br/>Stripe/Razorpay"]
  node_messaging["Messaging<br/>SMTP/Firebase/push"]
end

node_frontend_shell -->|"uses"| node_frontend_shared_state
node_frontend_shell -->|"routes to"| node_customer_portals
node_frontend_shell -->|"routes to"| node_merchant_portal
node_frontend_shell -->|"routes to"| node_delivery_portal
node_frontend_shell -->|"routes to"| node_admin_portal
node_customer_portals -->|"uses"| node_order_ui
node_merchant_portal -->|"uses"| node_restaurant_ui
node_delivery_portal -->|"uses"| node_delivery_ui
node_customer_portals -->|"augmented by"| node_ux_extras
node_frontend_integrations -->|"calls"| node_api_entry
node_frontend_integrations -.->|"auth/messaging"| node_messaging
node_api_entry -->|"mounts"| node_api_routes
node_api_routes -->|"dispatches"| node_api_controllers
node_api_controllers -->|"reads/writes"| node_api_models
node_api_controllers -->|"protected by"| node_api_middleware
node_api_entry -->|"initializes"| node_api_config
node_api_config -->|"connects"| node_db
node_api_config -.->|"optionally uses"| node_redis
node_api_controllers -->|"uploads to"| node_cloudinary
node_api_controllers -->|"charges via"| node_payments
node_api_controllers -->|"notifies via"| node_messaging
node_email_worker -->|"sends"| node_messaging
node_api_controllers -.->|"queues"| node_email_worker
node_api_controllers -->|"persists to"| node_db

click node_frontend_shell "https://github.com/theunstopabble/swadkart-pro/blob/main/frontend/src/App.jsx"
click node_frontend_shared_state "https://github.com/theunstopabble/swadkart-pro/blob/main/frontend/src/redux/store.js"
click node_customer_portals "https://github.com/theunstopabble/swadkart-pro/blob/main/frontend/src/pages/Home.jsx"
click node_merchant_portal "https://github.com/theunstopabble/swadkart-pro/blob/main/frontend/src/pages/RestaurantOwnerDashboard.jsx"
click node_delivery_portal "https://github.com/theunstopabble/swadkart-pro/blob/main/frontend/src/pages/DeliveryPartnerDashboard.jsx"
click node_admin_portal "https://github.com/theunstopabble/swadkart-pro/blob/main/frontend/src/pages/AdminDashboard.jsx"
click node_ux_extras "https://github.com/theunstopabble/swadkart-pro/blob/main/frontend/src/components/ChatBot.jsx"
click node_order_ui "https://github.com/theunstopabble/swadkart-pro/blob/main/frontend/src/components/CheckoutSteps.jsx"
click node_restaurant_ui "https://github.com/theunstopabble/swadkart-pro/blob/main/frontend/src/components/restaurant/MenuManagement.jsx"
click node_delivery_ui "https://github.com/theunstopabble/swadkart-pro/blob/main/frontend/src/components/delivery/DeliveryCard.jsx"
click node_frontend_integrations "https://github.com/theunstopabble/swadkart-pro/blob/main/frontend/src/utils/firebaseConfig.js"
click node_api_entry "https://github.com/theunstopabble/swadkart-pro/blob/main/backend/server.js"
click node_api_routes "https://github.com/theunstopabble/swadkart-pro/blob/main/backend/routes/orderRoutes.js"
click node_api_controllers "https://github.com/theunstopabble/swadkart-pro/blob/main/backend/controllers/orderController.js"
click node_api_models "https://github.com/theunstopabble/swadkart-pro/blob/main/backend/models/orderModel.js"
click node_api_middleware "https://github.com/theunstopabble/swadkart-pro/blob/main/backend/middleware/authMiddleware.js"
click node_api_config "https://github.com/theunstopabble/swadkart-pro/blob/main/backend/config/db.js"
click node_email_worker "https://github.com/theunstopabble/swadkart-pro/blob/main/backend/workers/emailWorker.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_frontend_shell,node_frontend_shared_state,node_customer_portals,node_merchant_portal,node_delivery_portal,node_admin_portal,node_ux_extras,node_order_ui,node_restaurant_ui,node_delivery_ui,node_frontend_integrations toneBlue
class node_api_entry,node_api_routes,node_api_controllers,node_api_models,node_api_middleware,node_api_config,node_email_worker toneAmber
class node_db,node_redis,node_cloudinary,node_payments,node_messaging toneMint
```

## Components

### Frontend

React client with role-based portals, shared state, and feature components

- [App shell](https://github.com/theunstopabble/swadkart-pro/blob/main/frontend/src/App.jsx): Vite React app · Root client app with routing and shared session state · `frontend/src/App.jsx`
- [Shared state](https://github.com/theunstopabble/swadkart-pro/blob/main/frontend/src/redux/store.js): Redux Toolkit · Cart and user/session state management · `frontend/src/redux/store.js`
- [Customer flows](https://github.com/theunstopabble/swadkart-pro/blob/main/frontend/src/pages/Home.jsx): pages · Discovery, cart, checkout, payment, orders, profile, and support pages · `frontend/src/pages/Home.jsx`
- [Merchant portal](https://github.com/theunstopabble/swadkart-pro/blob/main/frontend/src/pages/RestaurantOwnerDashboard.jsx): owner dashboard · Restaurant owner menu, live orders, and analytics views · `frontend/src/pages/RestaurantOwnerDashboard.jsx`
- [Delivery portal](https://github.com/theunstopabble/swadkart-pro/blob/main/frontend/src/pages/DeliveryPartnerDashboard.jsx): partner dashboard · Delivery workflow, OTP confirmation, earnings, and SOS support · `frontend/src/pages/DeliveryPartnerDashboard.jsx`
- [Admin portal](https://github.com/theunstopabble/swadkart-pro/blob/main/frontend/src/pages/AdminDashboard.jsx): admin dashboard · Operations overview, users, shops, orders, coupons, and heatmap tools · `frontend/src/pages/AdminDashboard.jsx`
- [UX extras](https://github.com/theunstopabble/swadkart-pro/blob/main/frontend/src/components/ChatBot.jsx): assistive UI · Chatbot, voice search, PWA install prompt, and notification helper · `frontend/src/components/ChatBot.jsx`
- [Order UI](https://github.com/theunstopabble/swadkart-pro/blob/main/frontend/src/components/CheckoutSteps.jsx): checkout components · Cart, address, coupon, tracking, summary, and success flow components · `frontend/src/components/CheckoutSteps.jsx`
- [Restaurant UI](https://github.com/theunstopabble/swadkart-pro/blob/main/frontend/src/components/restaurant/MenuManagement.jsx): merchant components · Menu management, live orders, analytics, and item editing components · `frontend/src/components/restaurant/MenuManagement.jsx`
- [Delivery UI](https://github.com/theunstopabble/swadkart-pro/blob/main/frontend/src/components/delivery/DeliveryCard.jsx): partner components · Delivery card, OTP section, earnings history, and SOS button · `frontend/src/components/delivery/DeliveryCard.jsx`
- [Client integrations](https://github.com/theunstopabble/swadkart-pro/blob/main/frontend/src/utils/firebaseConfig.js): auth and realtime helpers · Google auth, Firebase config, biometric client calls, and socket client · `frontend/src/utils/firebaseConfig.js`

### Backend

Express API, domain logic, persistence, and background jobs

- [API entry](https://github.com/theunstopabble/swadkart-pro/blob/main/backend/server.js): Express server · App composition, database bootstrap, sockets, and route mounting · `backend/server.js`
- [API routes](https://github.com/theunstopabble/swadkart-pro/blob/main/backend/routes/orderRoutes.js): HTTP routes · Endpoint surface for auth, orders, products, restaurants, coupons, payments, chat, upload, and biometrics · `backend/routes/orderRoutes.js`
- [Controllers](https://github.com/theunstopabble/swadkart-pro/blob/main/backend/controllers/orderController.js): business logic · Role-specific request handlers and workflow orchestration · `backend/controllers/orderController.js`
- [Data models](https://github.com/theunstopabble/swadkart-pro/blob/main/backend/models/orderModel.js): Mongoose schemas · Users, restaurants, products, orders, coupons, coupon usage, and emergency records · `backend/models/orderModel.js`
- [Middleware](https://github.com/theunstopabble/swadkart-pro/blob/main/backend/middleware/authMiddleware.js): security and errors · Auth protection, access control, sanitization, and centralized error handling · `backend/middleware/authMiddleware.js`
- [Backend config](https://github.com/theunstopabble/swadkart-pro/blob/main/backend/config/db.js): service config · Database, Cloudinary, Redis, and WebAuthn configuration · `backend/config/db.js`
- [Email worker](https://github.com/theunstopabble/swadkart-pro/blob/main/backend/workers/emailWorker.js): background job · Asynchronous transactional email processing · `backend/workers/emailWorker.js`

### External services

Datastores and third-party providers used by the app

- **MongoDB**: primary datastore · System of record for commerce, fulfillment, and identity data
- **Redis**: optional cache · Shared cache with in-memory fallback for local runs
- **Cloudinary**: media storage · Image upload and asset storage provider
- **Payments**: Stripe/Razorpay · External payment gateways for checkout
- **Messaging**: SMTP/Firebase/push · Email, push notifications, and device messaging providers

## Connections

- App shell → Shared state: uses · App consumes shared cart and user state
- App shell → Customer flows: routes to · Primary customer navigation
- App shell → Merchant portal: routes to · Restaurant owner portal navigation
- App shell → Delivery portal: routes to · Delivery partner portal navigation
- App shell → Admin portal: routes to · Admin portal navigation
- Customer flows → Order UI: uses · Checkout and order lifecycle UI
- Merchant portal → Restaurant UI: uses · Menu and live order management UI
- Delivery portal → Delivery UI: uses · Delivery execution and handoff UI
- Customer flows → UX extras: augmented by · Voice search, chatbot, install prompt, and notifications
- Client integrations → API entry: calls · Authenticated API and realtime communication
- Client integrations → Messaging: auth/messaging · Firebase and notification helpers
- API entry → API routes: mounts · HTTP endpoint registration
- API routes → Controllers: dispatches · Routes hand off to business logic
- Controllers → Data models: reads/writes · Business logic persists domain entities
- Controllers → Middleware: protected by · Role checks, sanitization, and error handling
- API entry → Backend config: initializes · Database and service configuration
- Backend config → MongoDB: connects · MongoDB connection
- Backend config → Redis: optionally uses · Cache with fallback to memory
- Controllers → Cloudinary: uploads to · Media handling for restaurant and product images
- Controllers → Payments: charges via · Checkout payment processing
- Controllers → Messaging: notifies via · OTP, email, push, and transactional messaging
- Email worker → Messaging: sends · Async email delivery
- Controllers → Email worker: queues · Offloads slow email work
- Controllers → MongoDB: persists to · Primary data store
