How vgprojects07/shopsphere works
1. ShopSphere is a three-tier e-commerce system: a React/Vite client, an Express/Node API server, and a MySQL database. The client never talks to the database directly; all persistent operations flow through the backend REST API.
2. The frontend is organized around route-level pages in client/src/pages such as Home, Listing, Product Details, Cart, Checkout, Profile, Orders History, Auth, and Admin Dashboard. These pages are composed from reusable UI components in client/src/components like product cards, carousels, timelines, ratings, review lists, and navigation/footer elements.
3. Client-side state and cross-page behavior are centralized in client/src/context/StoreContext.jsx, which is the likely boundary for cart, wishlist, user session, and other shared store state. Filtering/search logic is separated into useFilteredProducts, which suggests product discovery is a mix of server-backed data plus local UI filtering.
4. The client’s API boundary is explicit in client/src/api/client.js and client/src/api/socket.js. This indicates two communication paths: standard HTTP for CRUD and checkout flows, and a real-time channel for live updates where needed. The presence of socket code and a server-side utils/realTime.js suggests the app supports push-style updates for some events rather than relying only on polling.
5. The backend is structured as a classic layered Express application. Routes in server/src/routes map to controllers in server/src/controllers, with middleware handling auth, validation, and error normalization. This keeps HTTP concerns separate from business logic and data access.
6. Domain boundaries on the server are split by feature: auth, users, products, cart, wishlist, orders, reviews, and admin. Each has its own route/controller pair, which is the clearest signal for the application’s bounded contexts and the likely main boxes in an architecture diagram.
7. Authentication and authorization are JWT-based, with helpers in server/src/utils/jwt.js and protection in server/src/middleware/authMiddleware.js. Role-based access is especially important for the admin area, where admin-only routes expose analytics and management functions. Password handling is likely backed by bcrypt, as noted in the README.
8. Data access is abstracted below controllers. server/src/models/query.js and server/src/services/productService.js indicate a split between raw database querying and higher-level service logic, at least for products. This is where business rules, joins, and derived views such as catalog/search results likely live.
9. The database is a dedicated MySQL schema defined in database/schema.sql and preloaded via database/seed.sql; server/setup-db.js exists to bootstrap that database from the server side as well. The schema covers core commerce entities: users, products, categories, orders, cart, wishlist, and reviews, which implies a relational model with foreign-key style relationships between customer activity and catalog data.
10. Admin functionality is a separate operational slice rather than just another page. AdminDashboardPage.jsx, adminController.js, adminRoutes.js, and mockAnalytics.js show a management plane for analytics and operational actions like product/order oversight. The admin UI likely consumes aggregated metrics from the backend, with mock analytics available for local/demo rendering.
11. The runtime flow is straightforward: the user interacts with a page, the page/component calls the API client, the Express route dispatches to a controller, the controller applies validation/auth/business logic, and the server reads or writes MySQL. Shared UI state in the client reduces repetitive fetching, while backend middleware protects sensitive endpoints and standardizes failures.
12. From a deployment perspective, the repo is split cleanly into independently deployable client and server applications, with the database provisioned separately. Vite is used for frontend builds, while the backend is a standalone Node process that can be run behind a hosted MySQL instance.
13. The main architectural boundary to preserve in a diagram is: presentation/state on the client, domain/API logic on the server, and persistence in MySQL. Real-time messaging, admin analytics, and mock/demo datasets are secondary subsystems that support richer UX but do not replace the core request-response commerce flow.
Main entry points: pages Pages · index.js API routes · query.js Data access · client.js API client
Components 19
Client
React/Vite presentation, shared state, and API access
- App shell · Top-level React composition and routing entrypoints
client/src/App.jsx - Pages · Route-level views for shopping, auth, profile, and admin
client/src/pages - UI components · Reusable visual building blocks across pages
client/src/components - Store context · Shared cross-page state such as cart and session
client/src/context/StoreContext.jsx - Product filter · Client-side product filtering and search helpers
client/src/hooks/useFilteredProducts.js - API client · Frontend boundary for REST calls to the backend
client/src/api/client.js - Socket client · Frontend real-time channel for push updates
client/src/api/socket.js - Mock data · Local sample data for client-side rendering and fallback
client/src/data/mockData.js
Server
Express API, domain logic, and middleware
- Server app · Express application bootstrap and middleware assembly
server/src/app.js - API routes · HTTP route dispatch for feature domains
server/src/routes/index.js - Auth domain · Login, registration, and token-based access control
server/src/controllers/authController.js - Catalog domain · Product listing, product details, and catalog search logic
server/src/services/productService.js - Commerce domain · Cart, orders, wishlist, reviews, and user flows
server/src/controllers/orderController.js - Admin domain · Admin analytics and operational management endpoints
server/src/controllers/adminController.js - Middleware · Authentication, validation, and error normalization
server/src/middleware - Data access · Database querying and lower-level persistence access
server/src/models/query.js - Realtime utils · Server-side real-time event helpers
server/src/utils/realTime.js
Connections 21
- App shell → Pages: routes to · App shell wires route-level pages
- Pages → UI components: compose · Pages are built from reusable UI components
- Pages → Store context: read/write state · Pages share cart and session state through context
- Pages → Product filter: filter products · Listing and discovery pages use local filtering logic
- Pages → API client: fetch data · Pages call the HTTP API for persistent operations
- Pages → Socket client: subscribe · Some pages consume real-time updates
- Socket client → Realtime utils: connects to · Client socket path pairs with server real-time helpers
- API client → Server app: HTTP requests · REST calls flow from client to backend
- Mock data → Pages: fallback content · Demo content supports local rendering and examples
- Server app → API routes: mounts · Express app mounts feature routes
- API routes → Auth domain: auth · Authentication endpoints
- API routes → Catalog domain: catalog · Product and listing endpoints
- API routes → Commerce domain: commerce · Cart, order, wishlist, review, and user flows
- API routes → Admin domain: admin · Management and analytics endpoints
- API routes → Middleware: guard/validate · Routes rely on shared middleware for protection and validation
- Auth domain → Data access: persist auth · Auth controllers use data access for user records
- Catalog domain → Data access: query products · Catalog logic reads and shapes product data
- Commerce domain → Data access: persist commerce · Commerce flows read and write relational data
- Admin domain → Data access: aggregate data · Admin views summarize operational data
- Data access → Schema: SQL access · Query layer targets the MySQL schema
- Seed data → Schema: populate · Seed data initializes the schema