How theunstopabble/swadkart works
1. Overall shape
SwadKart is a two-tier MERN platform: a React/Vite frontend and an Express/Node backend. The backend exposes a large REST API plus Socket.io real-time channels; the frontend consumes both and is organized around role-based pages for customers, admins, restaurant owners, and delivery partners.
2. Frontend boundary
The frontend is a single-page app built with React 19, Redux Toolkit, React Router, Tailwind, and Socket.io-client. It owns UI state, cart/user state, i18n, PWA behavior, voice search, biometric login UX, and live views such as order tracking and chat streaming. The app shell in App.jsx is the main composition point for routing, guards, and lazy-loaded pages.
3. Backend entry and request pipeline
backend/server.js is the backend composition root. Requests flow through middleware for auth, roles, validation, cache, fraud detection, and error handling before reaching controllers. This boundary is important: controllers orchestrate business actions, while middleware enforces cross-cutting policy such as JWT auth, rate limits, and sanitization.
4. Domain/API layer
The backend is split into many route/controller pairs, roughly by business domain: auth/users, products/restaurants, orders/payments, reservations/group orders, delivery, coupons, subscriptions, loyalty/gamification, analytics, GDPR, notifications, and image upload. This suggests a modular monolith rather than microservices; each route module maps to a feature area and delegates to a matching controller.
5. Persistence layer
MongoDB is the primary system of record through Mongoose models. The models cover core commerce entities like users, restaurants, products, orders, reservations, coupons, subscriptions, referrals, group orders, notifications, payouts, and conversations. The architecture likely centers on MongoDB documents as the source of truth for both transactional flows and conversational history.
6. Caching and fast-path reads
Redis is used for response caching and also backs jobs/queues where available, with an in-memory fallback mentioned in config. This cache layer sits beside MongoDB to reduce repeated reads for GET-heavy endpoints, chat rate limiting, and async work coordination.
7. Payments, fulfillment, and commerce flow
The core transaction path is: browse menu → build cart → apply coupon/subscription/surge logic → pay via Razorpay or COD → create order → dispatch to delivery tracking/updates. Order-related controllers and calculators indicate pricing is computed server-side, not trusted from the client, which is important for diagramming the trust boundary.
8. Real-time and delivery tracking
Socket.io supports live order status and GPS-style delivery tracking. Frontend components such as live maps and order progress consume these updates, while backend delivery/order controllers publish state changes. This is a separate real-time channel from the REST API and should be shown as a parallel path.
9. AI chatbot subsystem
The backend/services/chat subtree is a distinct subsystem: intent classification, language detection, sentiment, retrieval, token budgeting, fallback responses, and Groq integration. Tooling modules allow the chatbot to invoke business actions like order status, cancel, reorder, coupon lookup, delivery ETA, and FAQ. On the frontend, the chatbot UI streams responses via SSE-style event parsing, so the chatbot path is a mix of REST, streaming, and action execution.
10. Media, identity, and external integrations
Cloudinary handles uploaded images, Firebase is used for Google auth and push-related client setup, WebAuthn supports biometric login, and email delivery is offloaded through a worker queue. These integrations are not incidental: they define external boundaries for authentication, storage, notifications, and asynchronous processing.
11. Async processing
backend/workers/emailWorker.js and the chat cleanup/queue services show that the backend includes background jobs, not just synchronous API handlers. Email delivery and chat maintenance are decoupled from request-response latency, which matters for showing non-blocking workflows in the architecture diagram.
12. Security and policy layer
The repo emphasizes multiple enforcement layers: JWT cookies, role-based authorization, CSRF/origin checks, rate limiting, fraud detection heuristics, and input sanitization. There is also GDPR-specific functionality for export and deletion. These are horizontal controls across the API rather than separate features.
13. Frontend product areas
The UI is segmented by user role and workflow: public marketing/home, restaurant browsing, cart/checkout/payment, customer order history, admin analytics, restaurant owner dashboards, delivery partner dashboard, subscription/gamification, reservations, and support/chat. Reusable components under src/components are organized by these domains, not by generic design-system layers.
14. Testing, documentation, and delivery
The repo includes substantial automated testing, especially property-based tests for the chat pipeline, tools, and streaming behavior, plus integration tests. GitHub Actions runs backend syntax checks, frontend lint/build, and deployment-related validation. The docs/ folder contains explicit architecture, API, DB schema, deployment, and workflow docs, indicating the repo is designed to be diagrammed and operated as a production system.
15. Deployment topology
The intended deployment splits frontend and backend: frontend on Vercel, backend on Render, MongoDB Atlas for persistence, Redis as optional cache/job backend, and Cloudinary/Razorpay/Firebase/Groq as external SaaS dependencies. For an architecture diagram, it’s best to show the frontend as an edge-hosted SPA that talks to the backend API and Socket.io endpoint, which in turn connects to MongoDB and external service providers.
Main entry points: orderController.js Domain Controllers · App.jsx App Shell · server.js Server · chatPipeline.js Chat Pipeline
Components 21
Frontend
React/Vite SPA with role-based UX, cart/order flows, and live chatbot/tracking views
- App Shell · Composes routes, guards, lazy pages, and global app state
frontend/src/App.jsx - Redux Store · Cart and user state shared across the SPA
frontend/src/redux/store.js - Chatbot UI · Chat widget, streaming parser, voice controls, and past conversations
frontend/src/components/ChatBot.jsx - Order Flow · Cart, checkout, payment, and live tracking screens
frontend/src/pages/Cart.jsx - Role Dashboards · Admin, restaurant owner, delivery partner, and customer pages
frontend/src/pages/AdminDashboard.jsx - PWA/i18n · Internationalization, install prompt, voice, and biometric login UX
frontend/src/i18n.js
Backend
Express/Node modular monolith with REST, realtime, and background jobs
- Server · Backend composition root and HTTP/Socket.io bootstrap
backend/server.js - Middleware Gate · Auth, roles, cache, validation, fraud detection, and error handling
backend/middleware/authMiddleware.js - REST Routes · Feature routes for auth, commerce, delivery, analytics, and utilities
backend/routes/orderRoutes.js - Domain Controllers · Controllers coordinating orders, products, payments, delivery, and admin features
backend/controllers/orderController.js - Chat Pipeline · Intent, retrieval, tools, streaming, fallback, and Groq integration
backend/services/chat/chatPipeline.js - Mongo Models · Source-of-truth documents for users, orders, restaurants, conversations, and commerce entities
backend/models/orderModel.js - Email Worker · Decoupled async delivery for email and maintenance tasks
backend/workers/emailWorker.js
Data & Infra
Persistence, cache, and external service boundaries
- Runtime Config · Database, Redis, Cloudinary, and WebAuthn setup
backend/config/db.js - Redis Cache · Fast-path reads, rate limiting support, and queue/fallback coordination
backend/config/redis.js - MongoDB · Primary persistence for transactional and conversational data
- Redis · Shared cache and job backend for low-latency and async workflows
- Cloudinary · External image upload and asset hosting boundary
- Firebase · External Google auth and push-related client integration
frontend/src/utils/firebaseConfig.js - Payments · External checkout payment boundary used by the backend payment flow
- Groq AI · External model provider used by chatbot generation and fallback flows
Connections 26
- App Shell → Redux Store: reads/writes · App shell uses shared client state
- App Shell → Chatbot UI: mounts · Chatbot is composed into the SPA shell
- App Shell → Order Flow: routes to · App shell exposes commerce and tracking pages
- App Shell → Role Dashboards: routes to · Role-specific dashboards are loaded from the main shell
- App Shell → PWA/i18n: enables · Global UX features are initialized at app level
- Order Flow → Server: API calls · Checkout and tracking screens consume backend endpoints
- Chatbot UI → Server: stream/api · Chat widget consumes REST and streaming responses
- Role Dashboards → Server: API calls · Dashboards fetch and mutate server state
- Server → Middleware Gate: passes through · Requests enter the middleware policy layer first
- Middleware Gate → REST Routes: allows · Validated requests reach feature routes
- REST Routes → Domain Controllers: delegates · Routes hand off to business controllers
- Domain Controllers → Mongo Models: reads/writes · Controllers persist and load Mongo documents
- Domain Controllers → Redis Cache: fast path · Controllers use cache for repeated reads and coordination
- Redis Cache → Redis: backed by · Redis provides shared cache and queue storage
- Mongo Models → MongoDB: stored in · MongoDB is the primary system of record
- Server → Chat Pipeline: hosts · Chat subsystem is exposed alongside REST
- Chat Pipeline → Groq AI: generates · LLM provider powers assistant responses
- Chat Pipeline → Mongo Models: reads/writes · Conversation history and chat state persist in Mongo
- Chat Pipeline → Redis: queues/cache · Chat rate limiting and async handling can use Redis
- Domain Controllers → Payments: charges · Payment controllers integrate with external checkout provider
- Domain Controllers → Cloudinary: uploads · Image and media flows reach Cloudinary
- Domain Controllers → Firebase: auth/push · Client and auth flows rely on Firebase integration
- Email Worker → Domain Controllers: consumes jobs from · Background work is decoupled from request latency
- Email Worker → Redis: pulls from · Worker queue can be backed by Redis
- Runtime Config → MongoDB: connects · Database configuration initializes Mongo connectivity
- Runtime Config → Redis: connects · Runtime config wires Redis when enabled