# vgprojects07/shopsphere architecture

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

- Interactive diagram: https://gitdiagram.com/vgprojects07/shopsphere
- Repository: https://github.com/vgprojects07/shopsphere

## Overview

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: [`client/src/pages`](https://github.com/vgprojects07/shopsphere/tree/main/client/src/pages) (Pages), [`server/src/routes/index.js`](https://github.com/vgprojects07/shopsphere/blob/main/server/src/routes/index.js) (API routes), [`server/src/models/query.js`](https://github.com/vgprojects07/shopsphere/blob/main/server/src/models/query.js) (Data access), [`client/src/api/client.js`](https://github.com/vgprojects07/shopsphere/blob/main/client/src/api/client.js) (API client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Client"]
  node_client_app["App shell<br/>react app<br/>[App.jsx]"]
  node_client_pages["Pages<br/>route views"]
  node_client_components["UI components<br/>shared ui"]
  node_client_store(("Store context<br/>client state<br/>[StoreContext.jsx]"))
  node_client_filter["Product filter<br/>ui logic"]
  node_client_api["API client<br/>http client<br/>[client.js]"]
  node_client_socket["Socket client<br/>realtime client<br/>[socket.js]"]
  node_client_mock["Mock data<br/>demo content<br/>[mockData.js]"]
end

subgraph group_server["Server"]
  node_server_app["Server app<br/>express app<br/>[app.js]"]
  node_server_routes["API routes<br/>route layer<br/>[index.js]"]
  node_server_auth["Auth domain<br/>controller+route<br/>[authController.js]"]
  node_server_catalog["Catalog domain<br/>controller+service<br/>[productService.js]"]
  node_server_orders["Commerce domain<br/>controllers<br/>[orderController.js]"]
  node_server_admin["Admin domain<br/>management api<br/>[adminController.js]"]
  node_server_middleware["Middleware<br/>cross-cutting"]
  node_server_models["Data access<br/>query layer<br/>[query.js]"]
  node_server_realtime["Realtime utils<br/>push support<br/>[realTime.js]"]
end

subgraph group_database["Database"]
  node_db_schema[("Schema<br/>[schema.sql]")]
  node_db_seed["Seed data<br/>mysql seed<br/>[seed.sql]"]
end

node_client_app -->|"routes to"| node_client_pages
node_client_pages -->|"compose"| node_client_components
node_client_pages -->|"read/write state"| node_client_store
node_client_pages -->|"filter products"| node_client_filter
node_client_pages -->|"fetch data"| node_client_api
node_client_pages -->|"subscribe"| node_client_socket
node_client_socket -->|"connects to"| node_server_realtime
node_client_api -->|"HTTP requests"| node_server_app
node_client_mock -.->|"fallback content"| node_client_pages
node_server_app -->|"mounts"| node_server_routes
node_server_routes -->|"auth"| node_server_auth
node_server_routes -->|"catalog"| node_server_catalog
node_server_routes -->|"commerce"| node_server_orders
node_server_routes -->|"admin"| node_server_admin
node_server_routes -->|"guard/validate"| node_server_middleware
node_server_auth -->|"persist auth"| node_server_models
node_server_catalog -->|"query products"| node_server_models
node_server_orders -->|"persist commerce"| node_server_models
node_server_admin -->|"aggregate data"| node_server_models
node_server_models -->|"SQL access"| node_db_schema
node_db_seed -->|"populate"| node_db_schema

click node_client_app "https://github.com/vgprojects07/shopsphere/blob/main/client/src/App.jsx"
click node_client_pages "https://github.com/vgprojects07/shopsphere/tree/main/client/src/pages"
click node_client_components "https://github.com/vgprojects07/shopsphere/tree/main/client/src/components"
click node_client_store "https://github.com/vgprojects07/shopsphere/blob/main/client/src/context/StoreContext.jsx"
click node_client_filter "https://github.com/vgprojects07/shopsphere/blob/main/client/src/hooks/useFilteredProducts.js"
click node_client_api "https://github.com/vgprojects07/shopsphere/blob/main/client/src/api/client.js"
click node_client_socket "https://github.com/vgprojects07/shopsphere/blob/main/client/src/api/socket.js"
click node_client_mock "https://github.com/vgprojects07/shopsphere/blob/main/client/src/data/mockData.js"
click node_server_app "https://github.com/vgprojects07/shopsphere/blob/main/server/src/app.js"
click node_server_routes "https://github.com/vgprojects07/shopsphere/blob/main/server/src/routes/index.js"
click node_server_auth "https://github.com/vgprojects07/shopsphere/blob/main/server/src/controllers/authController.js"
click node_server_catalog "https://github.com/vgprojects07/shopsphere/blob/main/server/src/services/productService.js"
click node_server_orders "https://github.com/vgprojects07/shopsphere/blob/main/server/src/controllers/orderController.js"
click node_server_admin "https://github.com/vgprojects07/shopsphere/blob/main/server/src/controllers/adminController.js"
click node_server_middleware "https://github.com/vgprojects07/shopsphere/tree/main/server/src/middleware"
click node_server_models "https://github.com/vgprojects07/shopsphere/blob/main/server/src/models/query.js"
click node_server_realtime "https://github.com/vgprojects07/shopsphere/blob/main/server/src/utils/realTime.js"
click node_db_schema "https://github.com/vgprojects07/shopsphere/blob/main/database/schema.sql"
click node_db_seed "https://github.com/vgprojects07/shopsphere/blob/main/database/seed.sql"

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_client_app,node_client_pages,node_client_components,node_client_store,node_client_filter,node_client_api,node_client_socket,node_client_mock toneBlue
class node_server_app,node_server_routes,node_server_auth,node_server_catalog,node_server_orders,node_server_admin,node_server_middleware,node_server_models,node_server_realtime toneAmber
class node_db_schema,node_db_seed toneMint
```

## Components

### Client

React/Vite presentation, shared state, and API access

- [App shell](https://github.com/vgprojects07/shopsphere/blob/main/client/src/App.jsx): react app · Top-level React composition and routing entrypoints · `client/src/App.jsx`
- [Pages](https://github.com/vgprojects07/shopsphere/tree/main/client/src/pages): route views · Route-level views for shopping, auth, profile, and admin · `client/src/pages`
- [UI components](https://github.com/vgprojects07/shopsphere/tree/main/client/src/components): shared ui · Reusable visual building blocks across pages · `client/src/components`
- [Store context](https://github.com/vgprojects07/shopsphere/blob/main/client/src/context/StoreContext.jsx): client state · Shared cross-page state such as cart and session · `client/src/context/StoreContext.jsx`
- [Product filter](https://github.com/vgprojects07/shopsphere/blob/main/client/src/hooks/useFilteredProducts.js): ui logic · Client-side product filtering and search helpers · `client/src/hooks/useFilteredProducts.js`
- [API client](https://github.com/vgprojects07/shopsphere/blob/main/client/src/api/client.js): http client · Frontend boundary for REST calls to the backend · `client/src/api/client.js`
- [Socket client](https://github.com/vgprojects07/shopsphere/blob/main/client/src/api/socket.js): realtime client · Frontend real-time channel for push updates · `client/src/api/socket.js`
- [Mock data](https://github.com/vgprojects07/shopsphere/blob/main/client/src/data/mockData.js): demo content · Local sample data for client-side rendering and fallback · `client/src/data/mockData.js`

### Server

Express API, domain logic, and middleware

- [Server app](https://github.com/vgprojects07/shopsphere/blob/main/server/src/app.js): express app · Express application bootstrap and middleware assembly · `server/src/app.js`
- [API routes](https://github.com/vgprojects07/shopsphere/blob/main/server/src/routes/index.js): route layer · HTTP route dispatch for feature domains · `server/src/routes/index.js`
- [Auth domain](https://github.com/vgprojects07/shopsphere/blob/main/server/src/controllers/authController.js): controller+route · Login, registration, and token-based access control · `server/src/controllers/authController.js`
- [Catalog domain](https://github.com/vgprojects07/shopsphere/blob/main/server/src/services/productService.js): controller+service · Product listing, product details, and catalog search logic · `server/src/services/productService.js`
- [Commerce domain](https://github.com/vgprojects07/shopsphere/blob/main/server/src/controllers/orderController.js): controllers · Cart, orders, wishlist, reviews, and user flows · `server/src/controllers/orderController.js`
- [Admin domain](https://github.com/vgprojects07/shopsphere/blob/main/server/src/controllers/adminController.js): management api · Admin analytics and operational management endpoints · `server/src/controllers/adminController.js`
- [Middleware](https://github.com/vgprojects07/shopsphere/tree/main/server/src/middleware): cross-cutting · Authentication, validation, and error normalization · `server/src/middleware`
- [Data access](https://github.com/vgprojects07/shopsphere/blob/main/server/src/models/query.js): query layer · Database querying and lower-level persistence access · `server/src/models/query.js`
- [Realtime utils](https://github.com/vgprojects07/shopsphere/blob/main/server/src/utils/realTime.js): push support · Server-side real-time event helpers · `server/src/utils/realTime.js`

### Database

MySQL schema and seed data

- [Schema](https://github.com/vgprojects07/shopsphere/blob/main/database/schema.sql): mysql schema · Relational tables for users, products, orders, cart, wishlist, and reviews · `database/schema.sql`
- [Seed data](https://github.com/vgprojects07/shopsphere/blob/main/database/seed.sql): mysql seed · Initial data used to populate the MySQL schema · `database/seed.sql`

## Connections

- 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
