How arifictedge/gadgethub works
1. Repo shape / deployment boundary
GadgetHub is split into three runtime areas: frontend/ for the React client, backend/ for the Express + MongoDB API, and api/ plus vercel.json for Vercel/serverless deployment glue. This is a decoupled frontend-backend architecture rather than a single monolith.
2. Client application shell
The React app is Vite-based and starts in frontend/src/main.jsx, with App.jsx handling top-level routing and composition. Global styling comes from Tailwind (tailwind.config.js, index.css), and the app is organized around pages plus reusable layout/product components.
3. Frontend presentation layer
The UI is split into reusable layout pieces (Navbar, Footer, Layout, MobileBottomNav, FloatingActions) and domain components like ProductCard. This suggests the visual shell is shared across pages, while product and commerce views are composed from smaller widgets.
4. Client-side state boundaries
AuthContext and CartContext are the main client-wide state containers. Authentication and cart state are not kept inside individual pages; they are lifted into context so product listing, checkout, navbar, dashboard, and admin views can all read/update them consistently.
5. Frontend feature pages
The pages map directly to commerce flows: browsing (Home, Products, Categories, ProductDetail, Compare), transaction flow (Cart, Checkout), auth (Login, Register), account (UserDashboard), and admin operations (AdminDashboard, AdminProducts, AdminOrders, AdminUsers). This gives a clear separation between customer-facing and staff-facing areas.
6. API access pattern
frontend/src/lib/api.js is the client’s dedicated API boundary. All server communication should flow through this helper rather than being scattered across components, which centralizes base URL handling and request behavior.
7. Backend request pipeline
The backend is a conventional Express service with src/index.js as the entry point and src/app.js as the app wiring layer. Routing is separated from business logic: route files dispatch to controllers, and controllers implement the actual product, order, auth, and user operations.
8. Backend domain model layer
MongoDB data is modeled with Mongoose in src/models/ for Product, User, and Order. Those three models define the core commerce entities and are the main persistence boundary for the system.
9. Security and cross-cutting middleware
authMiddleware.js guards protected routes, especially for authenticated user and admin operations. errorMiddleware.js centralizes API error handling, which keeps controller logic cleaner and makes the backend behavior more uniform.
10. Operational scripts and data hygiene
seed.js supports initial database population, and migrateSlugs.js exists for SEO-friendly product URL maintenance. The README’s mention of JWT, bcrypt, CORS, and rate limiting indicates the backend also handles stateless auth and API hardening as first-class concerns.
11. Main data flow
A typical request path is: user action in the React page → shared UI/context state → api.js request → Express route → controller → Mongoose model → MongoDB → JSON response back to the client. Authentication adds a JWT check in middleware before sensitive order/user/admin endpoints are processed.
Main entry points: App.jsx App shell · api.js API client · Layout.jsx Layout shell · app.js App wiring
Components 22
Frontend
React client, shared UI, and commerce pages
- Main entry · Starts the React client and mounts the app
frontend/src/main.jsx - App shell · Defines top-level routing and composition
frontend/src/App.jsx - Layout shell · Shared navigation, footer, and responsive action UI
frontend/src/components/layout/Layout.jsx - Navbar · Top navigation and session/cart entry points
frontend/src/components/layout/Navbar.jsx - Footer · Bottom page chrome and site links
frontend/src/components/layout/Footer.jsx - Mobile nav · Bottom navigation for small screens
frontend/src/components/layout/MobileBottomNav.jsx - Product card · Reusable product presentation component
frontend/src/components/product/ProductCard.jsx - Auth state · Client-wide authentication and session state
frontend/src/context/AuthContext.jsx - Cart state · Client-wide shopping cart state and actions
frontend/src/context/CartContext.jsx - API client · Central browser-side boundary for server requests
frontend/src/lib/api.js - Customer pages · Browse, compare, cart, checkout, and account flows
- Admin pages · Administrative dashboards for products, orders, and users
Backend
Express API, request pipeline, and MongoDB persistence
- Server entry · Starts the API process and launches the service
backend/src/index.js - App wiring · Configures middleware and mounts routes
backend/src/app.js - Routes · Endpoint layer for auth, products, orders, and users
- Controllers · Implements request handling for commerce and account operations
- Data models · Core MongoDB entities for products, users, and orders
- Auth guard · Protects authenticated and admin-only API routes
backend/src/middlewares/authMiddleware.js - Error handler · Centralizes API error responses and failure handling
backend/src/middlewares/errorMiddleware.js - MongoDB · Persistent store for commerce data
backend/src/config/db.js
Deployment
Serverless entrypoints and hosting glue
- Vercel API · Deployment entrypoint for serverless API handling
api/index.js - Vercel config · Hosting and routing configuration for deployment
vercel.json
Connections 25
- Main entry → App shell: bootstraps · Mounts the application shell and route tree
- App shell → Layout shell: uses · Wraps pages in shared UI chrome
- Layout shell → Navbar: contains · Includes the primary site navigation
- Layout shell → Footer: contains · Includes the shared footer
- Layout shell → Mobile nav: contains · Includes mobile navigation affordances
- App shell → Customer pages: routes · Directs customer traffic to feature pages
- App shell → Admin pages: routes · Directs staff traffic to admin pages
- App shell → Auth state: reads · Uses authentication state across the app
- App shell → Cart state: reads · Uses cart state across the app
- Customer pages → Product card: composes · Builds catalog views from reusable product cards
- Customer pages → API client: calls · Fetches products, cart, auth, and order data
- Admin pages → API client: calls · Performs administrative API operations
- Auth state → API client: auth flow · Coordinates login and session-related requests
- Cart state → API client: cart flow · Syncs cart-related requests with the backend
- API client → Vercel API: requests · Sends client traffic to the deployed API surface
- Vercel API → Vercel config: uses · Follows deployment routing and runtime rules
- Vercel API → Server entry: invokes · Serverless entrypoint forwards into the API server
- Server entry → App wiring: starts · Launches the Express application
- App wiring → Routes: mounts · Attaches route modules to the app
- Routes → Controllers: dispatches · Routes requests into domain handlers
- Controllers → Data models: reads/writes · Applies business logic through data models
- Data models → MongoDB: persists · Stores commerce entities in MongoDB
- Routes → Auth guard: protects · Applies auth checks to sensitive endpoints
- App wiring → Error handler: handles · Converts failures into consistent API responses
- App wiring → MongoDB: connects · Initializes database connectivity