# weihong931021/shopping-site architecture

> Architecture diagram of the GitHub repository weihong931021/shopping-site, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/weihong931021/shopping-site
- Repository: https://github.com/weihong931021/shopping-site

## Overview

##### Project type and purpose
- This is a full-stack e-commerce web application scaffolded with Vue 3 + Vite on the front end, and a Node.js/Express API server under the `server/` directory.
- Purpose: allow users to browse products, add to cart, register/login, and complete checkout.

##### File structure
- Top level:
- `index.html`, `vite.config.js`, `src/` → Vue 3 single-page application (SPA).
- `public/` → static assets served by Vite or production web server.
- `server/` → Node/Express backend.
- In `src/`:
- `App.vue`, `main.js`, `router.js` → SPA bootstrapping and client-side routing.
- `components/` → reusable UI pieces (buttons, cards, navbar, dialogs).
- `pages/` → page-level views (Home, Products, Cart, Checkout, Login, Register).
- In `server/`:
- `server.js` → Express app initialization, middleware, route mounting.
- `routes/*.js` → REST endpoints: auth, products, cart, checkout.
- `config/database.js` + `.env` → database connection settings.

##### Key insights from the README
- Confirms Vue 3 + Vite as front-end toolchain.
- Standard npm scripts: `dev`, `build`.

##### Main components
a. Client-side SPA
- Browser/mobile UI
- Vue router and components
- Assets (CSS, images)
b. API Server
- Express app
- Route handlers (auth, products, cart, checkout)
- Database connector
c. Database
- e.g. MySQL/PostgreSQL/MongoDB (as configured in `database.js`)
d. External services
- Payment gateway (invoked in `checkout.js`)
- Optional: Email service for order confirmations

##### Relationships and data flows
- User → Browser UI: interactions via Vue components and Vuex/router (if used).
- Browser → API server: REST calls to `/api/auth`, `/api/products`, `/api/cart`, `/api/checkout`.
- API server ↔ Database: queries/inserts for users, products, cart sessions, orders.
- API server → Payment gateway: tokenized payment request, response handling.
- Server → (optional) Email/SMS service: order confirmation.

