# ayub-alikhan-j/shree_jewel architecture

> Architecture diagram of the GitHub repository ayub-alikhan-j/shree_jewel, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-10-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ayub-alikhan-j/shree_jewel
- Repository: https://github.com/ayub-alikhan-j/shree_jewel

## Overview

##### Project type and purpose
- ShreeJewel is a full-stack e-commerce web application.
- Front-end: React + Vite SPA (client/)
- Back-end: Node.js + Express REST API (server/)
- Data stores and external services: MongoDB, Cloudinary (image uploads), Razorpay & PayPal (payments).

a. Client SPA
- Pages & components (shopping, auth, admin)
- Redux store slices (auth, shop, admin)
b. API Server
- HTTP endpoints (routes/controllers: auth, shop, admin, common, webhooks)
- Business logic (controllers/helpers/models)
- Env validation & middleware (server/config/validateEnv.js)
c. Database
- MongoDB (collections: Users, Products, Orders, Cart, Reviews, etc.)
d. External services
- Cloudinary (image upload)
- Razorpay & PayPal (payment flows)

##### Dataflow and interactions
1. User opens the SPA in the browser.
2. SPA reads configuration (VITE_API_BASE_URL) and renders UI.
3. For any action (login, fetch products, add to cart, place order):
- SPA dispatches Redux action → async API call to Express endpoints.
4. Express middleware verifies JWT or session.
5. Controller invokes model methods (Mongoose) → MongoDB queries/updates.
6. If uploading images, server helper uploads to Cloudinary and returns URL.
7. For checkout: server helper initiates Razorpay/PayPal transaction → returns payment link/tokens to client.
8. Payment provider sends webhook → server route/webhook controller verifies and updates Order record.
9. Final status (success/failure) returns to client, which updates store & UI.

