# vmt7308/160store architecture

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

- Interactive diagram: https://gitdiagram.com/vmt7308/160store
- Repository: https://github.com/vmt7308/160store

## Overview

##### Project type and purpose
- This is a full‑stack e‑commerce web application (“160Store”).
- The frontend is a React single‑page application (SPA) under src/ and public/.
- The backend is a Node.js/Express REST API under backend/.
- A relational database (SQL dump 160storeDB.sql) stores users, products, orders, categories, etc.

##### File structure
- Top‑level directories:
– backend/ (Express server, controllers, models, routes, middleware)
– public/ (static HTML, images, uploaded assets)
– src/ (React app: components, pages, assets, CSS, data)
- backend follows an MVC‑style pattern:
– models/ define data schemas (admin, user, product, order…)
– controllers/ implement business logic (authController, orderController…)
– routes/ wire endpoints to controllers (authRoutes, productRoutes…)
– middleware/ handles authentication (authMiddleware.js)
- Configuration files:
– backend/.env for environment variables
– backend/db.js for database connection
– server.js to bootstrap the Express app

##### README
- README is empty, but file names indicate standard RESTful API + React client.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Client Layer
    subgraph "Client (React SPA)"
        direction TB
        Browser["Browser"]:::frontend
        subgraph "React Application" 
            direction TB
            SRC_ROOT["src/"]:::frontend
            SRC_INDEX["src/index.js"]:::frontend
            SRC_APP["src/App.js"]:::frontend
            COMPONENTS["src/components/"]:::frontend
            PAGES["src/pages/"]:::frontend
            ASSETS["src/assets/"]:::frontend
        end
        subgraph "Public Assets"
            direction TB
            PUBLIC_HTML["public/index.html"]:::frontend
            PUBLIC_IMG["public/img/"]:::frontend
        end
        Browser -->|"loads SPA"| SRC_INDEX
        Browser -->|"loads SPA"| PUBLIC_HTML
    end

    %% API Server Layer
    subgraph "API Server (Node.js / Express)" 
        direction TB
        SERVER["server.js"]:::backend
        ENV[".env"]:::backend
        DB_CONN["db.js"]:::backend
        HASH_UTIL["hash-password.js"]:::backend

        subgraph "Routes"
            direction TB
            AUTH_ROUTES["authRoutes.js"]:::backend
            USER_ROUTES["userRoutes.js"]:::backend
            ORDER_ROUTES["orderRoutes.js"]:::backend
            PRODUCT_ROUTES["productRoutes.js"]:::backend
            CATEGORY_ROUTES["categoryRoutes.js"]:::backend
            LIST_PRODUCT_ROUTES["listProductRoute.js"]:::backend
            LIST_CATEGORY_ROUTES["listCategoryRoute.js"]:::backend
            ADMIN_ROUTES["adminRoutes.js"]:::backend
        end

        subgraph "Controllers"
            direction TB
            AUTH_CNTRL["authController.js"]:::backend
            USER_CNTRL["userController.js"]:::backend
            ORDER_CNTRL["orderController.js"]:::backend
            ADMIN_CNTRL["adminController.js"]:::backend
        end

        subgraph "Models"
            direction TB
            USER_MODEL["userModel.js"]:::backend
            ORDER_MODEL["orderModel.js"]:::backend
            PRODUCT_MODEL["productModel.js"]:::backend
            CATEGORY_MODEL["categoryModel.js"]:::backend
            LIST_PRODUCT_MODEL["listProductModel.js"]:::backend
            LIST_CATEGORY_MODEL["listCategoryModel.js"]:::backend
            ADMIN_MODEL["adminModel.js"]:::backend
        end

        subgraph "Middleware"
            direction TB
            AUTH_MW["authMiddleware.js"]:::backend
        end

        SERVER --> DB_CONN
        SERVER --> ENV
        SERVER --> HASH_UTIL

        SERVER --> AUTH_ROUTES
        SERVER --> USER_ROUTES
        SERVER --> ORDER_ROUTES
        SERVER --> PRODUCT_ROUTES
        SERVER --> CATEGORY_ROUTES
        SERVER --> LIST_PRODUCT_ROUTES
        SERVER --> LIST_CATEGORY_ROUTES
        SERVER --> ADMIN_ROUTES

        AUTH_ROUTES --> AUTH_CNTRL
        USER_ROUTES --> USER_CNTRL
        ORDER_ROUTES --> ORDER_CNTRL
        ADMIN_ROUTES --> ADMIN_CNTRL

        AUTH_CNTRL --> USER_MODEL
        USER_CNTRL --> USER_MODEL
        ORDER_CNTRL --> ORDER_MODEL
        ADMIN_CNTRL --> ADMIN_MODEL

        AUTH_MW -- authentication --> AUTH_CNTRL
    end

    %% Interactions
    Browser -->|"HTTP REST calls (JSON over HTTP)"| SERVER

    subgraph "Data Stores"
        direction TB
        DB["Relational Database\n(160storeDB.sql)"]:::datastore
        STORAGE["Static File Storage\n(public/uploads/, public/img/stores/)"]:::datastore
    end

    SERVER -->|"SQL queries"| DB
    SERVER -->|"File upload/download"| STORAGE

    subgraph "External Services"
        direction TB
        EMAIL["Email Service"]:::external
        PAYMENT["Payment Gateway"]:::external
        OAUTH["Third‑party Auth"]:::external
    end

    SERVER -->|"REST/Webhook"| EMAIL
    SERVER -->|"REST/Webhook"| PAYMENT
    SERVER -->|"OAuth calls"| OAUTH

    %% Click Events
    click SRC_ROOT "https://github.com/vmt7308/160store/tree/main/src/"
    click SRC_INDEX "https://github.com/vmt7308/160store/blob/main/src/index.js"
    click SRC_APP "https://github.com/vmt7308/160store/blob/main/src/App.js"
    click COMPONENTS "https://github.com/vmt7308/160store/tree/main/src/components/"
    click PAGES "https://github.com/vmt7308/160store/tree/main/src/pages/"
    click ASSETS "https://github.com/vmt7308/160store/tree/main/src/assets/"
    click PUBLIC_HTML "https://github.com/vmt7308/160store/blob/main/public/index.html"
    click PUBLIC_IMG "https://github.com/vmt7308/160store/tree/main/public/img/"
    click SERVER "https://github.com/vmt7308/160store/blob/main/backend/server.js"
    click DB_CONN "https://github.com/vmt7308/160store/blob/main/backend/db.js"
    click HASH_UTIL "https://github.com/vmt7308/160store/blob/main/backend/hash-password.js"
    click ENV "https://github.com/vmt7308/160store/blob/main/backend/.env"
    click AUTH_CNTRL "https://github.com/vmt7308/160store/blob/main/backend/controllers/authController.js"
    click USER_CNTRL "https://github.com/vmt7308/160store/blob/main/backend/controllers/userController.js"
    click ORDER_CNTRL "https://github.com/vmt7308/160store/blob/main/backend/controllers/orderController.js"
    click ADMIN_CNTRL "https://github.com/vmt7308/160store/blob/main/backend/controllers/adminController.js"
    click AUTH_ROUTES "https://github.com/vmt7308/160store/blob/main/backend/routes/authRoutes.js"
    click USER_ROUTES "https://github.com/vmt7308/160store/blob/main/backend/routes/userRoutes.js"
    click ORDER_ROUTES "https://github.com/vmt7308/160store/blob/main/backend/routes/orderRoutes.js"
    click PRODUCT_ROUTES "https://github.com/vmt7308/160store/blob/main/backend/routes/productRoutes.js"
    click CATEGORY_ROUTES "https://github.com/vmt7308/160store/blob/main/backend/routes/categoryRoutes.js"
    click LIST_PRODUCT_ROUTES "https://github.com/vmt7308/160store/blob/main/backend/routes/listProductRoute.js"
    click LIST_CATEGORY_ROUTES "https://github.com/vmt7308/160store/blob/main/backend/routes/listCategoryRoute.js"
    click ADMIN_ROUTES "https://github.com/vmt7308/160store/blob/main/backend/routes/adminRoutes.js"
    click USER_MODEL "https://github.com/vmt7308/160store/blob/main/backend/models/userModel.js"
    click ORDER_MODEL "https://github.com/vmt7308/160store/blob/main/backend/models/orderModel.js"
    click PRODUCT_MODEL "https://github.com/vmt7308/160store/blob/main/backend/models/productModel.js"
    click CATEGORY_MODEL "https://github.com/vmt7308/160store/blob/main/backend/models/categoryModel.js"
    click LIST_PRODUCT_MODEL "https://github.com/vmt7308/160store/blob/main/backend/models/listProductModel.js"
    click LIST_CATEGORY_MODEL "https://github.com/vmt7308/160store/blob/main/backend/models/listCategoryModel.js"
    click ADMIN_MODEL "https://github.com/vmt7308/160store/blob/main/backend/models/adminModel.js"
    click AUTH_MW "https://github.com/vmt7308/160store/blob/main/backend/middleware/authMiddleware.js"
    click DB "https://github.com/vmt7308/160store/blob/main/backend/160storeDB.sql"
    click STORAGE "https://github.com/vmt7308/160store/tree/main/public/uploads/"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#004085
    classDef backend fill:#d4edda,stroke:#155724
    classDef datastore fill:#fff3cd,stroke:#856404
    classDef external fill:#e2e3e5,stroke:#6c757d
```