##### Architectural patterns and design principles
- Client-server separation (clear API layer).
- Layered design in backend:
- HTTP layer (Express) → Business logic (route handlers) → Data access (database.js).
- Component-based UI in frontend.
- Environment-driven configuration (`.env`).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Environment" 
        direction TB
        Browser["User Browser/Mobile UI"]:::frontend
        subgraph "Vue 3 SPA (src/)" 
            direction TB
            Entry["main.js"]:::frontend
            RootComp["App.vue"]:::frontend
            Router["router.js"]:::frontend
            subgraph "Components (src/components/)" 
                direction TB
                BaseBtn["BaseButton.vue"]:::frontend
                CartDlg["CartDialog.vue"]:::frontend
                Navbar["Navbar.vue"]:::frontend
                Card["TheCard.vue"]:::frontend
                Resource["TheResource.vue"]:::frontend
                ProdRes["ProductResources.vue"]:::frontend
                LogAcc["LogAccount.vue"]:::frontend
                RegAcc["RegisterAccount.vue"]:::frontend
            end
            subgraph "Pages (src/pages/)" 
                direction TB
                HomePg["Home.vue"]:::frontend
                ProdsPg["Products.vue"]:::frontend
                CartPg["Cart.vue"]:::frontend
                CheckoutPg["Checkout.vue"]:::frontend
                LoginPg["Login.vue"]:::frontend
                RegisterPg["Register.vue"]:::frontend
            end
            subgraph "Assets & Config" 
                direction TB
                Assets["src/assets/"]:::frontend
                CSS["base.css / main.css"]:::frontend
                IndexHTML["index.html"]:::frontend
                Public["public/"]:::frontend
                ViteCfg["vite.config.js"]:::frontend
            end
        end
    end

    %% Backend Layer
    subgraph "Backend Environment (server/)"
        direction TB
        ExpressApp["server.js"]:::backend
        EnvCfg[".env"]:::backend
        DBConn["config/database.js"]:::backend
        subgraph "Routes (server/routes/)"
            direction TB
            AuthRt["auth.js"]:::backend
            ProdsRt["products.js"]:::backend
            CartRt["cart.js"]:::backend
            CheckoutRt["checkout.js"]:::backend
        end
        Package["package.json"]:::backend
    end

    %% Database and External Services
    DB["Database (Postgres/MongoDB)"]:::db
    Payment["Payment Gateway"]:::external
    Email["Email/SMS Service"]:::external

    %% Connections
    Browser -->|"Interacts via UI"| Entry
    Entry -->|"Bootstraps SPA"| RootComp
    RootComp --> Router
    Router -->|Navigates Pages| HomePg
    Router -->|Navigates Pages| ProdsPg
    Router -->|Navigates Pages| CartPg
    Router -->|Navigates Pages| CheckoutPg
    Router -->|Navigates Pages| LoginPg
    Router -->|Navigates Pages| RegisterPg
    RootComp --> BaseBtn
    RootComp --> Navbar
    BaseBtn --> CartDlg
    BaseBtn --> Card
    Card --> ProdRes
    RootComp --> LogAcc
    RootComp --> RegAcc

    Entry -->|"Serves Static"| IndexHTML
    Entry -->|"Loads Assets"| Assets
    Entry -->|"Reads Config"| ViteCfg

    Browser -->|"HTTPS REST"/api calls| ExpressApp
    ExpressApp -->|"Uses Env Vars"| EnvCfg
    ExpressApp -->|"Initializes DB"| DBConn
    ExpressApp -->|"Mounts Routes"| AuthRt
    ExpressApp -->|"Mounts Routes"| ProdsRt
    ExpressApp -->|"Mounts Routes"| CartRt
    ExpressApp -->|"Mounts Routes"| CheckoutRt

    ExpressApp -->|"SQL/NoSQL Queries"| DB
    CheckoutRt -->|"Payment Request"| Payment
    CheckoutRt -->|"Order Confirmation"| Email

    %% Click Events
    click Entry "https://github.com/weihong931021/shopping-site/blob/main/src/main.js"
    click RootComp "https://github.com/weihong931021/shopping-site/blob/main/src/App.vue"
    click Router "https://github.com/weihong931021/shopping-site/blob/main/src/router.js"
    click BaseBtn "https://github.com/weihong931021/shopping-site/blob/main/src/components/BaseButton.vue"
    click CartDlg "https://github.com/weihong931021/shopping-site/blob/main/src/components/CartDialog.vue"
    click Navbar "https://github.com/weihong931021/shopping-site/blob/main/src/components/Navbar.vue"
    click Card "https://github.com/weihong931021/shopping-site/blob/main/src/components/TheCard.vue"
    click Resource "https://github.com/weihong931021/shopping-site/blob/main/src/components/TheResource.vue"
    click ProdRes "https://github.com/weihong931021/shopping-site/blob/main/src/components/ProductResources.vue"
    click LogAcc "https://github.com/weihong931021/shopping-site/blob/main/src/components/LogAccount.vue"
    click RegAcc "https://github.com/weihong931021/shopping-site/blob/main/src/components/RegisterAccount.vue"
    click HomePg "https://github.com/weihong931021/shopping-site/blob/main/src/pages/Home.vue"
    click ProdsPg "https://github.com/weihong931021/shopping-site/blob/main/src/pages/Products.vue"
    click CartPg "https://github.com/weihong931021/shopping-site/blob/main/src/pages/Cart.vue"
    click CheckoutPg "https://github.com/weihong931021/shopping-site/blob/main/src/pages/Checkout.vue"
    click LoginPg "https://github.com/weihong931021/shopping-site/blob/main/src/pages/Login.vue"
    click RegisterPg "https://github.com/weihong931021/shopping-site/blob/main/src/pages/Register.vue"
    click Assets "https://github.com/weihong931021/shopping-site/tree/main/src/assets/"
    click IndexHTML "https://github.com/weihong931021/shopping-site/blob/main/index.html"
    click Public "https://github.com/weihong931021/shopping-site/tree/main/public/"
    click ViteCfg "https://github.com/weihong931021/shopping-site/blob/main/vite.config.js"
    click ExpressApp "https://github.com/weihong931021/shopping-site/blob/main/server/server.js"
    click EnvCfg "https://github.com/weihong931021/shopping-site/blob/main/server/.env"
    click DBConn "https://github.com/weihong931021/shopping-site/blob/main/server/config/database.js"
    click AuthRt "https://github.com/weihong931021/shopping-site/blob/main/server/routes/auth.js"
    click ProdsRt "https://github.com/weihong931021/shopping-site/blob/main/server/routes/products.js"
    click CartRt "https://github.com/weihong931021/shopping-site/blob/main/server/routes/cart.js"
    click CheckoutRt "https://github.com/weihong931021/shopping-site/blob/main/server/routes/checkout.js"
    click Package "https://github.com/weihong931021/shopping-site/blob/main/server/package.json"

    %% Styles
    classDef frontend fill:#C3DDF9,stroke:#0366D6,color:#0366D6
    classDef backend fill:#D4F5D4,stroke:#28A745,color:#28A745
    classDef db fill:#FFE4B5,stroke:#D2691E,color:#D2691E
    classDef external fill:#E2E2E2,stroke:#6A737D,color:#6A737D
```