##### Architectural patterns & design principles
- Front-end: Component-based design, unidirectional data flow (Redux).
- Back-end: MVC-style separation (routes → controllers → models), single Express app.
- Infrastructure as code: docker-compose, Nginx config, scripts for HTTPS.
- 12-factor app: environment variables, separate build steps, externalized configs.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client SPA
    subgraph "Client SPA" 
        direction TB
        CConfig["Vite Config"]:::frontend
        CEntry["main.jsx"]:::frontend
        CRoot["App.jsx"]:::frontend
        subgraph "Store" 
            direction TB
            CStore["store.js"]:::frontend
            subgraph "Slices"
                direction TB
                AuthSlice["auth-slice"]:::frontend
                ShopProductsSlice["shop/products-slice"]:::frontend
                ShopCartSlice["shop/cart-slice"]:::frontend
                ShopOrderSlice["shop/order-slice"]:::frontend
                ShopAddressSlice["shop/address-slice"]:::frontend
                ShopReviewSlice["shop/review-slice"]:::frontend
                ShopSearchSlice["shop/search-slice"]:::frontend
                AdminProductsSlice["admin/products-slice"]:::frontend
                AdminOrderSlice["admin/order-slice"]:::frontend
            end
        end
        subgraph "Pages & Components"
            direction TB
            UIPkg["ui components"]:::frontend
            ShoppingPages["shopping-view pages"]:::frontend
            ShoppingComps["shopping-view components"]:::frontend
            AuthPages["auth pages"]:::frontend
            AuthComps["auth components"]:::frontend
            AdminPages["admin-view pages"]:::frontend
            AdminComps["admin components"]:::frontend
        end
        PublicAssets["public"]:::frontend
    end

    %% API Server
    subgraph "API Server" 
        direction TB
        ServerEntry["server.js"]:::backend
        EnvValidation["validateEnv.js"]:::backend
        subgraph "Routes"
            direction TB
            AuthRoutes["auth-routes.js"]:::backend
            ShopRoutes["shop routes"]:::backend
            AdminRoutes["admin routes"]:::backend
            CommonRoutes["common routes"]:::backend
            WebhookRoutes["razorpay webhook"]:::backend
        end
        subgraph "Controllers"
            direction TB
            AuthCtrl["auth-controller.js"]:::backend
            ShopCtrls["shop controllers"]:::backend
            AdminCtrls["admin controllers"]:::backend
            CommonCtrl["feature-controller.js"]:::backend
        end
        Models["Mongoose Models"]:::backend
        subgraph "Helpers"
            direction TB
            Cloudinary["cloudinary.js"]:::backend
            RazorpayHelper["razorpay.js"]:::backend
            PayPalHelper["paypal.js"]:::backend
            InvoiceHelper["invoice-generator.js"]:::backend
        end
    end

    %% Database and External
    MongoDB[(MongoDB)]:::database
    CloudinarySrv["Cloudinary"]:::external
    RazorpaySrv["Razorpay"]:::external
    PayPalSrv["PayPal"]:::external

    %% Infra
    subgraph "Deployment & Infra"
        direction TB
        DockerCompose["docker-compose.yml"]:::infra
        ServerDocker["server/Dockerfile"]:::infra
        ClientNginx["client nginx configs"]:::infra
        SSL["SSL Certificates"]:::infra
    end

    %% Dataflow
    CEntry -->|"imports config"| CConfig
    CEntry --> CRoot
    CRoot --> CStore
    CStore --> AuthSlice
    CStore --> ShopProductsSlice
    CStore --> ShopCartSlice
    CStore --> ShopOrderSlice
    CStore --> ShopAddressSlice
    CStore --> ShopReviewSlice
    CStore --> ShopSearchSlice
    CStore --> AdminProductsSlice
    CStore --> AdminOrderSlice
    CRoot --> UIPkg
    CRoot --> ShoppingPages
    CRoot --> ShoppingComps
    CRoot --> AuthPages
    CRoot --> AuthComps
    CRoot --> AdminPages
    CRoot --> AdminComps
    CRoot --> PublicAssets

    CRoot -->|"HTTPS REST"| ServerEntry
    ServerEntry --> EnvValidation
    ServerEntry --> AuthRoutes
    ServerEntry --> ShopRoutes
    ServerEntry --> AdminRoutes
    ServerEntry --> CommonRoutes
    ServerEntry --> WebhookRoutes

    AuthRoutes --> AuthCtrl
    ShopRoutes --> ShopCtrls
    AdminRoutes --> AdminCtrls
    CommonRoutes --> CommonCtrl
    WebhookRoutes --> CommonCtrl

    AuthCtrl --> Models
    ShopCtrls --> Models
    AdminCtrls --> Models
    CommonCtrl --> Models

    ShopCtrls --> Cloudinary
    ShopCtrls --> RazorpayHelper
    ShopCtrls --> PayPalHelper
    ShopCtrls --> InvoiceHelper

    ServerEntry --> Models
    Models --> MongoDB

    RazorpayHelper --> RazorpaySrv
    PayPalHelper --> PayPalSrv

    RazorpaySrv -->|"Webhook"| WebhookRoutes
    PayPalSrv -->|"Webhook"| WebhookRoutes

    ServerEntry -->|"HTTP Response"| CRoot
    MongoDB --> ServerEntry

    %% Infra connections
    DockerCompose --> ServerEntry
    DockerCompose --> ClientNginx
    ServerDocker --> ServerEntry
    ClientNginx --> CEntry
    SSL --> ClientNginx
    SSL --> ServerEntry

    %% Click events
    click CConfig "https://github.com/ayub-alikhan-j/shree_jewel/blob/main/client/vite.config.js"
    click CEntry "https://github.com/ayub-alikhan-j/shree_jewel/blob/main/client/src/main.jsx"
    click CRoot "https://github.com/ayub-alikhan-j/shree_jewel/blob/main/client/src/App.jsx"
    click PublicAssets "https://github.com/ayub-alikhan-j/shree_jewel/tree/main/client/public"
    click CStore "https://github.com/ayub-alikhan-j/shree_jewel/blob/main/client/src/store/store.js"
    click AuthSlice "https://github.com/ayub-alikhan-j/shree_jewel/blob/main/client/src/store/auth-slice/index.js"
    click ShopProductsSlice "https://github.com/ayub-alikhan-j/shree_jewel/blob/main/client/src/store/shop/products-slice/index.js"
    click ShopCartSlice "https://github.com/ayub-alikhan-j/shree_jewel/blob/main/client/src/store/shop/cart-slice/index.js"
    click ShopOrderSlice "https://github.com/ayub-alikhan-j/shree_jewel/blob/main/client/src/store/shop/order-slice/index.js"
    click ShopAddressSlice "https://github.com/ayub-alikhan-j/shree_jewel/blob/main/client/src/store/shop/address-slice/index.js"
    click ShopReviewSlice "https://github.com/ayub-alikhan-j/shree_jewel/blob/main/client/src/store/shop/review-slice/index.js"
    click ShopSearchSlice "https://github.com/ayub-alikhan-j/shree_jewel/blob/main/client/src/store/shop/search-slice/index.js"
    click AdminProductsSlice "https://github.com/ayub-alikhan-j/shree_jewel/blob/main/client/src/store/admin/products-slice/index.js"
    click AdminOrderSlice "https://github.com/ayub-alikhan-j/shree_jewel/blob/main/client/src/store/admin/order-slice/index.js"
    click UIPkg "https://github.com/ayub-alikhan-j/shree_jewel/tree/main/client/src/components/ui"
    click ShoppingPages "https://github.com/ayub-alikhan-j/shree_jewel/tree/main/client/src/pages/shopping-view"
    click ShoppingComps "https://github.com/ayub-alikhan-j/shree_jewel/tree/main/client/src/components/shopping-view"
    click AuthPages "https://github.com/ayub-alikhan-j/shree_jewel/tree/main/client/src/pages/auth"
    click AuthComps "https://github.com/ayub-alikhan-j/shree_jewel/tree/main/client/src/components/auth"
    click AdminPages "https://github.com/ayub-alikhan-j/shree_jewel/tree/main/client/src/pages/admin-view"
    click AdminComps "https://github.com/ayub-alikhan-j/shree_jewel/tree/main/client/src/components/admin-view"
    click ServerEntry "https://github.com/ayub-alikhan-j/shree_jewel/blob/main/server/server.js"
    click EnvValidation "https://github.com/ayub-alikhan-j/shree_jewel/blob/main/server/config/validateEnv.js"
    click AuthRoutes "https://github.com/ayub-alikhan-j/shree_jewel/blob/main/server/routes/auth/auth-routes.js"
    click ShopRoutes "https://github.com/ayub-alikhan-j/shree_jewel/blob/main/server/routes/shop/*.js"
    click AdminRoutes "https://github.com/ayub-alikhan-j/shree_jewel/blob/main/server/routes/admin/*.js"
    click CommonRoutes "https://github.com/ayub-alikhan-j/shree_jewel/blob/main/server/routes/common/*.js"
    click WebhookRoutes "https://github.com/ayub-alikhan-j/shree_jewel/blob/main/server/routes/webhooks/razorpay.js"
    click AuthCtrl "https://github.com/ayub-alikhan-j/shree_jewel/blob/main/server/controllers/auth/auth-controller.js"
    click ShopCtrls "https://github.com/ayub-alikhan-j/shree_jewel/blob/main/server/controllers/shop/*.js"
    click AdminCtrls "https://github.com/ayub-alikhan-j/shree_jewel/blob/main/server/controllers/admin/*.js"
    click CommonCtrl "https://github.com/ayub-alikhan-j/shree_jewel/blob/main/server/controllers/common/feature-controller.js"
    click Models "https://github.com/ayub-alikhan-j/shree_jewel/blob/main/server/models/*.js"
    click Cloudinary "https://github.com/ayub-alikhan-j/shree_jewel/blob/main/server/helpers/cloudinary.js"
    click RazorpayHelper "https://github.com/ayub-alikhan-j/shree_jewel/blob/main/server/helpers/razorpay.js"
    click PayPalHelper "https://github.com/ayub-alikhan-j/shree_jewel/blob/main/server/helpers/paypal.js"
    click InvoiceHelper "https://github.com/ayub-alikhan-j/shree_jewel/blob/main/server/helpers/invoice-generator.js"
    click DockerCompose "https://github.com/ayub-alikhan-j/shree_jewel/blob/main/docker-compose.yml"
    click ServerDocker "https://github.com/ayub-alikhan-j/shree_jewel/tree/main/server/Dockerfile"
    click ClientNginx "https://github.com/ayub-alikhan-j/shree_jewel/blob/main/client/nginx.conf"
    click SSL "https://github.com/ayub-alikhan-j/shree_jewel/blob/main/ssl/privkey.pem"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0366d6,color:#0366d6
    classDef backend fill:#DFFFE0,stroke:#22863a,color:#22863a
    classDef database fill:#FFE4B5,stroke:#d18600,color:#d18600
    classDef external fill:#EDEDED,stroke:#6a737d,color:#6a737d
    classDef infra fill:#F3E8FF,stroke:#6f42c1,color:#6f42c1
```
