# akash2xd/mega-electricals- architecture

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

- Interactive diagram: https://gitdiagram.com/akash2xd/mega-electricals-
- Repository: https://github.com/akash2xd/mega-electricals-

## Overview

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: [`frontend/src/App.jsx`](https://github.com/akash2xd/mega-electricals-/blob/main/frontend/src/App.jsx) (SPA shell), [`backend/server.js`](https://github.com/akash2xd/mega-electricals-/blob/main/backend/server.js) (Server), [`frontend/src/components/ProductGrid.jsx`](https://github.com/akash2xd/mega-electricals-/blob/main/frontend/src/components/ProductGrid.jsx) (Product grid), [`frontend/src/components/Cart.jsx`](https://github.com/akash2xd/mega-electricals-/blob/main/frontend/src/components/Cart.jsx) (Cart view)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_frontend_main(("App entry<br/>vite/react bootstrap<br/>[main.jsx]"))
  node_frontend_shell["SPA shell<br/>react shell<br/>[App.jsx]"]
  node_frontend_nav["Navbar<br/>ui component<br/>[Navbar.jsx]"]
  node_frontend_store["Store view<br/>catalog page<br/>[Store.jsx]"]
  node_frontend_grid["Product grid<br/>catalog component<br/>[ProductGrid.jsx]"]
  node_frontend_details["Product details<br/>product view<br/>[ProductDetails.jsx]"]
  node_frontend_cart["Cart view<br/>shopping cart ui<br/>[Cart.jsx]"]
  node_frontend_auth["Auth UI<br/>login/register ui<br/>[Auth.jsx]"]
  node_frontend_admin["Admin panel<br/>admin ui<br/>[AdminPanel.jsx]"]
  node_frontend_inquiry["Bulk inquiry<br/>contact workflow ui<br/>[BulkInquiry.jsx]"]
  node_frontend_orders["My orders<br/>account ui<br/>[MyOrders.jsx]"]
  node_frontend_cartctx(("Cart context<br/>client store<br/>[CartContext.jsx]"))
  node_frontend_catalog["Catalog data<br/>static data<br/>[itemsData.js]"]
  node_frontend_content["Content pages<br/>informational pages"]
end

subgraph group_backend["Backend"]
  node_backend_server(("Server<br/>express entrypoint<br/>[server.js]"))
  node_backend_db["DB config<br/>mongodb connection<br/>[db.js]"]
  node_backend_authmw["Auth middleware<br/>jwt guard<br/>[authMiddleware.js]"]
  node_backend_auth["Auth API<br/>domain api"]
  node_backend_admin["Admin API<br/>domain api"]
  node_backend_cart["Cart API<br/>domain api"]
  node_backend_orders["Orders API<br/>domain api"]
  node_backend_inquiry["Inquiry API<br/>domain api"]
  node_backend_models[("Models<br/>mongoose schemas")]
  node_backend_user[("User<br/>mongoose model<br/>[User.js]")]
  node_backend_product[("Product<br/>mongoose model<br/>[Product.js]")]
  node_backend_cartmodel[("Cart<br/>mongoose model<br/>[Cart.js]")]
  node_backend_ordermodel[("Order<br/>mongoose model<br/>[Order.js]")]
  node_backend_inqmodel[("Inquiry<br/>mongoose model<br/>[Inquiry.js]")]
  node_backend_email["Email sender<br/>smtp integration<br/>[sendEmail.js]"]
end

subgraph group_external["External"]
  node_external_mongo[("MongoDB<br/>database")]
  node_external_smtp["SMTP<br/>mail service"]
end

node_frontend_main -->|"boots"| node_frontend_shell
node_frontend_shell -->|"composes"| node_frontend_nav
node_frontend_shell -->|"renders"| node_frontend_store
node_frontend_shell -->|"renders"| node_frontend_cart
node_frontend_shell -->|"renders"| node_frontend_auth
node_frontend_shell -->|"renders"| node_frontend_admin
node_frontend_shell -->|"renders"| node_frontend_inquiry
node_frontend_shell -->|"renders"| node_frontend_orders
node_frontend_store -->|"uses"| node_frontend_grid
node_frontend_grid -->|"opens"| node_frontend_details
node_frontend_grid -->|"reads"| node_frontend_catalog
node_frontend_cart -->|"shares state"| node_frontend_cartctx
node_frontend_details -->|"updates cart"| node_frontend_cartctx
node_frontend_auth -->|"calls"| node_backend_auth
node_frontend_admin -->|"calls"| node_backend_admin
node_frontend_cart -->|"syncs"| node_backend_cart
node_frontend_orders -->|"fetches"| node_backend_orders
node_frontend_inquiry -->|"submits"| node_backend_inquiry
node_frontend_content -->|"feeds"| node_frontend_shell
node_backend_server -->|"initializes"| node_backend_db
node_backend_server -->|"mounts"| node_backend_auth
node_backend_server -->|"mounts"| node_backend_admin
node_backend_server -->|"mounts"| node_backend_cart
node_backend_server -->|"mounts"| node_backend_orders
node_backend_server -->|"mounts"| node_backend_inquiry
node_backend_auth -->|"guards"| node_backend_authmw
node_backend_admin -->|"guards"| node_backend_authmw
node_backend_auth -->|"reads/writes"| node_backend_user
node_backend_admin -->|"reads/writes"| node_backend_product
node_backend_cart -->|"reads/writes"| node_backend_cartmodel
node_backend_orders -->|"reads/writes"| node_backend_ordermodel
node_backend_inquiry -->|"reads/writes"| node_backend_inqmodel
node_backend_models -->|"includes"| node_backend_user
node_backend_models -->|"includes"| node_backend_product
node_backend_models -->|"includes"| node_backend_cartmodel
node_backend_models -->|"includes"| node_backend_ordermodel
node_backend_models -->|"includes"| node_backend_inqmodel
node_backend_inquiry -->|"triggers"| node_backend_email
node_backend_email -->|"uses"| node_external_smtp
node_backend_db -->|"connects"| node_external_mongo
node_backend_user -->|"persists to"| node_external_mongo
node_backend_product -->|"persists to"| node_external_mongo
node_backend_cartmodel -->|"persists to"| node_external_mongo
node_backend_ordermodel -->|"persists to"| node_external_mongo
node_backend_inqmodel -->|"persists to"| node_external_mongo

click node_frontend_main "https://github.com/akash2xd/mega-electricals-/blob/main/frontend/src/main.jsx"
click node_frontend_shell "https://github.com/akash2xd/mega-electricals-/blob/main/frontend/src/App.jsx"
click node_frontend_nav "https://github.com/akash2xd/mega-electricals-/blob/main/frontend/src/components/Navbar.jsx"
click node_frontend_store "https://github.com/akash2xd/mega-electricals-/blob/main/frontend/src/components/Store.jsx"
click node_frontend_grid "https://github.com/akash2xd/mega-electricals-/blob/main/frontend/src/components/ProductGrid.jsx"
click node_frontend_details "https://github.com/akash2xd/mega-electricals-/blob/main/frontend/src/components/ProductDetails.jsx"
click node_frontend_cart "https://github.com/akash2xd/mega-electricals-/blob/main/frontend/src/components/Cart.jsx"
click node_frontend_auth "https://github.com/akash2xd/mega-electricals-/blob/main/frontend/src/components/Auth.jsx"
click node_frontend_admin "https://github.com/akash2xd/mega-electricals-/blob/main/frontend/src/components/AdminPanel.jsx"
click node_frontend_inquiry "https://github.com/akash2xd/mega-electricals-/blob/main/frontend/src/components/BulkInquiry.jsx"
click node_frontend_orders "https://github.com/akash2xd/mega-electricals-/blob/main/frontend/src/components/MyOrders.jsx"
click node_frontend_cartctx "https://github.com/akash2xd/mega-electricals-/blob/main/frontend/src/context/CartContext.jsx"
click node_frontend_catalog "https://github.com/akash2xd/mega-electricals-/blob/main/frontend/src/data/itemsData.js"
click node_backend_server "https://github.com/akash2xd/mega-electricals-/blob/main/backend/server.js"
click node_backend_db "https://github.com/akash2xd/mega-electricals-/blob/main/backend/config/db.js"
click node_backend_authmw "https://github.com/akash2xd/mega-electricals-/blob/main/backend/middleware/authMiddleware.js"
click node_backend_user "https://github.com/akash2xd/mega-electricals-/blob/main/backend/models/User.js"
click node_backend_product "https://github.com/akash2xd/mega-electricals-/blob/main/backend/models/Product.js"
click node_backend_cartmodel "https://github.com/akash2xd/mega-electricals-/blob/main/backend/models/Cart.js"
click node_backend_ordermodel "https://github.com/akash2xd/mega-electricals-/blob/main/backend/models/Order.js"
click node_backend_inqmodel "https://github.com/akash2xd/mega-electricals-/blob/main/backend/models/Inquiry.js"
click node_backend_email "https://github.com/akash2xd/mega-electricals-/blob/main/backend/utils/sendEmail.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_main,node_frontend_shell,node_frontend_nav,node_frontend_store,node_frontend_grid,node_frontend_details,node_frontend_cart,node_frontend_auth,node_frontend_admin,node_frontend_inquiry,node_frontend_orders,node_frontend_cartctx,node_frontend_catalog,node_frontend_content toneBlue
class node_backend_server,node_backend_db,node_backend_authmw,node_backend_auth,node_backend_admin,node_backend_cart,node_backend_orders,node_backend_inquiry,node_backend_models,node_backend_user,node_backend_product,node_backend_cartmodel,node_backend_ordermodel,node_backend_inqmodel,node_backend_email toneAmber
class node_external_mongo,node_external_smtp toneMint
```

## Components

### Frontend

React/Vite SPA, UI state, catalog browsing, and user workflows

- [App entry](https://github.com/akash2xd/mega-electricals-/blob/main/frontend/src/main.jsx): vite/react bootstrap · Bootstraps the single-page app · `frontend/src/main.jsx`
- [SPA shell](https://github.com/akash2xd/mega-electricals-/blob/main/frontend/src/App.jsx): react shell · Top-level app composition and routing surface · `frontend/src/App.jsx`
- [Navbar](https://github.com/akash2xd/mega-electricals-/blob/main/frontend/src/components/Navbar.jsx): ui component · Primary navigation and user entry points · `frontend/src/components/Navbar.jsx`
- [Store view](https://github.com/akash2xd/mega-electricals-/blob/main/frontend/src/components/Store.jsx): catalog page · Public shopping experience and product browsing · `frontend/src/components/Store.jsx`
- [Product grid](https://github.com/akash2xd/mega-electricals-/blob/main/frontend/src/components/ProductGrid.jsx): catalog component · Lists products and highlights catalog items · `frontend/src/components/ProductGrid.jsx`
- [Product details](https://github.com/akash2xd/mega-electricals-/blob/main/frontend/src/components/ProductDetails.jsx): product view · Shows item-specific information and actions · `frontend/src/components/ProductDetails.jsx`
- [Cart view](https://github.com/akash2xd/mega-electricals-/blob/main/frontend/src/components/Cart.jsx): shopping cart ui · Client-side cart management and checkout entry · `frontend/src/components/Cart.jsx`
- [Auth UI](https://github.com/akash2xd/mega-electricals-/blob/main/frontend/src/components/Auth.jsx): login/register ui · Authentication forms and session entry · `frontend/src/components/Auth.jsx`
- [Admin panel](https://github.com/akash2xd/mega-electricals-/blob/main/frontend/src/components/AdminPanel.jsx): admin ui · Privileged management interface in the SPA · `frontend/src/components/AdminPanel.jsx`
- [Bulk inquiry](https://github.com/akash2xd/mega-electricals-/blob/main/frontend/src/components/BulkInquiry.jsx): contact workflow ui · Inquiry submission and bulk contact flow · `frontend/src/components/BulkInquiry.jsx`
- [My orders](https://github.com/akash2xd/mega-electricals-/blob/main/frontend/src/components/MyOrders.jsx): account ui · Displays the user's order history · `frontend/src/components/MyOrders.jsx`
- [Cart context](https://github.com/akash2xd/mega-electricals-/blob/main/frontend/src/context/CartContext.jsx): client store · Shared cart state across product and cart views · `frontend/src/context/CartContext.jsx`
- [Catalog data](https://github.com/akash2xd/mega-electricals-/blob/main/frontend/src/data/itemsData.js): static data · Seeded/public item data used by the frontend · `frontend/src/data/itemsData.js`
- **Content pages**: informational pages · About, policies, and other non-transactional pages

### Backend

Express API, domain controllers, persistence, and authorization

- [Server](https://github.com/akash2xd/mega-electricals-/blob/main/backend/server.js): express entrypoint · Starts the API server and wires the application · `backend/server.js`
- [DB config](https://github.com/akash2xd/mega-electricals-/blob/main/backend/config/db.js): mongodb connection · Creates and manages the MongoDB connection · `backend/config/db.js`
- [Auth middleware](https://github.com/akash2xd/mega-electricals-/blob/main/backend/middleware/authMiddleware.js): jwt guard · Protects routes and enforces role boundaries · `backend/middleware/authMiddleware.js`
- **Auth API**: domain api · Registration, login, and profile access
- **Admin API**: domain api · Privileged management operations
- **Cart API**: domain api · Cart persistence and retrieval
- **Orders API**: domain api · Purchases and order lookup
- **Inquiry API**: domain api · Contact and bulk inquiry workflows
- **Models**: mongoose schemas · Persistent data definitions used by the API
- [User](https://github.com/akash2xd/mega-electricals-/blob/main/backend/models/User.js): mongoose model · Accounts and identity records · `backend/models/User.js`
- [Product](https://github.com/akash2xd/mega-electricals-/blob/main/backend/models/Product.js): mongoose model · Inventory and catalog records · `backend/models/Product.js`
- [Cart](https://github.com/akash2xd/mega-electricals-/blob/main/backend/models/Cart.js): mongoose model · Stored cart state · `backend/models/Cart.js`
- [Order](https://github.com/akash2xd/mega-electricals-/blob/main/backend/models/Order.js): mongoose model · Purchase and fulfillment records · `backend/models/Order.js`
- [Inquiry](https://github.com/akash2xd/mega-electricals-/blob/main/backend/models/Inquiry.js): mongoose model · Contact and bulk inquiry records · `backend/models/Inquiry.js`
- [Email sender](https://github.com/akash2xd/mega-electricals-/blob/main/backend/utils/sendEmail.js): smtp integration · Outbound email helper for workflows and notifications · `backend/utils/sendEmail.js`

### External

Runtime and service dependencies

- **MongoDB**: database · System of record for users, products, carts, orders, and inquiries
- **SMTP**: mail service · Outbound email transport used by backend workflows

## Connections

- 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
