How akash2xd/mega-electricals- works
1. This is a two-tier MERN application: a React single-page frontend and an Express/MongoDB backend. The boundary is a REST API consumed by the UI, with authentication and business operations enforced on the server.
2. The backend is the system of record. It uses MongoDB via Mongoose models for users, products, carts, orders, and inquiries. The config/db.js module handles database connection, and server.js is the app entrypoint.
3. Server-side concerns are split by domain in the backend:
- authController + authRoutes for registration/login/profile
- adminController + adminRoutes for privileged management
- cartController + cartRoutes for cart persistence
- orderController + orderRoutes for purchases/order retrieval
- inquiryController + inquiryRoutes for contact/bulk inquiry workflows
4. Authentication is JWT-based. middleware/authMiddleware.js likely protects routes and separates regular users from admin actions. That makes authorization a server-side boundary rather than a frontend-only check.
5. Email is part of the backend workflow through utils/sendEmail.js. This suggests inquiries or order-related events can trigger outbound SMTP mail, so email is an external integration alongside MongoDB.
6. The frontend is a React app built with Vite and styled with Tailwind. Its structure is mostly component-driven, with reusable UI pieces such as Navbar, Hero, Featured, Categories, ProductGrid, ProductDetails, Cart, AdminPanel, BulkInquiry, and MyOrders.
7. Frontend state is split between local UI and shared cart state. context/CartContext.jsx is the main global client-side store, coordinating cart interactions across product, cart, and checkout-related components.
8. Product browsing appears to be a mix of static catalog content and backend-managed inventory. frontend/src/data/itemsData.js provides seeded/catalog data for public browsing UI, while the backend Product model and admin routes imply that actual inventory management is persisted and controlled server-side.
9. User-facing pages cover both commerce and informational content. In addition to store/cart flows, there are standalone pages for About, shipping, returns, privacy, terms, and testimonials, which means the frontend also serves as a content site, not just an order flow.
10. The main data flow is: browser loads the React app, user browses catalog and manages cart locally, then authenticated actions call the backend API for login, orders, inquiries, and admin operations. Server responses come back as JSON, and the frontend renders results into the SPA.
11. Admin functionality is a distinct subsystem rather than a separate app. The admin UI lives in the frontend, but product/order/customer control is enforced by backend routes and database models, keeping privileged operations behind authenticated API endpoints.
12. Deployment is split by layer. The frontend has Vercel configuration, and the backend is designed to run as a Node service with environment variables for port, MongoDB URI, JWT secret, and email credentials. That makes external infrastructure dependencies explicit: MongoDB, SMTP, and a Node hosting platform.
Main entry points: App.jsx SPA shell · server.js Server · ProductGrid.jsx Product grid · Cart.jsx Cart view
Components 31
Frontend
React/Vite SPA, UI state, catalog browsing, and user workflows
- App entry · Bootstraps the single-page app
frontend/src/main.jsx - SPA shell · Top-level app composition and routing surface
frontend/src/App.jsx - Navbar · Primary navigation and user entry points
frontend/src/components/Navbar.jsx - Store view · Public shopping experience and product browsing
frontend/src/components/Store.jsx - Product grid · Lists products and highlights catalog items
frontend/src/components/ProductGrid.jsx - Product details · Shows item-specific information and actions
frontend/src/components/ProductDetails.jsx - Cart view · Client-side cart management and checkout entry
frontend/src/components/Cart.jsx - Auth UI · Authentication forms and session entry
frontend/src/components/Auth.jsx - Admin panel · Privileged management interface in the SPA
frontend/src/components/AdminPanel.jsx - Bulk inquiry · Inquiry submission and bulk contact flow
frontend/src/components/BulkInquiry.jsx - My orders · Displays the user's order history
frontend/src/components/MyOrders.jsx - Cart context · Shared cart state across product and cart views
frontend/src/context/CartContext.jsx - Catalog data · Seeded/public item data used by the frontend
frontend/src/data/itemsData.js - Content pages · About, policies, and other non-transactional pages
Backend
Express API, domain controllers, persistence, and authorization
- Server · Starts the API server and wires the application
backend/server.js - DB config · Creates and manages the MongoDB connection
backend/config/db.js - Auth middleware · Protects routes and enforces role boundaries
backend/middleware/authMiddleware.js - Auth API · Registration, login, and profile access
- Admin API · Privileged management operations
- Cart API · Cart persistence and retrieval
- Orders API · Purchases and order lookup
- Inquiry API · Contact and bulk inquiry workflows
- Models · Persistent data definitions used by the API
- User · Accounts and identity records
backend/models/User.js - Product · Inventory and catalog records
backend/models/Product.js - Cart · Stored cart state
backend/models/Cart.js - Order · Purchase and fulfillment records
backend/models/Order.js - Inquiry · Contact and bulk inquiry records
backend/models/Inquiry.js - Email sender · Outbound email helper for workflows and notifications
backend/utils/sendEmail.js
External
Runtime and service dependencies
- MongoDB · System of record for users, products, carts, orders, and inquiries
- SMTP · Outbound email transport used by backend workflows
Connections 45
- App entry → SPA shell: boots · Vite starts the React app from the entry module
- SPA shell → Navbar: composes · The app shell assembles shared navigation
- SPA shell → Store view: renders · The shell exposes the storefront experience
- SPA shell → Cart view: renders · The shell exposes cart workflows
- SPA shell → Auth UI: renders · The shell exposes sign-in and registration
- SPA shell → Admin panel: renders · The shell hosts admin management UI
- SPA shell → Bulk inquiry: renders · The shell exposes inquiry workflows
- SPA shell → My orders: renders · The shell shows user order history
- Store view → Product grid: uses · Store view delegates listing to the product grid
- Product grid → Product details: opens · Product listings lead into item detail views
- Product grid → Catalog data: reads · Public catalog content is sourced from local data
- Cart view → Cart context: shares state · Cart interactions are coordinated through context
- Product details → Cart context: updates cart · Item actions flow into shared cart state
- Auth UI → Auth API: calls · Authentication UI hits the auth API
- Admin panel → Admin API: calls · Admin UI uses privileged backend endpoints
- Cart view → Cart API: syncs · Cart UI persists cart state to the server
- My orders → Orders API: fetches · Order history is loaded from the API
- Bulk inquiry → Inquiry API: submits · Inquiry forms send requests to the backend
- Content pages → SPA shell: feeds · Informational pages are part of the same SPA
- Server → DB config: initializes · The server connects to MongoDB at startup
- Server → Auth API: mounts · Domain APIs are registered on the Express app
- Server → Admin API: mounts · Domain APIs are registered on the Express app
- Server → Cart API: mounts · Domain APIs are registered on the Express app
- Server → Orders API: mounts · Domain APIs are registered on the Express app
- Server → Inquiry API: mounts · Domain APIs are registered on the Express app
- Auth API → Auth middleware: guards · JWT checks separate authenticated users from public access
- Admin API → Auth middleware: guards · Admin actions are protected by authorization middleware
- Auth API → User: reads/writes · Authentication operates on user records
- Admin API → Product: reads/writes · Admin management updates inventory data
- Cart API → Cart: reads/writes · Cart persistence is backed by the cart model
- Orders API → Order: reads/writes · Orders are stored as persistent purchase records
- Inquiry API → Inquiry: reads/writes · Inquiry workflows store submitted requests
- Models → User: includes · The backend centralizes Mongoose schemas
- Models → Product: includes · The backend centralizes Mongoose schemas
- Models → Cart: includes · The backend centralizes Mongoose schemas
- Models → Order: includes · The backend centralizes Mongoose schemas
- Models → Inquiry: includes · The backend centralizes Mongoose schemas
- Inquiry API → Email sender: triggers · Inquiry-related workflows can send outbound mail
- Email sender → SMTP: uses · Email delivery relies on SMTP infrastructure
- DB config → MongoDB: connects · MongoDB stores the system of record
- User → MongoDB: persists to · User records are stored in MongoDB
- Product → MongoDB: persists to · Product records are stored in MongoDB
- Cart → MongoDB: persists to · Cart records are stored in MongoDB
- Order → MongoDB: persists to · Order records are stored in MongoDB
- Inquiry → MongoDB: persists to · Inquiry records are stored in MongoDB